Gurobi Java API
Hello support team,
I have worked on the transfer a GAMS/Gurobi model into the Gurobi Java API. The GAMS code is:
Binary variable rank(i,k);
Equations c1,c2;
c1(k).. sum(i, rank(i,k)) =e= 1;
c2(i).. sum(k, rank(i,k)) =e= 1;
Where indices i and k belong to the item set.
l try to code it using SOS1 as below:
GRBVar[] test = new GRBVar[item.length * item.length];
double[] weight = new double[item.length * item.length];
for (int k = 0; k < item.length; k++) {
for (int i = 0; i < item.length; i++) {
int v = i * item.length + k;
weight[v] = 1.0;
test[v] = rank[i][k];
}
}
model.addSOS(test, weight, GRB.SOS_TYPE1);
And for the second constraint like this.
I tried it with added "GRBLinExpr" to the above loop but, in both cases, the results are the same and equal to the zero.
Could you tell me please, is there a specific way to add such constraints using SOS1? and do I have any mistake to code it?
Thanks in advance
Omidi. A
-
Why do you want to use SOS1? An SOS1 constraint says that at most one of the variables must be non-zero. If all variables are binary (as in your case), an SOS1 constraint on a set x1, x2, ..., xn is therefore equivalent to a linear constraint
x1 + x2 + ... + xn <= 1
Consequently, the all-zero solution is feasible. But in your AMPL model you have equations. Why don't you just use linear constraints just like in the AMPL model?
0 -
Dear Tobias,
Thanks for your reply.
I have written the model using binary (or integer) variables and it works fine (using GUROBI Java API). AKAIK, the SOS1 variables could reduce the solving time. In the GAMS/Gurobi with the define of SOS1 variable it works and the solution is the same as the binary variable solution. I try to write the model using GUROBI Java API but, I have issues that mentioned before (to use SOS1). Unfortunately, I have a problem to write such constraint. Could you tell me is there any way to use SOS1 to my model or the only possible way is to use binary (or integer) variables?
I would be appreciated for any help.Regards
Omidi. A
0
サインインしてコメントを残してください。
コメント
2件のコメント