Stradivari
  • Member for 2 years, 6 months
  • Last seen this week
Creating a Continuous Decision Variable between 0 and 1 in Python-MIP Interface
Accepted answer
12 votes

I don't know much about Python-mip but looking at the code, maximize expects a LinExpr, so I tried: model.objective = maximize(1*x) which gives the expected output. Edit: I also opened a PR to ...

View answer
Precedence Constraint in OR-Tools
Accepted answer
8 votes

What you want is: AddLessOrEqual(LinearExpr(starts[j]).AddConstant(durations[j]), starts[succ[j][s]]) You might also want to take a look at the examples (ending with _sat.cc) to be more familiar ...

View answer
CP-SAT ortools - Is there any complete list of possible/available StringParameters for the CpSolver?
Accepted answer
7 votes

As many things in Google, OR-Tools uses Protocol Buffers to serialize data. Here's a list of all .proto files in OR-Tools: https://github.com/google/or-tools/search?l=Protocol+Buffer The parameters ...

View answer
Constraint Programming OR-Tools finding Matrix Combinations
Accepted answer
7 votes

You get the same result $2^{\operatorname{len}(y)}$ times because $y_i$ is not constrained. You can see that by adding this to your callback: print("y:", [self.Value(y) for y in self._y.values()]) ...

View answer
How exactly does OptionalIntervalVar work in OR-Tools?
6 votes

In the Python API there is a pretty good docstring of what an OptionalIntervalVar is: An optional interval variable is a constraint, that is itself used in other constraints like NoOverlap. This ...

View answer
OR-Tools: Partial Solution ignored due to "unknown rate is too large"
Accepted answer
5 votes

Try: SetSolverSpecificParametersAsString("heuristics/completesol/maxunknownrate = 0.9") References: SCIP params SetSolverSpecificParametersAsString usage

View answer
Error when defining variables in Pyomo
Accepted answer
5 votes

You are just importing the pyomo.environ module while the tutorials probably use the from syntax. These variables are inside pyomo.environ so you have 3 alternatives: Import them explicitly from ...

View answer
Creating a Decision Variable in Python-MIP with Dictionaries
Accepted answer
5 votes

Haven't used python-mip but to create multi-index variables I usually do: x = { (e, s, a): model.add_var( name="x({},{},{})".format(e, s, a), var_type=INTEGER, ub=...

View answer
What is the difference between optimization software APIs based on performance and speed?
5 votes

Python is a "slow" programming language because it is interpreted (at least CPython is), so in OR-Tools, for example, that impacts the model building speed if the model is big enough or your logic ...

View answer
assigning values to IntVar if and only if BoolVar, else zero [or-tools]
Accepted answer
5 votes

To create an intermediate boolean that is true iff s[j] == t you just have to create 2 constraints: cp_model.AddEquality(s[j], t).OnlyEnforceIf(b); cp_model.AddNotEqual(s[j], t).OnlyEnforceIf(Not(b));...

View answer
How to know which constraint in CP-SAT did not meet the feasibility gap
Accepted answer
4 votes

Not yet, see https://github.com/google/or-tools/issues/973 For debugging I would recommend you to divide your constraints into groups so you can activate/deactivate some of them to pin down the ...

View answer
How to balance the workload of teachers in OR-Tools (maximization of the minimum)
4 votes

min, max, functions do not work in OR-Tools, you should use AddMinEquality instead: ... workload = [] for j in range(num_of_teacher): tmp = model.NewIntVar(0, num_of_students, "") ...

View answer
ValidateModel or tools in c++ and proto problems
4 votes

CpModelProto is a protobuf representation of your model in ortools. You create it by using the CpModelBuilder class (your cp_model), and calling its Build() method, the SolveCpModel function that you ...

View answer
How to add logical OR constraint in OR-Tools?
Accepted answer
3 votes

You can also do: model.AddLinearExpressionInDomain(sum(variables), cp_model.Domain.FromValues([1, 3])) Or even: for d in all_days: for s in all_shifts: b = model.NewBoolVar("") ...

View answer
How to model two variables to NOT to belong to the same set partition using Constraint Programming
2 votes

Using intermediate booleans and AddLinearExpressionInDomain you get: from ortools.sat.python import cp_model model = cp_model.CpModel() solver = cp_model.CpSolver() x = model.NewIntVar(1, 1000, &...

View answer