or-tools

Rounding LinearExpr with google or-tools SAT solver

好久不见. 提交于 2020-07-21 07:08:53
问题 I'm creating a constraint (in Java) using or-tools SAT solver: IntVar x, y, z; IntVar[] variables = new IntVar{x, y, z}; int[] multiplier = new int{2, 3, 3}; LinearExpr expression = LinearExpr.scalProd(variables, multiplier); //2x + 3y + 3z model.addLessThan(expression, q); Where q is some given integer. The thing is that I need to round the expression result. Something like: if(expression < 25) { expression = 0; } else if(expression < 75) { expression = 50; } else if(expression < 125) {

Rounding LinearExpr with google or-tools SAT solver

南楼画角 提交于 2020-07-21 07:08:12
问题 I'm creating a constraint (in Java) using or-tools SAT solver: IntVar x, y, z; IntVar[] variables = new IntVar{x, y, z}; int[] multiplier = new int{2, 3, 3}; LinearExpr expression = LinearExpr.scalProd(variables, multiplier); //2x + 3y + 3z model.addLessThan(expression, q); Where q is some given integer. The thing is that I need to round the expression result. Something like: if(expression < 25) { expression = 0; } else if(expression < 75) { expression = 50; } else if(expression < 125) {

Rounding Non-LinearExpr with google or-tools SAT solver

与世无争的帅哥 提交于 2020-07-10 10:27:07
问题 Using CP-SAT of google or-tools I'm trying to write this constraint: q >= (50x + 100y + 150z + 200k + 250p + 300v) / (x + y + z + k + p + v) Where q is a simple integer. The thing is I need to round the right side of the equation (let's call it expression ) as follows: if(expression < 75) { expression = 50; } else if(expression < 125) { expression = 100; } else if(expression < 175) { expression = 150; } else if(expression < 225) { expression = 200; } else if(expression < 275) { expression =

How can I use CpModel to make three 1s appear in a 1D array ? (or-tools)

↘锁芯ラ 提交于 2020-07-09 17:13:24
问题 I want three 1s to appear in the shift array,I wrote the following code: model = cp_model.CpModel() solver = cp_model.CpSolver() shifts = {} for i in range(5): shifts[(i)] = model.NewIntVar(0, 3, "shifts(%i)" % i) for i in range(5): model.Add(sum([shifts[(i)]==1 for i in range(5) ]) == 3) solver = cp_model.CpSolver() status = solver.Solve(model) for i in range(5): print(solver.Value(shifts[(i)])) But it return: TypeError: unsupported operand type(s) for +: 'int' and 'BoundedLinearExpression'

Google OR-Tools in Intellij: UnsatisfiedLinkError

放肆的年华 提交于 2020-06-28 05:58:59
问题 I am setting up a java framework that should use the Google OR-Tools. The code below compiles successfully, but throws an exception at runtime: Exception in thread "main" java.lang.UnsatisfiedLinkError: com.google.ortools.linearsolver.operations_research_linear_solverJNI.MPSolver_CLP_LINEAR_PROGRAMMING_get()I at com.google.ortools.linearsolver.operations_research_linear_solverJNI.MPSolver_CLP_LINEAR_PROGRAMMING_get(Native Method) at com.google.ortools.linearsolver.MPSolver

or-tools NewIntVar seems not supporting int64 in python

梦想的初衷 提交于 2020-05-15 21:31:27
问题 Dears, I'm trying to create NewIntVar with lower bound an higher bound equal to the one of the int64: (-9.223.372.036.854.775.808 to +9.223.372.036.854.775.807) But I get the Model invalid error when I try to solve the model. The max range I found as working (trying manually) is the following model.NewIntVar(-93.372.036.854.775.808, 9.123.372.036.854.775.807,'pippo') Do you know why int64 is not supported? Thanks Stefano 回答1: From the source code I see: https://github.com/google/or-tools/blob

Linear Programming - Google ortools - incorrect decision variable final values

拜拜、爱过 提交于 2020-04-11 07:52:09
问题 I am trying to solve a linear programming problem. Following are specs of the problem: I have a network flow problem that's been converted to a linear programming problem. So, all the flow constraints, such as capacity, flow conservation etc., will have to be enforced. My objective is to minimize cost. Decision Variables - I have built two 8x8 matrices by defining a dictionary and adding decision variable at each of those 128 locations. Constraints - there are in total 24 constraints, namely: