【问题标题】:Can you use a variable in the [limit (x)] option of the cumulative predicate in prolog?你可以在prolog中累积谓词的[limit(x)]选项中使用变量吗?
【发布时间】:2014-10-08 10:09:05
【问题描述】:

我只是想做这样的事情

schedule(Activities, GLB) :-

    get_start_times(Activities,StartTimes),
    get_resources(Activities,Resources),
    get_durations(Activities,Durations),

    sum_list(Durations, MaxTime),
    StartTimes ins 0..MaxTime,
    GLB in 0..100,
    get_tasks(StartTimes,Durations,Resources, Tasks),
    cumulative(Tasks, [limit(GLB)]),

    labeling([min(GLB)],[StartTimes, GLB]).

我想检索按全局资源限制最小化排序的活动时间表,这是累积谓词的一个选项。但是在尝试将限制作为变量给出时,我不断得到没有充分实例化的参数。如果确实不可能,还有什么其他方法可以实现我想要的?

【问题讨论】:

  • 自己枚举GLB。在cumulative/2之前。

标签: prolog scheduling swi-prolog constraint-programming clpfd


【解决方案1】:

我只能重复false已经说过的话:您可以自己枚举GLB,以便在发布cumulative/2时将其实例化。目前无法将变量指定为资源限制。

您在正确的轨道上,只需将谓词的最后部分更改为:

StartTimes ins 0..MaxTime,
GLB in 0..100,
get_tasks(StartTimes,Durations,Resources, Tasks),
indomain(GLB),
cumulative(Tasks, [limit(GLB)]),
labeling([], StartTimes).

使用indomain/1 将按升序将GLB 的所有可能实例化为具体整数。因此,这为您提供了迭代深化,并将成功获得可接受的最小值 GLB

【讨论】:

  • 非常感谢,这正是我想要的。
猜你喜欢
  • 2012-01-08
  • 1970-01-01
  • 1970-01-01
  • 2021-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多