Hi,
One of the exercises from the course material for the Linear Programming course, involved baking cakes. For chocolate, vanilla, and lemon cakes it is known how many eggs and how much flour are needed and what is the baking time. The question is to maximize the profit.
This is the model in lpSolveAPI:
library (lpSolveAPI)
result <- make.lp(3,3)
set.column(result, 1, c(4, 4, 20))
set.column(result, 2, c(2, 5, 40))
set.column(result, 3, c(6, 6, 50))
set.objfn(result, c(3, 5, 7))
set.constr.type(result, rep("<=", 3))
set.rhs(result, c(32, 40, 260))
lp.control(result, sense = "max")
set.type(result, 1, "integer")
set.type(result, 2, "integer")
set.type(result, 3, "integer")
dimnames(result) <- list(c("Ei", "Bloem", "Tijd"), c("Chocola", "Vanille", "Citroen"))
4 Chocolate, 2 vanilla and 2 lemmon cakes give a profit of 36
I have defined the same problem with library(simplex):
:- use_module(library(simplex)).
cakes_3(S) :-
gen_state(S0),
post_constraints_v3(S0, S1),
maximize([3*chocola, 5*vanille, 7*citroen], S1, S).
post_constraints_v3 -->
constraint([4*chocola, 2*vanille, 6*citroen] =< 32),
constraint([4*chocola, 5*vanille, 6*citroen] =< 40),
constraint([20*chocola, 40*vanille, 50*citroen] =< 260),
constraint(integral(chocola)),
constraint(integral(vanille)),
constraint(integral(citroen)),
constraint([chocola] >= 0),
constraint([vanille] >= 0),
constraint([citroen] >= 0).
test_cakes_v3 :- cakes_3(S),
variable_value(S, chocola, Val1),
variable_value(S, vanille, Val2),
variable_value(S, citroen, Val3),
writeln(Val1),
writeln(Val2),
writeln(Val3), nl,
result(Val1, Val2, Val3), nl.
result(A, B, C) :-
Ei is A*4 + B*2 + C*6, writeln(Ei),
Bloem is A*4 + B*5 + C*6, writeln(Bloem),
Tijd is A*20 + B*40 + C*50, writeln(Tijd),
Winst is A*3 + B*5 + C*7, writeln(Winst).
Now 1 Chocolate, 1 vanilla and 4 lemmon cakes give a profit of 36
Both solutions are correct.
My question is why both environments produce diffent results? And since both solutions are correct, is it possible to have simplex return all the solutions?
Ben