虽然我已经知道没有太多关于使用 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
我可以通过 glpsol 命令通过求解器运行它并让它求解,但我需要使用 API 编写它。我从来没有真正使用过线性规划,文档还有一些不足之处。虽然这充其量只是简单化,但真正的问题涉及解决 12 个学期的 600 名学生,他们必须参加 18 门课程中的 12 门课程,其中某些课程仅在某些学期可用,而某些课程有先决条件。
我需要帮助将简单的问题转换为使用 API 的编码示例。我假设一旦我可以看到非常简单的问题如何映射到 API 调用,我就可以弄清楚如何为更复杂的问题创建应用程序。
从库中的示例中,我可以看到您设置了在这种情况下为学期的列,而行是学生
// 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);
在这一点上,我假设您需要设置行约束,但我不知所措。任何方向将不胜感激。