{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Assignment2Solution

# Assignment2Solution - Fall 2010 Optimization I(ORIE...

This preview shows pages 1–3. Sign up to view the full content.

Fall 2010 Optimization I (ORIE 3300/5300) Assignment 2 Solution Problem 1 By hand . 3 4 1 2 1 2 4 3 2 1 3 4 4 3 2 1 Using AMPL . The AMPL model file (e.g. we name it s udoku.mod): param N:=4; var x {i in 1..N, j in 1..N, k in 1..N} binary; # If the cell in row i, column j is assigned value k, then x[i, j, k] = 1 # otherwise x[i, j, k] = 0 var v {i in 1..N, j in 1..N} integer >= 0; # v[i, j] is the value assigned to the cell in row i column j maximize objective: sum {i in 1..N, j in 1..N, k in 1..N} x[i, j, k]; subject to cell124: x[1, 2, 4] = 1; # The cell in row 1, column 2 is assigned value 4 subject to cell243: x[2, 4, 3] = 1; # The cell in row 2, column 4 is assigned value 3 subject to cell321: x[3, 2, 1] = 1; # The cell in row 3, column 2 is assigned value 1 subject to cell432: x[4, 3, 2] = 1; # The cell in row 4, column 3 is assigned value 2 subject to AssignCell {i in 1..N, j in 1..N}: sum{k in 1..N} x[i, j, k] = 1; # Each cell must be assigned exactly one of each value subject to AssignRow {i in 1..N, k in 1..N}: sum{j in 1..N} x[i, j, k] = 1; # In each row, each number must appear exactly once subject to AssignColumn {j in 1..N, k in 1..N}: sum{i in 1..N} x[i, j, k] = 1; # In each column, each number must appear exactly once subject to AssignBoldSquare {i in {1, 3}, j in {1, 3}, k in 1..N}: x[i, j, k] + x[i+1, j, k] + x[i, j+1, k] + x[i+1, j+1, k] = 1; # In each bold square, each number must appear exactly once subject to values {i in 1..N, j in 1..N}: v[i, j] = sum{k in 1..N} k*x[i, j, k]; # Make the connection between indicator variables (the x variables) and the cell values 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Fall 2010 Optimization I (ORIE 3300/5300) Solving it, we obtain: ampl: model sudoku.mod; ampl: solve; Solution determined by presolve; objective objective = 16. ampl: display v; v := 1 1 3 1 2 4 1 3 1 1 4 2 2 1 1 2 2 2 2 3 4 2 4 3 3 1 2 3 2 1 3 3 3 3 4 4 4 1 4 4 2 3 4 3 2 4 4 1 ; (Note: the first row after v:= , i.e. 1 1 3 , means the cell in row 1 and column 1 takes value 3, etc.) Problem 2 We can rewrite the system of equations as: Ax = b, where A is the 3 × 5 matrix A = 1 3 2 - 1 2 0 2 3 - 3 1 4 4 1 - 2 4 , x is the vector x = x 1 x 2 x 3 x
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}