summaryrefslogtreecommitdiff
path: root/prolog/problems/clp_r
diff options
context:
space:
mode:
authorAleš Smodiš <aless@guru.si>2015-08-18 16:06:19 +0200
committerAleš Smodiš <aless@guru.si>2015-08-18 16:06:19 +0200
commit95e2fe57f6e4639f6ae9f1fef368829d5090dbf6 (patch)
tree462ba05eb0c4732ca1c97739548801258bf47b40 /prolog/problems/clp_r
Exported all problems from the SQLite database into the new directory structure.
Diffstat (limited to 'prolog/problems/clp_r')
-rw-r--r--prolog/problems/clp_r/bounding_box_3/common.py14
-rw-r--r--prolog/problems/clp_r/bounding_box_3/en.py12
-rw-r--r--prolog/problems/clp_r/center_3/common.py20
-rw-r--r--prolog/problems/clp_r/center_3/en.py13
-rw-r--r--prolog/problems/clp_r/linear_opt_3/common.py12
-rw-r--r--prolog/problems/clp_r/linear_opt_3/en.py16
-rw-r--r--prolog/problems/clp_r/max_sum_2/common.py12
-rw-r--r--prolog/problems/clp_r/max_sum_2/en.py14
-rw-r--r--prolog/problems/clp_r/megabytes_2/common.py9
-rw-r--r--prolog/problems/clp_r/megabytes_2/en.py14
-rw-r--r--prolog/problems/clp_r/turkey_3/common.py15
-rw-r--r--prolog/problems/clp_r/turkey_3/en.py10
12 files changed, 161 insertions, 0 deletions
diff --git a/prolog/problems/clp_r/bounding_box_3/common.py b/prolog/problems/clp_r/bounding_box_3/common.py
new file mode 100644
index 0000000..631f017
--- /dev/null
+++ b/prolog/problems/clp_r/bounding_box_3/common.py
@@ -0,0 +1,14 @@
+id = 157
+group = 'clp_r'
+number = 67
+visible = True
+facts = None
+
+solution = '''\
+bounding_box([], Xa/Ya, Xb/Yb) :-
+ minimize(Xb - Xa),
+ minimize(Yb - Ya).
+bounding_box([X/Y|L], Xa/Ya, Xb/Yb) :-
+ { Xa =< X, X =< Xb,
+ Ya =< Y, Y =< Yb },
+ bounding_box(L, Xa/Ya, Xb/Yb).'''
diff --git a/prolog/problems/clp_r/bounding_box_3/en.py b/prolog/problems/clp_r/bounding_box_3/en.py
new file mode 100644
index 0000000..bc800b9
--- /dev/null
+++ b/prolog/problems/clp_r/bounding_box_3/en.py
@@ -0,0 +1,12 @@
+id = 157
+name = 'bounding_box/3'
+slug = 'find the smallest bounding box'
+
+description = '''\
+<p><code>bounding_box(Points, X1/Y1, X2/Y2)</code>: <code>X1/Y1</code> and <code>X2/Y2</code> are the bottom-left and top-right points defining the smallest bounding box containing all points in the list <code>Points</code>.
+<pre>
+ ?- bounding_box([4.5/2.3, 3.6/1.2, 6.7/0.1], X1/Y1, X2/Y2).
+ X1 = 3.6, Y1 = 0.1, X2 = 6.7, Y2 = 2.3.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/clp_r/center_3/common.py b/prolog/problems/clp_r/center_3/common.py
new file mode 100644
index 0000000..1474ef1
--- /dev/null
+++ b/prolog/problems/clp_r/center_3/common.py
@@ -0,0 +1,20 @@
+id = 158
+group = 'clp_r'
+number = 68
+visible = True
+facts = None
+
+solution = '''\
+memb158(X, [X|_]).
+memb158(X, [_|T]) :-
+ memb158(X, T).
+
+check158([], _, _).
+check158([X/Y | T], R, Xc/Yc) :-
+ { (X-Xc)*(X-Xc) + (Y-Yc)*(Y-Yc) =< R*R },
+ check158(T, R, Xc/Yc).
+
+center(L, R, Xc/Yc) :-
+ memb158(Xc/Yc, L),
+ check158(L, R, Xc/Yc).
+'''
diff --git a/prolog/problems/clp_r/center_3/en.py b/prolog/problems/clp_r/center_3/en.py
new file mode 100644
index 0000000..b2b4c8d
--- /dev/null
+++ b/prolog/problems/clp_r/center_3/en.py
@@ -0,0 +1,13 @@
+id = 158
+name = 'center/3'
+slug = 'find central points'
+
+description = '''\
+<p><code>center(Points, R, X/Y)</code>: <code>X/Y</code> is a point in the list <code>Points</code> that is at most <code>R</code> away from all other points.</p>
+<pre>
+ ?- center([1.0/1.1, 2.0/2.1, 3.0/3.1, 4.0/4.1], 4.0, X/Y).
+ X = 2.0, Y = 2.1 ;
+ X = 3.0, Y = 3.1.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/clp_r/linear_opt_3/common.py b/prolog/problems/clp_r/linear_opt_3/common.py
new file mode 100644
index 0000000..95d7ea2
--- /dev/null
+++ b/prolog/problems/clp_r/linear_opt_3/common.py
@@ -0,0 +1,12 @@
+id = 159
+group = 'clp_r'
+number = 63
+visible = True
+facts = None
+
+solution = '''\
+linear_opt(X, Y, MaxE) :-
+ { X >= 0, Y >= 0, X =< 5,
+ X+Y =< 7, X+2*Y >= 4, Y =< X+5,
+ MaxE = -0.4*X+3.2*Y },
+ maximize(MaxE).'''
diff --git a/prolog/problems/clp_r/linear_opt_3/en.py b/prolog/problems/clp_r/linear_opt_3/en.py
new file mode 100644
index 0000000..645a6c8
--- /dev/null
+++ b/prolog/problems/clp_r/linear_opt_3/en.py
@@ -0,0 +1,16 @@
+id = 159
+name = 'linear_opt/3'
+slug = 'linear optimization'
+
+description = '''\
+<p>A set of points in the plane is defined by the inequalities</p>
+<ul>
+ <li>0 ≤ <code>X</code> ≤ 5,</li>
+ <li><code>Y</code> ≥ 0,</li>
+ <li><code>X</code> + <code>Y</code> ≤ 7,</li>
+ <li><code>X</code> + 2*<code>Y</code> ≥ 4 and</li>
+ <li><code>Y</code> ≤ <code>X</code> + 5.</li>
+</ul>
+<p>The predicate <code>linear_opt(X, Y, MaxE)</code> should return the point (<code>X</code>, <code>Y</code>) where the expression <code>E = -0.4*X + 3.2*Y</code> has the largest value.</p>'''
+
+hint = {}
diff --git a/prolog/problems/clp_r/max_sum_2/common.py b/prolog/problems/clp_r/max_sum_2/common.py
new file mode 100644
index 0000000..ef4ea79
--- /dev/null
+++ b/prolog/problems/clp_r/max_sum_2/common.py
@@ -0,0 +1,12 @@
+id = 156
+group = 'clp_r'
+number = 66
+visible = True
+facts = None
+
+solution = '''\
+max_sum([_], S) :-
+ minimize(S).
+max_sum([A,B|T], S) :-
+ { S >= A + B },
+ max_sum([B|T], S).'''
diff --git a/prolog/problems/clp_r/max_sum_2/en.py b/prolog/problems/clp_r/max_sum_2/en.py
new file mode 100644
index 0000000..3e8f136
--- /dev/null
+++ b/prolog/problems/clp_r/max_sum_2/en.py
@@ -0,0 +1,14 @@
+id = 156
+name = 'max_sum/2'
+slug = 'find maximal adjacent elements'
+
+description = '''\
+<p><code>max_sum(List, Max)</code>: <code>Max</code> is the maximal sum of two adjacent elements in <code>List</code>.</p>
+<pre>
+ ?- max_sum([4.5, 3.6, 1.2, 6.7], Max).
+ Max = 8.1.
+ ?- max_sum([1.1, 1.2, -12.3, 8.8], Max).
+ Max = 2.3.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/clp_r/megabytes_2/common.py b/prolog/problems/clp_r/megabytes_2/common.py
new file mode 100644
index 0000000..e528c3c
--- /dev/null
+++ b/prolog/problems/clp_r/megabytes_2/common.py
@@ -0,0 +1,9 @@
+id = 160
+group = 'clp_r'
+number = 65
+visible = True
+facts = None
+
+solution = '''\
+megabytes(SI, IEC) :-
+ { SI * 2^20 = IEC * 10^6 }.'''
diff --git a/prolog/problems/clp_r/megabytes_2/en.py b/prolog/problems/clp_r/megabytes_2/en.py
new file mode 100644
index 0000000..6db93c8
--- /dev/null
+++ b/prolog/problems/clp_r/megabytes_2/en.py
@@ -0,0 +1,14 @@
+id = 160
+name = 'megabytes/2'
+slug = 'convert mebibytes to megabytes'
+
+description = '''\
+<p>A <em>mega</em>byte is the SI unit meaning 10<sup>6</sup> bytes, while a <em>mebi</em>byte is the IEC unit meaning 2<sup>20</sup> bytes. Write the predicate <code>megabytes(SI, IEC)</code> that converts between the two using constraints.</p>
+<pre>
+ ?- megabytes(2, IEC).
+ IEC = 1.9073486328125.
+ ?- megabytes(SI, 2).
+ SI = 2.097152.
+</pre>'''
+
+hint = {}
diff --git a/prolog/problems/clp_r/turkey_3/common.py b/prolog/problems/clp_r/turkey_3/common.py
new file mode 100644
index 0000000..6a99fc4
--- /dev/null
+++ b/prolog/problems/clp_r/turkey_3/common.py
@@ -0,0 +1,15 @@
+id = 161
+group = 'clp_r'
+number = 64
+visible = True
+facts = None
+
+solution = '''\
+turkey(Brand1, Brand2, Cost) :-
+ {Cost = Brand1*0.20 + Brand2*0.30,
+ A = Brand1*5 + Brand2*10,
+ B = Brand1*4 + Brand2*3,
+ C = Brand1*0.5,
+ A >= 90, B >= 48, C >= 1.5},
+ minimize(Cost).
+'''
diff --git a/prolog/problems/clp_r/turkey_3/en.py b/prolog/problems/clp_r/turkey_3/en.py
new file mode 100644
index 0000000..3117e35
--- /dev/null
+++ b/prolog/problems/clp_r/turkey_3/en.py
@@ -0,0 +1,10 @@
+id = 161
+name = 'turkey/3'
+slug = 'turkey feed'
+
+description = '''\
+<p>The Holiday Meal Turkey Ranch is considering buying two different brands of turkey feed and blending them to provide a good, low-cost diet for its turkeys. Each brand of feed contains, in varying proportions, some or all of the three nutritional ingredients essential for fattening turkeys. Each kilogram of brand 1 contains 5 grams of ingredient <code>A</code>, 4 grams of ingredient <code>B</code> and 0.5 grams of ingredient <code>C</code>. Each kilogram of brand 2 contains 10 grams of ingredient <code>A</code>, 3 grams of ingredient <code>B</code>, but nothing of ingredient <code>C</code>. The brand 1 feed costs 0.20 € a kilogram, while the brand 2 feed costs 0.30 € a kilogram.</p>
+<p>The minimum monthly requirement per turkey is: 90 grams of ingredient <code>A</code>; 48 grams of ingredient <code>B</code> and 1.5 grams of ingredient <code>C</code>.</p>
+<p>Formulate an LP model to help the rancher decide how to mix the two brands of turkey feed so that the minimum monthly intake requirement for each nutritional ingredient is met at minimum cost. Write the predicate <code>turkey(Brand1, Brand2, Cost)</code> that returns the amount (in kg) of brands 1 and 2 per turkey per month, and the total cost (in €).</p>'''
+
+hint = {}