User:Miracle173/sandbox

Assignment Problem
Given an $$n\times n$$-dimensional quadratic matrix $$C$$ with nonnegative coefficients, the cost matrix, find a permutation $$\sigma$$ of $$1,\ldots,n$$, such that $$\sum_{i=1}^{n} c_{i,\sigma(i)}$$ is a minimum.

Matrix Operations
If $$C=(c_{i,j})_{n\times n}$$ is square matrix and $$C'=(c'_{i,j})_{n\times n}$$ is the matrix that we get by adding the value a to one of the rows or one of the columns of matrix $$C$$, then $$\sum_{i=1}^{n}c'_{i,\sigma(i)} =\sum_{i=1}^{n}c_{i,\sigma(i)} +a$$ and so if $$\sigma$$ is a permutation such that $$\sum_{i=1}^{n}c_{i,\sigma(i)}$$ is a minimum for $$C$$ then $$\sum_{i=1}^{n}c'_{i,\sigma(i)}$$ is a minimum for $$C'$$ If $$C=(c_{i,j})$$ is a square matrix with nonnegative coefficients, $$\sigma$$ a permutation and $$c_{i,\sigma(i)}=0,i=1,\ldots,n$$, then $$\sum_{i=1}^{n}c_{i,\sigma(i)} =0$$ and therefore $$\sum_{i=1}^{n}c_{i,\sigma(i)}$$ is minimal.

Notation
+ (1) 5 0* 7  0’ + (2) 1  2  0* 4 (3) 9  8  7  6 (4) 5  0’ 3  2   (1)(2)(3)(4)

The numbers in parentheses are the row and the column indexes of the matrix

If a row or column is tagged by a + symbol, we say the row or the column is covered because it can be covered by a line. If a 0 is tagged by a * we say the 0 is starred, if it is tagged by a ' we say the row is primed.

A sequence of 0s in a matrix is called a chain, if the first 0 is a primed one, the second 0 is a starred on in the same column as the first 0, the third 0 is a primed one in the same row as the second on and so on. So the zeroes build a sequence, either   (4,2)-(1,2)-(1,4) or  (1,4)-(1,2)-(4,2)

If all starred 0s of a matrix are pairwise independent and if we have a chain that starts with a primed 0 that does not contain a starred 0 in the same column and that ends with a primed 0 that does not contain a starred 0 in the same column and we remove all starts from the starred 0s and for all primed 0 we replace the primes by a start then the number of starred 0s increased by 1 and all starred 0s are still pairwise independent.

Assume we have tagged rows and columns and assume that the minimum of all coefficients when neither the row nor the column is tagged is $$a$$. Subtract $$a$$ from all coefficients where the column is untagged and add $$a$$ to all coefficients where the row is tagged. Then this has the following effect that $$a$$ is subtracted all coefficients where neither the row nor the column is tagged, that $$a$$ is added to all coefficients where the column as well as the row is tagged and a coefficient is unchanged if either the row or the column, but not both are tagged.

Format 2
Step 1 (prepare)
 * /* reduce rows */
 * for each row of the matrix $$C$$:
 * calculate the minimum of the coefficients of this row;
 * subtract this minimum from each coefficients of this row;
 * /* reduce cols */
 * for each column of the matrix $$C$$:
 * calculate the minimum of the coefficients of this column;
 * subtract this minimum from each coefficients of this column;

/* find maximal independent set of 0s */
 * while there is a $$0$$ where neither the row nor the column is tagged by a +:
 * choose a $$0$$ from $$C$$ where neither the row nor the column is tagged by a +;
 * tag the $$0$$ by an *;
 * tag the row and the column of this $$0$$ by a +;

/* init grid marks */
 * remove all + tags from the rows;

Step 2
 * If all columns are tagged finish there are $$n$$ independent $$0$$s found that constitute a solution

Step 3, find a minimal cover repeat:
 * while there is a 0 where neither the column nor its row is tagged:
 * find a 0 where neither the column nor the row is tagged;
 * tag this 0 by a prime ';
 * if there is a 0* in the same row:
 * remove the + of the column of the 0*;
 * tag the row by a +;
 * else:
 * find the chain starting with the 0 marked recently with a prime’;
 * for all zeros of that chain that are tagged by *:
 * remove the tag;
 * for all zeroes of this chain that are tagged by ‘:
 * replace this tag by the tag *;
 * remove all tags of columns and rows;
 * tag all columns that contain 0*;
 * go to step 2;
 * find the minimum of all fields where neither the row nor the column is tagged;
 * subtract this minimum from all rows that are untagged;
 * add this minimum to all columns that are tagged;

Algorithm 2
reduce rows reduce cols find maximal independent set of 0s

preprocess_matrix init grid marks while number of starred positions less than n    repeat pos_primed=get free_pos tag_with_prime(pos_primed) pos_starred=find_starred_in_row(pos_primed) if pos_starred is None: chain_exchange(pos_primed) init grid mark break swap boarder marks(pos_starred)

preprocess_matrix
 * init grid marks
 * while number of starred positions less than n
 * repeat
 * pos_primed=get free_pos
 * tag_with_prime(pos_primed)
 * pos_starred=find_starred_in_row(pos_primed)
 * if pos_starred is None:
 * chain_exchange(pos_primed)
 * init grid mark
 * break
 * swap boarder marks(pos_starred)

Examples of Tables
$$ \lim_{n \to \infty }\frac{1}{x}=0$$