如何使用 MS Solver Foundation 对简单的调度问题进行建模?

发布于 2024-08-04 08:34:17 字数 471 浏览 8 评论 0原文

我有以下简单问题,想用 MS Solver Foundation 进行实验:

我有一个时间表,每天需要 2 名工人,持续 30 天。我需要遵守以下限制:

  • 任何人都不应该连续工作两天。
  • 除非有特殊例外,否则人们每周只能工作一次。
  • 有些人只能在周末工作。
  • 有些人只能在工作日工作。

我计划使用 C# 来填充模型,但我需要帮助开始建模。我不确定如何设置决策、参数和约束来解决此类问题。

更新:虽然 ire-and-curses 有一个良好的开端,但我必须想象有一种更具声明性的方式来使用框架来表达这些约束,而不是必须为每个人单独编码。有谁更熟悉 MSF 可以帮助完成这个建设吗?

I have the following simple problem that I'd like to use to experiment with MS Solver Foundation:

I have a schedule where I need to have 2 workers per day for 30 days. I need to honor the following constraints:

  • No people should work two days in a row.
  • Unless a special exception is applied, people should only work once per week.
  • Some people can only work weekends.
  • Some people can only work weekdays.

I plan to use C# to populate the model, but I need help getting started with the modeling. I'm not sure how to setup the decisions, parameters and constraints to address this type of problem.

Update: While ire-and-curses has a good start, I have to imagine that there's a more declarative way to express those constraints using the framework rather than have to code them individually for every person. Anyone more familiar with MSF that can help with this construction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

这样的小城市 2024-08-11 08:34:18

如果您有 n 个人,则必须定义 30n 个二进制整数参数,每个参数指示一个人是否在特定日期工作。

P<xx>D<yy> == 1 => Person <xx> works on day <yy>
P<xx>D<yy> == 0 => Person <xx> does not work on day <yy>

然后你需要限制来防止连续两天工作。这将是 29n 约束。

P<xx>D<yy> + P<xx>D<yy+1> <= 1

那么你需要限制每周只工作一次。第一周如下,接下来三周类似。

P<xx>D00 + P<xx>D01 + P<xx>D02 + P<xx>D03 + P<xx>D04 + P<xx>D05 + P<xx>D06 <= 1

上周将如下。

P<xx>D28 + P<xx>D29 <= 1

这将产生另一个5n 约束。然后仅添加工作日

P<xx>D05 + P<xx>D06 == 0
P<xx>D12 + P<xx>D13 == 0
P<xx>D19 + P<xx>D20 == 0
P<xx>D26 + P<xx>D27 == 0

和周末

P<xx>D00 + P<xx>D01 + P<xx>D02 + P<xx>D03 + P<xx>D04 == 0
P<xx>D07 + P<xx>D08 + P<xx>D09 + P<xx>D10 + P<xx>D11 == 0
P<xx>D14 + P<xx>D15 + P<xx>D16 + P<xx>D17 + P<xx>D18 == 0
P<xx>D21 + P<xx>D22 + P<xx>D23 + P<xx>D24 + P<xx>D25 == 0
P<xx>D28 + P<xx>D29 == 0

的约束,最后添加目标函数。

If you have n people, you will have to define 30n binary integer parameters each indicating if a person works on a specific day or not.

P<xx>D<yy> == 1 => Person <xx> works on day <yy>
P<xx>D<yy> == 0 => Person <xx> does not work on day <yy>

Then you need constraints to prevent working on two days in row. This will be 29n constraints.

P<xx>D<yy> + P<xx>D<yy+1> <= 1

Then you need constraints to work only once per week. This will be the following for the first week and similar for the next three weeks.

P<xx>D00 + P<xx>D01 + P<xx>D02 + P<xx>D03 + P<xx>D04 + P<xx>D05 + P<xx>D06 <= 1

The last week will just be the following.

P<xx>D28 + P<xx>D29 <= 1

This will yield another 5n constraints. Then add constraints for weekdays only

P<xx>D05 + P<xx>D06 == 0
P<xx>D12 + P<xx>D13 == 0
P<xx>D19 + P<xx>D20 == 0
P<xx>D26 + P<xx>D27 == 0

and weekends only

P<xx>D00 + P<xx>D01 + P<xx>D02 + P<xx>D03 + P<xx>D04 == 0
P<xx>D07 + P<xx>D08 + P<xx>D09 + P<xx>D10 + P<xx>D11 == 0
P<xx>D14 + P<xx>D15 + P<xx>D16 + P<xx>D17 + P<xx>D18 == 0
P<xx>D21 + P<xx>D22 + P<xx>D23 + P<xx>D24 + P<xx>D25 == 0
P<xx>D28 + P<xx>D29 == 0

and finally add a target function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文