maximise the number of asset to go to the same bin

Viewed 45

I am new to pyomo. I would like to ask if there is a way to achieved this requirement.

  1. I want my asset to be assigned to 5 different bins. Each bin will have max capacity. for example, y1 has max 50, y2 has max 20,..
  2. some of my assets can only go to certain bin. For example, Asset1 can only go to y1, y2; asset2 can go to y4 and y5
  3. Although some assets have the option to go to any bin, I would prefer if they can go to the same bin as another assets which is defined by the user. For example, groupA:{A, J, C} , group B:{ E, B}.
    For group A , our common bin is [y1, y2] and I would choose to put it in the y1 or the first bin in the list. If there is no common bin between all assets in Group A, then we can try finding common bin between two of the assets in Group A and the other assets can go to different bin. Otherwise, all of the assets defined in group can go to different bin if there is no common bin in Group A. So, I want to maximise the number of asset defined in GroupA, Group B to be in the same year as the assets in the group.

Below is my code. Currently it is not able do the third requirement

from pyomo.opt import SolverFactory
value_asset = {'J': 2, 'B': 4, 'D': 18, 'C': 34, 'A': 20, 'E': 31}
bins = {'y1': 50, 'y2': 20, 'y3': 30, 'y4': 70, 'y5': 40}
Assets = {'A': ['y1', 'y2'], 'J': ['y1', 'y2'], 'E': ["y4", "y5"], 'B': ["y4", "y5"],
          'D': ['y5', "y4", "y3"],
          'C': ["y1", "y2", 'y3', 'y4', 'y5']}
Group ={'Group1':['A', 'J','E'],'Group2':['B','D','C'] }
model = pyo.ConcreteModel()

model.Assets = pyo.Set(initialize=Assets.keys())

model.budget = pyo.Set(initialize=bins.keys())
model.x = pyo.Var(model.Assets, model.budget, within=pyo.Integers, bounds=(0, None))
model.less_budget = pyo.ConstraintList()

# make sure that all the total are always less than or equal to the budget
for b in model.budget:
    model.less_budget.add(expr=sum(model.x[asset, b]*value_asset[asset] for asset in model.Assets) <= bins[b])
# we want to exclude certain year that some assets cannot do

model.excluded = pyo.ConstraintList()

for asset in model.Assets:
    inc = Assets[asset]
    exc = list(bins.keys() - inc)
    for t in exc:
        model.excluded.add(expr=model.x[asset, t] == 0)

# each item can only go to 1 bin
model.one_bins = pyo.ConstraintList()

for asset in model.Assets:
    model.one_bins.add(expr=sum(model.x[asset, b] for b in (model.budget )) <= 1)
        
model.obj = pyo.Objective(expr=sum(model.x[asset, b] for asset in model.Assets for b in model.budget),sense=pyo.maximize)


solver = pyo.SolverFactory('cbc', executable=r'C:\Users\cc\Downloads\Cbc-2.10-win64-msvc15-md\bin\cbc.exe')
solver.solve(model)

model.x.display()
0 Answers
Related