M Askar wrote:
Dear All Mozart users,
I am sorry to disturb you during the holiday.
I have just started working on Mozart. A path-finding-like problem
needs to find all the possible scenarios to walk from a starting node
to a final node.
We have the following constraints:
1- There are 8 nodes in total labeled as follows: R, AG, DS, VB, CDI,
EP, IMC, TH
2- Scenarios could begin only from nodes: R, AG, or DS
3- Scenarios terminate only in one of the following nodes: DS, CDI, TH or EP
4- Self-loops are allowed at nodes R, AG, VB, EP
5- A node should not be traversed more than "MaxLoop" times (Neither
selfloop nor repass) in the same scenario.
- MaxLoop is fed explicitly to the script
- nodes are connected as follows:
R AG DS VB CDI EP IMC TH
R 1 1 1 0 0 0 0 0
0
AG 0 1 1 1 1 1 1 0 0
DS 0 0 0 0 0 0 0 0 0
VB 0 0 1 1 1 1 1 0 0
CDI 0 0 0 1 0 1 1 1
1
EP 0 0 1 1 1 1 1 1
1
IMP 0 0 0 1 1 1 0 1
1
TH 0 0 0 0 0 1 0 0 0
- I wrote the following script:
declare
fun {AScenario Data MaxLoop}
StepsSymb = {List.mapInd Data fun {$ I S#_} I#S end}
StepsRec = {List.toRecord sr StepsSymb}
Steps = {Record.arity StepsRec}
Connections = {List.mapInd Data fun {$ I _#Cs} I#Cs end}
ConRec = {List.toRecord cr Connections}
NbSteps = {Length Steps}
MaxLength = 2*MaxLoop + NbSteps
%%ensures that transitions occur only between connected steps
proc {BelongsTo X Ys ?I}
if {List.member X Ys} then I = 1
else I = 0
end
end
in
proc {$ Scenario}
ScenarioLength = {FD.int 2#MaxLength}
in
{FD.distribute naive [ScenarioLength]}
%%Scenario: Step ---> Step_number
{FD.tuple scenario ScenarioLength 1#NbSteps Scenario}
%%Scenario Constraints%%%%%%%%%%%%%%%%%%%%%%
%% Starting node should be either R, AG or DS)
Scenario.1 =<: 3
%%Last step should always be "Fin"
Scenario.ScenarioLength =: NbSteps
%%
{For 1 ScenarioLength 1
proc {$ I}
J = Scenario.I
in
%%ensure that adjacent steps in the scenario are connected
{FD.impl I <: ScenarioLength {BelongsTo StepsRec.J ConRec.I} 1}
{FD.impl I <: ScenarioLength Scenario.I \=: {List.last Steps} 1}
end}
%% At most times a step should repeated
{For 1 NbSteps 1
proc {$ I}
{FD.atMost MaxLoop Scenario I}
end}
{FD.distribute ff Scenario}
end
end
%
%%Data structure that models connectivity, self-looping, a new node
called "fin" is added to model the finishing nodes.
%
Data = [ r # [r ag ds fin]
ag # [ag ds ep imc cdi vb]
ds # [fin]
vb # [vb cdi imc ds ep]
cdi # [ep imc th vb fin]
ep # [ep imc th vb ds cdi fin]
imc # [vb th cdi ep]
th # [ep fin]
fin # nil]
{ExploreAll {AScenario Data 2}}
I do not know what is wrong as it generates suspended solutions. Any
help or suggestion is highly appreciated.
You are getting undetermined solutions because the script is getting
stuck at:
{FD.impl I <: ScenarioLength {BelongsTo StepsRec.J ConRec.I} 1}
Notice that J needs to be determined in order to access the
corresponding element in StepsRec.
A simple fix could be to put the implication in a separate thread:
thread {FD.impl I <: ScenarioLength {BelongsTo StepsRec.J ConRec.I}
1} end
There is also a typo in this statement: I think you mean "ConRec.J".
Merry Christmas to you too!
Luis
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users