Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GLPK Java解决MILP类型的问题_Java_Solver_Glpk - Fatal编程技术网

GLPK Java解决MILP类型的问题

GLPK Java解决MILP类型的问题,java,solver,glpk,Java,Solver,Glpk,虽然我已经知道没有太多关于使用GLPK Java库的文档,但我还是要问一下。。。(不,我不能使用其他解算器) 我有一个基本的问题,涉及到日程安排。学生在本学期的课程中有一些基本的限制 问题的例子是: We consider {s1, s2} a set of two students. They need to take two courses {c1, c2} during two semesters {t1, t2}. We assume the courses are the same.

虽然我已经知道没有太多关于使用GLPK Java库的文档,但我还是要问一下。。。(不,我不能使用其他解算器)

我有一个基本的问题,涉及到日程安排。学生在本学期的课程中有一些基本的限制

问题的例子是:

We consider {s1, s2} a set of two students. They need to take two
courses {c1, c2} during two semesters {t1, t2}.
We assume the courses are the same. We also assume that the students
cannot take more than one course per semester, and we'd like to determine the
minimum capacity X that must be offered by the classroom, assuming they
all offer the same capacity.
我们以CPLEX格式给出的示例如下所示:

minimize X

subject to
y111 + y112 = 1
y121 + y122 = 1
y211 + y212 = 1
y221 + y222 = 1
y111 + y112 <= 1
y121 + y122 <= 1
y211 + y212 <= 1
y221 + y222 <= 1
y111 + y112 -X <= 0
y121 + y122 -X <= 0
y211 + y212 -X <= 0
y221 + y222 -X <= 0

end

此时,我假设您需要设置行约束,但我不知所措。使用API时,优化问题基本上由问题矩阵表示,其中列是变量,行是约束。 对于您的问题,您必须定义9列,表示y111、y112、。。。和X

然后,您可以通过设置使用的变量(列)继续使用约束(行)

这将表示
y111+y112=1
约束-11

GLPK for Java包中还应包含GLPK文档,其中包含GLPK函数的良好文档(GLPK for Java中也提供)。还可以看看lp.java示例

// Define Columns
GLPK.glp_add_cols(lp, 2);   // adds the number of columns
GLPK.glp_set_col_name(lp, 1, "Sem_1");
GLPK.glp_set_col_kind(lp, 1, GLPKConstants.GLP_IV);
GLPK.glp_set_col_bnds(lp, 1, GLPKConstants.GLP_LO, 0, 0);

GLPK.glp_set_col_name(lp, 2, "Sem_2");
GLPK.glp_set_col_kind(lp, 2, GLPKConstants.GLP_IV);
GLPK.glp_set_col_bnds(lp, 2, GLPKConstants.GLP_LO, 0, 0);
GLPK.glp_set_row_name(lp, 2, "constraint1");
GLPK.glp_set_row_bnds(lp, 2, GLPKConstants.GLP_FX, 0, 1.0); // equal to 1.0
GLPK.intArray_setitem(ind, 1, 1); // Add first column at first position
GLPK.intArray_setitem(ind, 2, 2); // Add second column at second position    
// set the coefficients to the variables (for all 1. except X is -1. in the example)
GLPK.doubleArray_setitem(val, 1, 1.); 
GLPK.doubleArray_setitem(val, 2, 1.);
GLPK.glp_set_mat_row(lp, 1, 2, ind, val);