diff --git a/com/google/ortools/constraintsolver/samples/AllDifferentExcept0.java b/com/google/ortools/constraintsolver/samples/AllDifferentExcept0.java index 044ebe12b4..30d2b6e43c 100644 --- a/com/google/ortools/constraintsolver/samples/AllDifferentExcept0.java +++ b/com/google/ortools/constraintsolver/samples/AllDifferentExcept0.java @@ -111,7 +111,7 @@ public class AllDifferentExcept0 { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/AllInterval.java b/com/google/ortools/constraintsolver/samples/AllInterval.java index 144422fcc1..f744666bdc 100644 --- a/com/google/ortools/constraintsolver/samples/AllInterval.java +++ b/com/google/ortools/constraintsolver/samples/AllInterval.java @@ -95,7 +95,7 @@ public class AllInterval { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/Circuit.java b/com/google/ortools/constraintsolver/samples/Circuit.java index 228af62b64..7e48404447 100644 --- a/com/google/ortools/constraintsolver/samples/Circuit.java +++ b/com/google/ortools/constraintsolver/samples/Circuit.java @@ -108,7 +108,7 @@ public class Circuit { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/CoinsGrid.java b/com/google/ortools/constraintsolver/samples/CoinsGrid.java index 0be203b034..941cf882e8 100644 --- a/com/google/ortools/constraintsolver/samples/CoinsGrid.java +++ b/com/google/ortools/constraintsolver/samples/CoinsGrid.java @@ -120,7 +120,7 @@ public class CoinsGrid { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/CoveringOpl.java b/com/google/ortools/constraintsolver/samples/CoveringOpl.java index 65f559520e..22955da75b 100644 --- a/com/google/ortools/constraintsolver/samples/CoveringOpl.java +++ b/com/google/ortools/constraintsolver/samples/CoveringOpl.java @@ -122,7 +122,7 @@ public class CoveringOpl { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/Crossword.java b/com/google/ortools/constraintsolver/samples/Crossword.java index ffc53987e3..5704e22259 100644 --- a/com/google/ortools/constraintsolver/samples/Crossword.java +++ b/com/google/ortools/constraintsolver/samples/Crossword.java @@ -172,7 +172,7 @@ public class Crossword { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/DeBruijn.java b/com/google/ortools/constraintsolver/samples/DeBruijn.java index 490dd1823e..6b6157bf13 100644 --- a/com/google/ortools/constraintsolver/samples/DeBruijn.java +++ b/com/google/ortools/constraintsolver/samples/DeBruijn.java @@ -196,7 +196,7 @@ public class DeBruijn { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/Diet.java b/com/google/ortools/constraintsolver/samples/Diet.java index d8af07591f..351099cefc 100644 --- a/com/google/ortools/constraintsolver/samples/Diet.java +++ b/com/google/ortools/constraintsolver/samples/Diet.java @@ -102,7 +102,7 @@ public class Diet { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/DivisibleBy9Through1.java b/com/google/ortools/constraintsolver/samples/DivisibleBy9Through1.java index d9ead5aed4..5ac47fe758 100644 --- a/com/google/ortools/constraintsolver/samples/DivisibleBy9Through1.java +++ b/com/google/ortools/constraintsolver/samples/DivisibleBy9Through1.java @@ -191,7 +191,7 @@ public class DivisibleBy9Through1 { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/LeastDiff.java b/com/google/ortools/constraintsolver/samples/LeastDiff.java index e7c19ff098..c83d52494e 100644 --- a/com/google/ortools/constraintsolver/samples/LeastDiff.java +++ b/com/google/ortools/constraintsolver/samples/LeastDiff.java @@ -59,9 +59,9 @@ public class LeastDiff { // int[] coeffs = {10000, 1000, 100, 10, 1}; IntVar x = solver.makeScalProd(new IntVar[]{a,b,c,d,e}, coeffs).var(); - x.set_name("x"); + x.setName("x"); IntVar y = solver.makeScalProd(new IntVar[]{f,g,h,i,j}, coeffs).var(); - y.set_name("y"); + y.setName("y"); // a > 0 solver.addConstraint(solver.makeGreater(a, 0)); @@ -70,7 +70,7 @@ public class LeastDiff { // diff = x - y IntVar diff = solver.makeDifference(x, y).var(); - diff.set_name("diff"); + diff.setName("diff"); solver.addConstraint(solver.makeAllDifferent(all)); @@ -97,7 +97,7 @@ public class LeastDiff { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/MagicSquare.java b/com/google/ortools/constraintsolver/samples/MagicSquare.java index 3277c1759a..594781593c 100644 --- a/com/google/ortools/constraintsolver/samples/MagicSquare.java +++ b/com/google/ortools/constraintsolver/samples/MagicSquare.java @@ -118,7 +118,7 @@ public class MagicSquare { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/Map.java b/com/google/ortools/constraintsolver/samples/Map.java index 075c1e2771..a316c72c55 100644 --- a/com/google/ortools/constraintsolver/samples/Map.java +++ b/com/google/ortools/constraintsolver/samples/Map.java @@ -59,24 +59,24 @@ public class Map { // // Constraints - // + // solver.addConstraint(solver.makeNonEquality(color[France], color[Belgium])); - solver.addConstraint(solver.makeNonEquality(color[France], + solver.addConstraint(solver.makeNonEquality(color[France], color[Luxembourg])); - solver.addConstraint(solver.makeNonEquality(color[France], + solver.addConstraint(solver.makeNonEquality(color[France], color[Germany])); - solver.addConstraint(solver.makeNonEquality(color[Luxembourg], + solver.addConstraint(solver.makeNonEquality(color[Luxembourg], color[Germany])); - solver.addConstraint(solver.makeNonEquality(color[Luxembourg], + solver.addConstraint(solver.makeNonEquality(color[Luxembourg], color[Belgium])); - solver.addConstraint(solver.makeNonEquality(color[Belgium], + solver.addConstraint(solver.makeNonEquality(color[Belgium], color[Netherlands])); - solver.addConstraint(solver.makeNonEquality(color[Belgium], + solver.addConstraint(solver.makeNonEquality(color[Belgium], color[Germany])); - solver.addConstraint(solver.makeNonEquality(color[Germany], + solver.addConstraint(solver.makeNonEquality(color[Germany], color[Netherlands])); - solver.addConstraint(solver.makeNonEquality(color[Germany], + solver.addConstraint(solver.makeNonEquality(color[Germany], color[Denmark])); // Symmetry breaking @@ -104,7 +104,7 @@ public class Map { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/Map2.java b/com/google/ortools/constraintsolver/samples/Map2.java index b300948387..669a3ff898 100644 --- a/com/google/ortools/constraintsolver/samples/Map2.java +++ b/com/google/ortools/constraintsolver/samples/Map2.java @@ -61,7 +61,7 @@ public class Map2 { {Belgium, Germany}, {Germany, Netherlands}, {Germany, Denmark}}; - + // // Variables @@ -70,10 +70,10 @@ public class Map2 { // // Constraints - // + // for(int i = 0; i < neighbours.length; i++) { solver.addConstraint( - solver.makeNonEquality(color[neighbours[i][0]], + solver.makeNonEquality(color[neighbours[i][0]], color[neighbours[i][1]])); } @@ -103,7 +103,7 @@ public class Map2 { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/Minesweeper.java b/com/google/ortools/constraintsolver/samples/Minesweeper.java index 6e37fbcd3f..b5969ffdd7 100644 --- a/com/google/ortools/constraintsolver/samples/Minesweeper.java +++ b/com/google/ortools/constraintsolver/samples/Minesweeper.java @@ -94,7 +94,7 @@ public class Minesweeper { // // Constraints - // + // for(int i = 0; i < r; i++) { for(int j = 0; j < c; j++) { if (game[i][j] >= 0) { @@ -119,7 +119,7 @@ public class Minesweeper { } if (game[i][j] > X) { - // This cell cannot be a mine since it + // This cell cannot be a mine since it // has some value assigned to it solver.addConstraint( solver.makeEquality(mines[i][j], 0)); @@ -137,7 +137,7 @@ public class Minesweeper { int sol = 0; while (solver.nextSolution()) { - sol++; + sol++; System.out.println("Solution #" + sol + ":"); for(int i = 0; i < r; i++) { for(int j = 0; j < c; j++) { @@ -155,7 +155,7 @@ public class Minesweeper { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } @@ -171,9 +171,9 @@ public class Minesweeper { * < * row number of neighbours lines... * > - * + * * 0..8 means number of neighbours, "." mean unknown (may be a mine) - * + * * Example (from minesweeper0.txt) * # Problem from Gecode/examples/minesweeper.cc problem 0 * 6 @@ -190,7 +190,7 @@ public class Minesweeper { System.out.println("readFile(" + file + ")"); int lineCount = 0; - + try { BufferedReader inr = new BufferedReader(new FileReader(file)); diff --git a/com/google/ortools/constraintsolver/samples/NQueens.java b/com/google/ortools/constraintsolver/samples/NQueens.java index c3b51b6467..086ddf1365 100644 --- a/com/google/ortools/constraintsolver/samples/NQueens.java +++ b/com/google/ortools/constraintsolver/samples/NQueens.java @@ -95,7 +95,7 @@ public class NQueens { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/NQueens2.java b/com/google/ortools/constraintsolver/samples/NQueens2.java index 10d962d1a2..e269a69dc4 100644 --- a/com/google/ortools/constraintsolver/samples/NQueens2.java +++ b/com/google/ortools/constraintsolver/samples/NQueens2.java @@ -86,7 +86,7 @@ public class NQueens2 { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } public static void main(String[] args) throws Exception { diff --git a/com/google/ortools/constraintsolver/samples/QuasigroupCompletion.java b/com/google/ortools/constraintsolver/samples/QuasigroupCompletion.java index b93a637c7d..69fc318a5c 100644 --- a/com/google/ortools/constraintsolver/samples/QuasigroupCompletion.java +++ b/com/google/ortools/constraintsolver/samples/QuasigroupCompletion.java @@ -154,7 +154,7 @@ public class QuasigroupCompletion { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/SendMoreMoney.java b/com/google/ortools/constraintsolver/samples/SendMoreMoney.java index 16c2c9f675..11797c36b2 100644 --- a/com/google/ortools/constraintsolver/samples/SendMoreMoney.java +++ b/com/google/ortools/constraintsolver/samples/SendMoreMoney.java @@ -84,7 +84,7 @@ public class SendMoreMoney { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/SendMoreMoney2.java b/com/google/ortools/constraintsolver/samples/SendMoreMoney2.java index 530967b29c..a4d24feffa 100644 --- a/com/google/ortools/constraintsolver/samples/SendMoreMoney2.java +++ b/com/google/ortools/constraintsolver/samples/SendMoreMoney2.java @@ -204,7 +204,7 @@ public class SendMoreMoney2 { System.out.println("Solutions: " + sol.solutions()); System.out.println("Failures: " + sol.failures()); System.out.println("Branches: " + sol.branches()); - System.out.println("Wall time: " + sol.wall_time() + "ms"); + System.out.println("Wall time: " + sol.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/SendMostMoney.java b/com/google/ortools/constraintsolver/samples/SendMostMoney.java index 1870421970..21aeb95491 100644 --- a/com/google/ortools/constraintsolver/samples/SendMostMoney.java +++ b/com/google/ortools/constraintsolver/samples/SendMostMoney.java @@ -118,7 +118,7 @@ public class SendMostMoney { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); return money_ret; diff --git a/com/google/ortools/constraintsolver/samples/Seseman.java b/com/google/ortools/constraintsolver/samples/Seseman.java index 1c55cbef6f..a61a21818d 100644 --- a/com/google/ortools/constraintsolver/samples/Seseman.java +++ b/com/google/ortools/constraintsolver/samples/Seseman.java @@ -128,7 +128,7 @@ public class Seseman { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/SetCovering.java b/com/google/ortools/constraintsolver/samples/SetCovering.java index 054d1903e8..3f212bf627 100644 --- a/com/google/ortools/constraintsolver/samples/SetCovering.java +++ b/com/google/ortools/constraintsolver/samples/SetCovering.java @@ -111,7 +111,7 @@ public class SetCovering { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/SetCovering2.java b/com/google/ortools/constraintsolver/samples/SetCovering2.java index 9bb1c960d4..fb19e80770 100644 --- a/com/google/ortools/constraintsolver/samples/SetCovering2.java +++ b/com/google/ortools/constraintsolver/samples/SetCovering2.java @@ -119,7 +119,7 @@ public class SetCovering2 { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/SetCovering3.java b/com/google/ortools/constraintsolver/samples/SetCovering3.java index 5c224b7f00..d9b6975685 100644 --- a/com/google/ortools/constraintsolver/samples/SetCovering3.java +++ b/com/google/ortools/constraintsolver/samples/SetCovering3.java @@ -130,7 +130,7 @@ public class SetCovering3 { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/SetCovering4.java b/com/google/ortools/constraintsolver/samples/SetCovering4.java index c56612c3d5..bbf7e66601 100644 --- a/com/google/ortools/constraintsolver/samples/SetCovering4.java +++ b/com/google/ortools/constraintsolver/samples/SetCovering4.java @@ -131,7 +131,7 @@ public class SetCovering4 { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/SetCoveringDeployment.java b/com/google/ortools/constraintsolver/samples/SetCoveringDeployment.java index e71c325112..778e5199cc 100644 --- a/com/google/ortools/constraintsolver/samples/SetCoveringDeployment.java +++ b/com/google/ortools/constraintsolver/samples/SetCoveringDeployment.java @@ -148,7 +148,7 @@ public class SetCoveringDeployment { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/StableMarriage.java b/com/google/ortools/constraintsolver/samples/StableMarriage.java index 5ffec13d57..6109301022 100644 --- a/com/google/ortools/constraintsolver/samples/StableMarriage.java +++ b/com/google/ortools/constraintsolver/samples/StableMarriage.java @@ -141,7 +141,7 @@ public class StableMarriage { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/Strimko2.java b/com/google/ortools/constraintsolver/samples/Strimko2.java index 597eff605f..cd404b78e4 100644 --- a/com/google/ortools/constraintsolver/samples/Strimko2.java +++ b/com/google/ortools/constraintsolver/samples/Strimko2.java @@ -149,7 +149,7 @@ public class Strimko2 { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/Sudoku.java b/com/google/ortools/constraintsolver/samples/Sudoku.java index 22b30eb1c4..45d662ad36 100644 --- a/com/google/ortools/constraintsolver/samples/Sudoku.java +++ b/com/google/ortools/constraintsolver/samples/Sudoku.java @@ -129,7 +129,7 @@ public class Sudoku { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/SurvoPuzzle.java b/com/google/ortools/constraintsolver/samples/SurvoPuzzle.java index d90fe23116..3c7a6d5a58 100644 --- a/com/google/ortools/constraintsolver/samples/SurvoPuzzle.java +++ b/com/google/ortools/constraintsolver/samples/SurvoPuzzle.java @@ -147,7 +147,7 @@ public class SurvoPuzzle { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/ToNum.java b/com/google/ortools/constraintsolver/samples/ToNum.java index eea936f67b..e606a9e038 100644 --- a/com/google/ortools/constraintsolver/samples/ToNum.java +++ b/com/google/ortools/constraintsolver/samples/ToNum.java @@ -108,7 +108,7 @@ public class ToNum { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/WhoKilledAgatha.java b/com/google/ortools/constraintsolver/samples/WhoKilledAgatha.java index 33860dd42a..3fe0b422fd 100644 --- a/com/google/ortools/constraintsolver/samples/WhoKilledAgatha.java +++ b/com/google/ortools/constraintsolver/samples/WhoKilledAgatha.java @@ -198,7 +198,7 @@ public class WhoKilledAgatha { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/Xkcd.java b/com/google/ortools/constraintsolver/samples/Xkcd.java index e97bdcc727..f40479f362 100644 --- a/com/google/ortools/constraintsolver/samples/Xkcd.java +++ b/com/google/ortools/constraintsolver/samples/Xkcd.java @@ -77,7 +77,7 @@ public class Xkcd { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/com/google/ortools/constraintsolver/samples/YoungTableaux.java b/com/google/ortools/constraintsolver/samples/YoungTableaux.java index 99f39fe313..654089db1f 100644 --- a/com/google/ortools/constraintsolver/samples/YoungTableaux.java +++ b/com/google/ortools/constraintsolver/samples/YoungTableaux.java @@ -142,7 +142,7 @@ public class YoungTableaux { System.out.println("Solutions: " + solver.solutions()); System.out.println("Failures: " + solver.failures()); System.out.println("Branches: " + solver.branches()); - System.out.println("Wall time: " + solver.wall_time() + "ms"); + System.out.println("Wall time: " + solver.wallTime() + "ms"); } diff --git a/constraint_solver/constraint_solver.swig b/constraint_solver/constraint_solver.swig index 94441d3583..6991060017 100644 --- a/constraint_solver/constraint_solver.swig +++ b/constraint_solver/constraint_solver.swig @@ -263,6 +263,7 @@ class PyDecisionBuilder(object): %rename (BestValueSolutionCollector) MakeBestValueSolutionCollector; %rename (BetweenCt) MakeBetweenCt; %rename (BoolVar) MakeBoolVar; +%rename (Branches) branches; %rename (BranchesLimit) MakeBranchesLimit; %rename (ConstantRestart) MakeConstantRestart; %rename (ConvexPiecewiseExpr) MakeConvexPiecewiseExpr; @@ -276,6 +277,7 @@ class PyDecisionBuilder(object): %rename (Distribute) MakeDistribute; %rename (Element) MakeElement; %rename (FailDecision) MakeFailDecision; +%rename (Failures) failures; %rename (FailuresLimit) MakeFailuresLimit; %rename (FalseConstraint) MakeFalseConstraint; %rename (FirstSolutionCollector) MakeFirstSolutionCollector; @@ -317,6 +319,7 @@ class PyDecisionBuilder(object): %rename (Minimize) MakeMinimize; %rename (NeighborhoodLimit) MakeNeighborhoodLimit; %rename (NoCycle) MakeNoCycle; +%rename (ObjectiveValue) objective_value; %rename (Operator) MakeOperator; %rename (Optimize) MakeOptimize; %rename (Pack) MakePack; @@ -334,8 +337,10 @@ class PyDecisionBuilder(object): %rename (SearchLog) MakeSearchLog; %rename (SearchTrace) MakeSearchTrace; %rename (SemiContinuousExpr) MakeSemiContinuousExpr; +%rename (SetName) set_name; %rename (SequenceVar) MakeSequenceVar; %rename (SimulatedAnnealing) MakeSimulatedAnnealing; +%rename (SolutionCount) solution_count; %rename (SolutionsLimit) MakeSolutionsLimit; %rename (SolveOnce) MakeSolveOnce; %rename (SplitVariableDomain) MakeSplitVariableDomain; @@ -351,6 +356,7 @@ class PyDecisionBuilder(object): %rename (TransitionConstraint) MakeTransitionConstraint; %rename (TreeMonitor) MakeTreeMonitor; %rename (TrueConstraint) MakeTrueConstraint; +%rename (WallTime) wall_time; %rename (WeightedMaximize) MakeWeightedMaximize; %rename (WeightedMinimize) MakeWeightedMinimize; %rename (WeightedOptimize) MakeWeightedOptimize; @@ -1364,8 +1370,11 @@ struct FailureProtect { %rename (addObjective) operations_research::SolutionCollector::AddObjective; %rename (durationValue) operations_research::SolutionCollector::DurationValue; %rename (endValue) operations_research::SolutionCollector::EndValue; +%rename (objectiveValue) operations_research::SolutionCollector::objective_value; %rename (performedValue) operations_research::SolutionCollector::PerformedValue; +%rename (solutionCount) operations_research::SolutionCollector::solution_count; %rename (startValue) operations_research::SolutionCollector::StartValue; +%rename (wallTime) operations_research::SolutionCollector::wall_time;; // Rename rules on Solver. %rename (addBacktrackAction) operations_research::Solver::AddBacktrackAction; @@ -1519,6 +1528,7 @@ struct FailureProtect { %rename (solve) operations_research::Solver::Solve; %rename (solveDepth) operations_research::Solver::SolveDepth; %rename (updateLimits) operations_research::Solver::UpdateLimits; +%rename (wallTime) operations_research::Solver::wall_time; // Rename rules on IntVar and IntExpr. %rename (var) operations_research::IntExpr::Var; @@ -1545,6 +1555,9 @@ struct FailureProtect { // Rename rules on Action. %rename (run) operations_research::Action::Run; +// Rename rules on PropagationBaseObject. +%rename (setName) operations_research::PropagationBaseObject::set_name; + // Rename rules on Search Monitor %rename (acceptDelta) operations_research::SearchMonitor::AcceptDelta; %rename (acceptNeighbor) operations_research::SearchMonitor::AcceptNeighbor; @@ -1841,6 +1854,9 @@ struct FailureProtect { // Rename rules on Action. %rename (Run) operations_research::Action::Run; +// Rename rules on PropagationBaseObject +%rename (SetName) operations_research::PropagationBaseObject::set_name; + CS_TYPEMAP_STDVECTOR_OBJECT(operations_research::IntVar, IntVar) CS_TYPEMAP_STDVECTOR_OBJECT(operations_research::SearchMonitor, SearchMonitor) CS_TYPEMAP_STDVECTOR_OBJECT(operations_research::DecisionBuilder, DecisionBuilder) diff --git a/linear_solver/linear_solver.swig b/linear_solver/linear_solver.swig index 3d148fa96e..a84ee4876e 100644 --- a/linear_solver/linear_solver.swig +++ b/linear_solver/linear_solver.swig @@ -23,19 +23,40 @@ #ifdef SWIGPYTHON // Define the renaming of methods. +%ignore MakeBoolVarArray; +%ignore MakeIntVarArray; +%ignore MakeNumVarArray; +%ignore MakeVarArray; +%rename (Activity) activity; +%rename (BasisStatus) basis_status; +%rename (BestObjectiveBound) best_objective_bound; %rename (BoolVar) MakeBoolVar; -%rename (IntVar) MakeIntVar; -%rename (NumVar) MakeNumVar; %rename (Constraint) MPConstraint; %rename (Constraint) MakeRowConstraint; -%rename (Solver) MPSolver; -%rename (Variable) MPVariable; -%ignore MakeVarArray; -%ignore MakeNumVarArray; -%ignore MakeIntVarArray; -%ignore MakeBoolVarArray; +%rename (DualValue) dual_value; +%rename (Index) index; +%rename (Infinity) infinity; +%rename (IntVar) MakeIntVar; +%rename (Integer) integer; +%rename (Iterations) iterations; +%rename (Lb) lb; %rename (LookupConstraint) LookupConstraintOrNull; %rename (LookupVariable) LookupVariableOrNull; +%rename (Nodes) nodes; +%rename (NumVar) MakeNumVar; +%rename (ObjectiveValue) objective_value; +%rename (Offset) offset; +%rename (ReducedCost) reduced_cost; +%rename (SetLb) SetLB; +%rename (SetTimeLimit) set_time_limit; +%rename (SetUb) SetUB; +%rename (SolutionValue) solution_value; +%rename (Solver) MPSolver; +%rename (TimeLimit) time_limit; +%rename (Ub) ub; +%rename (Variable) MPVariable; +%rename (WallTime) wall_time; + // Ignore non-mutable version of the Objective accessor, rename the mutable one. %ignore Objective; %rename (Objective) MutableObjective; @@ -217,8 +238,8 @@ class LinearConstraint(object): def Extract(self, solver, name=''): coeffs = {} constant = self.__expr.Visit(coeffs) - lb = -solver.infinity() - ub = solver.infinity() + lb = -solver.Infinity() + ub = solver.Infinity() if self.__lb > -1e308: lb = self.__lb - constant if self.__ub < 1e308: @@ -561,6 +582,7 @@ namespace operations_research { %rename (AddOffset) MPObjective::AddOffset; %rename (AddTerm) MPObjective::AddObjective; %rename (Clear) MPObjective::Clear; +%rename (Offset) MPObjective::offset; %rename (SetCoefficient) MPObjective::SetCoefficient; %rename (SetOffset) MPObjective::SetOffset; diff --git a/python/3_jugs_mip.py b/python/3_jugs_mip.py index 5a7dcf0cf7..00c700d41a 100644 --- a/python/3_jugs_mip.py +++ b/python/3_jugs_mip.py @@ -17,7 +17,7 @@ 3 jugs problem using MIP in Google or-tools. A.k.a. water jugs problem. - + Problem from Taha 'Introduction to Operations Research', page 245f . @@ -31,7 +31,7 @@ import sys from linear_solver import pywraplp def main(sol = 'GLPK'): - + # Create the solver. print 'Solver: ', sol @@ -70,7 +70,7 @@ def main(sol = 'GLPK'): '1,4,3', '4,4,0' # goal! ] - + # distance d = [[M, 1, M, M, M, M, M, M, 1, M, M, M, M, M, M], [M, M, 1, M, M, M, M, M, M, M, M, M, M, M, M], @@ -79,13 +79,13 @@ def main(sol = 'GLPK'): [M, M, M, M, M, 1, M, M, 1, M, M, M, M, M, M], [M, M, M, M, M, M, 1, M, M, M, M, M, M, M, M], [M, M, M, M, M, M, M, 1, 1, M, M, M, M, M, M], - [M, M, M, M, M, M, M, M, M, M, M, M, M, M, 1], + [M, M, M, M, M, M, M, M, M, M, M, M, M, M, 1], [M, M, M, M, M, M, M, M, M, 1, M, M, M, M, M], [M, 1, M, M, M, M, M, M, M, M, 1, M, M, M, M], [M, M, M, M, M, M, M, M, M, M, M, 1, M, M, M], [M, 1, M, M, M, M, M, M, M, M, M, M, 1, M, M], [M, M, M, M, M, M, M, M, M, M, M, M, M, 1, M], - [M, 1, M, M, M, M, M, M, M, M, M, M, M, M, 1], + [M, 1, M, M, M, M, M, M, M, M, M, M, M, M, 1], [M, M, M, M, M, M, M, M, M, M, M, M, M, M, M]] @@ -128,7 +128,7 @@ def main(sol = 'GLPK'): solver.Add(out_flow[i] == solver.Sum([x[i,j] for j in range(n) if d[i][j] < M])) - + # inflow constraint for j in range(n): solver.Add(in_flow[j] == solver.Sum([x[i,j] @@ -138,7 +138,7 @@ def main(sol = 'GLPK'): # inflow = outflow for i in range(n): solver.Add(out_flow[i]-in_flow[i] == rhs[i]) - + # objective objective = solver.Minimize(z) @@ -162,7 +162,7 @@ def main(sol = 'GLPK'): break print - print 'walltime :', solver.wall_time(), 'ms' + print 'walltime :', solver.WallTime(), 'ms' if sol == 'CBC': print 'iterations:', solver.iterations() @@ -175,5 +175,5 @@ if __name__ == '__main__': if sol != 'GLPK' and sol != 'CBC': print 'Solver must be either GLPK or CBC' sys.exit(1) - + main(sol) diff --git a/python/3_jugs_regular.py b/python/3_jugs_regular.py index 9770e33b1c..ab90a560b3 100644 --- a/python/3_jugs_regular.py +++ b/python/3_jugs_regular.py @@ -1,29 +1,29 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ 3 jugs problem using regular constraint in Google CP Solver. A.k.a. water jugs problem. - + Problem from Taha 'Introduction to Operations Research', page 245f . For more info about the problem, see: http://mathworld.wolfram.com/ThreeJugProblem.html - + This model use a regular constraint for handling the transitions between the states. Instead of minimizing the cost in a cost matrix (as shortest path problem), @@ -36,15 +36,15 @@ * Comet: http://www.hakank.org/comet/water_buckets1.co * MiniZinc: http://www.hakank.org/minizinc/3_jugs.mzn * MiniZinc: http://www.hakank.org/minizinc/3_jugs2.mzn - * SICStus: http://www.hakank.org/sicstus/3_jugs.pl - * ECLiPSe: http://www.hakank.org/eclipse/3_jugs.ecl + * SICStus: http://www.hakank.org/sicstus/3_jugs.pl + * ECLiPSe: http://www.hakank.org/eclipse/3_jugs.ecl * ECLiPSe: http://www.hakank.org/eclipse/3_jugs2.ecl * Gecode: http://www.hakank.org/gecode/3_jugs2.cpp This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ - + """ from constraint_solver import pywrapcp @@ -53,7 +53,7 @@ from collections import defaultdict # # Global constraint regular # -# This is a translation of MiniZinc's regular constraint (defined in +# This is a translation of MiniZinc's regular constraint (defined in # lib/zinc/globals.mzn), via the Comet code refered above. # All comments are from the MiniZinc code. # ''' @@ -73,7 +73,7 @@ from collections import defaultdict def regular(x, Q, S, d, q0, F): solver = x[0].solver() - + assert Q > 0, 'regular: "Q" must be greater than zero' assert S > 0, 'regular: "S" must be greater than zero' @@ -81,7 +81,7 @@ def regular(x, Q, S, d, q0, F): # each possible input; each extra transition is from state zero # to state zero. This allows us to continue even if we hit a # non-accepted input. - + # Comet: int d2[0..Q, 1..S] d2 = [] for i in range(Q+1): @@ -102,25 +102,25 @@ def regular(x, Q, S, d, q0, F): x_range = range(0,len(x)) m = 0 n = len(x) - - a = [solver.IntVar(0, Q+1, 'a[%i]' % i) for i in range(m, n+1)] - + + a = [solver.IntVar(0, Q+1, 'a[%i]' % i) for i in range(m, n+1)] + # Check that the final state is in F solver.Add(solver.MemberCt(a[-1], F)) # First state is q0 - solver.Add(a[m] == q0) + solver.Add(a[m] == q0) for i in x_range: solver.Add(x[i] >= 1) solver.Add(x[i] <= S) - + # Determine a[i+1]: a[i+1] == d2[a[i], x[i]] solver.Add(a[i+1] == solver.Element(d2_flatten, ((a[i])*S)+(x[i]-1))) - + def main(n): - + # Create the solver. solver = pywrapcp.Solver('3 jugs problem using regular constraint') @@ -137,9 +137,9 @@ def main(n): ## ## Manually crafted DFA ## (from the adjacency matrix used in the other models) - ## + ## # transition_fn = [ - # # 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + # # 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 # [0, 2, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0], # 1 # [0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 2 # [0, 0, 0, 4, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0], # 3 @@ -194,8 +194,8 @@ def main(n): nodes = [ '8,0,0', # 1 start '5,0,3', # 2 - '5,3,0', # 3 - '2,3,3', # 4 + '5,3,0', # 3 + '2,3,3', # 4 '2,5,1', # 5 '7,0,1', # 6 '7,1,0', # 7 @@ -208,29 +208,29 @@ def main(n): '1,4,3', # 14 '4,4,0' # 15 goal ] - - + + # # declare variables # - x = [solver.IntVar(1, input_max, 'x[%i]'% i) for i in range(n)] + x = [solver.IntVar(1, input_max, 'x[%i]'% i) for i in range(n)] # # constraints # regular(x, n_states, input_max, transition_fn, initial_state, accepting_states) - - + + # # solution and search - # + # db = solver.Phase(x, - solver.INT_VAR_DEFAULT, + solver.INT_VAR_DEFAULT, solver.INT_VALUE_DEFAULT) solver.NewSearch(db) - + num_solutions = 0 x_val = [] while solver.NextSolution(): @@ -239,15 +239,15 @@ def main(n): print 'x:', x_val for i in range(1, n+1): print '%s -> %s' % (nodes[x_val[i-1]-1], nodes[x_val[i]-1]) - + solver.EndSearch() - + if num_solutions > 0: print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' # return the solution (or an empty array) return x_val @@ -260,7 +260,7 @@ if __name__ == '__main__': result = main(n) result_len = len(result) if result_len: - print '\nFound a solution of length %i:' % result_len, + print '\nFound a solution of length %i:' % result_len, print result print break diff --git a/python/a_round_of_golf.py b/python/a_round_of_golf.py index 0492b64ce2..51c1945d10 100644 --- a/python/a_round_of_golf.py +++ b/python/a_round_of_golf.py @@ -158,9 +158,9 @@ def main(): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': main() diff --git a/python/all_interval.py b/python/all_interval.py index 59e26a6377..f4d989fb65 100644 --- a/python/all_interval.py +++ b/python/all_interval.py @@ -102,9 +102,9 @@ def main(n=12): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() n=12 if __name__ == '__main__': diff --git a/python/alldifferent_except_0.py b/python/alldifferent_except_0.py index 165bfc33a3..1495ab512a 100644 --- a/python/alldifferent_except_0.py +++ b/python/alldifferent_except_0.py @@ -115,16 +115,16 @@ def main(unused_argv): solver.ASSIGN_MIN_VALUE), [collector]) - num_solutions = collector.solution_count() + num_solutions = collector.SolutionCount() for s in range(num_solutions): print "x:", [collector.Value(s, x[i]) for i in range(n)] print "z:", collector.Value(s, z) print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/alphametic.py b/python/alphametic.py index 7c9193db3d..897909dd15 100644 --- a/python/alphametic.py +++ b/python/alphametic.py @@ -132,9 +132,9 @@ def main(problem_str="SEND+MORE=MONEY", base=10): print print "\nnum_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() def test_problems(base=10): diff --git a/python/assignment.py b/python/assignment.py index d002a775c3..e0621908f3 100644 --- a/python/assignment.py +++ b/python/assignment.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -41,7 +41,7 @@ def main(cost, rows, cols): # # data # - + # declare variables total_cost = solver.IntVar(0, 100, 'total_cost') @@ -51,7 +51,7 @@ def main(cost, rows, cols): for j in range(cols): t.append(solver.IntVar(0,1, 'x[%i,%i]'%(i,j))) x.append(t) - x_flat = [x[i][j] for i in range(rows) for j in range(cols)] + x_flat = [x[i][j] for i in range(rows) for j in range(cols)] # # constraints @@ -59,14 +59,14 @@ def main(cost, rows, cols): # total_cost solver.Add(total_cost == solver.Sum([solver.ScalProd(x_row, cost_row) for (x_row, cost_row) in zip(x, cost)])) - - + + # exacly one assignment per row, all rows must be assigned [solver.Add(solver.Sum([x[row][j] for j in range(cols)]) == 1) for row in range(rows)] # zero or one assignments per column [solver.Add(solver.Sum([x[i][col] for i in range(rows)]) <= 1) for col in range(cols)] - + objective = solver.Minimize(total_cost, 1) # @@ -74,17 +74,17 @@ def main(cost, rows, cols): # solution = solver.Assignment() solution.Add(x_flat) - solution.Add(total_cost) + solution.Add(total_cost) # db: DecisionBuilder db = solver.Phase(x_flat, solver.INT_VAR_SIMPLE, solver.ASSIGN_MIN_VALUE) - + solver.NewSearch(db,[objective]) num_solutions = 0 - while solver.NextSolution(): + while solver.NextSolution(): print "total_cost:", total_cost.Value() for i in range(rows): for j in range(cols): @@ -98,15 +98,15 @@ def main(cost, rows, cols): if x[i][j].Value() == 1: print " is done by ", j print - - num_solutions += 1 + + num_solutions += 1 solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() # Problem instance diff --git a/python/assignment6_mip.py b/python/assignment6_mip.py index d2f4499055..40ff8c0dd9 100644 --- a/python/assignment6_mip.py +++ b/python/assignment6_mip.py @@ -20,18 +20,18 @@ ''' The assignment problem is one of the fundamental combinatorial optimization problems. - + In its most general form, the problem is as follows: - + There are a number of agents and a number of tasks. Any agent can be assigned to perform any task, incurring some cost that may vary depending on the agent-task assignment. It is required to perform all tasks by assigning exactly one agent to each task in such a way that the total cost of the assignment is minimized. - - (From Wikipedia, the free encyclopedia.) + + (From Wikipedia, the free encyclopedia.) ''' - + Compare with the Comet model: http://www.hakank.org/comet/assignment6.co @@ -43,7 +43,7 @@ import sys from linear_solver import pywraplp def main(sol = 'GLPK'): - + # Create the solver. print 'Solver: ', sol @@ -63,18 +63,18 @@ def main(sol = 'GLPK'): # # number of agents - m = 8 + m = 8 # number of tasks n = 8 - # set of agents + # set of agents I = range(m) - # set of tasks + # set of tasks J = range(n) - # cost of allocating task j to agent i + # cost of allocating task j to agent i # """ # These data correspond to an example from [Christofides]. # @@ -96,7 +96,7 @@ def main(sol = 'GLPK'): # For the output: the assignment as task number. assigned = [solver.IntVar(0, 10000, 'assigned[%i]' % j) for j in J] - costs = [solver.IntVar(0, 10000, 'costs[%i]' % i) for i in I] + costs = [solver.IntVar(0, 10000, 'costs[%i]' % i) for i in I] x = {} for i in range(n): @@ -111,12 +111,12 @@ def main(sol = 'GLPK'): # # constraints # - # each agent can perform at most one task + # each agent can perform at most one task for i in I: solver.Add(solver.Sum([x[i,j] for j in J]) <= 1) - # each task must be assigned exactly to one agent - for j in J: + # each task must be assigned exactly to one agent + for j in J: solver.Add(solver.Sum([x[i,j] for i in I]) == 1) @@ -140,7 +140,7 @@ def main(sol = 'GLPK'): print 'Assigned' for j in J: - print int(assigned[j].solution_value()), + print int(assigned[j].solution_value()), print print 'Matrix:' @@ -153,7 +153,7 @@ def main(sol = 'GLPK'): print - print 'walltime :', solver.wall_time(), 'ms' + print 'walltime :', solver.WallTime(), 'ms' if sol == 'CBC': print 'iterations:', solver.iterations() @@ -166,5 +166,5 @@ if __name__ == '__main__': if sol != 'GLPK' and sol != 'CBC': print 'Solver must be either GLPK or CBC' sys.exit(1) - + main(sol) diff --git a/python/blending.py b/python/blending.py index 299187961d..69a68fcdb8 100644 --- a/python/blending.py +++ b/python/blending.py @@ -17,7 +17,7 @@ Blending problem in Google or-tools. From the OPL model blending.mod. - + This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ """ @@ -26,7 +26,7 @@ from linear_solver import pywraplp def main(sol = 'GLPK'): - + # Create the solver. print 'Solver: ', sol @@ -69,10 +69,10 @@ def main(sol = 'GLPK'): # p = [solver.NumVar(0, solver.infinity(), 'p[%i]' % i) for i in Metals] r = [solver.NumVar(0, solver.infinity(), 'r[%i]' % i) for i in Raws] - s = [solver.NumVar(0, solver.infinity(), 's[%i]' % i) for i in Scraps] + s = [solver.NumVar(0, solver.infinity(), 's[%i]' % i) for i in Scraps] ii = [solver.IntVar(0, solver.infinity(), 'ii[%i]' % i) for i in Ingos] metal = [solver.NumVar(Low[j]*Alloy, Up[j]*Alloy, 'metal[%i]' % j) - for j in Metals] + for j in Metals] z = solver.NumVar(0, solver.infinity(), 'z') @@ -82,15 +82,15 @@ def main(sol = 'GLPK'): solver.Add(z == solver.Sum([CostMetal[i] * p[i] for i in Metals]) + - solver.Sum([CostRaw[i] * r[i] for i in Raws]) + + solver.Sum([CostRaw[i] * r[i] for i in Raws]) + solver.Sum([CostScrap[i] * s[i] for i in Scraps]) + solver.Sum([CostIngo[i] * ii[i] for i in Ingos])) - + for j in Metals: solver.Add( metal[j] == p[j] + - solver.Sum([PercRaw[j][k] * r[k] for k in Raws]) + + solver.Sum([PercRaw[j][k] * r[k] for k in Raws]) + solver.Sum([PercScrap[j][k] * s[k] for k in Scraps]) + solver.Sum([PercIngo[j][k] * ii[k] for k in Ingos])) @@ -134,7 +134,7 @@ def main(sol = 'GLPK'): print - print 'walltime :', solver.wall_time(), 'ms' + print 'walltime :', solver.WallTime(), 'ms' if sol == 'CBC': print 'iterations:', solver.iterations() @@ -147,5 +147,5 @@ if __name__ == '__main__': if sol != 'GLPK' and sol != 'CBC': print 'Solver must be either GLPK or CBC' sys.exit(1) - + main(sol) diff --git a/python/broken_weights.py b/python/broken_weights.py index a42b78e600..14d684b864 100644 --- a/python/broken_weights.py +++ b/python/broken_weights.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the 'License'); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an 'AS IS' BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -18,31 +18,31 @@ From http://www.mathlesstraveled.com/?p=701 ''' - Here's a fantastic problem I recently heard. Apparently it was first - posed by Claude Gaspard Bachet de Meziriac in a book of arithmetic problems - published in 1612, and can also be found in Heinrich Dorrie's 100 + Here's a fantastic problem I recently heard. Apparently it was first + posed by Claude Gaspard Bachet de Meziriac in a book of arithmetic problems + published in 1612, and can also be found in Heinrich Dorrie's 100 Great Problems of Elementary Mathematics. - - A merchant had a forty pound measuring weight that broke - into four pieces as the result of a fall. When the pieces were - subsequently weighed, it was found that the weight of each piece - was a whole number of pounds and that the four pieces could be - used to weigh every integral weight between 1 and 40 pounds. What + + A merchant had a forty pound measuring weight that broke + into four pieces as the result of a fall. When the pieces were + subsequently weighed, it was found that the weight of each piece + was a whole number of pounds and that the four pieces could be + used to weigh every integral weight between 1 and 40 pounds. What were the weights of the pieces? - - Note that since this was a 17th-century merchant, he of course used a - balance scale to weigh things. So, for example, he could use a 1-pound - weight and a 4-pound weight to weigh a 3-pound object, by placing the - 3-pound object and 1-pound weight on one side of the scale, and + + Note that since this was a 17th-century merchant, he of course used a + balance scale to weigh things. So, for example, he could use a 1-pound + weight and a 4-pound weight to weigh a 3-pound object, by placing the + 3-pound object and 1-pound weight on one side of the scale, and the 4-pound weight on the other side. ''' - + Compare with the following problems: * MiniZinc: http://www.hakank.org/minizinc/broken_weights.mzn * ECLiPSE: http://www.hakank.org/eclipse/broken_weights.ecl * Gecode: http://www.hakank.org/gecode/broken_weights.cpp * Comet: http://hakank.org/comet/broken_weights.co - + This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ """ @@ -53,14 +53,14 @@ from constraint_solver import pywrapcp def main(m=40, n=4): - + # Create the solver. solver = pywrapcp.Solver('Broken weights') - + # # data # - print 'total weight (m):', m + print 'total weight (m):', m print 'number of pieces (n):', n print @@ -81,7 +81,7 @@ def main(m=40, n=4): # symmetry breaking for j in range(1, n): solver.Add(weights[j-1] < weights[j]) - + solver.Add(solver.SumEquality(weights, m)) # Check that all weights from 1 to 40 can be made. @@ -101,7 +101,7 @@ def main(m=40, n=4): # # search and result - # + # db = solver.Phase(weights + x_flat, solver.CHOOSE_FIRST_UNBOUND, solver.ASSIGN_MIN_VALUE) @@ -116,7 +116,7 @@ def main(m=40, n=4): print 'weights: ', for w in [weights[j].Value() for j in range(n)]: print '%3i ' % w, - print + print print '-' * 30 for i in range(m): print 'weight %2i:' % (i+1), @@ -126,11 +126,11 @@ def main(m=40, n=4): print print solver.EndSearch() - + print 'num_solutions:', num_solutions - print 'failures :', solver.failures() - print 'branches :', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures :', solver.Failures() + print 'branches :', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' m = 40 diff --git a/python/bus_schedule.py b/python/bus_schedule.py index 24e0dc80a6..d581396b92 100644 --- a/python/bus_schedule.py +++ b/python/bus_schedule.py @@ -92,7 +92,7 @@ def main(num_buses_check=0): solver.ASSIGN_MIN_VALUE), cargs) - num_solutions = collector.solution_count() + num_solutions = collector.SolutionCount() num_buses_check_value = 0 for s in range(num_solutions): print "x:", [collector.Value(s, x[i]) for i in range(len(x))], @@ -101,9 +101,9 @@ def main(num_buses_check=0): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() print if num_buses_check == 0: return num_buses_check_value diff --git a/python/car.py b/python/car.py index 5983877a54..3441b897d7 100644 --- a/python/car.py +++ b/python/car.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -36,10 +36,10 @@ from constraint_solver import pywrapcp def main(num_sol=3): - + # Create the solver. solver = pywrapcp.Solver('Car sequence') - + # # data # @@ -51,7 +51,7 @@ def main(num_sol=3): Options = range(nbOptions) Slots = range(nbSlots) - # car 0 1 2 3 4 5 + # car 0 1 2 3 4 5 demand = [1, 1, 2, 2, 2, 2] option = [ @@ -73,7 +73,7 @@ def main(num_sol=3): optionDemand = [sum([demand[j]*option[i][j] for j in Cars]) \ for i in Options] - + # # declare variables # @@ -112,18 +112,18 @@ def main(num_sol=3): # # search and result - # + # db = solver.Phase(slot + setup_flat, solver.CHOOSE_FIRST_UNBOUND, solver.ASSIGN_MIN_VALUE) - + solver.NewSearch(db) num_solutions = 0 while solver.NextSolution(): print "slot:%s" % ",".join([str(slot[i].Value()) for i in Slots]) print "setup:" for o in Options: - print "%i/%i:" % (capacity[o][0], capacity[o][1]), + print "%i/%i:" % (capacity[o][0], capacity[o][1]), for s in Slots: print setup[o,s].Value(), print @@ -132,14 +132,14 @@ def main(num_sol=3): if num_solutions >= num_sol: break - + solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() num_sol = 3 if __name__ == '__main__': diff --git a/python/circuit.py b/python/circuit.py index 8f21c58034..541fd6c009 100644 --- a/python/circuit.py +++ b/python/circuit.py @@ -111,15 +111,15 @@ def main(n=5): solver.ASSIGN_MIN_VALUE), [collector]) - num_solutions = collector.solution_count() + num_solutions = collector.SolutionCount() for s in range(num_solutions): print "x:", [collector.Value(s, x[i]) for i in range(len(x))] print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() print diff --git a/python/coins3.py b/python/coins3.py index a726f10023..e6617e8597 100644 --- a/python/coins3.py +++ b/python/coins3.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -71,7 +71,7 @@ def main(): # objective objective = solver.Minimize(num_coins, 1) - + # # solution and search # @@ -83,21 +83,21 @@ def main(): db = solver.Phase(x, solver.CHOOSE_MIN_SIZE_LOWEST_MAX, solver.ASSIGN_MIN_VALUE) - + solver.NewSearch(db, [objective]) num_solutions = 0 - while solver.NextSolution(): + while solver.NextSolution(): print "x: ", [x[i].Value() for i in range(n)] print "num_coins:", num_coins.Value() print num_solutions += 1 solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/coins_grid.py b/python/coins_grid.py index f201ffe0d8..66b530dfca 100644 --- a/python/coins_grid.py +++ b/python/coins_grid.py @@ -108,9 +108,9 @@ def main(unused_argv): print print - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/coins_grid_mip.py b/python/coins_grid_mip.py index faf1f21d28..c8060b3f6f 100644 --- a/python/coins_grid_mip.py +++ b/python/coins_grid_mip.py @@ -43,7 +43,7 @@ from linear_solver import pywraplp def main(unused_argv): - + # Create the solver. # using GLPK @@ -97,7 +97,7 @@ def main(unused_argv): print print - print 'walltime :', solver.wall_time(), 'ms' + print 'walltime :', solver.WallTime(), 'ms' # print 'iterations:', solver.iterations() diff --git a/python/coloring_ip.py b/python/coloring_ip.py index df025b5f88..1999210343 100644 --- a/python/coloring_ip.py +++ b/python/coloring_ip.py @@ -42,7 +42,7 @@ from linear_solver import pywraplp def main(sol = 'GLPK'): - + # Create the solver. print 'Solver: ', sol @@ -68,14 +68,14 @@ def main(sol = 'GLPK'): n = 11 # set of nodes V = range(n) - + num_edges = 20 # # Neighbours # # This data correspond to the instance myciel3.col from: - # http://mat.gsia.cmu.edu/COLOR/instances.html + # http://mat.gsia.cmu.edu/COLOR/instances.html # # Note: 1-based (adjusted below) E = [[1, 2], @@ -99,19 +99,19 @@ def main(sol = 'GLPK'): [9, 11], [10, 11]] - + # # declare variables # - - # x[i,c] = 1 means that node i is assigned color c + + # x[i,c] = 1 means that node i is assigned color c x = {} for v in V: for j in range(nc): x[v,j] = solver.IntVar(0, 1, 'v[%i,%i]' % (v, j)) - - # u[c] = 1 means that color c is used, i.e. assigned to some node + + # u[c] = 1 means that color c is used, i.e. assigned to some node u = [solver.IntVar(0, 1, 'u[%i]' % i) for i in range(nc)] # number of colors used, to minimize @@ -122,7 +122,7 @@ def main(sol = 'GLPK'): # constraints # - # each node must be assigned exactly one color + # each node must be assigned exactly one color for i in V: solver.Add(solver.Sum([x[i,c] for c in range(nc)]) == 1) @@ -144,7 +144,7 @@ def main(sol = 'GLPK'): print print "number of colors:", int(solver.objective_value()) - print "colors used:", [int(u[i].solution_value()) for i in range(nc)] + print "colors used:", [int(u[i].solution_value()) for i in range(nc)] print for v in V: @@ -154,10 +154,10 @@ def main(sol = 'GLPK'): print c print - print "wall_time:", solver.wall_time() + print "WallTime:", solver.WallTime() if sol == 'CBC': print 'iterations:', solver.iterations() - + if __name__ == '__main__': @@ -168,5 +168,5 @@ if __name__ == '__main__': if sol != 'GLPK' and sol != 'CBC': print 'Solver must be either GLPK or CBC' sys.exit(1) - + main(sol) diff --git a/python/combinatorial_auction2.py b/python/combinatorial_auction2.py index 3c770f7a8c..b604983890 100644 --- a/python/combinatorial_auction2.py +++ b/python/combinatorial_auction2.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -36,7 +36,7 @@ from constraint_solver import pywrapcp def main(): - + # Create the solver. solver = pywrapcp.Solver('Problem') @@ -44,7 +44,7 @@ def main(): # data # N = 5 - + # the items for each bid items = [ [0,1], # A,B @@ -55,18 +55,18 @@ def main(): ] # collect the bids for each item items_t = defaultdict(list) - + # [items_t.setdefault(j,[]).append(i) for i in range(N) for j in items[i] ] # nicer: [items_t[j].append(i) for i in range(N) for j in items[i] ] - + bid_amount = [10,20,30,40,14] # # declare variables # X = [solver.BoolVar("x%i"%i) for i in range(N)] - obj = solver.IntVar(0,100,'obj') + obj = solver.IntVar(0,100,'obj') # # constraints @@ -90,7 +90,7 @@ def main(): db = solver.Phase(X, solver.CHOOSE_FIRST_UNBOUND, solver.ASSIGN_MIN_VALUE) - + solver.NewSearch(db,[objective]) num_solutions = 0 while solver.NextSolution(): @@ -98,14 +98,14 @@ def main(): print "obj:", obj.Value() print num_solutions += 1 - + solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': main() diff --git a/python/costas_array.py b/python/costas_array.py index d6ca2dd414..a2c0638e51 100644 --- a/python/costas_array.py +++ b/python/costas_array.py @@ -164,9 +164,9 @@ def main(n=6): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() n = 6 if __name__ == '__main__': diff --git a/python/covering_opl.py b/python/covering_opl.py index 2d95a7ed70..cfdae599e0 100644 --- a/python/covering_opl.py +++ b/python/covering_opl.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -18,17 +18,17 @@ This example is from the OPL example covering.mod ''' - Consider selecting workers to build a house. The construction of a - house can be divided into a number of tasks, each requiring a number of - skills (e.g., plumbing or masonry). A worker may or may not perform a - task, depending on skills. In addition, each worker can be hired for a - cost that also depends on his qualifications. The problem consists of - selecting a set of workers to perform all the tasks, while minimizing the - cost. This is known as a set-covering problem. The key idea in modeling - a set-covering problem as an integer program is to associate a 0/1 - variable with each worker to represent whether the worker is hired. - To make sure that all the tasks are performed, it is sufficient to - choose at least one worker by task. This constraint can be expressed by a + Consider selecting workers to build a house. The construction of a + house can be divided into a number of tasks, each requiring a number of + skills (e.g., plumbing or masonry). A worker may or may not perform a + task, depending on skills. In addition, each worker can be hired for a + cost that also depends on his qualifications. The problem consists of + selecting a set of workers to perform all the tasks, while minimizing the + cost. This is known as a set-covering problem. The key idea in modeling + a set-covering problem as an integer program is to associate a 0/1 + variable with each worker to represent whether the worker is hired. + To make sure that all the tasks are performed, it is sufficient to + choose at least one worker by task. This constraint can be expressed by a simple linear inequality. ''' @@ -63,10 +63,10 @@ from constraint_solver import pywrapcp def main(): - + # Create the solver. solver = pywrapcp.Solver('Set covering') - + # # data # @@ -114,7 +114,7 @@ def main(): # (also, make 0-base) b = solver.Sum([Hire[c-1] for c in Qualified[j]]) solver.Add(b >= 1) - + # objective: Minimize total cost @@ -122,32 +122,32 @@ def main(): # # search and result - # + # db = solver.Phase(Hire, solver.CHOOSE_FIRST_UNBOUND, solver.ASSIGN_MIN_VALUE) solver.NewSearch(db, [objective]) - + num_solutions = 0 while solver.NextSolution(): num_solutions += 1 - print "Total cost", total_cost.Value() - print "We should hire these workers: ", + print "Total cost", total_cost.Value() + print "We should hire these workers: ", for w in Workers: if Hire[w].Value() == 1: print w, print print - + solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/crew.py b/python/crew.py index e3f7cbfcc3..3a13a7ffc5 100644 --- a/python/crew.py +++ b/python/crew.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -69,7 +69,7 @@ def main(sols=1): "Heather", "Juliet" ] - + num_persons = len(names) # number of persons attributes = [ @@ -135,10 +135,10 @@ def main(sols=1): # constraints # - # number of working persons + # number of working persons solver.Add(num_working == solver.Sum( [solver.IsGreaterOrEqualCstVar(solver.Sum([crew[(f,p)] - for f in range(num_flights)]), 1) + for f in range(num_flights)]), 1) for p in range(num_persons) ]) ) for f in range(num_flights): @@ -175,7 +175,7 @@ def main(sols=1): # # result - # + # solver.NewSearch(db) num_solutions = 0 while solver.NextSolution(): @@ -205,16 +205,16 @@ def main(sols=1): print flight, print print - + if num_solutions >= sols: break solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() num_solutions_to_show = 1 if __name__ == '__main__': diff --git a/python/crossword2.py b/python/crossword2.py index 6e7f1458e5..79431c4b58 100644 --- a/python/crossword2.py +++ b/python/crossword2.py @@ -165,9 +165,9 @@ def main(_): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() def print_solution(A, E, alpha, n, word_len): diff --git a/python/crypta.py b/python/crypta.py index 1e0af80ae4..b8adbfa755 100644 --- a/python/crypta.py +++ b/python/crypta.py @@ -110,9 +110,9 @@ def main(): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/crypto.py b/python/crypto.py index 1b94a3bc7c..12d87917ad 100644 --- a/python/crypto.py +++ b/python/crypto.py @@ -133,9 +133,9 @@ def main(): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/curious_set_of_integers.py b/python/curious_set_of_integers.py index e11fee6145..2e29ccd117 100644 --- a/python/curious_set_of_integers.py +++ b/python/curious_set_of_integers.py @@ -121,9 +121,9 @@ def main(): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/debruijn_binary.py b/python/debruijn_binary.py index 167f4f77b2..fa95c7b209 100644 --- a/python/debruijn_binary.py +++ b/python/debruijn_binary.py @@ -174,9 +174,9 @@ def main(base=2, n=3, m=8): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() diff --git a/python/diet1.py b/python/diet1.py index 6dbe4a9ae3..0f8c9b04fa 100644 --- a/python/diet1.py +++ b/python/diet1.py @@ -105,9 +105,9 @@ def main(unused_argv): print "cost:", collector.objective_value(0) print [("abcdefghij"[i],collector.Value(0, x[i])) for i in range(n)] print - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() print diff --git a/python/diet1_b.py b/python/diet1_b.py index fd1e2e7f32..e9eaf425d8 100644 --- a/python/diet1_b.py +++ b/python/diet1_b.py @@ -105,9 +105,9 @@ def main(unused_argv): print "cost:", collector.objective_value(0) print [("abcdefghij"[i], collector.Value(0, x[i])) for i in range(n)] print - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() print diff --git a/python/diet1_mip.py b/python/diet1_mip.py index 89f751a5e4..91872d61f3 100644 --- a/python/diet1_mip.py +++ b/python/diet1_mip.py @@ -40,7 +40,7 @@ from linear_solver import pywraplp def main(sol = 'GLPK'): - + # Create the solver. print 'Solver: ', sol @@ -98,10 +98,10 @@ def main(sol = 'GLPK'): print [int(x[i].solution_value()) for i in range(n)] print - print "wall_time:", solver.wall_time() + print "WallTime:", solver.WallTime() if sol == 'CBC': print 'iterations:', solver.iterations() - + if __name__ == '__main__': @@ -112,5 +112,5 @@ if __name__ == '__main__': if sol != 'GLPK' and sol != 'CBC': print 'Solver must be either GLPK or CBC' sys.exit(1) - + main(sol) diff --git a/python/discrete_tomography.py b/python/discrete_tomography.py index 89150160c4..984f16b750 100644 --- a/python/discrete_tomography.py +++ b/python/discrete_tomography.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -28,22 +28,22 @@ ?- go. 0 0 7 1 6 3 4 5 2 7 0 0 - 0 - 0 - 8 * * * * * * * * - 2 * * - 6 * * * * * * - 4 * * * * - 5 * * * * * - 3 * * * - 7 * * * * * * * - 0 - 0 + 0 + 0 + 8 * * * * * * * * + 2 * * + 6 * * * * * * + 4 * * * * + 5 * * * * * + 3 * * * + 7 * * * * * * * + 0 + 0 Eclipse solution by Joachim Schimpf, IC-Parc ''' - Compare with the following models: + Compare with the following models: * Comet: http://www.hakank.org/comet/discrete_tomography.co * Gecode: http://www.hakank.org/gecode/discrete_tomography.cpp * MiniZinc: http://www.hakank.org/minizinc/tomography.mzn @@ -58,7 +58,7 @@ from constraint_solver import pywrapcp def main(row_sums="", col_sums=""): - + # Create the solver. solver = pywrapcp.Solver('n-queens') @@ -82,13 +82,13 @@ def main(row_sums="", col_sums=""): for j in range(c): t.append(solver.IntVar(0,1, 'x[%i,%i]'%(i,j))) x.append(t) - x_flat = [x[i][j] for i in range(r) for j in range(c)] + x_flat = [x[i][j] for i in range(r) for j in range(c)] # # constraints # [solver.Add(solver.Sum([x[i][j] for j in range(c)]) == row_sums[i]) for i in range(r)] - [solver.Add(solver.Sum([x[i][j] for i in range(r)]) == col_sums[j]) for j in range(c)] + [solver.Add(solver.Sum([x[i][j] for i in range(r)]) == col_sums[j]) for j in range(c)] # # solution and search @@ -101,22 +101,22 @@ def main(row_sums="", col_sums=""): db = solver.Phase(x_flat, solver.INT_VAR_SIMPLE, solver.ASSIGN_MIN_VALUE) - + solver.NewSearch(db) num_solutions = 0 while solver.NextSolution(): print_solution(x, r, c, row_sums, col_sums) print - - num_solutions += 1 + + num_solutions += 1 solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() # # Print solution @@ -125,7 +125,7 @@ def print_solution(x, rows, cols, row_sums, col_sums): print " ", for j in range(cols): print col_sums[j], - print + print for i in range(rows): print row_sums[i], for j in range(cols): @@ -145,7 +145,7 @@ def read_problem(file): col_sums = f.readline() row_sums = [int(r) for r in (row_sums.rstrip()).split(",")] col_sums = [int(c) for c in (col_sums.rstrip()).split(",")] - + return [row_sums, col_sums] if __name__ == '__main__': diff --git a/python/divisible_by_9_through_1.py b/python/divisible_by_9_through_1.py index 8c6961d505..0c53a89e62 100644 --- a/python/divisible_by_9_through_1.py +++ b/python/divisible_by_9_through_1.py @@ -157,9 +157,9 @@ def main(base=10): solver.EndSearch() print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() base = 10 diff --git a/python/dudeney.py b/python/dudeney.py index 3b969075f0..b705e67aea 100644 --- a/python/dudeney.py +++ b/python/dudeney.py @@ -32,12 +32,12 @@ def dudeney(n): solver.INT_VALUE_DEFAULT), [collector]) - for i in range(collector.solution_count()): + for i in range(collector.SolutionCount()): nbsol = collector.Value(i, nb) print nbsol - print '#fails:', solver.failures() - print 'time:', solver.wall_time(), 'ms' + print '#fails:', solver.Failures() + print 'time:', solver.WallTime(), 'ms' if __name__ == '__main__': dudeney(6) diff --git a/python/einav_puzzle.py b/python/einav_puzzle.py index 78a1bedcdf..0fad820430 100644 --- a/python/einav_puzzle.py +++ b/python/einav_puzzle.py @@ -1,22 +1,22 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the 'License'); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an 'AS IS' BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ A programming puzzle from Einav in Google CP Solver. - From + From 'A programming puzzle from Einav' http://gcanyon.wordpress.com/2009/10/28/a-programming-puzzle-from-einav/ ''' @@ -25,7 +25,7 @@ 33 30 -10 -6 18 7 -11 -23 6 ... -25 4 16 30 33 -23 -4 4 -23 - + You can flip the sign of entire rows and columns, as many of them as you like. The goal is to make all the rows and columns sum to positive numbers (or zero), and then to find the solution (there are more than one) @@ -37,16 +37,16 @@ 33 30 -10 -16 19 9 17 12 14 - Now all the rows and columns have positive sums, and the overall total is + Now all the rows and columns have positive sums, and the overall total is 108. - But you could instead flip the second and third columns, and the second + But you could instead flip the second and third columns, and the second row, to get this array: 33 -30 10 16 19 9 -17 12 14 - All the rows and columns still total positive, and the overall sum is just + All the rows and columns still total positive, and the overall sum is just 66. So this solution is better (I don't know if it's the best) - A pure brute force solution would have to try over 30 billion solutions. + A pure brute force solution would have to try over 30 billion solutions. I wrote code to solve this in J. I'll post that separately. ''' @@ -55,9 +55,9 @@ * SICStus: http://hakank.org/sicstus/einav_puzzle.pl Note: - einav_puzzle2.py is Laurent Perron version, which don't use as many + einav_puzzle2.py is Laurent Perron version, which don't use as many decision variables as this version. - + This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ @@ -67,10 +67,10 @@ from constraint_solver import pywrapcp def main(): - + # Create the solver. solver = pywrapcp.Solver('Einav puzzle') - + # # data # @@ -83,7 +83,7 @@ def main(): # [-16, 19, 9], # [-17, -12, -14] # ] - + # Full problem rows = 27 cols = 9 @@ -136,11 +136,11 @@ def main(): row_signs = [solver.IntVar([-1, 1], 'row_signs(%i)' % i) for i in range(rows)] col_signs = [solver.IntVar([-1, 1], 'col_signs(%i)' % j) - for j in range(cols)] + for j in range(cols)] # total sum: to be minimized total_sum = solver.IntVar(0, 1000, 'total_sum') - + # # constraints # @@ -186,21 +186,21 @@ def main(): print 'row_sums:', [row_sums[i].Value() for i in range(rows)] print 'col_sums:', [col_sums[j].Value() for j in range(cols)] print 'row_signs:', [row_signs[i].Value() for i in range(rows)] - print 'col_signs:', [col_signs[j].Value() for j in range(cols)] + print 'col_signs:', [col_signs[j].Value() for j in range(cols)] print 'x:' for i in range(rows): for j in range(cols): print '%3i' % x[i,j].Value(), print print - + solver.EndSearch() - + print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': diff --git a/python/einav_puzzle2.py b/python/einav_puzzle2.py index 49dc4e63c3..c5e8d58647 100644 --- a/python/einav_puzzle2.py +++ b/python/einav_puzzle2.py @@ -190,9 +190,9 @@ def main(): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/eq10.py b/python/eq10.py index 1ad3a00ebd..24167f8dc6 100644 --- a/python/eq10.py +++ b/python/eq10.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -31,10 +31,10 @@ from constraint_solver import pywrapcp def main(): - + # Create the solver. solver = pywrapcp.Solver('Eq 10') - + # # data # @@ -49,40 +49,40 @@ def main(): # # constraints # - solver.Add(0+98527*X1+34588*X2+5872*X3+59422*X5+65159*X7 + solver.Add(0+98527*X1+34588*X2+5872*X3+59422*X5+65159*X7 == 1547604+30704*X4+29649*X6) - solver.Add(0+98957*X2+83634*X3+69966*X4+62038*X5+37164*X6+85413*X7 + solver.Add(0+98957*X2+83634*X3+69966*X4+62038*X5+37164*X6+85413*X7 == 1823553+93989*X1) - solver.Add(900032+10949*X1+77761*X2+67052*X5 + solver.Add(900032+10949*X1+77761*X2+67052*X5 == 0+80197*X3+61944*X4+92964*X6+44550*X7) - solver.Add(0+73947*X1+84391*X3+81310*X5 + solver.Add(0+73947*X1+84391*X3+81310*X5 == 1164380+96253*X2+44247*X4+70582*X6+33054*X7) - solver.Add(0+13057*X3+42253*X4+77527*X5+96552*X7 + solver.Add(0+13057*X3+42253*X4+77527*X5+96552*X7 == 1185471+60152*X1+21103*X2+97932*X6) - solver.Add(1394152+66920*X1+55679*X4 + solver.Add(1394152+66920*X1+55679*X4 == 0+64234*X2+65337*X3+45581*X5+67707*X6+98038*X7) - solver.Add(0+68550*X1+27886*X2+31716*X3+73597*X4+38835*X7 + solver.Add(0+68550*X1+27886*X2+31716*X3+73597*X4+38835*X7 == 279091+88963*X5+76391*X6) - solver.Add(0+76132*X2+71860*X3+22770*X4+68211*X5+78587*X6 + solver.Add(0+76132*X2+71860*X3+22770*X4+68211*X5+78587*X6 == 480923+48224*X1+82817*X7) - solver.Add(519878+94198*X2+87234*X3+37498*X4 + solver.Add(519878+94198*X2+87234*X3+37498*X4 == 0+71583*X1+25728*X5+25495*X6+70023*X7) - solver.Add(361921+78693*X1+38592*X5+38478*X6 + solver.Add(361921+78693*X1+38592*X5+38478*X6 == 0+94129*X2+43188*X3+82528*X4+69025*X7) # # search and result - # + # db = solver.Phase(X, solver.INT_VAR_SIMPLE, solver.INT_VALUE_SIMPLE) @@ -94,14 +94,14 @@ def main(): num_solutions += 1 print "X:", [X[i].Value() for i in range(n)] print - + solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/eq20.py b/python/eq20.py index c2758d9b6e..1e027991c8 100644 --- a/python/eq20.py +++ b/python/eq20.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -22,7 +22,7 @@ * Gecode/R: http://hakank.org/gecode_r/eq20.rb * ECLiPSe: http://hakank.org/eclipse/eq20.ecl * SICStus: http://hakank.org/sicstus/eq20.pl - + This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ """ @@ -31,10 +31,10 @@ from constraint_solver import pywrapcp def main(): - + # Create the solver. solver = pywrapcp.Solver('Eq 20') - + # # data # @@ -49,31 +49,31 @@ def main(): # # constraints # - solver.Add(-76706*X0 + 98205*X1 + 23445*X2 + 67921*X3 + 24111*X4 + + solver.Add(-76706*X0 + 98205*X1 + 23445*X2 + 67921*X3 + 24111*X4 + -48614*X5 + -41906*X6 == 821228) solver.Add(87059*X0 + -29101*X1 + -5513*X2 + -21219*X3 + 22128*X4 + 7276*X5 + 57308*X6 == 22167) - solver.Add(-60113*X0 + 29475*X1 + 34421*X2 + -76870*X3 + 62646*X4 + + solver.Add(-60113*X0 + 29475*X1 + 34421*X2 + -76870*X3 + 62646*X4 + 29278*X5 + -15212*X6 == 251591) - solver.Add(49149*X0 + 52871*X1 + -7132*X2 + 56728*X3 + -33576*X4 + + solver.Add(49149*X0 + 52871*X1 + -7132*X2 + 56728*X3 + -33576*X4 + -49530*X5 + -62089*X6 == 146074) - solver.Add(-10343*X0 + 87758*X1 + -11782*X2 + 19346*X3 + 70072*X4 + + solver.Add(-10343*X0 + 87758*X1 + -11782*X2 + 19346*X3 + 70072*X4 + -36991*X5 + 44529*X6 == 740061) solver.Add(85176*X0 + -95332*X1 + -1268*X2 + 57898*X3 + 15883*X4 + 50547*X5 + 83287*X6 == 373854) solver.Add(-85698*X0 + 29958*X1 + 57308*X2 + 48789*X3 + -78219*X4 + 4657*X5 + 34539*X6 == 249912) - solver.Add(-67456*X0 + 84750*X1 + -51553*X2 + 21239*X3 + 81675*X4 + + solver.Add(-67456*X0 + 84750*X1 + -51553*X2 + 21239*X3 + 81675*X4 + -99395*X5 + -4254*X6 == 277271) - solver.Add(94016*X0 + -82071*X1 + 35961*X2 + 66597*X3 + -30705*X4 + + solver.Add(94016*X0 + -82071*X1 + 35961*X2 + 66597*X3 + -30705*X4 + -44404*X5 + -38304*X6 == 25334) - solver.Add(-60301*X0 + 31227*X1 + 93951*X2 + 73889*X3 + 81526*X4 + + solver.Add(-60301*X0 + 31227*X1 + 93951*X2 + 73889*X3 + 81526*X4 + -72702*X5 + 68026*X6 == 1410723) - solver.Add(-16835*X0 + 47385*X1 + 97715*X2 + -12640*X3 + 69028*X4 + + solver.Add(-16835*X0 + 47385*X1 + 97715*X2 + -12640*X3 + 69028*X4 + 76212*X5 + -81102*X6 == 1244857) solver.Add(-43277*X0 + 43525*X1 + 92298*X2 + 58630*X3 + 92590*X4 + -9372*X5 + -60227*X6 == 1503588) - solver.Add(-64919*X0 + 80460*X1 + 90840*X2 + -59624*X3 + -75542*X4 + + solver.Add(-64919*X0 + 80460*X1 + 90840*X2 + -59624*X3 + -75542*X4 + 25145*X5 + -47935*X6 == 18465) solver.Add(-45086*X0 + 51830*X1 + -4578*X2 + 96120*X3 + 21231*X4 + 97919*X5 + 65651*X6 == 1198280) @@ -81,19 +81,19 @@ def main(): 78169*X5 + -79785*X6 == 90614) solver.Add(8874*X0 + -58412*X1 + 73947*X2 + 17147*X3 + 62335*X4 + 16005*X5 + 8632*X6 == 752447) - solver.Add(71202*X0 + -11119*X1 + 73017*X2 + -38875*X3 + -14413*X4 + + solver.Add(71202*X0 + -11119*X1 + 73017*X2 + -38875*X3 + -14413*X4 + -29234*X5 + 72370*X6 == 129768) solver.Add(1671*X0 + -34121*X1 + 10763*X2 + 80609*X3 + 42532*X4 + 93520*X5 + -33488*X6 == 915683) solver.Add(51637*X0 + 67761*X1 + 95951*X2 + 3834*X3 + -96722*X4 + 59190*X5 + 15280*X6 == 533909) - solver.Add(-16105*X0 + 62397*X1 + -6704*X2 + 43340*X3 + 95100*X4 + + solver.Add(-16105*X0 + 62397*X1 + -6704*X2 + 43340*X3 + 95100*X4 + -68610*X5 + 58301*X6 == 876370) # # search and result - # + # db = solver.Phase(X, solver.CHOOSE_FIRST_UNBOUND, solver.ASSIGN_MIN_VALUE) @@ -105,14 +105,14 @@ def main(): num_solutions += 1 print "X:", [X[i].Value() for i in range(n)] print - + solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/fill_a_pix.py b/python/fill_a_pix.py index 161865ec28..47e347e458 100644 --- a/python/fill_a_pix.py +++ b/python/fill_a_pix.py @@ -18,20 +18,20 @@ From http://www.conceptispuzzles.com/index.aspx?uri=puzzle/fill-a-pix/basiclogic ''' - Each puzzle consists of a grid containing clues in various places. The - object is to reveal a hidden picture by painting the squares around each - clue so that the number of painted squares, including the square with - the clue, matches the value of the clue. + Each puzzle consists of a grid containing clues in various places. The + object is to reveal a hidden picture by painting the squares around each + clue so that the number of painted squares, including the square with + the clue, matches the value of the clue. ''' - + http://www.conceptispuzzles.com/index.aspx?uri=puzzle/fill-a-pix/rules ''' - Fill-a-Pix is a Minesweeper-like puzzle based on a grid with a pixilated - picture hidden inside. Using logic alone, the solver determines which - squares are painted and which should remain empty until the hidden picture + Fill-a-Pix is a Minesweeper-like puzzle based on a grid with a pixilated + picture hidden inside. Using logic alone, the solver determines which + squares are painted and which should remain empty until the hidden picture is completely exposed. ''' - + Fill-a-pix History: http://www.conceptispuzzles.com/index.aspx?uri=puzzle/fill-a-pix/history @@ -53,7 +53,7 @@ import sys from constraint_solver import pywrapcp -# Puzzle 1 from +# Puzzle 1 from # http://www.conceptispuzzles.com/index.aspx?uri=puzzle/fill-a-pix/rules default_n = 10 X = -1 @@ -88,7 +88,7 @@ def main(puzzle='', n=''): print 'n:', n # for the neighbors of 'this' cell - S = [-1,0,1] + S = [-1,0,1] # print problem instance print 'Problem:' @@ -134,7 +134,7 @@ def main(puzzle='', n=''): db = solver.Phase(pict_flat, solver.INT_VAR_DEFAULT, solver.INT_VALUE_DEFAULT) - + solver.NewSearch(db) num_solutions = 0 print "Solution:" @@ -151,9 +151,9 @@ def main(puzzle='', n=''): print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' # diff --git a/python/furniture_moving.py b/python/furniture_moving.py index 47cd3b56bb..6a87354940 100644 --- a/python/furniture_moving.py +++ b/python/furniture_moving.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -31,7 +31,7 @@ * SICStus: http://hakank.org/sicstus/furniture_moving.pl * Zinc: http://hakank.org/minizinc/furniture_moving.zinc - + This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ """ @@ -60,7 +60,7 @@ from constraint_solver import pywrapcp # b: resource limit assumption: IntVar or int # def my_cumulative(solver, s, d, r, b): - + # tasks = [i for i in range(len(s))] tasks = [i for i in range(len(s)) if r[i] > 0 and d[i] > 0] times_min = min([s[i].Min() for i in tasks]) @@ -69,14 +69,14 @@ def my_cumulative(solver, s, d, r, b): bb = [] for i in tasks: c1 = solver.IsLessOrEqualCstVar(s[i], t) # s[i] <= t - c2 = solver.IsGreaterCstVar(s[i]+d[i], t) # t < s[i] + d[i] + c2 = solver.IsGreaterCstVar(s[i]+d[i], t) # t < s[i] + d[i] bb.append(c1*c2*r[i]) solver.Add(solver.Sum(bb) <= b) # Somewhat experimental: # This constraint is needed to contrain the upper limit of b. if not isinstance(b, int): - solver.Add(b <= sum(r)) + solver.Add(b <= sum(r)) def main(): @@ -86,7 +86,7 @@ def main(): # # data - # + # n = 4 duration = [30,10,15,15] demand = [ 3, 1, 3, 2] @@ -117,7 +117,7 @@ def main(): # # Some extra constraints to play with # - + ## all tasks must end within an hour # solver.Add(end_time <= 60) @@ -125,16 +125,16 @@ def main(): # for i in range(n): # solver.Add(start_times[i] == 0) - + ## limitation of the number of people # solver.Add(num_resources <= 3) # # objective - # + # # objective = solver.Minimize(end_time, 1) - objective = solver.Minimize(num_resources, 1) + objective = solver.Minimize(num_resources, 1) # # solution and search @@ -143,7 +143,7 @@ def main(): solution.Add(start_times) solution.Add(end_times) solution.Add(end_time) - solution.Add(num_resources) + solution.Add(num_resources) db = solver.Phase(start_times, solver.CHOOSE_FIRST_UNBOUND, @@ -151,25 +151,25 @@ def main(): # # result - # + # solver.NewSearch(db, [objective]) num_solutions = 0 while solver.NextSolution(): num_solutions += 1 - print "num_resources:", num_resources.Value() + print "num_resources:", num_resources.Value() print "start_times :", [start_times[i].Value() for i in range(n)] - print "duration :", [duration[i] for i in range(n)] + print "duration :", [duration[i] for i in range(n)] print "end_times :", [end_times[i].Value() for i in range(n)] print "end_time :", end_time.Value() print solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': main() diff --git a/python/futoshiki.py b/python/futoshiki.py index 61bf293238..787e0abd66 100644 --- a/python/futoshiki.py +++ b/python/futoshiki.py @@ -118,9 +118,9 @@ def main(values, lt): solver.EndSearch() print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() # diff --git a/python/game_theory_taha.py b/python/game_theory_taha.py index 8d01b03585..6fa66c29d5 100644 --- a/python/game_theory_taha.py +++ b/python/game_theory_taha.py @@ -18,7 +18,7 @@ 2 player zero sum game. - From Taha, Operations Research (8'th edition), page 528. + From Taha, Operations Research (8'th edition), page 528. This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ @@ -28,7 +28,7 @@ import sys from linear_solver import pywraplp def main(sol = 'GLPK'): - + # Create the solver. # using GLPK @@ -44,9 +44,9 @@ def main(sol = 'GLPK'): # data rows = 3 cols = 3 - + game = [[3.0, -1.0, -3.0], - [-2.0, 4.0, -1.0], + [-2.0, 4.0, -1.0], [-5.0, -6.0, 2.0] ] @@ -109,10 +109,10 @@ def main(sol = 'GLPK'): print - print 'walltime :', solver.wall_time(), 'ms' + print 'walltime :', solver.WallTime(), 'ms' print 'iterations:', solver.iterations() print - + if __name__ == '__main__': sol = 'GLPK' @@ -121,5 +121,5 @@ if __name__ == '__main__': if sol != 'GLPK' and sol != 'CBC': print 'Solver must be either GLPK or CBC' sys.exit(1) - + main(sol) diff --git a/python/golomb8.py b/python/golomb8.py index 74fddb8dc0..4f33679982 100644 --- a/python/golomb8.py +++ b/python/golomb8.py @@ -63,16 +63,16 @@ def main(unused_argv): solver.CHOOSE_FIRST_UNBOUND, solver.ASSIGN_MIN_VALUE), [objective, collector]) - for i in range(0, collector.solution_count()): + for i in range(0, collector.SolutionCount()): obj_value = collector.Value(i, marks[size -1]) - time = collector.wall_time(i) + time = collector.WallTime(i) branches = collector.branches(i) failures = collector.failures(i) print ('Solution #%i: value = %i, failures = %i, branches = %i,' 'time = %i ms') % (i, obj_value, failures, branches, time) - time = solver.wall_time() - branches = solver.branches() - failures = solver.failures() + time = solver.WallTime() + branches = solver.Branches() + failures = solver.Failures() print ('Total run : failures = %i, branches = %i, time = %i ms' % (failures, branches, time)) diff --git a/python/grocery.py b/python/grocery.py index 401844fbdc..3020bb5997 100644 --- a/python/grocery.py +++ b/python/grocery.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -43,16 +43,16 @@ from constraint_solver import pywrapcp def main(): - + # Create the solver. solver = pywrapcp.Solver('Grocery') - + # # data # - n = 4 + n = 4 c = 711 - + # # declare variables # @@ -62,7 +62,7 @@ def main(): # constraints # solver.Add(solver.Sum(item) == c) - solver.Add(reduce(lambda x, y: x * y, item) == c * 100**3) + solver.Add(reduce(lambda x, y: x * y, item) == c * 100**3) # symmetry breaking for i in range(1,n): @@ -70,25 +70,25 @@ def main(): # # search and result - # + # db = solver.Phase(item, solver.INT_VAR_SIMPLE, solver.INT_VALUE_SIMPLE) - + solver.NewSearch(db) num_solutions = 0 while solver.NextSolution(): print "item:", [item[i].Value() for i in range(n)] print num_solutions += 1 - + solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': main() diff --git a/python/hidato.py b/python/hidato.py index a9dd816e70..260284f523 100644 --- a/python/hidato.py +++ b/python/hidato.py @@ -228,9 +228,9 @@ def main(): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() def print_board(x, rows, cols): diff --git a/python/hidato_table.py b/python/hidato_table.py index 2462b688e8..0e0db5d62f 100644 --- a/python/hidato_table.py +++ b/python/hidato_table.py @@ -175,9 +175,9 @@ def Solve(model): solver.EndSearch() print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time() + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime() def PrintOneSolution(positions, rows, cols, num_solution): diff --git a/python/integer_programming.py b/python/integer_programming.py index 3c3263f9f0..5787fae7a9 100644 --- a/python/integer_programming.py +++ b/python/integer_programming.py @@ -25,7 +25,7 @@ def RunIntegerExampleNaturalLanguageAPI(optimization_problem_type): """Example of simple integer program with natural language API.""" solver = pywraplp.Solver('RunIntegerExampleNaturalLanguageAPI', optimization_problem_type) - infinity = solver.infinity() + infinity = solver.Infinity() # x1 and x2 are integer non-negative variables. x1 = solver.IntVar(0.0, infinity, 'x1') x2 = solver.IntVar(0.0, infinity, 'x2') @@ -40,7 +40,7 @@ def RunIntegerExampleCppStyleAPI(optimization_problem_type): """Example of simple integer program with the C++ style API.""" solver = pywraplp.Solver('RunIntegerExampleCppStyleAPI', optimization_problem_type) - infinity = solver.infinity() + infinity = solver.Infinity() # x1 and x2 are integer non-negative variables. x1 = solver.IntVar(0.0, infinity, 'x1') x2 = solver.IntVar(0.0, infinity, 'x2') @@ -67,17 +67,17 @@ def SolveAndPrint(solver, variable_list): # The problem has an optimal solution. assert result_status == pywraplp.Solver.OPTIMAL - print 'Problem solved in %f milliseconds' % solver.wall_time() + print 'Problem solved in %f milliseconds' % solver.WallTime() # The objective value of the solution. - print 'Optimal objective value = %f' % solver.objective_value() + print 'Optimal objective value = %f' % solver.ObjectiveValue() # The value of each variable in the solution. for variable in variable_list: - print '%s = %f' % (variable.name(), variable.solution_value()) + print '%s = %f' % (variable.name(), variable.SolutionValue()) print 'Advanced usage:' - print 'Problem solved in %d branch-and-bound nodes' % solver.nodes() + print 'Problem solved in %d branch-and-bound nodes' % solver.Nodes() def Announce(solver, api_type): diff --git a/python/just_forgotten.py b/python/just_forgotten.py index dd0106aa1a..6e65a1adc8 100644 --- a/python/just_forgotten.py +++ b/python/just_forgotten.py @@ -110,9 +110,9 @@ def main(): solver.EndSearch() print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': main() diff --git a/python/kakuro.py b/python/kakuro.py index 4b5c1ce435..edf7565057 100644 --- a/python/kakuro.py +++ b/python/kakuro.py @@ -194,9 +194,9 @@ def main(): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/kenken2.py b/python/kenken2.py index 69fff8996f..f3e0f7732f 100644 --- a/python/kenken2.py +++ b/python/kenken2.py @@ -195,9 +195,9 @@ def main(): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/killer_sudoku.py b/python/killer_sudoku.py index 1040748418..e9ccc6410c 100644 --- a/python/killer_sudoku.py +++ b/python/killer_sudoku.py @@ -192,9 +192,9 @@ def main(): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/knapsack_cp.py b/python/knapsack_cp.py index c326c7ac8e..f8fb1a7af6 100644 --- a/python/knapsack_cp.py +++ b/python/knapsack_cp.py @@ -1,15 +1,15 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and # limitations under the License. """ @@ -17,7 +17,7 @@ Knapsack problem in Google CP Solver. Simple knapsack problem. - + This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ """ @@ -32,7 +32,7 @@ def knapsack(solver, values, weights, n): solver.Add(solver.ScalProd(x, weights) <= n) return [x, z] - + def main(values, weights, n): # Create the solver. @@ -45,9 +45,9 @@ def main(values, weights, n): print "weights:", weights print "n:", n print - + # declare variables - + # # constraints @@ -64,28 +64,28 @@ def main(values, weights, n): # solution = solver.Assignment() solution.Add(x) - solution.Add(z) + solution.Add(z) # db: DecisionBuilder db = solver.Phase(x, solver.CHOOSE_FIRST_UNBOUND, solver.ASSIGN_MAX_VALUE) - + solver.NewSearch(db,[objective]) num_solutions = 0 - while solver.NextSolution(): + while solver.NextSolution(): print "x:", [x[i].Value() for i in range(len(values))] print "z:", z.Value() print - num_solutions += 1 + num_solutions += 1 solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() values = [15, 100, 90, 60, 40, 15, 10, 1, 12, 12, 100] diff --git a/python/knapsack_mip.py b/python/knapsack_mip.py index f863ccff3e..58a03c501c 100644 --- a/python/knapsack_mip.py +++ b/python/knapsack_mip.py @@ -25,7 +25,7 @@ import sys from linear_solver import pywraplp def main(sol = 'GLPK'): - + # Create the solver. print 'Solver: ', sol @@ -90,12 +90,12 @@ def main(sol = 'GLPK'): print 'take:', for i in items: - print int(take[i].solution_value()), + print int(take[i].solution_value()), print print - print 'walltime :', solver.wall_time(), 'ms' + print 'walltime :', solver.WallTime(), 'ms' if sol == 'CBC': print 'iterations:', solver.iterations() @@ -108,5 +108,5 @@ if __name__ == '__main__': if sol != 'GLPK' and sol != 'CBC': print 'Solver must be either GLPK or CBC' sys.exit(1) - + main(sol) diff --git a/python/labeled_dice.py b/python/labeled_dice.py index 71675d0997..dc6addb7f3 100644 --- a/python/labeled_dice.py +++ b/python/labeled_dice.py @@ -137,9 +137,9 @@ def main(): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': main() diff --git a/python/langford.py b/python/langford.py index 7833f90362..1e9f8899d2 100644 --- a/python/langford.py +++ b/python/langford.py @@ -100,9 +100,9 @@ def main(k=8, num_sol=0): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() k = 8 num_sol = 0 diff --git a/python/least_diff.py b/python/least_diff.py index 016539dfe7..1fbf504941 100644 --- a/python/least_diff.py +++ b/python/least_diff.py @@ -107,9 +107,9 @@ def main(unused_argv): print xval,"-", yval,"=", diffval print [("abcdefghij"[i], collector.Value(0, letters[i])) for i in range(10)] print - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() print if __name__ == '__main__': diff --git a/python/lectures.py b/python/lectures.py index e69402270e..2f21852d9c 100644 --- a/python/lectures.py +++ b/python/lectures.py @@ -56,7 +56,7 @@ def main(): # # data # - + # # The schedule requirements: # lecture a cannot be held at the same time as b @@ -113,9 +113,9 @@ def main(): db = solver.Phase(v, solver.CHOOSE_MIN_SIZE_LOWEST_MIN, solver.ASSIGN_CENTER_VALUE) - + solver.NewSearch(db, [objective]) - + num_solutions = 0 while solver.NextSolution(): num_solutions += 1 @@ -124,9 +124,9 @@ def main(): print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': diff --git a/python/linear_programming.py b/python/linear_programming.py index 8cbebcf019..fc2851bbbf 100644 --- a/python/linear_programming.py +++ b/python/linear_programming.py @@ -25,7 +25,7 @@ def RunLinearExampleNaturalLanguageAPI(optimization_problem_type): """Example of simple linear program with natural language API.""" solver = pywraplp.Solver('RunLinearExampleNaturalLanguageAPI', optimization_problem_type) - infinity = solver.infinity() + infinity = solver.Infinity() # x1, x2 and x3 are continuous non-negative variables. x1 = solver.NumVar(0.0, infinity, 'x1') x2 = solver.NumVar(0.0, infinity, 'x2') @@ -45,7 +45,7 @@ def RunLinearExampleCppStyleAPI(optimization_problem_type): """Example of simple linear program with the C++ style API.""" solver = pywraplp.Solver('RunLinearExampleCppStyle', optimization_problem_type) - infinity = solver.infinity() + infinity = solver.Infinity() # x1, x2 and x3 are continuous non-negative variables. x1 = solver.NumVar(0.0, infinity, 'x1') x2 = solver.NumVar(0.0, infinity, 'x2') @@ -88,23 +88,23 @@ def SolveAndPrint(solver, variable_list, constraint_list): # The problem has an optimal solution. assert result_status == pywraplp.Solver.OPTIMAL - print 'Problem solved in %f milliseconds' % solver.wall_time() + print 'Problem solved in %f milliseconds' % solver.WallTime() # The objective value of the solution. - print 'Optimal objective value = %f' % solver.objective_value() + print 'Optimal objective value = %f' % solver.ObjectiveValue() # The value of each variable in the solution. for variable in variable_list: - print '%s = %f' % (variable.name(), variable.solution_value()) + print '%s = %f' % (variable.name(), variable.SolutionValue()) print 'Advanced usage:' - print 'Problem solved in %d iterations' % solver.iterations() + print 'Problem solved in %d iterations' % solver.Iterations() for variable in variable_list: - print '%s: reduced cost = %f' % (variable.name(), variable.reduced_cost()) + print '%s: reduced cost = %f' % (variable.name(), variable.ReducedCost()) for i, constraint in enumerate(constraint_list): print ('constraint %d: dual value = %f\n' ' activity = %f' % - (i, constraint.dual_value(), constraint.activity())) + (i, constraint.DualValue(), constraint.Activity())) def Announce(solver, api_type): diff --git a/python/magic_square.py b/python/magic_square.py index 07fb2c66ec..2c0f57a3d0 100644 --- a/python/magic_square.py +++ b/python/magic_square.py @@ -95,9 +95,9 @@ def main(n=4): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() n = 4 if __name__ == '__main__': diff --git a/python/magic_square_and_cards.py b/python/magic_square_and_cards.py index 5ebd84f574..eeb3be87a3 100644 --- a/python/magic_square_and_cards.py +++ b/python/magic_square_and_cards.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -23,7 +23,7 @@ ''' - + This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ """ @@ -58,11 +58,11 @@ def main(n=3): solver.Add(solver.Distribute(x_flat, range(14), counts)) # the standard magic square constraints (sans all_different) - [solver.Add(solver.Sum([x[(i,j)] for j in range(n)]) == s) for i in range(n)] - [solver.Add(solver.Sum([x[(i,j)] for i in range(n)]) == s) for j in range(n)] + [solver.Add(solver.Sum([x[(i,j)] for j in range(n)]) == s) for i in range(n)] + [solver.Add(solver.Sum([x[(i,j)] for i in range(n)]) == s) for j in range(n)] solver.Add(solver.Sum([ x[(i,i)] for i in range(n)]) == s ) # diag 1 - solver.Add(solver.Sum([ x[(i,n-i-1)] for i in range(n)]) == s) # diag 2 + solver.Add(solver.Sum([ x[(i,n-i-1)] for i in range(n)]) == s) # diag 2 # redundant constraint solver.Add(solver.Sum(counts) == n*n) @@ -78,14 +78,14 @@ def main(n=3): solution = solver.Assignment() solution.Add(x_flat) solution.Add(s) - solution.Add(counts) + solution.Add(counts) # db: DecisionBuilder db = solver.Phase(x_flat, solver.CHOOSE_FIRST_UNBOUND, solver.ASSIGN_MAX_VALUE) - + solver.NewSearch(db,[objective]) num_solutions = 0 while solver.NextSolution(): @@ -97,14 +97,14 @@ def main(n=3): print print - num_solutions += 1 + num_solutions += 1 solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() n = 3 diff --git a/python/magic_square_mip.py b/python/magic_square_mip.py index 37bcf7a4b2..9215f3dc17 100644 --- a/python/magic_square_mip.py +++ b/python/magic_square_mip.py @@ -19,15 +19,15 @@ Translated from GLPK:s example magic.mod ''' MAGIC, Magic Square - + Written in GNU MathProg by Andrew Makhorin - + In recreational mathematics, a magic square of order n is an arrangement of n^2 numbers, usually distinct integers, in a square, such that n numbers in all rows, all columns, and both diagonals sum to the same constant. A normal magic square contains the integers from 1 to n^2. - + (From Wikipedia, the free encyclopedia.) ''' @@ -37,7 +37,7 @@ Here we also experiment with how long it takes when using an output_matrix (much longer). - + This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ """ @@ -50,7 +50,7 @@ from linear_solver import pywraplp # use_output_matrix: use the output_matrix # def main(n = 3, sol = 'GLPK', use_output_matrix = 0): - + # Create the solver. print 'Solver: ', sol @@ -114,14 +114,14 @@ def main(n = 3, sol = 'GLPK', use_output_matrix = 0): for i in range_n for j in range_n]) == 1) - # # the sum in each row must be the magic sum + # # the sum in each row must be the magic sum for i in range_n: solver.Add(solver.Sum([k * x[i,j,k] for j in range_n for k in range_N]) == s) # # the sum in each column must be the magic sum - for j in range_n: + for j in range_n: solver.Add(solver.Sum([k * x[i,j,k] for i in range_n for k in range_N]) == s) @@ -159,14 +159,14 @@ def main(n = 3, sol = 'GLPK', use_output_matrix = 0): print - print 's: ', int(s.solution_value()) + print 's: ', int(s.solution_value()) if use_output_matrix == 1: for i in range_n: for j in range_n: print int(square[i, j].solution_value()), print print - else: + else: for i in range_n: for j in range_n: print sum([int(k * x[i,j,k].solution_value()) for k in range_N]), " ", @@ -180,7 +180,7 @@ def main(n = 3, sol = 'GLPK', use_output_matrix = 0): print print - print 'walltime :', solver.wall_time(), 'ms' + print 'walltime :', solver.WallTime(), 'ms' if sol == 'CBC': print 'iterations:', solver.iterations() @@ -197,7 +197,7 @@ if __name__ == '__main__': if sol != 'GLPK' and sol != 'CBC': print 'Solver must be either GLPK or CBC' sys.exit(1) - + if len(sys.argv) > 3: use_output_matrix = int(sys.argv[3]) diff --git a/python/map.py b/python/map.py index 5c4195c7a9..43045d56c7 100644 --- a/python/map.py +++ b/python/map.py @@ -87,7 +87,7 @@ def main(): [collector]) - num_solutions = collector.solution_count() + num_solutions = collector.SolutionCount() print "num_solutions: ", num_solutions if num_solutions > 0: for s in range(num_solutions): @@ -96,9 +96,9 @@ def main(): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() else: print "No solutions found" diff --git a/python/marathon2.py b/python/marathon2.py index a3f4a86de6..3c94ba0216 100644 --- a/python/marathon2.py +++ b/python/marathon2.py @@ -129,9 +129,9 @@ def main(): print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': diff --git a/python/max_flow_taha.py b/python/max_flow_taha.py index 44db77bf6a..7803406930 100644 --- a/python/max_flow_taha.py +++ b/python/max_flow_taha.py @@ -17,9 +17,9 @@ Max flow problem in Google CP Solver. From Taha 'Introduction to Operations Research', Example 6.4-2 - + Translated from the AMPL code at - http://taha.ineg.uark.edu/maxflo.txt + http://taha.ineg.uark.edu/maxflo.txt Compare with the following model: * MiniZinc: http://www.hakank.org/minizinc/max_flow_taha.mzn @@ -34,7 +34,7 @@ def main(): # Create the solver. solver = pywrapcp.Solver('Max flow problem, Taha') - + # # data # @@ -65,7 +65,7 @@ def main(): x_flat = [x[i,j] for i in nodes for j in nodes] out_flow = [solver.IntVar(0, 10000, 'out_flow[%i]' % i) for i in nodes] - in_flow = [solver.IntVar(0, 10000, 'in_flow[%i]' % i) for i in nodes] + in_flow = [solver.IntVar(0, 10000, 'in_flow[%i]' % i) for i in nodes] total = solver.IntVar(0, 10000, 'z') @@ -109,14 +109,14 @@ def main(): db = solver.Phase(x_flat, solver.INT_VAR_DEFAULT, solver.ASSIGN_MAX_VALUE) - + solver.NewSearch(db, [objective]) num_solutions = 0 while solver.NextSolution(): num_solutions += 1 - print 'total:', total.Value() + print 'total:', total.Value() print 'in_flow:', [in_flow[i].Value() for i in nodes] - print 'out_flow:', [out_flow[i].Value() for i in nodes] + print 'out_flow:', [out_flow[i].Value() for i in nodes] for i in nodes: for j in nodes: print '%2i' % x[i,j].Value(), @@ -124,9 +124,9 @@ def main(): print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': main() diff --git a/python/max_flow_winston1.py b/python/max_flow_winston1.py index 446e7695b2..6e7c4bf2c5 100644 --- a/python/max_flow_winston1.py +++ b/python/max_flow_winston1.py @@ -55,7 +55,7 @@ def main(): [4, 5], [5, 1] ] - + # convert arcs to 0-based arcs = [] for (a_from, a_to) in arcs1: @@ -67,7 +67,7 @@ def main(): # capacities cap = [2,3,3,4,2,1,100] - + # convert arcs to matrix # for sanity checking below mat = {} @@ -100,12 +100,12 @@ def main(): # capacity of arcs for i in range(num_arcs): solver.Add(flow[arcs[i][0], arcs[i][1]] <= cap[i]) - + # inflows == outflows for i in nodes: s1 = solver.Sum([flow[arcs[k][0], arcs[k][1]] - for k in range(num_arcs) if arcs[k][1] == i]) + for k in range(num_arcs) if arcs[k][1] == i]) s2 = solver.Sum([flow[arcs[k][0], arcs[k][1]] for k in range(num_arcs) if arcs[k][0] == i]) solver.Add(s1 == s2) @@ -127,7 +127,7 @@ def main(): db = solver.Phase(flow_flat, solver.INT_VAR_DEFAULT, solver.INT_VALUE_DEFAULT) - + solver.NewSearch(db, [objective]) num_solutions = 0 while solver.NextSolution(): @@ -140,9 +140,9 @@ def main(): print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': main() diff --git a/python/minesweeper.py b/python/minesweeper.py index 07c1c6a252..8d2bb23237 100644 --- a/python/minesweeper.py +++ b/python/minesweeper.py @@ -170,7 +170,7 @@ def main(game="", r="", c=""): solver.ASSIGN_MIN_VALUE), [collector]) - num_solutions = collector.solution_count() + num_solutions = collector.SolutionCount() print "num_solutions: ", num_solutions if num_solutions > 0: for s in range(num_solutions): @@ -184,9 +184,9 @@ def main(game="", r="", c=""): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() else: print "No solutions found" diff --git a/python/mr_smith.py b/python/mr_smith.py index 385819cadb..4abebdd8ba 100644 --- a/python/mr_smith.py +++ b/python/mr_smith.py @@ -61,7 +61,7 @@ def main(): # n = 5 - + # # declare variables # @@ -77,7 +77,7 @@ def main(): # I've kept the MiniZinc constraints for clarity # and debugging. # - + # If Mr Smith comes then his wife will come too. # (Mr_Smith -> Mrs_Smith) solver.Add(Mr_Smith-Mrs_Smith <= 0) @@ -106,9 +106,9 @@ def main(): db = solver.Phase(x, solver.INT_VAR_DEFAULT, solver.INT_VALUE_DEFAULT) - + solver.NewSearch(db) - + num_solutions = 0 while solver.NextSolution(): num_solutions += 1 @@ -116,9 +116,9 @@ def main(): print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': diff --git a/python/nonogram_default_search.py b/python/nonogram_default_search.py index 7f7e977601..28093575f4 100644 --- a/python/nonogram_default_search.py +++ b/python/nonogram_default_search.py @@ -90,7 +90,7 @@ def make_transition_tuples(pattern): def check_rule(rules, y): cleaned_rule = [rules[i] for i in range(len(rules)) if rules[i] > 0] (transition_tuples, last_state) = make_transition_tuples(cleaned_rule) - + initial_state = 1 accepting_states = [last_state] @@ -144,10 +144,10 @@ def main(rows, row_rule_len, row_rules, cols, col_rule_len, col_rules): # parameters = pywrapcp.DefaultPhaseParameters() parameters.heuristic_period = 200000 - - db = solver.DefaultPhase(board_label, parameters) - print 'before solver, wall time = ', solver.wall_time(), 'ms' + db = solver.DefaultPhase(board_label, parameters) + + print 'before solver, wall time = ', solver.WallTime(), 'ms' solver.NewSearch(db) num_solutions = 0 @@ -174,9 +174,9 @@ def main(rows, row_rule_len, row_rules, cols, col_rule_len, col_rules): solver.EndSearch() print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' # diff --git a/python/nonogram_regular.py b/python/nonogram_regular.py index 261b739813..bf63e32fd3 100644 --- a/python/nonogram_regular.py +++ b/python/nonogram_regular.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the 'License'); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an 'AS IS' BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -18,20 +18,20 @@ http://en.wikipedia.org/wiki/Nonogram ''' - Nonograms or Paint by Numbers are picture logic puzzles in which cells in a - grid have to be colored or left blank according to numbers given at the - side of the grid to reveal a hidden picture. In this puzzle type, the - numbers measure how many unbroken lines of filled-in squares there are - in any given row or column. For example, a clue of '4 8 3' would mean - there are sets of four, eight, and three filled squares, in that order, + Nonograms or Paint by Numbers are picture logic puzzles in which cells in a + grid have to be colored or left blank according to numbers given at the + side of the grid to reveal a hidden picture. In this puzzle type, the + numbers measure how many unbroken lines of filled-in squares there are + in any given row or column. For example, a clue of '4 8 3' would mean + there are sets of four, eight, and three filled squares, in that order, with at least one blank square between successive groups. - + ''' See problem 12 at http://www.csplib.org/. - + http://www.puzzlemuseum.com/nonogram.htm - + Haskell solution: http://twan.home.fmf.nl/blog/haskell/Nonograms.details @@ -44,7 +44,7 @@ was a major influence when writing this Google CP solver model. I have also blogged about the development of a Nonogram solver in Comet - using the regular constraint. + using the regular constraint. * 'Comet: Nonogram improved: solving problem P200 from 1:30 minutes to about 1 second' http://www.hakank.org/constraint_programming_blog/2009/03/comet_nonogram_improved_solvin_1.html @@ -54,15 +54,15 @@ http://www.hakank.org/constraint_programming_blog/2009/02/comet_regular_constraint_a_muc_1.html Compare with the other models: - * Gecode/R: http://www.hakank.org/gecode_r/nonogram.rb (using 'regexps') + * Gecode/R: http://www.hakank.org/gecode_r/nonogram.rb (using 'regexps') * MiniZinc: http://www.hakank.org/minizinc/nonogram_regular.mzn - * MiniZinc: http://www.hakank.org/minizinc/nonogram_create_automaton.mzn + * MiniZinc: http://www.hakank.org/minizinc/nonogram_create_automaton.mzn * MiniZinc: http://www.hakank.org/minizinc/nonogram_create_automaton2.mzn Note: nonogram_create_automaton2.mzn is the preferred model This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ - + """ import sys @@ -73,7 +73,7 @@ from constraint_solver import pywrapcp # # Global constraint regular # -# This is a translation of MiniZinc's regular constraint (defined in +# This is a translation of MiniZinc's regular constraint (defined in # lib/zinc/globals.mzn), via the Comet code refered above. # All comments are from the MiniZinc code. # ''' @@ -93,7 +93,7 @@ from constraint_solver import pywrapcp def regular(x, Q, S, d, q0, F): solver = x[0].solver() - + assert Q > 0, 'regular: "Q" must be greater than zero' assert S > 0, 'regular: "S" must be greater than zero' @@ -101,7 +101,7 @@ def regular(x, Q, S, d, q0, F): # each possible input; each extra transition is from state zero # to state zero. This allows us to continue even if we hit a # non-accepted input. - + # int d2[0..Q, 1..S] d2 = [] for i in range(Q+1): @@ -122,29 +122,29 @@ def regular(x, Q, S, d, q0, F): x_range = range(0,len(x)) m = 0 n = len(x) - + a = [solver.IntVar(0, Q+1, 'a[%i]' % i) for i in range(m, n+1)] - + # Check that the final state is in F solver.Add(solver.MemberCt(a[-1], F)) # First state is q0 - solver.Add(a[m] == q0) + solver.Add(a[m] == q0) for i in x_range: solver.Add(x[i] >= 1) solver.Add(x[i] <= S) # Determine a[i+1]: a[i+1] == d2[a[i], x[i]] solver.Add(a[i+1] == solver.Element(d2_flatten, ((a[i])*S)+(x[i]-1))) - + # # Make a transition (automaton) matrix from a # single pattern, e.g. [3,2,1] # def make_transition_matrix(pattern): - + p_len = len(pattern) num_states = p_len + sum(pattern) - + # this is for handling 0-clues. It generates # just the state 1,2 if num_states == 0: @@ -156,7 +156,7 @@ def make_transition_matrix(pattern): for j in range(2): row.append(0) t_matrix.append(row) - + # convert pattern to a 0/1 pattern for easy handling of # the states tmp = [0 for i in range(num_states)] @@ -172,7 +172,7 @@ def make_transition_matrix(pattern): t_matrix[num_states-1][0] = num_states t_matrix[num_states-1][1] = 0 - + for i in range(num_states): if tmp[i] == 0: t_matrix[i][0] = i+1 @@ -191,7 +191,7 @@ def make_transition_matrix(pattern): # for i in range(num_states): # for j in range(2): # print t_matrix[i][j], - # print + # print # print return t_matrix @@ -202,7 +202,7 @@ def make_transition_matrix(pattern): # def check_rule(rules, y): solver = y[0].solver() - + r_len = sum([1 for i in range(len(rules)) if rules[i] > 0]) rules_tmp = [] for i in range(len(rules)): @@ -224,7 +224,7 @@ def check_rule(rules, y): def main(rows, row_rule_len, row_rules, cols, col_rule_len, col_rules): - + # Create the solver. solver = pywrapcp.Solver('Regular test') @@ -250,11 +250,11 @@ def main(rows, row_rule_len, row_rules, for j in range(cols): board_label.append(board[i,j]) else: - for j in range(cols): + for j in range(cols): for i in range(rows): board_label.append(board[i,j]) - - + + # # constraints # @@ -266,19 +266,19 @@ def main(rows, row_rule_len, row_rules, check_rule([col_rules[j][k] for k in range(col_rule_len)], [board[i,j] for i in range(rows)]) - + # # solution and search # db = solver.Phase(board_label, - solver.CHOOSE_FIRST_UNBOUND, + solver.CHOOSE_FIRST_UNBOUND, solver.ASSIGN_MIN_VALUE) solver.NewSearch(db) - + num_solutions = 0 while solver.NextSolution(): - print + print num_solutions += 1 for i in range(rows): row = [board[i,j].Value()-1 for j in range(cols)] @@ -289,20 +289,20 @@ def main(rows, row_rule_len, row_rules, else: row_pres.append(' ') print ' ', ''.join(row_pres) - + print print ' ', '-' * cols - + if num_solutions >= 2: print '2 solutions is enough...' break - + solver.EndSearch() print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' diff --git a/python/nonogram_table.py b/python/nonogram_table.py index c6da7da519..f95bf521b1 100644 --- a/python/nonogram_table.py +++ b/python/nonogram_table.py @@ -294,9 +294,9 @@ def main(rows, row_rule_len, row_rules, solver.EndSearch() print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' diff --git a/python/nonogram_table2.py b/python/nonogram_table2.py index 141cc66e22..3b3c16237d 100644 --- a/python/nonogram_table2.py +++ b/python/nonogram_table2.py @@ -114,7 +114,7 @@ def make_transition_tuples(pattern): def check_rule(rules, y): cleaned_rule = [rules[i] for i in range(len(rules)) if rules[i] > 0] (transition_tuples, last_state) = make_transition_tuples(cleaned_rule) - + initial_state = 1 accepting_states = [last_state] @@ -170,7 +170,7 @@ def main(rows, row_rule_len, row_rules, cols, col_rule_len, col_rules): solver.CHOOSE_FIRST_UNBOUND, solver.ASSIGN_MIN_VALUE) - print 'before solver, wall time = ', solver.wall_time(), 'ms' + print 'before solver, wall time = ', solver.WallTime(), 'ms' solver.NewSearch(db) num_solutions = 0 @@ -197,9 +197,9 @@ def main(rows, row_rule_len, row_rules, cols, col_rule_len, col_rules): solver.EndSearch() print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' diff --git a/python/nontransitive_dice.py b/python/nontransitive_dice.py index e8d9f73551..6ca335ca57 100644 --- a/python/nontransitive_dice.py +++ b/python/nontransitive_dice.py @@ -1,33 +1,33 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ Nontransitive dice in Google CP Solver. - From + From http://en.wikipedia.org/wiki/Nontransitive_dice ''' - A set of nontransitive dice is a set of dice for which the relation - 'is more likely to roll a higher number' is not transitive. See also + A set of nontransitive dice is a set of dice for which the relation + 'is more likely to roll a higher number' is not transitive. See also intransitivity. - - This situation is similar to that in the game Rock, Paper, Scissors, - in which each element has an advantage over one choice and a + + This situation is similar to that in the game Rock, Paper, Scissors, + in which each element has an advantage over one choice and a disadvantage to the other. ''' - + I start with the 3 dice version ''' * die A has sides {2,2,4,4,9,9}, @@ -43,13 +43,13 @@ [2, 5, 5, 5, 5, 5], [1, 1, 4, 4, 4, 7]] max_win: 27 - + Number of solutions: 1 Nodes: 1649873 Time: 25.94 getFailures: 1649853 getBacktracks: 1649873 getPropags: 98105090 - + Max winnings where they are the same: 21 comp: [21, 21, 21] dice: @@ -71,7 +71,7 @@ import string from constraint_solver import pywrapcp def main(m=3, n=6, minimize_val=0): - + # Create the solver. solver = pywrapcp.Solver('Nontransitive dice') @@ -88,7 +88,7 @@ def main(m=3, n=6, minimize_val=0): dice = {} for i in range(m): for j in range(n): - dice[(i,j)] = solver.IntVar(1, n*2, 'dice(%i,%i)' % (i, j)) + dice[(i,j)] = solver.IntVar(1, n*2, 'dice(%i,%i)' % (i, j)) dice_flat = [dice[(i,j)] for i in range(m) for j in range(n)] comp = {} @@ -103,7 +103,7 @@ def main(m=3, n=6, minimize_val=0): gap_sum = solver.IntVar(0, m*n*n, "gap_sum") max_val = solver.IntVar(0, n*2, "max_val") - max_win = solver.IntVar(0, n*n, "max_win") + max_win = solver.IntVar(0, n*n, "max_win") # number of occurrences of each value of the dice counts = [solver.IntVar(0,n*m,"counts(%i)" %i) for i in range(n*2+1)] @@ -111,7 +111,7 @@ def main(m=3, n=6, minimize_val=0): # # constraints # - + # number of occurrences for each number solver.Add(solver.Distribute(dice_flat, range(n*2+1), counts)) @@ -127,7 +127,7 @@ def main(m=3, n=6, minimize_val=0): # probability gap [solver.Add(gap[i] == comp[i,0] - comp[i,1]) for i in range(m)] - [solver.Add(gap[i] > 0) for i in range(m)] + [solver.Add(gap[i] > 0) for i in range(m)] solver.Add(gap_sum == solver.Sum(gap)) # and now we roll... @@ -136,7 +136,7 @@ def main(m=3, n=6, minimize_val=0): b1 = [solver.MakeIsGreaterVar(dice[d % m, r1], dice[(d+1) % m, r2]) for r1 in range(n) for r2 in range(n)] solver.Add(comp[d%m,0] == solver.Sum(b1)) - + b2 = [solver.MakeIsGreaterVar(dice[(d+1) % m, r1], dice[d % m, r2]) for r1 in range(n) for r2 in range(n)] solver.Add(comp[d%m,1] == solver.Sum(b2)) @@ -148,7 +148,7 @@ def main(m=3, n=6, minimize_val=0): objective = solver.Minimize(max_val, 1) # other experiments # objective = solver.Maximize(max_win, 1) - # objective = solver.Maximize(gap_sum, 1) + # objective = solver.Maximize(gap_sum, 1) # # solution and search @@ -161,14 +161,14 @@ def main(m=3, n=6, minimize_val=0): solver.NewSearch(db, [objective]) else: solver.NewSearch(db) - + num_solutions = 0 while solver.NextSolution(): print "gap_sum:", gap_sum.Value() print "gap:", [gap[i].Value() for i in range(m)] print "max_val:", max_val.Value() print "max_win:", max_win.Value() - print "dice:" + print "dice:" for i in range(m): for j in range(n): print dice[(i,j)].Value(), @@ -184,12 +184,12 @@ def main(m=3, n=6, minimize_val=0): num_solutions += 1 solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() m = 3 # number of dice @@ -202,6 +202,6 @@ if __name__ == '__main__': n = string.atoi(sys.argv[2]) if len(sys.argv) > 3: minimize_val = string.atoi(sys.argv[3]) - + main(m, n, minimize_val) diff --git a/python/nqueens.py b/python/nqueens.py index ae4239803e..84c69dd32e 100644 --- a/python/nqueens.py +++ b/python/nqueens.py @@ -70,7 +70,7 @@ def main(n=8): [collector]) - num_solutions = collector.solution_count() + num_solutions = collector.SolutionCount() print "num_solutions: ", num_solutions if num_solutions > 0: for s in range(num_solutions): @@ -87,9 +87,9 @@ def main(n=8): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() else: print "No solutions found" diff --git a/python/nqueens2.py b/python/nqueens2.py index 35b853b03e..6c2dc39067 100644 --- a/python/nqueens2.py +++ b/python/nqueens2.py @@ -89,9 +89,9 @@ def main(n=8): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() n = 8 diff --git a/python/nqueens3.py b/python/nqueens3.py index f33995ae4e..7b0c3282a1 100644 --- a/python/nqueens3.py +++ b/python/nqueens3.py @@ -86,9 +86,9 @@ def main(n=8, num_sol=0, print_sol=1): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time(), "ms" + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime(), "ms" n = 8 diff --git a/python/nurse_rostering.py b/python/nurse_rostering.py index 16cd45fef5..9203e9c00b 100644 --- a/python/nurse_rostering.py +++ b/python/nurse_rostering.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -26,7 +26,7 @@ This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ - + """ from constraint_solver import pywrapcp @@ -35,7 +35,7 @@ from collections import defaultdict # # Global constraint regular # -# This is a translation of MiniZinc's regular constraint (defined in +# This is a translation of MiniZinc's regular constraint (defined in # lib/zinc/globals.mzn), via the Comet code refered above. # All comments are from the MiniZinc code. # ''' @@ -55,7 +55,7 @@ from collections import defaultdict def regular(x, Q, S, d, q0, F): solver = x[0].solver() - + assert Q > 0, 'regular: "Q" must be greater than zero' assert S > 0, 'regular: "S" must be greater than zero' @@ -63,7 +63,7 @@ def regular(x, Q, S, d, q0, F): # each possible input; each extra transition is from state zero # to state zero. This allows us to continue even if we hit a # non-accepted input. - + # Comet: int d2[0..Q, 1..S] d2 = [] for i in range(Q+1): @@ -84,25 +84,25 @@ def regular(x, Q, S, d, q0, F): x_range = range(0,len(x)) m = 0 n = len(x) - - a = [solver.IntVar(0, Q+1, 'a[%i]' % i) for i in range(m, n+1)] - + + a = [solver.IntVar(0, Q+1, 'a[%i]' % i) for i in range(m, n+1)] + # Check that the final state is in F solver.Add(solver.MemberCt(a[-1], F)) # First state is q0 - solver.Add(a[m] == q0) + solver.Add(a[m] == q0) for i in x_range: solver.Add(x[i] >= 1) solver.Add(x[i] <= S) - + # Determine a[i+1]: a[i+1] == d2[a[i], x[i]] solver.Add(a[i+1] == solver.Element(d2_flatten, ((a[i])*S)+(x[i]-1))) - + def main(): - + # Create the solver. solver = pywrapcp.Solver('Nurse rostering using regular') @@ -115,7 +115,7 @@ def main(): # on nurse_stat and/or day_stat. num_nurses = 7 num_days = 14 - + day_shift = 1 night_shift = 2 off_shift = 3 @@ -131,7 +131,7 @@ def main(): # d,n,o [2,3,1], # state 1 [4,4,1], # state 2 - [4,5,1], # state 3 + [4,5,1], # state 3 [6,6,1], # state 4 [6,0,1], # state 5 [0,0,1] # state 6 @@ -159,7 +159,7 @@ def main(): for j in shifts: day_stat[i,j] = solver.IntVar(0, num_nurses, 'day_stat[%i,%i]'% (i,j)) - day_stat_flat = [day_stat[i,j] for i in range(num_days) for j in shifts] + day_stat_flat = [day_stat[i,j] for i in range(num_days) for j in shifts] # @@ -183,8 +183,8 @@ def main(): # Each nurse must work between 7 and 10 # days during this period solver.Add(nurse_stat[i] >= 7) - solver.Add(nurse_stat[i] <= 10) - + solver.Add(nurse_stat[i] <= 10) + # # Statistics and constraints for each day @@ -202,36 +202,36 @@ def main(): # the number of shifts. # Using atleast constraints is much harder # in this model. - # + # if j % 7 == 5 or j % 7 == 6: # special constraints for the weekends solver.Add(day_stat[j,day_shift] == 2) solver.Add(day_stat[j,night_shift] == 1) - solver.Add(day_stat[j,off_shift] == 4 ) + solver.Add(day_stat[j,off_shift] == 4 ) else: # workdays: - + # - exactly 3 on day shift solver.Add(day_stat[j,day_shift] == 3) # - exactly 2 on night solver.Add(day_stat[j,night_shift] == 2) # - exactly 1 off duty - solver.Add(day_stat[j,off_shift] == 2 ) + solver.Add(day_stat[j,off_shift] == 2 ) + - # # solution and search - # + # db = solver.Phase(day_stat_flat + x_flat + nurse_stat, - solver.CHOOSE_FIRST_UNBOUND, + solver.CHOOSE_FIRST_UNBOUND, solver.ASSIGN_MIN_VALUE) solver.NewSearch(db) - + num_solutions = 0 while solver.NextSolution(): num_solutions += 1 - + for i in range(num_nurses): print 'Nurse%i: ' % i, this_day_stat = defaultdict(int) @@ -255,13 +255,13 @@ def main(): if num_solutions >= 2: break - + solver.EndSearch() print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': diff --git a/python/olympic.py b/python/olympic.py index d72b68795b..fec4027ade 100644 --- a/python/olympic.py +++ b/python/olympic.py @@ -107,9 +107,9 @@ def main(): print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': diff --git a/python/organize_day.py b/python/organize_day.py index 2d0c863f8b..4fb0550026 100644 --- a/python/organize_day.py +++ b/python/organize_day.py @@ -22,7 +22,7 @@ Slides on (Finite Domain) Constraint Logic Programming, page 38f http://eclipse-clp.org/reports/eclipse.ppt - + Compare with the following models: * MiniZinc: http://www.hakank.org/minizinc/organize_day.mzn * Comet: http://www.hakank.org/comet/organize_day.co @@ -86,7 +86,7 @@ def main(): no_overlap(solver, begins[i], durations[i], begins[j], durations[j]) - + # specific constraints for (before, after) in before_tasks: solver.Add(ends[before] <= begins[after]) @@ -100,9 +100,9 @@ def main(): db = solver.Phase(begins + ends, solver.INT_VAR_DEFAULT, solver.INT_VALUE_DEFAULT) - + solver.NewSearch(db) - + num_solutions = 0 while solver.NextSolution(): num_solutions += 1 @@ -111,9 +111,9 @@ def main(): print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': diff --git a/python/p_median.py b/python/p_median.py index fdb3b1cc8d..89f275f9f2 100644 --- a/python/p_median.py +++ b/python/p_median.py @@ -18,11 +18,11 @@ Model and data from the OPL Manual, which describes the problem: ''' - The P-Median problem is a well known problem in Operations Research. - The problem can be stated very simply, like this: given a set of customers - with known amounts of demand, a set of candidate locations for warehouses, - and the distance between each pair of customer-warehouse, choose P - warehouses to open that minimize the demand-weighted distance of serving + The P-Median problem is a well known problem in Operations Research. + The problem can be stated very simply, like this: given a set of customers + with known amounts of demand, a set of candidate locations for warehouses, + and the distance between each pair of customer-warehouse, choose P + warehouses to open that minimize the demand-weighted distance of serving all customers from those P warehouses. ''' @@ -106,9 +106,9 @@ def main(): db = solver.Phase(open + ship_flat, solver.INT_VAR_DEFAULT, solver.INT_VALUE_DEFAULT) - + solver.NewSearch(db, [objective]) - + num_solutions = 0 while solver.NextSolution(): num_solutions += 1 @@ -121,9 +121,9 @@ def main(): print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': diff --git a/python/pandigital_numbers.py b/python/pandigital_numbers.py index c9b728f1f7..f9918439ca 100644 --- a/python/pandigital_numbers.py +++ b/python/pandigital_numbers.py @@ -138,9 +138,9 @@ def main(base=10, start=1, len1=1, len2=4): if 0 and num_solutions > 0: print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() print diff --git a/python/photo_problem.py b/python/photo_problem.py index b24295c34d..67e4c64692 100644 --- a/python/photo_problem.py +++ b/python/photo_problem.py @@ -142,9 +142,9 @@ def main(show_all_max=0): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() show_all_max = 0 # show all maximal solutions diff --git a/python/place_number_puzzle.py b/python/place_number_puzzle.py index f8c4eb0630..6350b06876 100644 --- a/python/place_number_puzzle.py +++ b/python/place_number_puzzle.py @@ -119,15 +119,15 @@ def main(): solver.ASSIGN_MIN_VALUE), [collector]) - num_solutions = collector.solution_count() + num_solutions = collector.SolutionCount() for s in range(num_solutions): print "x:", [collector.Value(s, x[i]) for i in range(len(x))] print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() print if __name__ == '__main__': diff --git a/python/post_office_problem2.py b/python/post_office_problem2.py index 4d4752adb9..f443f39ac8 100644 --- a/python/post_office_problem2.py +++ b/python/post_office_problem2.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -18,19 +18,19 @@ Problem statement: http://www-128.ibm.com/developerworks/linux/library/l-glpk2/ - + From Winston 'Operations Research: Applications and Algorithms': ''' - A post office requires a different number of full-time employees working - on different days of the week [summarized below]. Union rules state that - each full-time employee must work for 5 consecutive days and then receive - two days off. For example, an employee who works on Monday to Friday - must be off on Saturday and Sunday. The post office wants to meet its - daily requirements using only full-time employees. Minimize the number + A post office requires a different number of full-time employees working + on different days of the week [summarized below]. Union rules state that + each full-time employee must work for 5 consecutive days and then receive + two days off. For example, an employee who works on Monday to Friday + must be off on Saturday and Sunday. The post office wants to meet its + daily requirements using only full-time employees. Minimize the number of employees that must be hired. - + To summarize the important information about the problem: - + * Every full-time worker works for 5 consecutive days and takes 2 days off * Day 1 (Monday): 17 workers needed * Day 2 : 13 workers needed @@ -39,9 +39,9 @@ * Day 5 : 14 workers needed * Day 6 : 16 workers needed * Day 7 (Sunday) : 11 workers needed - + The post office needs to minimize the number of employees it needs - to hire to meet its demand. + to hire to meet its demand. ''' * MiniZinc: http://www.hakank.org/minizinc/post_office_problem2.mzn @@ -57,8 +57,8 @@ from constraint_solver import pywrapcp -def main(): - +def main(): + # Create the solver. solver = pywrapcp.Solver('Post office problem') @@ -93,7 +93,7 @@ def main(): # solver.Add(total_cost == solver.ScalProd(x, cost)) solver.Add(num_workers == solver.Sum(x)) - + for i in days: s = solver.Sum([x[j] for j in days if j != (i+5) % n and j != (i+6) % n]) @@ -106,29 +106,29 @@ def main(): # search and result # db = solver.Phase(x, - solver.CHOOSE_MIN_SIZE_LOWEST_MIN, - solver.ASSIGN_MIN_VALUE - ) + solver.CHOOSE_MIN_SIZE_LOWEST_MIN, + solver.ASSIGN_MIN_VALUE + ) solver.NewSearch(db, [objective]) - + num_solutions = 0 while solver.NextSolution(): num_solutions += 1 print 'num_workers:', num_workers.Value() - print 'total_cost:', total_cost.Value() - print 'x:', [x[i].Value() for i in days] - + print 'total_cost:', total_cost.Value() + print 'x:', [x[i].Value() for i in days] + solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() + - if __name__ == '__main__': main() diff --git a/python/quasigroup_completion.py b/python/quasigroup_completion.py index acea56197a..9846bc2ec7 100644 --- a/python/quasigroup_completion.py +++ b/python/quasigroup_completion.py @@ -149,7 +149,7 @@ def main(puzzle="", n=0): # solver.ASSIGN_MIN_VALUE), # [collector]) # - # num_solutions = collector.solution_count() + # num_solutions = collector.SolutionCount() # print "\nnum_solutions: ", num_solutions # if num_solutions > 0: # print "\nJust showing the first solution..." @@ -163,9 +163,9 @@ def main(puzzle="", n=0): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() diff --git a/python/regular.py b/python/regular.py index 6a5e7dcbf0..d198eb1d2d 100644 --- a/python/regular.py +++ b/python/regular.py @@ -1,22 +1,22 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ Global constraint regular in Google CP Solver. - This is a translation of MiniZinc's regular constraint (defined in + This is a translation of MiniZinc's regular constraint (defined in lib/zinc/globals.mzn). All comments are from the MiniZinc code. ''' The sequence of values in array 'x' (which must all be in the range 1..S) @@ -35,7 +35,7 @@ This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ - + """ from constraint_solver import pywrapcp @@ -44,7 +44,7 @@ from constraint_solver import pywrapcp # # Global constraint regular # -# This is a translation of MiniZinc's regular constraint (defined in +# This is a translation of MiniZinc's regular constraint (defined in # lib/zinc/globals.mzn), via the Comet code refered above. # All comments are from the MiniZinc code. # ''' @@ -64,7 +64,7 @@ from constraint_solver import pywrapcp def regular(x, Q, S, d, q0, F): solver = x[0].solver() - + assert Q > 0, 'regular: "Q" must be greater than zero' assert S > 0, 'regular: "S" must be greater than zero' @@ -72,7 +72,7 @@ def regular(x, Q, S, d, q0, F): # each possible input; each extra transition is from state zero # to state zero. This allows us to continue even if we hit a # non-accepted input. - + # int d2[0..Q, 1..S]; d2 = [] for i in range(Q+1): @@ -93,28 +93,28 @@ def regular(x, Q, S, d, q0, F): x_range = range(0,len(x)) m = 0 n = len(x) - + a = [solver.IntVar(0, Q+1, 'a[%i]' % i) for i in range(m, n+1)] - + # Check that the final state is in F solver.Add(solver.MemberCt(a[-1], F)) # First state is q0 - solver.Add(a[m] == q0) + solver.Add(a[m] == q0) for i in x_range: solver.Add(x[i] >= 1) solver.Add(x[i] <= S) - + # Determine a[i+1]: a[i+1] == d2[a[i], x[i]] solver.Add(a[i+1] == solver.Element(d2_flatten, ((a[i])*S)+(x[i]-1))) - + # # Make a transition (automaton) matrix from a # single pattern, e.g. [3,2,1] -# +# def make_transition_matrix(pattern): - + p_len = len(pattern) print 'p_len:', p_len num_states = p_len + sum(pattern) @@ -125,7 +125,7 @@ def make_transition_matrix(pattern): for j in range(2): row.append(0) t_matrix.append(row) - + # convert pattern to a 0/1 pattern for easy handling of # the states tmp = [0 for i in range(num_states)] @@ -140,10 +140,10 @@ def make_transition_matrix(pattern): tmp[c] = 0 print 'tmp:', tmp - + t_matrix[num_states-1][0] = num_states t_matrix[num_states-1][1] = 0 - + for i in range(num_states): if tmp[i] == 0: t_matrix[i][0] = i+1 @@ -161,13 +161,13 @@ def make_transition_matrix(pattern): for i in range(num_states): for j in range(2): print t_matrix[i][j], - print + print print return t_matrix def main(): - + # Create the solver. solver = pywrapcp.Solver('Regular test') @@ -181,7 +181,7 @@ def main(): transition_fn = make_transition_matrix(pp) n_states = len(transition_fn) input_max = 2 - + # Note: we use '1' and '2' (rather than 0 and 1) # since 0 represents the failing state. initial_state = 1 @@ -198,27 +198,27 @@ def main(): regular(reg_input, n_states, input_max, transition_fn, initial_state, accepting_states) - + # # solution and search # db = solver.Phase(reg_input, - solver.CHOOSE_MIN_SIZE_HIGHEST_MAX, + solver.CHOOSE_MIN_SIZE_HIGHEST_MAX, solver.ASSIGN_MIN_VALUE) solver.NewSearch(db) - + num_solutions = 0 while solver.NextSolution(): print 'reg_input:', [reg_input[i].Value()-1 for i in range(this_len)] num_solutions += 1 - + solver.EndSearch() print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': diff --git a/python/regular_table.py b/python/regular_table.py index c97eb9a593..e25236cd4d 100644 --- a/python/regular_table.py +++ b/python/regular_table.py @@ -209,9 +209,9 @@ def main(): solver.EndSearch() print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': diff --git a/python/regular_table2.py b/python/regular_table2.py index b86d682fac..defd87af85 100644 --- a/python/regular_table2.py +++ b/python/regular_table2.py @@ -190,9 +190,9 @@ def main(): solver.EndSearch() print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': diff --git a/python/rogo2.py b/python/rogo2.py index bfed19294e..fdd8884350 100644 --- a/python/rogo2.py +++ b/python/rogo2.py @@ -1,16 +1,16 @@ # Copyright 2011 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -33,7 +33,7 @@ * http://www.hakank.org/google_or_tools/rogo_mike_trick.py * http://www.hakank.org/google_or_tools/rogo_20110106.py * http://www.hakank.org/google_or_tools/rogo_20110107.py - + Compare with the following models: * Answer Set Programming: @@ -49,7 +49,7 @@ import sys, string, re from constraint_solver import pywrapcp def main(problem, rows, cols, max_steps): - + # Create the solver. solver = pywrapcp.Solver('Rogo grid puzzle') @@ -66,14 +66,14 @@ def main(problem, rows, cols, max_steps): max_sum = sum(problem_flatten) print "max_sum:", max_sum print - + # # declare variables # # the coordinates x = [solver.IntVar(0, rows-1, "x[%i]"%i) for i in range(max_steps)] - y = [solver.IntVar(0, cols-1, "y[%i]"%i) for i in range(max_steps)] + y = [solver.IntVar(0, cols-1, "y[%i]"%i) for i in range(max_steps)] # the collected points points = [solver.IntVar(0, max_point, "points[%i]"%i) for i in range(max_steps)] @@ -125,7 +125,7 @@ def main(problem, rows, cols, max_steps): # objective # objective = solver.Maximize(sum_points, 1) - + # # solution and search # @@ -135,7 +135,7 @@ def main(problem, rows, cols, max_steps): # Default search parameters = pywrapcp.DefaultPhaseParameters() - + parameters.heuristic_period = 200000 # parameters.var_selection_schema = parameters.CHOOSE_MAX_SUM_IMPACT parameters.var_selection_schema = parameters.CHOOSE_MAX_AVERAGE_IMPACT # <- @@ -145,8 +145,8 @@ def main(problem, rows, cols, max_steps): # parameters.value_selection_schema = parameters.SELECT_MAX_IMPACT # parameters.initialization_splits = 10 - - db = solver.DefaultPhase(x + y, parameters) + + db = solver.DefaultPhase(x + y, parameters) solver.NewSearch(db, [objective]) @@ -157,12 +157,12 @@ def main(problem, rows, cols, max_steps): print "adding 1 to coords..." for s in range(max_steps): print "%i %i" % (x[s].Value()+1,y[s].Value()+1) - print - + print + print "\nnum_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() diff --git a/python/safe_cracking.py b/python/safe_cracking.py index 3a66187ecc..aec9243f62 100644 --- a/python/safe_cracking.py +++ b/python/safe_cracking.py @@ -100,9 +100,9 @@ def main(): print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': diff --git a/python/scheduling_speakers.py b/python/scheduling_speakers.py index a9075914e9..1460212e96 100644 --- a/python/scheduling_speakers.py +++ b/python/scheduling_speakers.py @@ -88,9 +88,9 @@ def main(): print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': diff --git a/python/secret_santa.py b/python/secret_santa.py index eac5ad936d..69c38707b7 100644 --- a/python/secret_santa.py +++ b/python/secret_santa.py @@ -54,7 +54,7 @@ This model gives 4089600 solutions and the following statistics: - failures: 31264 - branches: 8241726 - - wall_time: 23735 ms (note: without any printing of the solutions) + - WallTime: 23735 ms (note: without any printing of the solutions) This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ @@ -109,9 +109,9 @@ def main(): print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': main() diff --git a/python/secret_santa2.py b/python/secret_santa2.py index e8273b3d7b..c3f01d996d 100644 --- a/python/secret_santa2.py +++ b/python/secret_santa2.py @@ -212,9 +212,9 @@ def main(singe=0): print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' single = 0 if __name__ == '__main__': diff --git a/python/send_more_money_any_base.py b/python/send_more_money_any_base.py index 060a440c85..6c5a7a31af 100644 --- a/python/send_more_money_any_base.py +++ b/python/send_more_money_any_base.py @@ -93,16 +93,16 @@ def main(base=10): solver.ASSIGN_MAX_VALUE), [collector]) - num_solutions = collector.solution_count() + num_solutions = collector.SolutionCount() money_val = 0 for s in range(num_solutions): print "x:", [collector.Value(s, x[i]) for i in range(len(x))] print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() print diff --git a/python/send_most_money.py b/python/send_most_money.py index 7e7d609691..df6ebf022a 100644 --- a/python/send_most_money.py +++ b/python/send_most_money.py @@ -99,7 +99,7 @@ def main(MONEY=0): solver.ASSIGN_MAX_VALUE), cargs) - num_solutions = collector.solution_count() + num_solutions = collector.SolutionCount() money_val = 0 for s in range(num_solutions): print "x:", [collector.Value(s, x[i]) for i in range(len(x))] @@ -108,9 +108,9 @@ def main(MONEY=0): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if MONEY == 0: return money_val diff --git a/python/seseman.py b/python/seseman.py index 6d3b1bf9b8..29bd4693ed 100644 --- a/python/seseman.py +++ b/python/seseman.py @@ -113,7 +113,7 @@ def main(unused_argv): [collector]) #[collector, search_log]) - num_solutions = collector.solution_count() + num_solutions = collector.SolutionCount() # print "x:", x print "num_solutions:", num_solutions print @@ -127,9 +127,9 @@ def main(unused_argv): print print - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() print "num_solutions:", num_solutions diff --git a/python/seseman_b.py b/python/seseman_b.py index b51e5b7533..61edb20c1a 100644 --- a/python/seseman_b.py +++ b/python/seseman_b.py @@ -1,22 +1,22 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ Seseman Convent problem in Google CP Solver. - + n is the length of a border There are (n-2)^2 "holes", i.e. there are n^2 - (n-2)^2 variables to find out. @@ -24,10 +24,10 @@ The simplest problem, n = 3 (n x n matrix) which is represented by the following matrix: - a b c - d e - f g h - + a b c + d e + f g h + Where the following constraints must hold: a + b + c = border_sum @@ -65,7 +65,7 @@ def main(unused_argv): # data n = 3 border_sum = n*n - + # declare variables total_sum = solver.IntVar(1,n*n*n*n, 'total_sum') # x[0..n-1,0..n-1] @@ -74,11 +74,11 @@ def main(unused_argv): for j in range(n): x[(i,j)] = solver.IntVar(0,n*n, 'x %i %i' % (i, j)) - + # # constraints # - # zero all middle cells + # zero all middle cells for i in range(1,n-1): for j in range(1,n-1): solver.Add(x[(i,j)] == 0) @@ -92,7 +92,7 @@ def main(unused_argv): # sum the borders (border_sum) solver.Add(solver.Sum([x[(i,0)] for i in range(n)]) == border_sum) - solver.Add(solver.Sum([x[(i,n-1)] for i in range(n)]) == border_sum) + solver.Add(solver.Sum([x[(i,n-1)] for i in range(n)]) == border_sum) solver.Add(solver.Sum([x[(0,i)] for i in range(n)]) == border_sum) solver.Add(solver.Sum([x[(n-1,i)] for i in range(n)]) == border_sum) @@ -105,7 +105,7 @@ def main(unused_argv): solution = solver.Assignment() solution.Add([x[(i,j)] for i in range(n) for j in range(n)]) solution.Add(total_sum) - + db = solver.Phase([x[(i,j)] for i in range(n) for j in range(n)], solver.CHOOSE_PATH, solver.ASSIGN_MIN_VALUE) @@ -125,10 +125,10 @@ def main(unused_argv): print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() - + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() + if __name__ == '__main__': main("cp sample") diff --git a/python/set_covering.py b/python/set_covering.py index 5b189436c2..ba60606bc3 100644 --- a/python/set_covering.py +++ b/python/set_covering.py @@ -88,9 +88,9 @@ def main(unused_argv): print "z:", collector.objective_value(0) print "x:", [collector.Value(0, x[i]) for i in range(num_cities)] - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/set_covering2.py b/python/set_covering2.py index 5bde6a3eae..4821afeeca 100644 --- a/python/set_covering2.py +++ b/python/set_covering2.py @@ -98,9 +98,9 @@ def main(unused_argv): print "z:", collector.objective_value(0) print "x:", [collector.Value(0, x[i]) for i in range(n)] - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/set_covering3.py b/python/set_covering3.py index 5d27c355cb..5b9375f741 100644 --- a/python/set_covering3.py +++ b/python/set_covering3.py @@ -116,9 +116,9 @@ def main(unused_argv): print print - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/set_covering4.py b/python/set_covering4.py index 3fd19390d7..2a54c489e0 100644 --- a/python/set_covering4.py +++ b/python/set_covering4.py @@ -143,9 +143,9 @@ def main(set_partition=1): print "selected alternatives:", [i + 1 for i in range(num_alternatives) if collector.Value(0, x[i]) == 1] - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/set_covering_deployment.py b/python/set_covering_deployment.py index 5a35be00f4..b7ecb835f9 100644 --- a/python/set_covering_deployment.py +++ b/python/set_covering_deployment.py @@ -135,9 +135,9 @@ def main(): print - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/set_covering_skiena.py b/python/set_covering_skiena.py index 42f0a34e19..944b85f5b2 100644 --- a/python/set_covering_skiena.py +++ b/python/set_covering_skiena.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the 'License'); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an 'AS IS' BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -19,15 +19,15 @@ Example from Steven Skiena, The Stony Brook Algorithm Repository http://www.cs.sunysb.edu/~algorith/files/set-cover.shtml ''' - Input Description: A set of subsets S_1, ..., S_m of the + Input Description: A set of subsets S_1, ..., S_m of the universal set U = {1,...,n}. - - Problem: What is the smallest subset of subsets T subset S such + + Problem: What is the smallest subset of subsets T subset S such that \cup_{t_i in T} t_i = U? ''' Data is from the pictures INPUT/OUTPUT. - Compare with the following models: + Compare with the following models: * MiniZinc: http://www.hakank.org/minizinc/set_covering_skiena.mzn * Comet: http://www.hakank.org/comet/set_covering_skiena.co * ECLiPSe: http://www.hakank.org/eclipse/set_covering_skiena.ecl @@ -42,8 +42,8 @@ from constraint_solver import pywrapcp -def main(): - +def main(): + # Create the solver. solver = pywrapcp.Solver('Set covering Skiena') @@ -67,19 +67,19 @@ def main(): # variables # x = [solver.IntVar(0, 1, 'x[%i]' % i) for i in range(num_sets)] - + # number of choosen sets z = solver.IntVar(0, num_sets*2, 'z') # total number of elements in the choosen sets tot_elements = solver.IntVar(0, num_sets*num_elements) - + # # constraints # solver.Add(z == solver.Sum(x)) - + # all sets must be used for j in range(num_elements): s = solver.Sum([belongs[i][j]*x[i] for i in range(num_sets)]) @@ -98,13 +98,13 @@ def main(): # search and result # db = solver.Phase(x, - solver.INT_VAR_DEFAULT, - solver.INT_VALUE_DEFAULT - ) + solver.INT_VAR_DEFAULT, + solver.INT_VALUE_DEFAULT + ) solver.NewSearch(db, [objective]) - + num_solutions = 0 while solver.NextSolution(): num_solutions += 1 @@ -113,13 +113,13 @@ def main(): print 'x:', [x[i].Value() for i in range(num_sets)] solver.EndSearch() - + print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' + - if __name__ == '__main__': main() diff --git a/python/set_partition.py b/python/set_partition.py index 3519af59b1..0e41ec8ff2 100644 --- a/python/set_partition.py +++ b/python/set_partition.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -22,20 +22,20 @@ This is a partition problem. Given the set S = {1, 2, ..., n}, it consists in finding two sets A and B such that: - + A U B = S, |A| = |B|, sum(A) = sum(B), sum_squares(A) = sum_squares(B) - + ''' This model uses a binary matrix to represent the sets. - + Also, compare with other models which uses var sets: * MiniZinc: http://www.hakank.org/minizinc/set_partition.mzn - * Gecode/R: http://www.hakank.org/gecode_r/set_partition.rb + * Gecode/R: http://www.hakank.org/gecode_r/set_partition.rb * Comet: http://hakank.org/comet/set_partition.co * Gecode: http://hakank.org/gecode/set_partition.cpp * ECLiPSe: http://hakank.org/eclipse/set_partition.ecl @@ -55,13 +55,13 @@ from constraint_solver import pywrapcp # def partition_sets(x, num_sets, n): solver = x.values()[0].solver() - + for i in range(num_sets): for j in range(num_sets): if i != j: b = solver.Sum([x[i,k]*x[j,k] for k in range(n)]) solver.Add(b == 0) - + # ensure that all integers is in # (exactly) one partition b = [x[i,j] for i in range(num_sets) for j in range(n) ] @@ -69,10 +69,10 @@ def partition_sets(x, num_sets, n): def main(n=16,num_sets=2): - + # Create the solver. solver = pywrapcp.Solver('Set partition') - + # # data # @@ -82,7 +82,7 @@ def main(n=16,num_sets=2): # Check sizes assert n % num_sets == 0, "Equal sets is not possible." - + # # variables # @@ -98,22 +98,22 @@ def main(n=16,num_sets=2): # # constraints # - + # partition set partition_sets(a, num_sets, n) - + for i in range(num_sets): for j in range(i, num_sets): - + # same cardinality solver.Add(solver.Sum([a[i,k] for k in range(n)]) == solver.Sum([a[j,k] for k in range(n)])) - + # same sum solver.Add(solver.Sum([k*a[i,k] for k in range(n)]) == - solver.Sum([k*a[j,k] for k in range(n)])) + solver.Sum([k*a[j,k] for k in range(n)])) # same sum squared @@ -131,14 +131,14 @@ def main(n=16,num_sets=2): # # search and result - # + # db = solver.Phase(a_flat, solver.INT_VAR_DEFAULT, solver.INT_VALUE_DEFAULT) solver.NewSearch(db) - + num_solutions = 0 while solver.NextSolution(): a_val = {} @@ -149,8 +149,8 @@ def main(n=16,num_sets=2): sq = sum([(j+1)*a_val[0,j] for j in range(n)]) print "sums:", sq sq2 = sum([((j+1)*a_val[0,j])**2 for j in range(n)]) - print "sums squared:", sq2 - + print "sums squared:", sq2 + for i in range(num_sets): if sum([a_val[i,j] for j in range(n)]): print i+1, ":", @@ -161,14 +161,14 @@ def main(n=16,num_sets=2): print num_solutions += 1 - + solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() n = 16 diff --git a/python/sicherman_dice.py b/python/sicherman_dice.py index 42ade77849..c86ea5b7af 100644 --- a/python/sicherman_dice.py +++ b/python/sicherman_dice.py @@ -1,27 +1,27 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ Sicherman Dice in Google CP Solver. From http://en.wikipedia.org/wiki/Sicherman_dice - "" - Sicherman dice are the only pair of 6-sided dice which are not normal dice, - bear only positive integers, and have the same probability distribution for + "" + Sicherman dice are the only pair of 6-sided dice which are not normal dice, + bear only positive integers, and have the same probability distribution for the sum as normal dice. - + The faces on the dice are numbered 1, 2, 2, 3, 3, 4 and 1, 3, 4, 5, 6, 8. "" @@ -31,7 +31,7 @@ This model gets the two different ways, first the standard way and then the Sicherman dice: - + x1 = [1, 2, 3, 4, 5, 6] x2 = [1, 2, 3, 4, 5, 6] ---------- @@ -39,15 +39,15 @@ x2 = [1, 3, 4, 5, 6, 8] - Extra: If we also allow 0 (zero) as a valid value then the + Extra: If we also allow 0 (zero) as a valid value then the following two solutions are also valid: - + x1 = [0, 1, 1, 2, 2, 3] x2 = [2, 4, 5, 6, 7, 9] ---------- x1 = [0, 1, 2, 3, 4, 5] x2 = [2, 3, 4, 5, 6, 7] - + These two extra cases are mentioned here: http://mathworld.wolfram.com/SichermanDice.html @@ -63,7 +63,7 @@ from constraint_solver import pywrapcp def main(): - + # Create the solver. solver = pywrapcp.Solver('Sicherman dice') @@ -79,7 +79,7 @@ def main(): # # declare variables # - + # the two dice x1 = [solver.IntVar(0, m,"x1(%i)"%i) for i in range(n)] x2 = [solver.IntVar(0, m,"x2(%i)"%i) for i in range(n)] @@ -100,39 +100,39 @@ def main(): # symmetry breaking [solver.Add(x1[i] <= x1[i+1]) for i in range(n-1)], [solver.Add(x2[i] <= x2[i+1]) for i in range(n-1)], - [solver.Add(x1[i] <= x2[i]) for i in range(n-1)], + [solver.Add(x1[i] <= x2[i]) for i in range(n-1)], # # solution and search # solution = solver.Assignment() solution.Add(x1) - solution.Add(x2) + solution.Add(x2) # db: DecisionBuilder db = solver.Phase(x1 + x2, solver.INT_VAR_SIMPLE, solver.ASSIGN_MIN_VALUE) - + solver.NewSearch(db) num_solutions = 0 while solver.NextSolution(): print "x1:", [x1[i].Value() for i in range(n)] print "x2:", [x2[i].Value() for i in range(n)] print - - num_solutions += 1 + + num_solutions += 1 solver.EndSearch() - + print print "num_solutions:", num_solutions, "solver.solutions:", solver.solutions() - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() print "MemoryUsage:", solver.MemoryUsage() print "SearchDepth:", solver.SearchDepth() - print "SolveDepth:", solver.SolveDepth() + print "SolveDepth:", solver.SolveDepth() print "stamp:", solver.stamp() print "solver", solver diff --git a/python/simple_meeting.py b/python/simple_meeting.py index 0205bab374..7d74bb9fcf 100644 --- a/python/simple_meeting.py +++ b/python/simple_meeting.py @@ -201,7 +201,7 @@ def main(unused_argv): solver.Solve(main_phase, [collector, search_log, objective]) - if collector.solution_count() > 0: + if collector.SolutionCount() > 0: print ('we could schedule %d persons in room %d starting at quarter %d' % (collector.Value(0, people_count), diff --git a/python/ski_assignment.py b/python/ski_assignment.py index 7f58c8b05d..4627580ccc 100644 --- a/python/ski_assignment.py +++ b/python/ski_assignment.py @@ -114,9 +114,9 @@ def main(): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/stable_marriage.py b/python/stable_marriage.py index f83bbdf853..ce09426eb8 100644 --- a/python/stable_marriage.py +++ b/python/stable_marriage.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -19,7 +19,7 @@ Problem and OPL model from Pascal Van Hentenryck 'The OPL Optimization Programming Language', page 43ff. - Also, see + Also, see http://www.comp.rgu.ac.uk/staff/ha/ZCSP/additional_problems/stable_marriage/stable_marriage.pdf Note: This model is translated from my Comet model @@ -35,7 +35,7 @@ This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ - + """ import string, sys @@ -52,9 +52,9 @@ def main(ranks, problem_name): # data # print "Problem name:", problem_name - + rankMen = ranks["rankMen"] - rankWomen = ranks["rankWomen"] + rankWomen = ranks["rankWomen"] n = len(rankMen) @@ -62,23 +62,23 @@ def main(ranks, problem_name): # declare variables # wife = [solver.IntVar(0, n-1, 'wife[%i]' % i) for i in range(n)] - husband = [solver.IntVar(0, n-1, 'husband[%i]' % i) for i in range(n)] + husband = [solver.IntVar(0, n-1, 'husband[%i]' % i) for i in range(n)] # # constraints # - + # forall(m in Men) # cp.post(husband[wife[m]] == m); for m in range(n): solver.Add(solver.Element(husband, wife[m]) == m) - + # forall(w in Women) # cp.post(wife[husband[w]] == w); for w in range(n): solver.Add(solver.Element(wife, husband[w]) == w) - + # forall(m in Men, o in Women) # cp.post(rankMen[m,o] < rankMen[m, wife[m]] => rankWomen[o,husband[o]] < rankWomen[o,m]); for m in range(n): @@ -94,36 +94,36 @@ def main(ranks, problem_name): b1 = solver.IsGreaterCstVar(solver.Element(rankWomen[w], husband[w]), rankWomen[w][o]) b2 = solver.IsLessCstVar(solver.Element(rankMen[o], wife[o]), rankMen[o][w]) solver.Add(b1-b2<=0) - + # # solution and search # solution = solver.Assignment() solution.Add(wife) - solution.Add(husband) + solution.Add(husband) db = solver.Phase(wife + husband, solver.CHOOSE_FIRST_UNBOUND, solver.ASSIGN_MIN_VALUE) - + solver.NewSearch(db) num_solutions = 0 solutions = [] while solver.NextSolution(): # solutions.append([x[i].Value() for i in range(x_len)]) print "wife : ", [wife[i].Value() for i in range(n)] - print "husband: ", [husband[i].Value() for i in range(n)] + print "husband: ", [husband[i].Value() for i in range(n)] print num_solutions += 1 - + solver.EndSearch() print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() print "#############" print @@ -153,8 +153,8 @@ van_hentenryck = { # # Data from MathWorld # http://mathworld.wolfram.com/StableMarriageProblem.html -# -mathworld = { +# +mathworld = { "rankWomen" : [ [3, 1, 5, 2, 8, 7, 6, 9, 4], [9, 4, 8, 1, 7, 6, 3, 2, 5], @@ -165,7 +165,7 @@ mathworld = { [9, 3, 8, 2, 7, 5, 4, 6, 1], [6, 3, 2, 1, 8, 4, 5, 9, 7], [8, 2, 6, 4, 9, 1, 3, 7, 5]], - + "rankMen" : [ [7, 3, 8, 9, 6, 4, 2, 1, 5], [5, 4, 8, 3, 1, 2, 6, 7, 9], @@ -179,7 +179,7 @@ mathworld = { } # -# Data from +# Data from # http://www.csee.wvu.edu/~ksmani/courses/fa01/random/lecnotes/lecture5.pdf # problem3 = { @@ -188,14 +188,14 @@ problem3 = { [4,3,2,1], [1,2,3,4], [3,4,1,2]], - + "rankMen" : [ [1,2,3,4], [2,1,3,4], [1,4,3,2], [4,3,1,2]] } - + # diff --git a/python/stigler.py b/python/stigler.py index a107aa70c4..733e82b9e3 100644 --- a/python/stigler.py +++ b/python/stigler.py @@ -19,7 +19,7 @@ From GLPK:s example stigler.mod ''' STIGLER, original Stigler's 1939 diet problem - + The Stigler Diet is an optimization problem named for George Stigler, a 1982 Nobel Laureate in economics, who posed the following problem: For a moderately active man weighing 154 pounds, how much of each of @@ -27,20 +27,20 @@ nine nutrients will be at least equal to the recommended dietary allowances (RDSs) suggested by the National Research Council in 1943, with the cost of the diet being minimal? - + The nutrient RDAs required to be met in Stigler's experiment were calories, protein, calcium, iron, vitamin A, thiamine, riboflavin, niacin, and ascorbic acid. The result was an annual budget allocated to foods such as evaporated milk, cabbage, dried navy beans, and beef liver at a cost of approximately $0.11 a day in 1939 U.S. dollars. - + While the name 'Stigler Diet' was applied after the experiment by outsiders, according to Stigler, 'No one recommends these diets for anyone, let alone everyone.' The Stigler diet has been much ridiculed for its lack of variety and palatability, however his methodology has received praise and is considered to be some of the earliest work in linear programming. - + The Stigler diet question is a linear programming problem. Lacking any sophisticated method of solving such a problem, Stigler was forced to utilize heuristic methods in order to find a solution. The @@ -58,9 +58,9 @@ consumer price index, the cost of the diet in 2005 dollars is $561.43. The specific combination of foods and quantities is as follows: - + Stigler's 1939 Diet - + Food Annual Quantities Annual Cost ---------------- ----------------- ----------- Wheat Flour 370 lb. $13.33 @@ -70,12 +70,12 @@ Dried Navy Beans 285 lb. 16.80 ---------------------------------------------- Total Annual Cost $39.93 - + The 9 nutrients that Stigler's diet took into consideration and their respective recommended daily amounts were: - + Table of nutrients considered in Stigler's diet - + Nutrient Daily Recommended Intake ------------------------- ------------------------ Calories 3,000 Calories @@ -87,7 +87,7 @@ Riboflavin (Vitamin B2) 2.7 milligrams Niacin 18 milligrams Ascorbic Acid (Vitamin C) 75 milligrams - + Seven years after Stigler made his initial estimates, the development of George Dantzig's Simplex algorithm made it possible to solve the problem without relying on heuristic methods. The exact value was @@ -95,25 +95,25 @@ algorithm describes a method of traversing the vertices of a polytope of N+1 dimensions in order to find the optimal solution to a specific situation. - + (From Wikipedia, the free encyclopedia.) - + Translated from GAMS by Andrew Makhorin . - + For the original GAMS model stigler1939.gms see [3]. - + References: - + 1. George J. Stigler, 'The Cost of Subsistence,' J. Farm Econ. 27, 1945, pp. 303-14. - + 2. National Research Council, 'Recommended Daily Allowances,' Reprint and Circular Series No. 115, January, 1943. - + 3. Erwin Kalvelagen, 'Model building with GAMS,' Chapter 2, 'Building linear programming models,' pp. 128-34. ''' - + This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ """ @@ -122,7 +122,7 @@ from linear_solver import pywraplp def main(sol = 'GLPK'): - + # Create the solver. print 'Solver: ', sol @@ -144,24 +144,24 @@ def main(sol = 'GLPK'): num_commodities = 77 C = range(num_commodities) - # days in a year + # days in a year days = 365.25 - # nutrients + # nutrients num_nutrients = 9 N = range(num_nutrients) nutrients = [ - "calories", # Calories, unit = 1000 - "protein", # Protein, unit = grams - "calcium", # Calcium, unit = grams - "iron", # Iron, unit = milligrams - "vitaminA", # Vitamin A, unit = 1000 International Units - "thiamine", # Thiamine, Vit. B1, unit = milligrams - "riboflavin", # Riboflavin, Vit. B2, unit = milligrams - "niacin", # Niacin (Nicotinic Acid), unit = milligrams - "ascorbicAcid" # Ascorbic Acid, Vit. C, unit = milligrams + "calories", # Calories, unit = 1000 + "protein", # Protein, unit = grams + "calcium", # Calcium, unit = grams + "iron", # Iron, unit = milligrams + "vitaminA", # Vitamin A, unit = 1000 International Units + "thiamine", # Thiamine, Vit. B1, unit = milligrams + "riboflavin", # Riboflavin, Vit. B2, unit = milligrams + "niacin", # Niacin (Nicotinic Acid), unit = milligrams + "ascorbicAcid" # Ascorbic Acid, Vit. C, unit = milligrams ] commodities = [ @@ -325,7 +325,7 @@ def main(sol = 'GLPK'): [13.6, 3752.0, 9.0, 0.0, 10.3, 244.0, 0.0, 1.9, 7.5, 146.0, 0.0], [20.5, 2213.0, 6.4, 11.0, 0.4, 7.0, 0.2, 0.2, 0.4, 3.0, 0.0]] - # recommended daily allowance for a moderately active man + # recommended daily allowance for a moderately active man allowance = [3.0, 70.0, 0.8, 12.0, 5.0, 1.8, 2.7, 18.0, 75.0] @@ -334,7 +334,7 @@ def main(sol = 'GLPK'): # x = [solver.NumVar(0, 1000, 'x[%i]' % i) for i in C] x_cost = [solver.NumVar(0, 1000, 'x_cost[%i]' % i) for i in C] - quant = [solver.NumVar(0, 1000, 'quant[%i]' % i) for i in C] + quant = [solver.NumVar(0, 1000, 'quant[%i]' % i) for i in C] # total food bill total_cost = solver.NumVar(0, 1000, 'total_cost') @@ -354,7 +354,7 @@ def main(sol = 'GLPK'): # nutrient balance for n in range(2, num_nutrients+2): solver.Add(solver.Sum([data[c][n] * x[c] for c in C]) >= allowance[n-2]) - + objective = solver.Minimize(cost) @@ -371,12 +371,12 @@ def main(sol = 'GLPK'): print for i in C: if x[i].solution_value() > 0: - print "%-21s %-11s %0.2f %0.2f" % (commodities[i][0], commodities[i][1], + print "%-21s %-11s %0.2f %0.2f" % (commodities[i][0], commodities[i][1], x_cost[i].solution_value(), quant[i].solution_value()) print - print 'walltime :', solver.wall_time(), 'ms' + print 'walltime :', solver.WallTime(), 'ms' if sol == 'CBC': print 'iterations:', solver.iterations() @@ -389,5 +389,5 @@ if __name__ == '__main__': if sol != 'GLPK' and sol != 'CBC': print 'Solver must be either GLPK or CBC' sys.exit(1) - + main(sol) diff --git a/python/strimko2.py b/python/strimko2.py index c6003a791d..2f958cadec 100644 --- a/python/strimko2.py +++ b/python/strimko2.py @@ -145,9 +145,9 @@ def main(streams="", placed=""): print print 'num_solutions:', num_solutions - print 'failures:', solver.failures() - print 'branches:', solver.branches() - print 'wall_time:', solver.wall_time(), 'ms' + print 'failures:', solver.Failures() + print 'branches:', solver.Branches() + print 'WallTime:', solver.WallTime(), 'ms' if __name__ == '__main__': if len(sys.argv) > 1: diff --git a/python/subset_sum.py b/python/subset_sum.py index 517a14eb1d..ce67f7c348 100644 --- a/python/subset_sum.py +++ b/python/subset_sum.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -20,7 +20,7 @@ http://ioe.engin.umich.edu/people/fac/books/murty/opti_model/junior-7.pdf ''' Example 7.8.1 - + A bank van had several bags of coins, each containing either 16, 17, 23, 24, 39, or 40 coins. While the van was parked on the street, thieves stole some bags. A total of 100 coins were lost. @@ -34,7 +34,7 @@ * MiniZinc: http://www.hakank.org/minizinc/subset_sum.mzn * Tailor/Essence': http://www.hakank.org/tailor/subset_sum.py * SICStus: http://hakank.org/sicstus/subset_sum.pl - + This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ """ @@ -47,14 +47,14 @@ def subset_sum(solver, values, total): x = [solver.IntVar(0, n) for i in range(n)] ss = solver.IntVar(0, n) - + solver.Add(ss == solver.Sum(x)) solver.Add(total == solver.ScalProd(x, values)) return x, ss def main(coins, total): - + # Create the solver. solver = pywrapcp.Solver('n-queens') @@ -64,7 +64,7 @@ def main(coins, total): print "coins:", coins print "total:", total print - + # # declare variables # @@ -74,7 +74,7 @@ def main(coins, total): # x, ss = subset_sum(solver, coins, total) - + # # solution and search # @@ -87,21 +87,21 @@ def main(coins, total): solver.CHOOSE_FIRST_UNBOUND, solver.ASSIGN_MIN_VALUE ) - + solver.NewSearch(db) num_solutions = 0 while solver.NextSolution(): print "ss:", ss.Value() print "x: ", [x[i].Value() for i in range(len(x))] print - num_solutions += 1 + num_solutions += 1 solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() coins = [16, 17, 23, 24, 39, 40] total = 100 diff --git a/python/sudoku.py b/python/sudoku.py index 523396df31..fd41a55861 100644 --- a/python/sudoku.py +++ b/python/sudoku.py @@ -85,7 +85,7 @@ def main(unused_argv): # And solve. solver.Solve(vars_phase, [collector]) - if collector.solution_count() == 1: + if collector.SolutionCount() == 1: for i in line: print [int(collector.Value(0, grid[(i, j)])) for j in line] diff --git a/python/survo_puzzle.py b/python/survo_puzzle.py index fb07a58c19..249523b77a 100644 --- a/python/survo_puzzle.py +++ b/python/survo_puzzle.py @@ -125,7 +125,7 @@ def main(r=0, c=0, rowsums=[], colsums=[], game=[]): solver.ASSIGN_MIN_VALUE), [collector]) - num_solutions = collector.solution_count() + num_solutions = collector.SolutionCount() print "\nnum_solutions: ", num_solutions if num_solutions > 0: for s in range(num_solutions): @@ -140,9 +140,9 @@ def main(r=0, c=0, rowsums=[], colsums=[], game=[]): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() else: print "No solutions found" diff --git a/python/toNum.py b/python/toNum.py index d1c4b9c3ea..56c6e3c9ca 100644 --- a/python/toNum.py +++ b/python/toNum.py @@ -70,15 +70,15 @@ def main(unused_argv): solver.ASSIGN_MIN_VALUE), [collector]) - num_solutions = collector.solution_count() + num_solutions = collector.SolutionCount() for s in range(num_solutions): print "x:", [collector.Value(s, x[i]) for i in range(n)] print "y:", collector.Value(s, y) print - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() if __name__ == '__main__': diff --git a/python/traffic_lights.py b/python/traffic_lights.py index 255b75fdc6..d906db3ae4 100644 --- a/python/traffic_lights.py +++ b/python/traffic_lights.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -20,35 +20,35 @@ http://www.cs.st-andrews.ac.uk/~ianm/CSPLib/prob/prob016/index.html ''' Specification: - Consider a four way traffic junction with eight traffic lights. Four of the traffic - lights are for the vehicles and can be represented by the variables V1 to V4 with domains - {r,ry,g,y} (for red, red-yellow, green and yellow). The other four traffic lights are + Consider a four way traffic junction with eight traffic lights. Four of the traffic + lights are for the vehicles and can be represented by the variables V1 to V4 with domains + {r,ry,g,y} (for red, red-yellow, green and yellow). The other four traffic lights are for the pedestrians and can be represented by the variables P1 to P4 with domains {r,g}. - - The constraints on these variables can be modelled by quaternary constraints on - (Vi, Pi, Vj, Pj ) for 1<=i<=4, j=(1+i)mod 4 which allow just the tuples + + The constraints on these variables can be modelled by quaternary constraints on + (Vi, Pi, Vj, Pj ) for 1<=i<=4, j=(1+i)mod 4 which allow just the tuples {(r,r,g,g), (ry,r,y,r), (g,g,r,r), (y,r,ry,r)}. - - It would be interesting to consider other types of junction (e.g. five roads - intersecting) as well as modelling the evolution over time of the traffic light sequence. + + It would be interesting to consider other types of junction (e.g. five roads + intersecting) as well as modelling the evolution over time of the traffic light sequence. ... - + Results Only 2^2 out of the 2^12 possible assignments are solutions. - - (V1,P1,V2,P2,V3,P3,V4,P4) = + + (V1,P1,V2,P2,V3,P3,V4,P4) = {(r,r,g,g,r,r,g,g), (ry,r,y,r,ry,r,y,r), (g,g,r,r,g,g,r,r), (y,r,ry,r,y,r,ry,r)} [(1,1,3,3,1,1,3,3), ( 2,1,4,1, 2,1,4,1), (3,3,1,1,3,3,1,1), (4,1, 2,1,4,1, 2,1)} - - The problem has relative few constraints, but each is very tight. Local propagation + + The problem has relative few constraints, but each is very tight. Local propagation appears to be rather ineffective on this problem. - + ''' Note: In this model we use only the constraint solver.AllowedAssignments(). - - Compare with these models: + + Compare with these models: * MiniZinc: http://www.hakank.org/minizinc/traffic_lights.mzn * Comet : http://www.hakank.org/comet/traffic_lights.co * ECLiPSe : http://www.hakank.org/eclipse/traffic_lights.ecl @@ -58,7 +58,7 @@ This model was created by Hakan Kjellerstrand (hakank@bonetmail.com) Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ - + """ import string, sys @@ -67,7 +67,7 @@ from constraint_solver import pywrapcp def main(base=10, start=1, len1=1, len2=4): - + # Create the solver. solver = pywrapcp.Solver('Traffic lights') @@ -80,18 +80,18 @@ def main(base=10, start=1, len1=1, len2=4): # The allowed combinations allowed = [ - (r,r,g,g), - (ry,r,y,r), - (g,g,r,r), + (r,r,g,g), + (ry,r,y,r), + (g,g,r,r), (y,r,ry,r) ] - + # # declare variables # V = [solver.IntVar(0, n-1, 'V[%i]' % i) for i in range(n)] - P = [solver.IntVar(0, n-1, 'P[%i]' % i) for i in range(n)] + P = [solver.IntVar(0, n-1, 'P[%i]' % i) for i in range(n)] # # constraints @@ -103,26 +103,26 @@ def main(base=10, start=1, len1=1, len2=4): # # Search and result - # + # db = solver.Phase(V + P, solver.INT_VAR_SIMPLE, solver.INT_VALUE_DEFAULT) - + solver.NewSearch(db) num_solutions = 0 while solver.NextSolution(): for i in range(n): - print "%+2s %+2s" % (lights[V[i].Value()], lights[P[i].Value()]), + print "%+2s %+2s" % (lights[V[i].Value()], lights[P[i].Value()]), print num_solutions += 1 - + solver.EndSearch() print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() print diff --git a/python/volsay3.py b/python/volsay3.py index 8bc33f65fc..2495900b6d 100644 --- a/python/volsay3.py +++ b/python/volsay3.py @@ -26,7 +26,7 @@ from linear_solver import pywraplp def main(unused_argv): - + # Create the solver. # using GLPK @@ -40,7 +40,7 @@ def main(unused_argv): # data num_products = 2 - + products = ['Gas', 'Chloride'] components = ['nitrogen', 'hydrogen', 'chlorine'] @@ -58,7 +58,7 @@ def main(unused_argv): for c in range(len(components)): solver.Add(solver.Sum([demand[p][c]*production[p] for p in range(len(products)) ]) <= stock[c]) - + # objective # Note: there is no support for solver.ScalProd in the LP/IP interface @@ -82,9 +82,9 @@ def main(unused_argv): print 'reduced_cost = ', production[i].reduced_cost() print - print 'walltime :', solver.wall_time(), 'ms' + print 'walltime :', solver.WallTime(), 'ms' print 'iterations:', solver.iterations() - - + + if __name__ == '__main__': main('Volsay') diff --git a/python/who_killed_agatha.py b/python/who_killed_agatha.py index c765a035b9..047a0c9860 100644 --- a/python/who_killed_agatha.py +++ b/python/who_killed_agatha.py @@ -1,16 +1,16 @@ # Copyright 2010 Hakan Kjellerstrand hakank@bonetmail.com # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ @@ -20,17 +20,17 @@ http://www.lsv.ens-cachan.fr/~goubault/H1.dist/H1.1/Doc/h1003.html ''' - Someone in Dreadsbury Mansion killed Aunt Agatha. - Agatha, the butler, and Charles live in Dreadsbury Mansion, and - are the only ones to live there. A killer always hates, and is no - richer than his victim. Charles hates noone that Agatha hates. Agatha - hates everybody except the butler. The butler hates everyone not richer - than Aunt Agatha. The butler hates everyone whom Agatha hates. - Noone hates everyone. Who killed Agatha? + Someone in Dreadsbury Mansion killed Aunt Agatha. + Agatha, the butler, and Charles live in Dreadsbury Mansion, and + are the only ones to live there. A killer always hates, and is no + richer than his victim. Charles hates noone that Agatha hates. Agatha + hates everybody except the butler. The butler hates everyone not richer + than Aunt Agatha. The butler hates everyone whom Agatha hates. + Noone hates everyone. Who killed Agatha? ''' - Originally from F. J. Pelletier: - Seventy-five problems for testing automatic theorem provers. + Originally from F. J. Pelletier: + Seventy-five problems for testing automatic theorem provers. Journal of Automated Reasoning, 2: 216, 1986. Note1: Since Google CP Solver/Pythons (currently) don't have @@ -41,7 +41,7 @@ Note2: There are 8 different solutions, all stating that Agatha killed herself - Compare with the following models: + Compare with the following models: * Choco : http://www.hakank.org/choco/WhoKilledAgatha.java * Choco : http://www.hakank.org/choco/WhoKilledAgatha_element.java * Comet : http://www.hakank.org/comet/who_killed_agatha.co @@ -70,7 +70,7 @@ def var_matrix_array(solver, rows, cols, lb, ub, name): t.append(solver.IntVar(lb, ub, '%s[%i,%i]'%(name, i,j))) x.append(t) return x - + def flatten_matrix(solver, m, rows, cols): return [m[i][j] for i in range(rows) for j in range(cols)] @@ -81,10 +81,10 @@ def print_flat_matrix(m_flat, rows, cols): print m_flat[i*cols+j].Value(), print print - + def main(the_killers): - + # Create the solver. solver = pywrapcp.Solver('Who killed agatha?') @@ -95,29 +95,29 @@ def main(the_killers): agatha = 0 butler = 1 charles = 2 - + # # declare variables # the_killer = solver.IntVar(0,2, 'the_killer') - the_victim = solver.IntVar(0,2, 'the_victim' ) + the_victim = solver.IntVar(0,2, 'the_victim' ) hates = var_matrix_array(solver, n, n, 0, 1, 'hates') - richer = var_matrix_array(solver, n, n, 0, 1, 'richer') + richer = var_matrix_array(solver, n, n, 0, 1, 'richer') hates_flat = flatten_matrix(solver, hates, n, n) - richer_flat = flatten_matrix(solver, richer, n, n) + richer_flat = flatten_matrix(solver, richer, n, n) # # constraints # - # Agatha, the butler, and Charles live in Dreadsbury Mansion, and - # are the only ones to live there. + # Agatha, the butler, and Charles live in Dreadsbury Mansion, and + # are the only ones to live there. - # A killer always hates, and is no richer than his victim. + # A killer always hates, and is no richer than his victim. # solver.Add(hates[the_killer, the_victim] == 1) - solver.Add(solver.Element(hates_flat,the_killer*n+the_victim) == 1) + solver.Add(solver.Element(hates_flat,the_killer*n+the_victim) == 1) # solver.Add(richer[the_killer, the_victim] == 0) solver.Add(solver.Element(richer_flat,the_killer*n+the_victim) == 0) @@ -135,46 +135,46 @@ def main(the_killers): bj = solver.IsEqualCstVar(richer[j][i], 0) solver.Add(bi == bj) - # Charles hates noone that Agatha hates. - #forall i : Range . + # Charles hates noone that Agatha hates. + #forall i : Range . # (hates[agatha, i] = 1) => (hates[charles, i] = 0), for i in range(n): b1a = solver.IsEqualCstVar(hates[agatha][i], 1) b1b = solver.IsEqualCstVar(hates[charles][i], 0) solver.Add(b1a-b1b <= 0) - # Agatha hates everybody except the butler. + # Agatha hates everybody except the butler. solver.Add(hates[agatha][charles] == 1) solver.Add(hates[agatha][agatha] == 1) solver.Add(hates[agatha][butler] == 0) - # The butler hates everyone not richer than Aunt Agatha. + # The butler hates everyone not richer than Aunt Agatha. # forall i : Range . # (richer[i, agatha] = 0) => (hates[butler, i] = 1), for i in range(n): b2a = solver.IsEqualCstVar(richer[i][agatha], 0) b2b = solver.IsEqualCstVar(hates[butler][i], 1) solver.Add(b2a-b2b<=0) - - # The butler hates everyone whom Agatha hates. + + # The butler hates everyone whom Agatha hates. #forall i : Range . # (hates[agatha, i] = 1) => (hates[butler, i] = 1), for i in range(n): b3a = solver.IsEqualCstVar(hates[agatha][i], 1) b3b = solver.IsEqualCstVar(hates[butler][i], 1) solver.Add(b3a-b3b <= 0) - - # Noone hates everyone. + + # Noone hates everyone. # forall i : Range . # (sum j : Range . hates[i,j]) <= 2, for i in range(n): solver.Add(solver.Sum([hates[i][j] for j in range(n)]) <= 2) - # Who killed Agatha? + # Who killed Agatha? solver.Add(the_victim == agatha) # @@ -182,15 +182,15 @@ def main(the_killers): # solution = solver.Assignment() solution.Add(the_killer) - solution.Add(the_victim) + solution.Add(the_victim) solution.Add(hates_flat) - solution.Add(richer_flat) + solution.Add(richer_flat) # db: DecisionBuilder db = solver.Phase(hates_flat + richer_flat, solver.CHOOSE_FIRST_UNBOUND, solver.ASSIGN_MIN_VALUE) - + solver.NewSearch(db) num_solutions = 0 while solver.NextSolution(): @@ -199,25 +199,25 @@ def main(the_killers): print "the_victim:", the_victim.Value() print "hates:" print_flat_matrix(hates_flat,n,n) - print "richer:" - print_flat_matrix(richer_flat,n,n) + print "richer:" + print_flat_matrix(richer_flat,n,n) print num_solutions += 1 - + solver.EndSearch() - + print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() the_killers = defaultdict(int) p = ["agatha", "butler", "charles"] if __name__ == '__main__': main(the_killers) - + print "\n" for k in the_killers: print "the killer %s was choosen in %i solutions" % (p[k], the_killers[k]) diff --git a/python/word_square.py b/python/word_square.py index 88856f3005..366eabb8a3 100644 --- a/python/word_square.py +++ b/python/word_square.py @@ -109,9 +109,9 @@ def main(words, word_len, num_answers=20): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() # diff --git a/python/xkcd.py b/python/xkcd.py index aab41877a2..c566940872 100644 --- a/python/xkcd.py +++ b/python/xkcd.py @@ -84,7 +84,7 @@ def main(): [collector]) - num_solutions = collector.solution_count() + num_solutions = collector.SolutionCount() print "num_solutions: ", num_solutions if num_solutions > 0: for s in range(num_solutions): @@ -99,9 +99,9 @@ def main(): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() else: print "No solutions found" diff --git a/python/young_tableaux.py b/python/young_tableaux.py index b2012cc834..579f057c39 100644 --- a/python/young_tableaux.py +++ b/python/young_tableaux.py @@ -151,9 +151,9 @@ def main(n = 5): print print "num_solutions:", num_solutions - print "failures:", solver.failures() - print "branches:", solver.branches() - print "wall_time:", solver.wall_time() + print "failures:", solver.Failures() + print "branches:", solver.Branches() + print "WallTime:", solver.WallTime() n=5 if __name__ == '__main__':