使用累积量 [英] Use of cumulatives

查看:63
本文介绍了使用累积量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在解决使用 cumulatives/[2,3] 谓词的问题.但是当我尝试将其与 labeling

I'm working on a problem where I use the cumulatives/[2,3] predicate. But I get very bad performance when I try to combine this with minimize in labeling

我有以下演示.10 个任务,所有持续时间为 1,4 台机器,所有容量=1.我的目标是最小化总时间,即 minimize(maximum(Es)):

I have the following demo. 10 task, all with duration 1, 4 machines, all with capacity=1. My goal is to minimize the total time, i.e. minimize(maximum(Es)):

:- use_module(library(clpfd)).
:- use_module(library(lists)).

go( Ss, Es, Ms, Tm, Lab ) :-

    Ss = [S1, S2, S3, S4,S5,S6,S7,S8,S9,S10], %Starttimes
    Es = [E1, E2, E3, E4,E5,E6,E7,E8,E9,E10], %Endtimeds
    Ms = [M1, M2, M3, M4,M5,M6,M7,M8,M9,M10], %MachineIds


    domain(Ss, 1, 20),
    domain(Es, 1, 20),
    domain(Ms, 1, 10),

    %All task has duration = 1
    Tasks = [
        task(  S1, 1,  E1,  1, M1 ), 
        task(  S2, 1,  E2,  1, M2 ), 
        task(  S3, 1,  E3,  1, M3 ), 
        task(  S4, 1,  E4,  1, M4 ), 
        task(  S5, 1,  E5,  1, M5 ), 
        task(  S6, 1,  E6,  1, M6 ), 
        task(  S7, 1,  E7,  1, M7 ), 
        task(  S8, 1,  E8,  1, M8 ), 
        task(  S9, 1,  E9,  1, M9 ), 
        task( S10, 1,  E10, 1, M10 ) 
    ],

    %All machines has resource capacity = 1
    Machines = [
        machine(  1, 1 ),
        machine(  2, 1 ),
        machine(  3, 1 ),
        machine(  4, 1 ) 
    ],

    cumulatives(Tasks, Machines, [bound(upper)] ),

    maximum( MaxEndTime, Es ),

    %Make the list of options to pass to the labeling predicate
    append( [ [minimize(MaxEndTime)], [time_out( Tm, _)], Lab ], LabOpt ),
    %The variables to lable:
    append([Ms, Ss ], Vars),

    labeling( LabOpt, Vars). 

如果我现在运行它并解决 1 秒钟,我会得到:

If I now run this and solve for 1 second I get:

| ?- go( S, E, M, 1000, []).
E = [2,3,4,5,6,7,8,9,10,11],
M = [1,1,1,1,1,1,1,1,1,1],
S = [1,2,3,4,5,6,7,8,9,10] ? 

即所有任务都已安排在机器 1 上运行

I.e. all tasks has been scheduled to run on machine 1

在看到任何最小化迹象之前,我需要运行求解器 30 秒:

I need to run the solver for 30 second before I see any sign of minimization:

| ?- go( S, E, M, 30000, []).
E = [2,3,4,5,6,7,8,9,10,2],
M = [1,1,1,1,1,1,1,1,1,2],
S = [1,2,3,4,5,6,7,8,9,1] ? 

如果我跑了 60 秒,我开始得到可以接受的结果:

If I run for 60 second I start to get acceptable results:

| ?- go( S, E, M, 60000, []).
E = [2,3,4,2,3,4,2,3,4,2],
M = [1,1,1,2,2,2,3,3,3,4],
S = [1,2,3,1,2,3,1,2,3,1] ? 

我觉得这花费的时间太长了.关于为什么需要这么长时间的任何评论?

I feel that this is taking way too long time. Any comments on why it takes so long time?

推荐答案

通过在 cumulatives 谓词上使用 task_intervals(true) 选项,速度确实得到了提高:

By using the task_intervals(true) option on the cumulativespredicate the speed is really improved:

cumulatives(Tasks, Machines, [bound(upper),task_intervals(true)] )

为原始问题中的代码提供 2 毫秒的求解时间,而无需更改任何其他内容.

gives solvingtime of 2ms to the code in the original question without changing anyting else.

这篇关于使用累积量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆