gurobi

How to prevent Gurobi from converting a Max into a Min prob?

99封情书 提交于 2020-01-06 20:01:48
问题 I am using Gurobi (via C++) as part of my MSc thesis to solve Quadratic Knapsack Problem instances. So far, I was able to generate a model with binary decision variables, quadratic objective function and the capacity constraint and Gurobi solved it just fine. Then I wanted to solve the continuous relaxation of the QKP. I built the model as before but with continuous variables instead of binary ones and Gurobi threw me an exception when I tried to optimize it: 10020 - Objective Q not PSD

Can I presolve an ILP model before optimization?

筅森魡賤 提交于 2019-12-24 15:18:03
问题 I am getting out of memory while building the model. Is there any way, to reduce the model while building it using existing functions? Details: Assume I have the following model (from the docs here section Presolve. The real code also uses sparse matrices, so this is just to figure out what can be done further): min 2*x1 - 5*x2 + 3*x3 + 10*x4 s.t. x1 + x2 + x3 = 15 (1) x1 <= 7 (2) x2 <= 3 (3) x3 <= 5 (4) x4 > 1 (5) Clearly the only way that all of these constraints can be satisfied is if x1 =

How can you use Gurobi's vbasis and cbasis with the R-Interface?

自古美人都是妖i 提交于 2019-12-24 08:30:09
问题 I found an explanation in the docs here and here: vbasis Variable basis status values for the computed optimal basis. You generally should not concern yourself with the contents of this array. If you wish to use an advanced start later, you would simply copy the vbasis and cbasis arrays into the corresponding fields for the next model. This array contains one entry for each column of A. cbasis Constraint basis status values for the computed optimal basis. This array contains one entry for

Gurobi: Save model after presolve for reuse

随声附和 提交于 2019-12-24 06:10:32
问题 I'm looking for a way to save a presolved model in gurobi, so that I can save the time necessary for presolving the next time I'm running the model. I have tried to write the model to a .mps/.lp file using a callback function after presolve, but when I load the file it starts to presolve again. I'd also be thankful for negative answers, if what I'm looking for isn't possible. PS.: I'm using Gurobi 7.5.2 with python 3.6 回答1: It is very uncommon to save the presolved model. The key exceptions

Gurobi, How to change a continuous variable to a binary variable

半腔热情 提交于 2019-12-24 00:52:29
问题 I am using gurobi-python interface. Is there anyway to convert a continuous variable to a binary variable. I just do not want to convert m.addVar(lb=0, ub=1, vtype=GRB.CONTINUOUS) to m.addVar(lb=0, ub=1, vtype=GRB.BINARY). I have to do it in another way, not using m.addVar() I appreciate your possible feedback. Thank you. 回答1: In the gurobi python API, you can simply set the vtype attribute on the variable. It is easy if you save a reference to the variable In your case, if you create a

TypeError: unsupported operand type(s) for +: 'generator' and 'generator'

点点圈 提交于 2019-12-22 12:23:03
问题 I have a problem with adding three expressions in my objective function. I used quicksum to build each expression. However, when I try to add them together I get an error that I cannot use +/- operands on class 'generator'. Here is the last part of my code: # the shipping cost expression expr_sc = [] for j in J: for k in K: expr_sc.append(quicksum(r_jk[(j, k)]*x[(i, j, k)]) for i in I) m.setObjective((quicksum(item_rev) for item_rev in expr_rev) - ((quicksum(item_pc) for item_pc in expr_pc) +

Get constraints in matrix format from gurobipy

冷暖自知 提交于 2019-12-18 11:44:34
问题 I coded my model in gurobipy and I want to get the matrix of constraints and vector of cost. Is there any way to access those? 回答1: From the python API, there's no single function to get the matrix coefficients from a Gurobi model, but it's not to hard to write one yourself. It is convenient to have lists of your variables and constraints. If you have a gurobi model in variable m dvars = m.getVars() constrs = m.getConstrs() will give you the list of variables and constraints. You can then use

Adding multiple quadratic terms to objective function in Gurobi Python

拈花ヽ惹草 提交于 2019-12-13 04:44:22
问题 I'd like to set up an objective function in Gurobi to minimize x^2 + y^2 . I've done my best to provide an example below: import gurobipy as gbPy model = gbPy.Model() A = [1, 2, 3, 4, 5] B = [1, 2, 3] x = model.addVars(5, lb = 0) y = model.addVars(3, lb = 0) for i in range(len(x)): model.addConstr(x[i] >= A[i]) for i in range(len(y)): model.addConstr(y[i] >= B[i]) objExp = gbPy.QuadExpr() objExp.addTerms(???) model.setObjective(objExp, gbPy.GRB.MINIMIZE) But I'm not sure how to indicate the

Constraint violation for Linear Integer Programming in Python Gurobi

半腔热情 提交于 2019-12-13 03:10:34
问题 I am trying to implement LIP in Gurobi but somehow the constraints related to single edge into the node and single edge out of the node is being violated. The following are the equations ( I am not copying the equations exactly interms of the summations limits so its (i,j) 0 - N for now, however the constraint should not be violated regardless ) So the bottom equation simply states that there should be one edge coming in and leaving the vertex or node. However in the following code I added

Using gurobi with java vs gurobi with ampl

霸气de小男生 提交于 2019-12-12 23:35:03
问题 What are the advantages of using Gurobi with AMPL instead of using Gurobi direct API (java, C#, C++, etc.) for solving large MIP problems? Are there performance benefits when using Gurobi's API instead of AMPL? 回答1: Up until the mid 90's the only practical options for using a MIP solver with large scale problems (so excluding spreadsheets) were creating mps files using the low-level C interface (known as the callable library in cplex) using a domain specific language like AMPL or GAMS. At the