我目前正在尝试在序言中为公交车司机创建时间表。我希望找到数量有限的解决方案。但我得到了"Out of local stack"
错误,我想这是因为我得到了太多的解决方案。
给定以下代码,如何防止该错误?关于我做得不对的任何提示也将有很大帮助。
count_drivers: counts the number of drivers with D_id as driver_id
( I need them to work less than "max_hours").
vehicle: represents the bus and respective routes.
connected: represents the connection between the relief opportunities
( a route consists of a group of relief points and the respective "connection"
between them)
workpiece: is a segment of work in the same vehicle between two relief points
spell: is a group of workpieces done by the same driver
spreadover: is the whole shift one driver has to do.
这是代码:
?- use_module(library(clpfd)).
?- use_module(library(lists)).
?- use_module(library(aggregate)).
%workpiece(Bus,[Ro1,Ro2],Weight).
workpiece(1,[1,2],1).
workpiece(1,[2,3],2).
workpiece(1,[3,4],1).
workpiece(1,[4,5],2).
workpiece(1,[5,6],1).
workpiece(2,[7,8],2).
workpiece(2,[8,9],2).
workpiece(2,[9,10],1).
workpiece(2,[10,11],2).
workpiece(2,[11,12],1).
workpiece(3,[13,14],2).
workpiece(3,[14,15],1).
workpiece(3,[15,16],2).
workpiece(3,[16,17],1).
workpiece(3,[17,18],2).
%spell
spell(Vehicle,[[Ro1,Ro2]|Tail]):-Vars = [Ro1,Ro2], Vars in 1..18, workpiece(Vehicle,[Ro1,Ro2],_),spell(Vehicle,Tail,Ro2),labeling([],Vars).
spell(_,[],_).
spell(Vehicle,[[Ro1,Ro2]|Tail],Ro3):- Vars = [Ro3], Vars in 1..18, Ro3 #= Ro1, workpiece(Vehicle,[Ro1,Ro2],_),spell(Vehicle,Tail,Ro2), labeling([],Vars).
%spreadover de cada driver
spreadover(_,List):- Vars = I, Vars in 1..15, length(List,I), I #>= 1.
spreadover(Driver,[Head|Tail]):- Vars = [Vehicle,I], Vars in 1..9, Vehicle #>= 1, Vehicle #=< 3, spell(Vehicle,Head), length(Head,I), I #>= 1, spreadover(Driver,Tail), labeling([],Vars).
%ocupar as workpieces todas
%minimizando os shifts
%cobrir todas as routes
%length 15
%drivershifts
drivershifts(_,List):- Vars = I, Vars in 1..15, length(List,I), I #= 15.
drivershifts(NumDrivers,[[Driver|List]|Tail]):-Vars = Driver, Vars in 1..NumDrivers, Driver #>= 1, Driver #=< NumDrivers, spreadover(Driver,List), labeling([],Vars).
我提前感谢大家,感谢你们随时可以帮助我。
编辑:我稍微更改了代码,现在我从 forall(spreadover(1,List),writeln(List)) 的查询中得到了一堆未分配的变量。或来自 spreadover(1,List) 的一个未分配变量。我尽可能地限制了域,但不确定我是否正确执行此操作。从上面的查询中,我应该为驱动程序 1 生成扩展(一组咒语)。
不确定我是否应该发布一个新问题或重写这个问题,所以决定重写这个问题。