写点什么

一起玩 OptaPlanner-Study,玩转第一个程序

作者:OptaPlanner
  • 2022 年 10 月 01 日
    广东
  • 本文字数:2601 字

    阅读完需:约 9 分钟

国庆看着女篮比赛,中国 vs 美国,落后 20 多分,还不放弃的追赶,实在太难了。

还好用 OptaPlanner 做 APS 排程,也没有那么难嘛!

1、代码工程

这个是在官方 sample 基础上,做了简化优化的版本,方便各位初学者调试。

git clone https://gitee.com/optaplanner/optaplanner-study.git

复制代码

用 IDEA 工具,打开 optaplanner-study\OptaPlannerHelloworld,如下图,更新 maven 配置后,运行主程序 TimeTableApp,即可。


2、运行效果

控制台输出以下信息,说明运行正常。输出的是 教师、教室、课程的排程表。

15:28:56.204 [main        ] INFO  Solving started: time spent (228), best score (-40init/0hard/0soft), environment mode (REPRODUCIBLE), move thread count (NONE), random (JDK with seed 0).15:28:57.249 [main        ] INFO  Construction Heuristic phase (0) ended: time spent (1276), best score (-1hard/-15soft), score calculation speed (601/sec), step total (20).15:29:00.973 [main        ] INFO  Local Search phase (1) ended: time spent (5000), best score (0hard/6soft), score calculation speed (17074/sec), step total (8463).15:29:00.975 [main        ] INFO  Solving ended: time spent (5000), best score (0hard/6soft), score calculation speed (12796/sec), phase total (2), environment mode (REPRODUCIBLE), move thread count (NONE).15:29:00.975 [main        ] INFO  15:29:00.977 [main        ] INFO  |            | ROOM A     | ROOM B     | ROOM C     |15:29:00.977 [main        ] INFO  |------------|------------|------------|------------|15:29:00.980 [main        ] INFO  | MON 08:30  |            | Geography  | English    |15:29:00.981 [main        ] INFO  |            |            | C. Darwin  | I. Jones   |15:29:00.982 [main        ] INFO  |            |            | 10th grade | 9th grade  |15:29:00.982 [main        ] INFO  |------------|------------|------------|------------|15:29:00.983 [main        ] INFO  | MON 09:30  | Physics    |            | Spanish    |15:29:00.983 [main        ] INFO  |            | M. Curie   |            | P. Cruz    |15:29:00.984 [main        ] INFO  |            | 9th grade  |            | 10th grade |15:29:00.984 [main        ] INFO  |------------|------------|------------|------------|15:29:00.984 [main        ] INFO  | MON 10:30  |            | Math       | Spanish    |15:29:00.984 [main        ] INFO  |            |            | A. Turing  | P. Cruz    |15:29:00.985 [main        ] INFO  |            |            | 10th grade | 9th grade  |15:29:00.985 [main        ] INFO  |------------|------------|------------|------------|15:29:00.985 [main        ] INFO  | MON 13:30  | Physics    |            | Spanish    |15:29:00.985 [main        ] INFO  |            | M. Curie   |            | P. Cruz    |15:29:00.985 [main        ] INFO  |            | 10th grade |            | 9th grade  |15:29:00.986 [main        ] INFO  |------------|------------|------------|------------|15:29:00.986 [main        ] INFO  | MON 14:30  |            | Math       | English    |15:29:00.987 [main        ] INFO  |            |            | A. Turing  | P. Cruz    |15:29:00.988 [main        ] INFO  |            |            | 9th grade  | 10th grade |15:29:00.988 [main        ] INFO  |------------|------------|------------|------------|15:29:00.988 [main        ] INFO  | TUE 08:30  | Chemistry  | Math       |            |15:29:00.989 [main        ] INFO  |            | M. Curie   | A. Turing  |            |15:29:00.989 [main        ] INFO  |            | 9th grade  | 10th grade |            |15:29:00.989 [main        ] INFO  |------------|------------|------------|------------|15:29:00.989 [main        ] INFO  | TUE 09:30  | Chemistry  |            | English    |15:29:00.990 [main        ] INFO  |            | M. Curie   |            | I. Jones   |15:29:00.990 [main        ] INFO  |            | 10th grade |            | 9th grade  |15:29:00.990 [main        ] INFO  |------------|------------|------------|------------|15:29:00.992 [main        ] INFO  | TUE 10:30  | French     | Biology    |            |15:29:00.992 [main        ] INFO  |            | M. Curie   | C. Darwin  |            |15:29:00.992 [main        ] INFO  |            | 10th grade | 9th grade  |            |15:29:00.992 [main        ] INFO  |------------|------------|------------|------------|15:29:00.993 [main        ] INFO  | TUE 13:30  |            | Math       | History    |15:29:00.993 [main        ] INFO  |            |            | A. Turing  | I. Jones   |15:29:00.993 [main        ] INFO  |            |            | 10th grade | 9th grade  |15:29:00.993 [main        ] INFO  |------------|------------|------------|------------|15:29:00.993 [main        ] INFO  | TUE 14:30  |            | Math       | History    |15:29:00.994 [main        ] INFO  |            |            | A. Turing  | I. Jones   |15:29:00.994 [main        ] INFO  |            |            | 9th grade  | 10th grade |15:29:00.994 [main        ] INFO  |------------|------------|------------|------------|
Process finished with exit code 0
复制代码


3、进阶

当你已经可以运行第一个 OptaPlanner 的程序,我们来点高阶的:

布置一个小作业,如果教室从 3 个,变成 4 个;

年级从 9、10 两个年级,变成 9、10、11 三个年级。

如何修改程序,获得最优的课程表? 做

完的朋友,欢迎把结果发给我;遇到困难的同学,也欢迎留言说明遇到的问题。


发布于: 刚刚阅读数: 6
用户头像

OptaPlanner

关注

寻觅世界最强求解器,找出人生难题最佳答案 2017.12.08 加入

OptaPlanner中文开发指南,开发好用的APS系统~

评论

发布
暂无评论
一起玩OptaPlanner-Study,玩转第一个程序_OptaPlanner_InfoQ写作社区