This code objective value 568 in python gekko but this code's MATLAB version gives 70. I don't understand why. Maybe about with solver options?
from gekko import GEKKO
import numpy as np
m = GEKKO(remote=False)
capacity=np.array([70, 55, 51, 43, 41, 80])
demand=np.array([60, 57, 62, 38, 70])
cost=np.array([[5, 4, 5, 7, 2],
[2, 9, 2, 6, 3],
[6, 5, 1, 7, 9],
[7, 3, 9, 3, 5],
[4, 8, 7, 9, 7],
[2, 5, 4, 2, 1]])
x = m.Array(m.Var,(6,5),lb=0,integer=True)
for i in range(6):
for j in range(5):
m.Minimize(cost[i,j]*x[i,j])
for i in range(6):
m.Equation(m.sum(x[i,:])<=capacity[i])
for j in range(5):
m.Equation(m.sum(x[:,j])==demand[j])
m.options.solver = 1
m.solve()
print('Objective Function: ' + str(m.options.objfcnval))
print(x)
Here is MATLAB version of code that give fval=70. Maybe I wrote the code wrong, but it seems mostly same, I cant understand why. Thanks for help.
clear
clc
capacity_points=6;
demand_points=5;
capacity=[70 55 51 43 41 80];
demand=[60 57 62 38 70];
cost=[5 4 5 7 2;
2 9 2 6 3;
6 5 1 7 9;
7 3 9 3 5;
4 8 7 9 7;
2 5 4 2 1];
x=optimvar('x',capacity_points,demand_points,'Type','integer','LowerBound',0);
%expr=optimexpr;
expr=0;
for i=1:capacity_points
for j= 1:demand_points
expr=expr+cost(i,j)*x(i,j);
end
end
%const1=optimconstr(capacity_points);
for i=1:capacity_points
const1=sum(x(i,:)) <=capacity(i);
end
%const2=optimconstr(demand_points);
for j=1:demand_points
const2=sum(x(:,j)) ==demand(j);
end
prob=optimproblem;
prob.Objective=expr;
prob.Constraints.const1=const1;
prob.Constraints.const2=const2;
sol=solve(prob)
[sol,fval] = solve(prob)