welcome: please sign in
location: attachment:Weighted-Sequence-Problem-ENCODING.txt of OfficialProblemSuite

Attachment 'Weighted-Sequence-Problem-ENCODING.txt'

Download

   1 %clingo 1 instance encoding
   2 
   3 
   4 color(red).
   5 color(blue).
   6 color(green).
   7 
   8 
   9 
  10 leafWeight(X,W)  :-leafWeightCardinality(X,W,C).
  11 
  12 leafCard(X,C)  :-leafWeightCardinality(X,W,C).
  13 
  14 leaf(X):-leafWeightCardinality(X,W,C).
  15 
  16 
  17 
  18 %%
  19 %% Sequence Definition
  20 %%
  21 
  22 coloredPos(1).
  23 coloredPos(X+1):- coloredPos(X),  X < N-1, num(N).
  24 %coloredPos(X):-  X=1..N-1, num(N).
  25 location(0).
  26 location(X+1) :- location(X), X < N-1, num(N).
  27 %location(X):-X=0..N-1, num(N).
  28 
  29 1 <= {leafPos(L,N) : location(N) } <= 1 :- leaf(L).
  30 % No sharing locations
  31 %:- leafPos(L1, N), leafPos(L2, N), location(N), L1 != L2.
  32 1 <= { leafPos(L,N) : leaf(L) } <= 1 :- location(N).
  33 
  34 
  35 %%
  36 %% each node at colordPos has a unique color
  37 %%
  38 1 <= {posColor(P,C):color(C)} <= 1:-coloredPos(P).
  39 
  40 % BEGIN Weight T  definition
  41 
  42 %  if color of X is green
  43 %    weight(X) = weight(right child of X) + cardinality(right child of X) 
  44 %
  45 nWeight(0,W):- leafWeightCardinality(L,W,C), leafPos(L,0).
  46 
  47 nWeight(P,W):- W= W1+C, posColor(P,green),
  48 			leafWeight(R,W1), leafCard(R,C),
  49             coloredPos(P), leafPos(R,P), leaf(R),  W<=M, max_total_weight(M).
  50 
  51 
  52 
  53 
  54 %  if color of X is red
  55 %     weight(X) = weight(right child of X) + weight(left child of X) 
  56 nWeight(P,W):- W= W1+W2, posColor(P,red),
  57 			leafWeight(R,W1),nWeight(P-1,W2),
  58 			coloredPos(P), leafPos(R,P),
  59             leaf(R),  W<=M, max_total_weight(M).
  60 
  61 
  62 
  63 %  if color(X) is blue
  64 %     weight(X) = cardinality(right child of X) + weight(left child of X) 
  65 nWeight(P,W):- W= W1+C,   posColor(P,blue),
  66 			leafCard(R,C), nWeight(P-1,W1),
  67 			coloredPos(P),leafPos(R,P),   
  68             leaf(R),  W<=M, max_total_weight(M).
  69 
  70 
  71 
  72 %%
  73 %% Weights related Tests
  74 %%
  75 
  76 %% 
  77 %% definition of a total weight of a prime tree T'
  78 tWeight(1,W):-nWeight(1,W), coloredPos(1),  W<=M, max_total_weight(M).
  79 tWeight(N,W):-W=W1+W2, tWeight(N-1,W1), nWeight(N,W2),coloredPos(N),N>1,  W<=M, max_total_weight(M).
  80 
  81 
  82 
  83 % END Weight T definition
  84 % --------------------------------------------------------------
  85 % --------------------------------------------------------------
  86 % --------------------------------------------------------------
  87 % exists Definition
  88 
  89 
  90 exists:-tWeight(N-1,W), W<=M, max_total_weight(M),num(N).
  91 :-not exists.
  92 
  93 
  94 
  95 %#show posColor(N,C).
  96 %#show leafWeightCardinality(X,W,C).
  97 %#show max_total_weight(M).
  98 %#show num(N).
  99 %#show exists.

Attached Files

You are not allowed to attach a file to this page.