Solving linear programming with Prolog -


i trying solve first linear programming problem example on http://www.zweigmedia.com/realworld/tutorialsf4/frameslinprogr.html. x , y 0 or positives, sum can upto 50, 2x+y can upto 60. function x+3y has maximized.

i using following code:

mysol2(x,y,z):-     x in 0..sup,  % error: syntax error: operator expected     y in 0..sup,     x + y =< 50,     2 * x + y =< 60,     z max(x + 3*y). 

however, not load (error indicated above).

with following code:

mysol2(x,y,z):-     x >= 0,     y >= 0,     x + y =< 50,     2 * x + y =< 60,     z max(x + 3*y). 

the program loads, on running:

error: >=/2: arguments not sufficiently instantiated 

how can correct these errors?

(>=)/2 , (is)/2 very low-level predicates. can use them in special circumstances. in cases, these predicates lead instantiation errors because 1 or both arguments not sufficiently instantiated.

constraints declarative solution in such cases, working correctly in cases.

for example, can use clp(q) available in sicstus prolog minimal modifications of code:

 :- use_module(library(clpq)).  solution(x, y) :-     { x >= 0,       y >= 0,       x + y =< 50,       2*x + y =< 60 }. 

sample query , result:

 | ?- solutionx, y), maximize(x+3*y). x = 0, y = 50  ? ; no 

the used prolog , prolog-like systems (sicstus, eclipse etc.) ship powerful constraint libraries, meant used notably when reasoning on integers , rationals.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -