This is the sixtieth second part of the ILP series. For your convenience you can find other parts in the table of contents in Part 1 – Boolean algebra
Today we are going to solve a chess problem variation. We want to generate a chess board (with regular pieces for each player) with maximal attacking score. An attack is the same as in chess — a position in which one piece can capture another one in subsequent move.
We are interested in any position, it doesn’t need to be a legal one (so both kings can be under check, pawns can be in any rank or file etc) nor achievable (so we don’t care if there is a sequence of legal moves leading to a given position). We need to use all 32 pieces, no promotions are allowed.
The code is rather trivial, however, it is pretty hard to maximize the function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
var solver = new CplexMilpSolver(new CplexMilpSolverSettings { IntegerWidth = 15, Epsilon = 0.1, StoreDebugExpressions = false, CacheConstants = false, StoreDebugConstraints = false }); var width = 8; var height = 8; Console.WriteLine("Create variables"); var fields = Enumerable.Range(0, height).Select(r => Enumerable.Range(0, width).Select(c => new System.Dynamic.ExpandoObject()).ToArray()).ToArray(); var fieldsFlattened = fields.SelectMany(f => f).ToArray(); for(int row=0;row<height;++row){ for(int column=0;column<width;++column){ dynamic self = fields[row][column]; self.IsWhitePawn = solver.Create("WhitePawn_" + row + "_" + column, Domain.BinaryInteger); self.IsBlackPawn = solver.Create("BlackPawn_" + row + "_" + column, Domain.BinaryInteger); self.IsWhiteKnight = solver.Create("WhiteKnight_" + row + "_" + column, Domain.BinaryInteger); self.IsBlackKnight = solver.Create("BlackKnight_" + row + "_" + column, Domain.BinaryInteger); self.IsWhiteBishop = solver.Create("WhiteBishop_" + row + "_" + column, Domain.BinaryInteger); self.IsBlackBishop = solver.Create("BlackBishop_" + row + "_" + column, Domain.BinaryInteger); self.IsWhiteRook = solver.Create("WhiteRook_" + row + "_" + column, Domain.BinaryInteger); self.IsBlackRook = solver.Create("BlackRook_" + row + "_" + column, Domain.BinaryInteger); self.IsWhiteQueen = solver.Create("WhiteQueen_" + row + "_" + column, Domain.BinaryInteger); self.IsBlackQueen = solver.Create("BlackQueen_" + row + "_" + column, Domain.BinaryInteger); self.IsWhiteKing = solver.Create("WhiteKing_" + row + "_" + column, Domain.BinaryInteger); self.IsBlackKing = solver.Create("BlackKing_" + row + "_" + column, Domain.BinaryInteger); } } Console.WriteLine("Make some general variables"); for(int row=0;row<height;++row){ for(int column=0;column<width;++column){ dynamic self = fields[row][column]; self.IsKnight = solver.Operation<Disjunction>(self.IsWhiteKnight, self.IsBlackKnight); self.IsBishop = solver.Operation<Disjunction>(self.IsWhiteBishop, self.IsBlackBishop); self.IsRook = solver.Operation<Disjunction>(self.IsWhiteRook, self.IsBlackRook); self.IsQueen = solver.Operation<Disjunction>(self.IsWhiteQueen, self.IsBlackQueen); self.IsKing = solver.Operation<Disjunction>(self.IsWhiteKing, self.IsBlackKing); self.IsWhite = solver.Operation<Disjunction>(self.IsWhiteKing, self.IsWhiteQueen, self.IsWhiteRook, self.IsWhiteBishop, self.IsWhiteKnight, self.IsWhitePawn); self.IsBlack = solver.Operation<Disjunction>(self.IsBlackKing, self.IsBlackQueen, self.IsBlackRook, self.IsBlackBishop, self.IsBlackKnight, self.IsBlackPawn); self.IsAny = solver.Operation<Disjunction>(self.IsWhite, self.IsBlack); self.IsNotAny = solver.Operation<BinaryNegation>(self.IsAny); } } Console.WriteLine("Each field has one type"); for(int row=0;row<height;++row){ for(int column=0;column<width;++column){ dynamic self = fields[row][column]; var type = solver.Operation<Addition>(self.IsWhitePawn, self.IsBlackPawn, self.IsWhiteKnight, self.IsBlackKnight, self.IsWhiteBishop, self.IsBlackBishop, self.IsWhiteRook, self.IsBlackRook, self.IsWhiteQueen, self.IsBlackQueen, self.IsWhiteKing, self.IsBlackKing); solver.Set<LessOrEqual>(type, solver.FromConstant(1)); } } Console.WriteLine("Chess number of pieces"); solver.Set<Equal>(solver.FromConstant(8), solver.Operation<Addition>(fieldsFlattened.Select(f => (IVariable)((dynamic)f).IsWhitePawn).ToArray())); solver.Set<Equal>(solver.FromConstant(8), solver.Operation<Addition>(fieldsFlattened.Select(f => (IVariable)((dynamic)f).IsBlackPawn).ToArray())); solver.Set<Equal>(solver.FromConstant(2), solver.Operation<Addition>(fieldsFlattened.Select(f => (IVariable)((dynamic)f).IsWhiteKnight).ToArray())); solver.Set<Equal>(solver.FromConstant(2), solver.Operation<Addition>(fieldsFlattened.Select(f => (IVariable)((dynamic)f).IsBlackKnight).ToArray())); solver.Set<Equal>(solver.FromConstant(2), solver.Operation<Addition>(fieldsFlattened.Select(f => (IVariable)((dynamic)f).IsWhiteBishop).ToArray())); solver.Set<Equal>(solver.FromConstant(2), solver.Operation<Addition>(fieldsFlattened.Select(f => (IVariable)((dynamic)f).IsBlackBishop).ToArray())); solver.Set<Equal>(solver.FromConstant(2), solver.Operation<Addition>(fieldsFlattened.Select(f => (IVariable)((dynamic)f).IsWhiteRook).ToArray())); solver.Set<Equal>(solver.FromConstant(2), solver.Operation<Addition>(fieldsFlattened.Select(f => (IVariable)((dynamic)f).IsBlackRook).ToArray())); solver.Set<Equal>(solver.FromConstant(1), solver.Operation<Addition>(fieldsFlattened.Select(f => (IVariable)((dynamic)f).IsWhiteQueen).ToArray())); solver.Set<Equal>(solver.FromConstant(1), solver.Operation<Addition>(fieldsFlattened.Select(f => (IVariable)((dynamic)f).IsBlackQueen).ToArray())); solver.Set<Equal>(solver.FromConstant(1), solver.Operation<Addition>(fieldsFlattened.Select(f => (IVariable)((dynamic)f).IsWhiteKing).ToArray())); solver.Set<Equal>(solver.FromConstant(1), solver.Operation<Addition>(fieldsFlattened.Select(f => (IVariable)((dynamic)f).IsBlackKing).ToArray())); var goal = solver.FromConstant(0); Action<int, int, Action<dynamic>> withField = (row, column, lambda) => { if(row >= 0 && row < height && column >= 0 && column < width){ dynamic field = fields[row][column]; lambda(field); } }; Action<IVariable> addToGoal = v => goal = solver.Operation<Addition>(goal, v); Action<int, Func<int, int>, Func<int, int>, IVariable, Func<dynamic, IVariable>> handleMatching = (range, rowCounter, columnCounter, isMatching, targetExtractor) => { var isFree = solver.FromConstant(1); for(int i=1;i<=range;++i){ withField(rowCounter(i), columnCounter(i), t => addToGoal(solver.Operation<Conjunction>(isMatching, targetExtractor(t), isFree))); withField(rowCounter(i), columnCounter(i), t => isFree = solver.Operation<Conjunction>(isFree, t.IsNotAny)); } }; Console.WriteLine("Add points from pawns"); for(int row=0;row<height;++row){ for(int column=0;column<width;++column){ dynamic self = fields[row][column]; withField(row-1, column-1, t => addToGoal(solver.Operation<Conjunction>(self.IsWhitePawn, t.IsBlack))); withField(row-1, column+1, t => addToGoal(solver.Operation<Conjunction>(self.IsWhitePawn, t.IsBlack))); withField(row+1, column-1, t => addToGoal(solver.Operation<Conjunction>(self.IsBlackPawn, t.IsWhite))); withField(row+1, column+1, t => addToGoal(solver.Operation<Conjunction>(self.IsBlackPawn, t.IsWhite))); } } Console.WriteLine("Add points from knights"); for(int row=0;row<height;++row){ for(int column=0;column<width;++column){ dynamic self = fields[row][column]; withField(row-2, column-1, t => addToGoal(solver.Operation<Conjunction>(self.IsWhiteKnight, t.IsBlack))); withField(row-1, column-2, t => addToGoal(solver.Operation<Conjunction>(self.IsWhiteKnight, t.IsBlack))); withField(row+1, column-2, t => addToGoal(solver.Operation<Conjunction>(self.IsWhiteKnight, t.IsBlack))); withField(row+2, column-1, t => addToGoal(solver.Operation<Conjunction>(self.IsWhiteKnight, t.IsBlack))); withField(row+2, column+1, t => addToGoal(solver.Operation<Conjunction>(self.IsWhiteKnight, t.IsBlack))); withField(row+1, column+2, t => addToGoal(solver.Operation<Conjunction>(self.IsWhiteKnight, t.IsBlack))); withField(row-1, column+2, t => addToGoal(solver.Operation<Conjunction>(self.IsWhiteKnight, t.IsBlack))); withField(row-2, column+1, t => addToGoal(solver.Operation<Conjunction>(self.IsWhiteKnight, t.IsBlack))); withField(row-2, column-1, t => addToGoal(solver.Operation<Conjunction>(self.IsBlackKnight, t.IsWhite))); withField(row-1, column-2, t => addToGoal(solver.Operation<Conjunction>(self.IsBlackKnight, t.IsWhite))); withField(row+1, column-2, t => addToGoal(solver.Operation<Conjunction>(self.IsBlackKnight, t.IsWhite))); withField(row+2, column-1, t => addToGoal(solver.Operation<Conjunction>(self.IsBlackKnight, t.IsWhite))); withField(row+2, column+1, t => addToGoal(solver.Operation<Conjunction>(self.IsBlackKnight, t.IsWhite))); withField(row+1, column+2, t => addToGoal(solver.Operation<Conjunction>(self.IsBlackKnight, t.IsWhite))); withField(row-1, column+2, t => addToGoal(solver.Operation<Conjunction>(self.IsBlackKnight, t.IsWhite))); withField(row-2, column+1, t => addToGoal(solver.Operation<Conjunction>(self.IsBlackKnight, t.IsWhite))); } } Console.WriteLine("Add points from bishops"); for(int row=0;row<height;++row){ for(int column=0;column<width;++column){ dynamic self = fields[row][column]; handleMatching(7, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column - i), self.IsWhiteBishop, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column - i), self.IsWhiteBishop, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column + i), self.IsWhiteBishop, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column + i), self.IsWhiteBishop, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column - i), self.IsBlackBishop, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(7, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column - i), self.IsBlackBishop, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(7, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column + i), self.IsBlackBishop, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(7, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column + i), self.IsBlackBishop, (Func<dynamic, IVariable>)(t => t.IsWhite)); } } Console.WriteLine("Add points from rooks"); for(int row=0;row<height;++row){ for(int column=0;column<width;++column){ dynamic self = fields[row][column]; handleMatching(7, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column), self.IsWhiteRook, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column), self.IsWhiteRook, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row), (Func<int, int>)(i => column - i), self.IsWhiteRook, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row), (Func<int, int>)(i => column + i), self.IsWhiteRook, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column), self.IsBlackRook, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(7, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column), self.IsBlackRook, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(7, (Func<int, int>)(i => row), (Func<int, int>)(i => column - i), self.IsBlackRook, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(7, (Func<int, int>)(i => row), (Func<int, int>)(i => column + i), self.IsBlackRook, (Func<dynamic, IVariable>)(t => t.IsWhite)); } } Console.WriteLine("Add points from queens"); for(int row=0;row<height;++row){ for(int column=0;column<width;++column){ dynamic self = fields[row][column]; handleMatching(7, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column - i), self.IsWhiteQueen, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column - i), self.IsWhiteQueen, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column + i), self.IsWhiteQueen, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column + i), self.IsWhiteQueen, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column), self.IsWhiteQueen, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column), self.IsWhiteQueen, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row), (Func<int, int>)(i => column - i), self.IsWhiteQueen, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row), (Func<int, int>)(i => column + i), self.IsWhiteQueen, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(7, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column - i), self.IsBlackQueen, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(7, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column - i), self.IsBlackQueen, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(7, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column + i), self.IsBlackQueen, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(7, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column + i), self.IsBlackQueen, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(7, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column), self.IsBlackQueen, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(7, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column), self.IsBlackQueen, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(7, (Func<int, int>)(i => row), (Func<int, int>)(i => column - i), self.IsBlackQueen, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(7, (Func<int, int>)(i => row), (Func<int, int>)(i => column + i), self.IsBlackQueen, (Func<dynamic, IVariable>)(t => t.IsWhite)); } } Console.WriteLine("Add points from kings"); for(int row=0;row<height;++row){ for(int column=0;column<width;++column){ dynamic self = fields[row][column]; handleMatching(1, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column - i), self.IsWhiteKing, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(1, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column - i), self.IsWhiteKing, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(1, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column + i), self.IsWhiteKing, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(1, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column + i), self.IsWhiteKing, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(1, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column), self.IsWhiteKing, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(1, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column), self.IsWhiteKing, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(1, (Func<int, int>)(i => row), (Func<int, int>)(i => column - i), self.IsWhiteKing, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(1, (Func<int, int>)(i => row), (Func<int, int>)(i => column + i), self.IsWhiteKing, (Func<dynamic, IVariable>)(t => t.IsBlack)); handleMatching(1, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column - i), self.IsBlackKing, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(1, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column - i), self.IsBlackKing, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(1, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column + i), self.IsBlackKing, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(1, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column + i), self.IsBlackKing, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(1, (Func<int, int>)(i => row - i), (Func<int, int>)(i => column), self.IsBlackKing, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(1, (Func<int, int>)(i => row + i), (Func<int, int>)(i => column), self.IsBlackKing, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(1, (Func<int, int>)(i => row), (Func<int, int>)(i => column - i), self.IsBlackKing, (Func<dynamic, IVariable>)(t => t.IsWhite)); handleMatching(1, (Func<int, int>)(i => row), (Func<int, int>)(i => column + i), self.IsBlackKing, (Func<dynamic, IVariable>)(t => t.IsWhite)); } } solver.AddGoal("Goal", goal); solver.SaveModel(new SaveFileSettings { Path = "C:\\afish\\Chess.mps" }); solver.Solve(); Console.WriteLine(solver.GetValue(goal)); for(var row = 0; row < height;++row){ for(var column = 0; column < width; ++ column){ var backColor = ((column + (row % 2)) % 2 == 0) ? ConsoleColor.DarkGreen : ConsoleColor.Green; Console.BackgroundColor = backColor; dynamic self = fields[row][column]; Console.ForegroundColor = ConsoleColor.White; if(solver.GetValue(self.IsWhitePawn) > 0.5){ Console.Write("P"); }else if(solver.GetValue(self.IsWhiteKnight) > 0.5){ Console.Write("N"); }else if(solver.GetValue(self.IsWhiteBishop) > 0.5){ Console.Write("B"); }else if(solver.GetValue(self.IsWhiteRook) > 0.5){ Console.Write("R"); }else if(solver.GetValue(self.IsWhiteQueen) > 0.5){ Console.Write("Q"); }else if(solver.GetValue(self.IsWhiteKing) > 0.5){ Console.Write("K"); }else { Console.ForegroundColor = ConsoleColor.Black; if(solver.GetValue(self.IsBlackPawn) > 0.5){ Console.Write("P"); }else if(solver.GetValue(self.IsBlackKnight) > 0.5){ Console.Write("N"); }else if(solver.GetValue(self.IsBlackBishop) > 0.5){ Console.Write("B"); }else if(solver.GetValue(self.IsBlackRook) > 0.5){ Console.Write("R"); }else if(solver.GetValue(self.IsBlackQueen) > 0.5){ Console.Write("Q"); }else if(solver.GetValue(self.IsBlackKing) > 0.5){ Console.Write("K"); }else{ Console.ForegroundColor = backColor; Console.Write(" "); } } } Console.ResetColor(); Console.WriteLine(); } Console.ResetColor(); |
In lines 13-32 we define binary flags describing what piece a field is. Next, in lines 34-48 we define some helper variables (to avoid recalculation) and then in lines 50-57 we make sure each field is of an exactly one type (or is empty). Finally, in lines 59-71 we make sure we have correct number of pieces on the board.
Then we define our goal. We start with some helper functions in lines 73-90 and then start adding rules for each piece. Pawns in lines 91-102 are rather trivial, we just check if a pawn attacks one of two neighbours (notice that we number rows from top to bottom so white pawns would move form higher ranks to lower ones). Similarly for knights in lines 104-127 (knight is essentially a pawn attacking some different fields).
Bishops, rooks, queens and kings are based on the same approach. We move farther and farther away from the starting position (whether in rank/file for rooks or diagonally for bishops), calculate a variable if given direction is still allowed (as we cannot “jump over” pieces) and update the state. For queens and kings it’s essentially the same.
Finally, we save the model, solve it and print the solution. Below is an example of some (non-optimal) result:
This is after running for 10 minutes on my machine using CPLEX. However, I ran it through Neos for 8 hours and found solution of value 98 which is presented below:
I actually don’t know if this is the optimal one but according to Gurobi it cannot be higher than 116. Maybe one day I’ll run it for more time to explore all nodes.
We can use this snippet to set a lower bound for the solution:
1 2 3 4 |
solver.Cplex.SetParam(ILOG.CPLEX.Cplex.Param.MIP.Tolerances.MIPGap, 1); solver.Cplex.SetParam(ILOG.CPLEX.Cplex.Param.MIP.Tolerances.AbsMIPGap, 100); solver.Cplex.SetParam(ILOG.CPLEX.Cplex.Param.MIP.Tolerances.LowerCutoff, 81); solver.Cplex.SetParam(ILOG.CPLEX.Cplex.Param.MIP.Limits.Solutions, 1); |
This allows for getting any solution as soon as possible or improving above something we know is possible.