我正在努力收集java中的解决方案。这个问题需要一个混合整数线性问题,其中我必须收集多个解决方案。我使用gurobi进行优化,我们应该为决策变量获得多个解决方案。我正在使用下面给出的Solutioncollection。在解决方案类中,检索解决方案并且可以设置目标值。我的问题是如何获得决策变量的不同值。到目前为止,我在优化器和解决方案集合中有以下代码:
CLSPSolutionCollection collection = new CLSPSolutionCollection ();
CLSPSolution sol = new CLSPSolution (K,T);
model.optimize();
// 6. determine production quantities, setups and overtime ----------------------------------------------------------
if (model.get(GRB.IntAttr.Status) == GRB.Status.OPTIMAL) {
int s = model.get(GRB.IntAttr.SolCount);
model.set(GRB.IntParam.SolutionNumber, s);
sol.setObjectiveValue((int) model.get(GRB.DoubleAttr.ObjNVal)); // produce result
for (int k = 0; k < K; k++) {
for (int t = 0; t < T; t++) {
sol.setProductionQuantity(k, t, q[k][t].get(GRB.DoubleAttr.Xn)); // set decision variable q
sol.setSetupDecision(k, t, gamma[k][t].get(GRB.DoubleAttr.Xn)); // set decision variable Q
sol.setOvertimeDecision(t, beta[t].get(GRB.DoubleAttr.Xn)); // set decision variable Q
//collection.add();
}}
}
// if
// clean up ---------------------------------------------------------------------------------------------------------
model.dispose();
env.dispose();
} catch ( GRBException e){
e.printStackTrace();
} // catcher in the rye
return collection;
// COLLECTION CLASS 公共类CLSPSolutionCollection {
private ArrayList<CLSPSolution> solutions;
public CLSPSolutionCollection ( ) {
// TODO
} // constructor
//TODO ..
public void add ( CLSPSolution solution ) {
solutions.add(solution);
} // add
public int size ( ) {
return solutions.size();
} // size
public CLSPSolution get ( int index ) {
return solutions.get(index);
} // get
} // CLSPSolutionCollection