this repo has no description
1/***
2!Test
3solvers:
4- gecode
5- cbc # Can't check as floats are imprecise
6expected: !Result
7 status: SATISFIED
8 solution: !Solution
9 P: !Approx 373.0277986476333
10 mortgage: [!Approx 260.3305785123967, !Approx 136.3636363636363, !Approx 0.0]
11***/
12
13% Constraint Programming: Mortgage
14%
15%
16% This Minizinc program is written by Hakan Kjellerstrand, hakank@bonetmail.com,
17% and is commented in the (swedish) blog post
18% Constraint Programming: Minizinc, Gecode/flatzinc och ECLiPSe/minizinc
19% http://www.hakank.org/webblogg/archives/001209.html
20%
21% See also my MiniZinc page: http://www.hakank.org/minizinc
22%
23% Marriot & Stuckey: Programming with Constraints, page 175f
24% (famous early example)
25%
26% Since Minizinc don't allow recursion, it is implemented as an array.
27%
28% This example shows the flexibility of Minizinc:
29% the same code can calculate P, R _or_ I with just a simple change of the declarations.
30%
31%
32% Calculates P, given I and R:
33% P: 373.02779864763335
34%
35% Calculates R, given P and I:
36% R: 149.944102252456 (which is close to 150)
37%
38% Calculates I, given R and P:
39% I: 0.099995922287248337__0.10000424331679297 (close to 0.1)
40
41% Note: As of 2008-06-23 this don't work in version >= 0.8.
42% It may work with later version, though.
43
44int: T = 3; % time period
45
46% comment one of the initiations to calculate it:
47var 0.0..10000.0: I = 10.0/100.0;
48var 0.0..10000.0: R = 150.0;
49var 0.0..10000.0: P; % = 373.02779864763318;
50
51array[1..T] of var float: mortgage;
52
53solve satisfy;
54% solve minimize P;
55
56constraint
57 % start value:
58 mortgage[1] = P + (P * I) - R /\
59 forall(i in 2..T) (
60 % calculate the next value using a local variable
61 let {
62 var float: NP = mortgage[i-1] + (mortgage[i-1] * I) - R
63 }
64 in
65 mortgage[i] = NP /\ NP >= 0.0
66 )
67;
68
69output [
70 "P: ", show(P), "\n",
71 "I: ", show(I), "\n",
72 "R: ", show(R), "\n",
73 "mortgage: ", show(mortgage),"\n" % is not especially interesting
74];