XiongPengNUS / rsome

Robust Stochastic Optimization Made Easy
GNU General Public License v3.0
290 stars 56 forks source link

Location problem by using RSOME #2

Closed RenYi377 closed 2 years ago

RenYi377 commented 3 years ago

Hi, I want to test a little location problem by using Robust analyse RSOME. here is my code:

from rsome import ro import rsome.grb_solver as grb import numpy as np import numpy.random as rd import matplotlib.pyplot as plt from numpy import array

model = ro.Model('WLP model') # define a model

n = 7 # customer j N = range(n)

m = 5 # possible location i

f = np.array([ 5, 7, 5, 6, 5]).reshape((1, 5)) # fixcost of opened location i
a = np.array([ 7, 7, 7, 7, 7]).reshape((1, 5)) # location capacity b_0 = np.array([ 1, 1, 1, 1, 1, 1, 1]).reshape((7, 1)) # demand of customer
c = ([1, 2, 10, 9, 6, 7, 3], # cost of transportation from i to j [2, 9, 0, 7, 3, 6, 10], [7, 6, 1, 5, 3, 10, 5], [6, 5, 10, 2, 6, 3, 6], [6, 4, 6, 3, 7, 2, 6])

theta_ub = 0.2 theta_lb = -0.2 theta = model.rvar(n) uset = (theta.sum()==0,theta >= theta_lb, theta <= theta_ub) for i in range(m): b = b_0[i] + theta #box uncertainty set of demands

y_i= model.dvar((1,5),vtype = 'B') # location decisions x_i_j = model.dvar((5,7)) # Transport amount

Define model objective and constraints

model.min((cx_i_j).sum() + (fy_i).sum()) #min cost of transport and open facility model.st(x_i_j.sum(axis=1) <= y_i * a) # transport amounts are lower than storage capacity of all locationes
model.st((x_i_j.sum(axis=0) == b).forall(u_set)) # transport amounts are bigger than demand of every customer model.st(y_i >= 0) model.st(x_i_j >= 0)

model.solve(grb) print('min_cost :', model.get()) print(y_i.get()) there is a Error: AttributeError: 'RoAffine' object has no attribute 'model' how canI improve my code? thanks a lot!

XiongPengNUS commented 3 years ago

Thank you for reporting the bug. It is fixed in the 0.1.2 version.