我最近开始使用sicstus prolog并用CLP(约束逻辑编程)解决这个问题,请帮助我理解问题,我应该寻找什么以及我做错了什么。所以,
建筑公司:
卑诗省假装建造一座地上150层,地下15层的摩天大楼,如何组织建筑,以便最大化利润,最大限度地缩短时间?
将问题定义为约束满足问题并使用CLP解决它,以便可以使用不同的参数(更多或更少的楼层,或调整团队的sobreposition时间)来解决它。
到目前为止我所拥有的:
:- use_module(library(clpfd)).
start(Fdigs,Floors,Vars):-
length(Vars,5),
%S -> start, E -> end, D -> duration
%t -> transport, e -> excavating, f -> floor (build)
Vars=[St,Et,Se,Ee,Cost],
Se #>= Et,
Ee #= Se + 10,
Et #>=6,
Cost #>= Ee * 80, %transport cost since it starts at 0 Ee will be the days needed
domain(Vars,0,2000),
construct(0,Fdigs,Floors,Vars),
labeling([minimize(Cost)],Vars).
construct(Stock,0,Floors,Vars).
construct(Stock,Fdigs,Floors,[St,Et,Se,Ee,Cost]):-
Tasks=[
task(St,6,Et,0,1), %transport task
task(Se,10,Ee,5,2) %dig task, 5 because I'm digging all then building (20-15)
%10 because build is 10 so dig is 10
],
cumulative(Tasks,[limit(Stock)]),
Nfdigs is Fdigs - 1,
Nstock is Stock + 25,
construct(Nstock,Nfdigs,[Et,_Et,Ee,_Ee,Cost]).
它当然不起作用,因为我无法使用累积来处理需要5个资源的任务,而且0个资源的限制是我无法解决的许多问题中的第一个......
答案 0 :(得分:3)
这是我到目前为止所提出的,似乎要容易得到预期的结果:
:- use_module(library(clpfd)).
start(Floors,Fdigs,Vars):-
length(Vars,20),
domain(Vars,0,999999999), %all vars must be bounded
Vars=[ % S-start,D-duration,E-end,C-cost (money)
St,Dt,Et,Ct, % transport vars
Se,De,Ee,Ce, % excavation vars
Sb,Db,Eb,Cb, % building vars
Sc,Dc,Ec,Cc, % electricity vars
Machines,Crane,Cost,Time],
Machines in 1..2,
Crane in 0..1,
St is 0,
Dt is ceiling(((Floors*15)+(Fdigs*20))/25)*6,
Et is Dt,
Ct is 80 * Dt,
Se is 0,
De #= (13 - (Machines*3)) * Fdigs,
Ee #= De,
Ce #= De * (75*Machines),
Sb #>=6 #/\ Sb #>= Ee,
Db #= ((Fdigs * (10-(Crane*3))) + (Floors * (10-(Crane*3)))),
Eb #= Sb + Db,
Cb #= (Fdigs + Floors) * 150 + (Crane*Db*120),
Sc #= (Eb * 75 / 100),
Dc #>= (Eb * 25 / 100) + 5 #/\ Dc #=((Floors + Fdigs) * 5) + 5,
Ec #= Sc + Dc #/\ Ec #> Eb,
Cc is (Fdigs + Floors) * 200,
%Costs
Cost #= (Ct + Ce + Cb + Cc),
%Times (will be end time of final & nonoverlaping task)
Time #= Ec,
%labeling([minimize(Cost)],Vars), % - cost, + time
labeling([maximize(Cost)],Vars), % + cost, - time
writeVars(Vars).
writeVars([St,Dt,Et,Ct,Se,De,Ee,Ce,Sb,Db,Eb,Cb,Sc,Dc,Ec,Cc,Machines,Crane,Cost,Time]):-
write('1 '),write(St),write(' '),write(Dt),write(' '),write(Et),write(' '),write(Ct),write('\n'),
write('2 '),write(Se),write(' '),write(De),write(' '),write(Ee),write(' '),write(Ce),write('\n'),
write('3 '),write(Sb),write(' '),write(Db),write(' '),write(Eb),write(' '),write(Cb),write('\n'),
write('4 '),write(Sc),write(' '),write(Dc),write(' '),write(Ec),write(' '),write(Cc),write('\n'),
write('Cost: '),write(Cost),write('\n'),
write('Time: '),write(Time),write('\n'),
write('Crane: '),write(Crane),write('\n'),
write('Machines: '),write(Machines).
%write('4 ',St,' ', Dt,' ', Et,' ', Ct),
%write('5 ',St,' ', Dt,' ', Et,' ', Ct).
非常欢迎任何提及我的回答的评论。