This repository has been archived by the owner on Jul 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nocrossing_clockwise_with_choice.ecl
96 lines (83 loc) · 3.45 KB
/
nocrossing_clockwise_with_choice.ecl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
%% BOOLEAN USED TO CHOICE CONSTRAINTS TO APPLY:
%% Ch1 -> clockwise (Clockwise constraint: propagation of predecessors before instantiation)
%% Ch2 -> CrossAbsence (Ch2=true does not admit crossing)
%% Ch3 -> Sort (Sorted visit as convex hull)
:-[pred_prog].
:-[sortedConstraintTsp].
nocrossing_and_clockwise(BoolSucc,OnlySuccL,HullClusterId,ConcaveCluster,PredL,Direction,Ch1,Ch2,Ch3):-
(Ch1=1 ->
pred_to_succ_propagation(1,PredL,OnlySuccL,HullClusterId,ConcaveCluster,Direction)
; true
),
nocrossing_and_clockwise1(1,BoolSucc,OnlySuccL,HullClusterId,ConcaveCluster,Direction,Ch1,Ch2,Ch3).
nocrossing_and_clockwise1(_,[],_,_,_,_,_,_,_).
nocrossing_and_clockwise1(I,[BSC|BSCl],OnlySuccL,HullClusterId,ConcaveCluster,Direction,Ch1,Ch2,Ch3):-
(param(I),foreach(Succ,OnlySuccL), count(ID,1,_), fromto(SuccClusteredL,Out,In,[]) do
cluster(I,ID) -> Out=[Succ|In] ; Out=In
),
%
(once(member(I,HullClusterId)),Ch3=1,nonmember(I,ConcaveCluster) ->
sortConstraint(I,SuccClusteredL,HullClusterId,ConcaveCluster,Direction)
; true
),
%
ic_global:sumlist(SuccClusteredL,Somma),
(var(Somma) ->
suspend(nocrossing_and_clockwise_propagation(BSC,OnlySuccL,HullClusterId,ConcaveCluster,Direction,Ch1,Ch2),5,Somma->suspend:inst)
; nocrossing_and_clockwise_propagation(BSC,OnlySuccL,HullClusterId,ConcaveCluster,Direction,Ch1,Ch2)
),
Inext is I + 1,
nocrossing_and_clockwise1(Inext,BSCl,OnlySuccL,HullClusterId,ConcaveCluster,Direction,Ch1,Ch2,Ch3).
nocrossing_and_clockwise_propagation(BSC,OnlySuccL,HullClusterId,ConcaveCluster,Direction,Ch1,Ch2):-
once(member(c(IdNode,1),BSC)),
nth1(IdNode,OnlySuccL,Succ),
once(point(IdNode,X0,Y0)),
once(point(Succ,X1,Y1)),
once(cluster(Cl1,IdNode)),
once(cluster(Cl2,Succ)),
remove_left_and_cross_points(IdNode,X0,Y0,X1,Y1,1,OnlySuccL,OnlySuccL,Cl1,Cl2,HullClusterId,ConcaveCluster,Direction,Ch1,Ch2).
remove_left_and_cross_points(_,_,_,_,_,_,[],_,_,_,_,_,_,_,_).
remove_left_and_cross_points(Id,XA,YA,XB,YB,N,[C|L],OnlySuccL,Cl1,Cl2,HullClusterId,ConcaveCluster,Direction,Ch1,Ch2):-
once(point(N,Xc,Yc)),
SignABc is (Yc-YA)*(XB-XA) - (Xc-XA)*(YB-YA),
((Ch1=1,cluster(I,Id),once(member(I,HullClusterId)),nonmember(I,ConcaveCluster)) ->
(check_sign_direction(Direction,SignABc) ->
exclude(C,Id)
; true
)
; true
),
(Ch2=1 ->
((cluster(Clust,N),Clust\=Cl1,Clust\=Cl2) ->
once(cluster(Clc,N)),
remove_crosspath_bypoint(1,C,Clc,OnlySuccL,SignABc,XA,YA,XB,YB,Xc,Yc,Cl1,Cl2)
; true)
; true
),
N1 is N+1,
remove_left_and_cross_points(Id,XA,YA,XB,YB,N1,L,OnlySuccL,Cl1,Cl2,HullClusterId,ConcaveCluster,Direction,Ch1,Ch2).
check_sign_direction(Direction,Sign):-
(Direction="<" ->
(Sign<0 -> true;fail)
; (Sign>0 -> true;fail)
).
remove_crosspath_bypoint(_,_,_,[],_,_,_,_,_,_,_,_,_).
remove_crosspath_bypoint(N,C,Clc,[_|OnlySuccL],SignABc,XA,YA,XB,YB,XC,YC,Cl1,Cl2):-
((cluster(Clust,N),Clc\=Clust) ->
once(point(N,Xh,Yh)),
SignAC is (Yh-YA)*(XC-XA) - (Xh-XA)*(YC-YA),
SignBC is (Yh-YC)*(XB-XC) - (Xh-XC)*(YB-YC),
SignABh is (Yh-YA)*(XB-XA) - (Xh-XA)*(YB-YA),
(check_sign_eq(SignABc,SignAC,SignBC,SignABh) ->
exclude(C,N)
; true
)
; true
),
N1 is N+1,
remove_crosspath_bypoint(N1,C,Clc,OnlySuccL,SignABc,XA,YA,XB,YB,XC,YC,Cl1,Cl2).
check_sign_eq(SignABc,SignAC,SignBC,SignABh):-
(SignABc < 0 ->
((SignAC>0,SignBC>0,SignABh>0) -> true;fail)
; ((SignAC<0,SignBC<0,SignABh<0) -> true;fail)
).