From 95e2fe57f6e4639f6ae9f1fef368829d5090dbf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Tue, 18 Aug 2015 16:06:19 +0200 Subject: Exported all problems from the SQLite database into the new directory structure. --- prolog/problems/clp_r/bounding_box_3/common.py | 14 ++++++++++++++ prolog/problems/clp_r/bounding_box_3/en.py | 12 ++++++++++++ prolog/problems/clp_r/center_3/common.py | 20 ++++++++++++++++++++ prolog/problems/clp_r/center_3/en.py | 13 +++++++++++++ prolog/problems/clp_r/linear_opt_3/common.py | 12 ++++++++++++ prolog/problems/clp_r/linear_opt_3/en.py | 16 ++++++++++++++++ prolog/problems/clp_r/max_sum_2/common.py | 12 ++++++++++++ prolog/problems/clp_r/max_sum_2/en.py | 14 ++++++++++++++ prolog/problems/clp_r/megabytes_2/common.py | 9 +++++++++ prolog/problems/clp_r/megabytes_2/en.py | 14 ++++++++++++++ prolog/problems/clp_r/turkey_3/common.py | 15 +++++++++++++++ prolog/problems/clp_r/turkey_3/en.py | 10 ++++++++++ 12 files changed, 161 insertions(+) create mode 100644 prolog/problems/clp_r/bounding_box_3/common.py create mode 100644 prolog/problems/clp_r/bounding_box_3/en.py create mode 100644 prolog/problems/clp_r/center_3/common.py create mode 100644 prolog/problems/clp_r/center_3/en.py create mode 100644 prolog/problems/clp_r/linear_opt_3/common.py create mode 100644 prolog/problems/clp_r/linear_opt_3/en.py create mode 100644 prolog/problems/clp_r/max_sum_2/common.py create mode 100644 prolog/problems/clp_r/max_sum_2/en.py create mode 100644 prolog/problems/clp_r/megabytes_2/common.py create mode 100644 prolog/problems/clp_r/megabytes_2/en.py create mode 100644 prolog/problems/clp_r/turkey_3/common.py create mode 100644 prolog/problems/clp_r/turkey_3/en.py (limited to 'prolog/problems/clp_r') 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 = '''\ +

bounding_box(Points, X1/Y1, X2/Y2): X1/Y1 and X2/Y2 are the bottom-left and top-right points defining the smallest bounding box containing all points in the list Points. +

+  ?- 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.
+
''' + +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 = '''\ +

center(Points, R, X/Y): X/Y is a point in the list Points that is at most R away from all other points.

+
+  ?- 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.
+
''' + +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 = '''\ +

A set of points in the plane is defined by the inequalities

+ +

The predicate linear_opt(X, Y, MaxE) should return the point (X, Y) where the expression E = -0.4*X + 3.2*Y has the largest value.

''' + +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 = '''\ +

max_sum(List, Max): Max is the maximal sum of two adjacent elements in List.

+
+  ?- 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.
+
''' + +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 = '''\ +

A megabyte is the SI unit meaning 106 bytes, while a mebibyte is the IEC unit meaning 220 bytes. Write the predicate megabytes(SI, IEC) that converts between the two using constraints.

+
+  ?- megabytes(2, IEC).
+    IEC = 1.9073486328125.
+  ?- megabytes(SI, 2).
+    SI = 2.097152.
+
''' + +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 = '''\ +

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 A, 4 grams of ingredient B and 0.5 grams of ingredient C. Each kilogram of brand 2 contains 10 grams of ingredient A, 3 grams of ingredient B, but nothing of ingredient C. The brand 1 feed costs 0.20 € a kilogram, while the brand 2 feed costs 0.30 € a kilogram.

+

The minimum monthly requirement per turkey is: 90 grams of ingredient A; 48 grams of ingredient B and 1.5 grams of ingredient C.

+

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 turkey(Brand1, Brand2, Cost) that returns the amount (in kg) of brands 1 and 2 per turkey per month, and the total cost (in €).

''' + +hint = {} -- cgit v1.2.1