146 lines
4.2 KiB
Plaintext
146 lines
4.2 KiB
Plaintext
|
% From Christian Holzbaur Tue, 14 Jul 1992 14:49:16 +0200
|
||
|
% adapted by Thom Fruehwirth for CHRs
|
||
|
|
||
|
/*
|
||
|
With the mortgage definition
|
||
|
*/
|
||
|
mg1(P,T,I,B,MP):-
|
||
|
T=:=1,
|
||
|
B + MP =:= P * (1 + I).
|
||
|
mg1(P,T,I,B,MP):-
|
||
|
T >= 2,
|
||
|
T1 =:= T-1,
|
||
|
mg1(P * (1 + I) - MP, T1, I, B, MP).
|
||
|
|
||
|
|
||
|
mg2(P,T,I,B,MP):-
|
||
|
T > 0,
|
||
|
T =< 1,
|
||
|
B + MP = P * (1 + I).
|
||
|
mg2(P,T,I,B,MP):-
|
||
|
T > 1,
|
||
|
mg2(P * (1 + I) - MP, T - 1, I, B, MP).
|
||
|
/*
|
||
|
and the queries
|
||
|
|
||
|
:- mg(P,120,0.01,B,MP).
|
||
|
|
||
|
:- mg(P, 5, Int, B, MP).
|
||
|
*/
|
||
|
|
||
|
|
||
|
example( [X0,X1,X2,X3,X4]) :-
|
||
|
+87*X0 +52*X1 +27*X2 -54*X3 +56*X4 =< -93,
|
||
|
+33*X0 -10*X1 +61*X2 -28*X3 -29*X4 =< 63,
|
||
|
-68*X0 +8*X1 +35*X2 +68*X3 +35*X4 =< -85,
|
||
|
+90*X0 +60*X1 -76*X2 -53*X3 +24*X4 =< -68,
|
||
|
-95*X0 -10*X1 +64*X2 +76*X3 -24*X4 =< 33,
|
||
|
+43*X0 -22*X1 +67*X2 -68*X3 -92*X4 =< -97,
|
||
|
+39*X0 +7*X1 +62*X2 +54*X3 -26*X4 =< -27,
|
||
|
+48*X0 -13*X1 +7*X2 -61*X3 -59*X4 =< -2,
|
||
|
+49*X0 -23*X1 -31*X2 -76*X3 +27*X4 =< 3,
|
||
|
-50*X0 +58*X1 -1*X2 +57*X3 +20*X4 =< 6,
|
||
|
-13*X0 -63*X1 +81*X2 -3*X3 +70*X4 =< 64,
|
||
|
+20*X0 +67*X1 -23*X2 -41*X3 -66*X4 =< 52,
|
||
|
-81*X0 -44*X1 +19*X2 -22*X3 -73*X4 =< -17,
|
||
|
-43*X0 -9*X1 +14*X2 +27*X3 +40*X4 =< 39,
|
||
|
+16*X0 +83*X1 +89*X2 +25*X3 +55*X4 =< 36,
|
||
|
+2*X0 +40*X1 +65*X2 +59*X3 -32*X4 =< 13,
|
||
|
-65*X0 -11*X1 +10*X2 -13*X3 +91*X4 =< 49,
|
||
|
+93*X0 -73*X1 +91*X2 -1*X3 +23*X4 =< -87.
|
||
|
|
||
|
|
||
|
|
||
|
top2 :- example( [X0,X1,X2,X3,X4]).
|
||
|
|
||
|
% X3=<-5/4-35/68*X2-2/17*X1+X0-35/68*X4,
|
||
|
% X3>=68/53-76/53*X2+60/53*X1+90/53*X0+24/53*X4,
|
||
|
% X3=<-1/2-31/27*X2-7/54*X1-13/18*X0+13/27*X4,
|
||
|
% X3>=17/22+19/22*X2-2*X1-81/22*X0-73/22*X4,
|
||
|
% X3=<33/76-16/19*X2+5/38*X1+5/4*X0+6/19*X4,
|
||
|
% X3>=87+91*X2-73*X1+93*X0+23*X4,
|
||
|
% X3>=-3/76-31/76*X2-23/76*X1+49/76*X0+27/76*X4,
|
||
|
% X3=<13/9-14/27*X2+1/3*X1+43/27*X0-40/27*X4,
|
||
|
% X3=<2/19+1/57*X2-58/57*X1+50/57*X0-20/57*X4
|
||
|
|
||
|
top3 :- example( [X0,_,_,_,X4]).
|
||
|
|
||
|
% X0>=477804/40409+6973307/969816*X4,
|
||
|
% X0>=7357764/4517605-5006476/13552815*X4,
|
||
|
% X0>=58416/36205-4659804/12418315*X4,
|
||
|
% X0>=3139326/1972045-745308/1972045*X4,
|
||
|
% X0>=67158/43105-16394/43105*X4,
|
||
|
% X0>=1327097/6210451-2619277/6210451*X4,
|
||
|
% X0=<-688135/1217232-2174029/811488*X4
|
||
|
|
||
|
% Detection of Implied Equalities
|
||
|
|
||
|
top4 :- A=<B,
|
||
|
B=<C,
|
||
|
C=<D,
|
||
|
A>=D.
|
||
|
|
||
|
% B =:= A,
|
||
|
% C =:= A,
|
||
|
% D =:= A
|
||
|
|
||
|
top5 :-
|
||
|
X11 + X12 + X13 + X14 + X15 =:= 1000,
|
||
|
X21 + X22 + X23 + X24 + X25 =:= 1000,
|
||
|
|
||
|
4*X11 + 5*X21 - Y21 - Z21 =< 0,
|
||
|
-4*X12 - 5*X22 + Y22 + Z22 =:= 0,
|
||
|
-4*X13 - 5*X23 + Y24 - Y25 + Z24 - Z25 =:= 0,
|
||
|
-4*X14 - 5*X24 + Y21 - Y22 - Y23 + Y25
|
||
|
+ Z21 - Z22 - Z23 + Z25 =:= 0,
|
||
|
-4*X15 - 5*X25 + Y23 - Y24 + Z23 - Z24 =:= 0,
|
||
|
|
||
|
7*X11 + 9*X21 >= 0,
|
||
|
7*X12 + 9*X22 =< 3000,
|
||
|
7*X13 + 9*X23 =< 200,
|
||
|
7*X14 + 9*X24 =< 10000,
|
||
|
7*X15 + 9*X25 =< 7000,
|
||
|
|
||
|
Z21 =< 5000,
|
||
|
Z22 =< 250,
|
||
|
Z23 =< 600,
|
||
|
Z24 =< 7000,
|
||
|
Z25 =< 4000,
|
||
|
|
||
|
X11 >= 0, X12 >= 0, X13 >= 0, X14 >= 0, X15 >= 0,
|
||
|
X21 >= 0, X22 >= 0, X23 >= 0, X24 >= 0, X25 >= 0,
|
||
|
|
||
|
Y21 >= 0, Y22 >= 0, Y23 >= 0, Y24 >= 0, Y25 >= 0,
|
||
|
|
||
|
Z21 >= 0, Z22 >= 0, Z23 >= 0, Z24 >= 0, Z25 >= 0,
|
||
|
% should be optimization here:
|
||
|
M =:= 99999,
|
||
|
- Min =:= 99999 * X11 + 99999 * X21 + 4 * Y21 + 7 * Y22 +
|
||
|
3 * Y23 + 8*Y24 + 5*Y25.
|
||
|
|
||
|
% M =:= 99999,
|
||
|
% Min =:= 23450,
|
||
|
% X11 =:= 0,
|
||
|
% X12 =:= 0,
|
||
|
% X13 =:= 0,
|
||
|
% X14 =:= 1000,
|
||
|
% X15 =:= 0,
|
||
|
% X21 =:= 0,
|
||
|
% X22 =:= 50,
|
||
|
% X23 =:= 1850/3-X25,
|
||
|
% X24 =:= 1000/3,
|
||
|
% Y21 =:= 4000,
|
||
|
% Y22 =:= 0,
|
||
|
% Y23 =:= 7450/3,
|
||
|
% Y24 =:= 0,
|
||
|
% Y25 =:= 0,
|
||
|
% Z21 =:= 5000,
|
||
|
% Z22 =:= 250,
|
||
|
% Z23 =:= 600,
|
||
|
% Z24 =:= 9250/3-5*X25,
|
||
|
% Z25 =:= 0,
|
||
|
% X25 >= 5350/9,
|
||
|
% X25 =< 1850/3
|
||
|
|
||
|
%=============================================================================
|