-1

現在、プロローグでバスの運転手のスケジュールを作成しようとしています。限られた数の解を見つけたい。しかし、"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 つの割り当てられていない変数。可能な限りドメインを制限しましたが、これが正しく行われているかどうかわかりません。上記のクエリから、ドライバー 1 のスプレッドオーバー (呪文のセット) を生成する必要があります。

新しい質問を投稿するか、これを書き直すべきかどうかわからないので、これを書き直すことにしました。

4

1 に答える 1

0

シングルトン変数から多くの警告があり、それらを解決するのは良いスタイルです。少なくとも、警告を回避するために、既知のプレフィックス変数はアンダースコアで使用されていません。

ループに移りましょう:無料の変数を使用してダイアグラムを呼び出すと、部分的にインスタンス化された変数の無限リストを「構築」する無限再帰が発生します。

図/1の意図された意味が理解できません。確かに、あなたは基本的なケースを見逃しています:次のようなものを追加してください

diagram([]).
于 2013-05-21T19:20:45.430 に答える