-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptimizationComponent.lp
93 lines (63 loc) · 3.16 KB
/
optimizationComponent.lp
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% Instantiation %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Nodes identification
node(X) :- edge(X,_,_,_).
node(X) :- edge(_,X,_,_).
% Target identification
target(X) :- edge(_,X,_,_).
% Candidate solution generation
0{coloringUp(I)}1 :- node(I).
%#show coloringUp/1.
%Symetric reduction
coloringUp(node0).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% Constraints %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Cas de la cohérence
% Up
consistentTarget(X) :- node(X), coloringUp(X), coloringUp(Y), edge(Y,X,1,_).
consistentTarget(X) :- node(X), coloringUp(X), not coloringUp(Y), edge(Y,X,-1,_).
% Down
consistentTarget(X) :- node(X), not coloringUp(X), not coloringUp(Y), edge(Y,X,1,_).
consistentTarget(X) :- node(X), not coloringUp(X), coloringUp(Y), edge(Y,X,-1,_).
%Imperfect target coloring
% up
imperfectcoloring(X) :- coloringUp(X), not coloringUp(Z), edge(Z,X,1,_).
imperfectcoloring(X) :- coloringUp(X), coloringUp(Z), edge(Z,X,-1,_).
% Down
imperfectcoloring(X) :- not coloringUp(X), coloringUp(Z), edge(Z,X,1,_).
imperfectcoloring(X) :- not coloringUp(X), not coloringUp(Z), edge(Z,X,-1,_).
% Imperfect weighted regulator
% up
imperfectWeightedRegulator(X, Y, 1..W) :- edge(X,Y,1,W), coloringUp(X), not coloringUp(Y).
imperfectWeightedRegulator(X, Y, 1..W) :- edge(X,Y,-1,W), coloringUp(X), coloringUp(Y).
% down
imperfectWeightedRegulator(X, Y, 1..W) :- edge(X,Y,1,W), not coloringUp(X), coloringUp(Y).
imperfectWeightedRegulator(X, Y, 1..W) :- edge(X,Y,-1,W), not coloringUp(X), not coloringUp(Y).
% Correlation
% Pos
correlePositif(X,Y) :- coloringUp(X), coloringUp(Y), edge(X,Y,_,_).
correlePositif(X,Y) :- not coloringUp(X), not coloringUp(Y), node(Y), node(X), edge(X,Y,_,_).
% neg
correleNegatif(X,Y) :- not coloringUp(X), coloringUp(Y), node(X), edge(X,Y,_,_).
correleNegatif(X,Y) :- coloringUp(X), not coloringUp(Y), node(Y), edge(X,Y,_,_).
#show correleNegatif/2.
#show correlePositif/2.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% Optimization %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Inconsistency minimization
inconsistentTarget(X) :- not consistentTarget(X), target(X).
sumInconsistencyTargets(X) :- X =#count{ node(Z) :inconsistentTarget(Z) }.
#minimize {X@3 : sumInconsistencyTargets(X)}.
% Imperfect target coloring minimization
sumImperfectcoloring(X) :- X =#count{ node(Z) :imperfectcoloring(Z) }.
#minimize {X@2 : sumImperfectcoloring(X)}.
% Imperfect weighted regulator minimization
sumImperfectWeightedRegulatorPerTarget(X,Y) :- Y=#count{ x(A, B) : imperfectWeightedRegulator(A,X,B)}, imperfectcoloring(X).
imperfectWeightedRegulatorPerTarget(X,1..W) :- sumImperfectWeightedRegulatorPerTarget(X,W).
sumImperfectWeightedRegulator(X) :- X=#count{ x(Y,Z) : imperfectWeightedRegulatorPerTarget(Y,Z),imperfectcoloring(Y)}.
#minimize {X@1 : sumImperfectWeightedRegulator(X)}.
%clingo graphePoidsCompacte.lp scriptASPIntersections/optimizationComponent.lp -n 0 -t 3 --opt-mode=optN
%clingo graphePoidsCompacte.lp scriptASPIntersections/optimizationComponent.lp -n 0 -t 3 --opt-mode=optN --enum-mode=cautious --quiet=1