Is Prolog the best language to solve this problem?

I have this problem containing some inequalities and the requirement to minimize the value. After doing some research on the Internet, I came to the conclusion that using Prolog may be the easiest way to solve it. However, I had never used Prolog before, and I would not have allowed my time to study it simply to find that this is not the tool that is suitable for this work.

Please, if you know Prolog, take a look at this problem and tell me if Prolog is the right one. Or if you know some other language that is really suitable for this.

a + b + c >= 100
d + e + f >= 50
g + h     >= 30

if (8b + 2e + 7h > 620) then y = 0.8 else y = 1.0
if (d > 35)             then x = 0.9 else x = 1.0

5xa + 8yb + 5c + 3xd + 2ye + 2f + 6xg + 7yh = w.

I need to find values ​​for a, b, c, d, e, f, g and h that minimize w.

Please note that the above is just an example. In a real program, I would use up to 10,000 variables and up to 20 if ... more. This eliminates linear programming as an alternative method, because it would take a huge amount of RAM and time to check all problems with the LP.

I really don't ask for the code, although I would appreciate some hint on how to handle this if Prolog is really good for it. Thank.

+3
source share
3 answers

, . Prolog . Prolog ( ), ; , .

+1

Constraint, CLP (R), CLP (Q) CLP (FD). CLP (R) ( ):

:- use_module(library(clpr)).

test(sol([A,B,C,D,E,F,G,H], [X,Y,W])) :-
    {A >=0, B >=0, C>=0, D>=0, E>=0, F>=0, G>=0, H>=0},
    {A + B + C >= 100},
    {D + E + F >= 50},
    {G + H     >= 30},
    {5*X*A + 8*Y*B + 5*C + 3*X*D + 2*Y*E + 2*F + 6*X*G  + 7*Y*H = W},
    (({8*B + 2*E + 7*H > 620},{Y=0.8}) ; ({8*B + 2*E + 7*H =35},{X=0.9}) ; ({D=

Using SICStus Prolog, I get the following answer:

| ?- test(A). A = sol([_A,0.0,_B,0.0,_C,_D,30.0,0.0],[1.0,1.0,780.0]), {_A=100.0-_B}, {_C=50.0-_D}, {_B==0.0}, {_D>=0.0} ? ; no
+4

(LP), , LP. LP .

( LP if, ):

Constraints:
a + b + c >= 100
d + e + f >= 50
g + h     >= 30
8b + 2e + 7h > 620

Linear function:
5 * 0.8a + 8 * 1.0b + 5c + 3 * 0.8d + 2 * 1.0e + 2f + 6 * 0.8g + 7 * 1.0h = w

Constraints:
a + b + c >= 100
d + e + f >= 50
g + h     >= 30
d > 35

Linear function:
5 * 1.0a + 8 * 0.9b + 5c + 3 * 1.0d + 2 * 0.9e + 2f + 6 * 1.0g + 7 * 0.9h = w

, LP, a, b, c, d, e, f, g, h w. w a, b, c, d, e, f, g, h.

?

if , x y. (, , x y, , ), LP. LP , , , w.

LP Wikipedia, . , Excel , , , , , , C, , glpk.

, !

+3
source

Source: https://habr.com/ru/post/1737637/


All Articles