Optimize installation fleet for floating offshore wind
OngoingI am trying to optimize a vessel configuration for installation of a floating wind turbine. I have made a simple model and later I will add more constraints to achieve more realistic results. But I have a problem that I don´t get results from the simple model and I wonder what I am doing wrong. I am reading data from excel into Python but I only get 0 as best objective. And how should the data from the excel files be read?
Here is my code:
VesselBook = xl.open_workbook("Thomas_vessel_INF.xlsx")
sh1 = VesselBook.sheet_by_index(0) # Cost data
sh2 = VesselBook.sheet_by_index(1) # Time of operation data
sh3 = VesselBook.sheet_by_index(2) # Operation requirements
sh4 = VesselBook.sheet_by_index(3) # Operation time
# --- Sets ---
vessels = list(range(0,5))
activities = [0, 1, 2, 3, 4, 5]
#time_periods = list(range(0, 73))
time_periods = [0 ,1 , 2]
noTurbines = 1
length_period = 7
solutions = []
mobilization = []
print(vessels)
data1 = [[sh1.cell_value(r,c) for c in range(sh1.ncols)] for r in range(sh1.nrows)]
dayRate = []
cost_mobilization =[]
for i in range(1, len(data1)): # Creating a list of the costs associated with the vessels
dayRate.append(data1[i][1])
cost_mobilization.append(data1[i][2])
print(dayRate)
print(cost_mobilization)
matrix1 = []
for row in range(sh2.nrows - 1):
_row = []
for col in range(sh2.ncols - 1):
_row.append(sh2.cell_value((row + 1), (col + 1)))
matrix1.append(_row)
matrix2 = []
for row in range(sh3.nrows - 1):
_row = []
for col in range(sh3.ncols - 2):
_row.append(sh3.cell_value((row + 1), (col + 2)))
matrix2.append(_row)
print(matrix1)
# Time of operation
time_operation = np.array(matrix1)
# Vessel requirement
operation_requirement = np.array(matrix2)
print(matrix2)
# ------ MODEL -----------------------
m = Model('vessel_configuration')
# ------ VARIABLES --------------------
vessel_selected = m.addVars(vessels, activities, vtype=GRB.BINARY, name="vessel_selected")
# ------ OBJECTIVE FUNCTION -----------
m.setObjective(sum(vessel_selected[v,i] * cost_mobilization[v] for v in vessels for i in activities), GRB.MINIMIZE)
# --- Constraints ---
# Requirement constraint
#for v in vessels:
# for i in activities:
# m.addConstr(
# (vessel_selected[v, i] <= operation_requirement[v, i]), "task_requirement")
# Operations timing constraints
#for i in activities:
# m.addConstr(
# (sum(vessel_selected[v, t,i] for v in vessels for t in time_periods) == 1), "task_one")
#for v in vessels:
#m.addConstr(
# (sum(vessel_selected[v,t,i] for i in activities for t in time_periods) <= 1), "task_two")
# Precedence constraints
#for i in activities:
#for j in activities:
#for t in time_periods:
#m.addConstr(sum(vessel_selected[v, t, i] for v in vessels)
#+ sum(vessel_selected[v,t,j] for v in vessels) >= 0, "constraint")
# Compute optimal solution
m.optimize()
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
In the current form (with the comments), your model does not have any constraints. So it is not surprising that the objective value is 0. What happens if you don't comment out your constraint code? For debugging a model it may help to write it to a file in the LP format. If you know a feasible solution that you think is better than what Gurobi finds, go through your constraints and check whether it satisfies them. (You could also try passing a MIP start, but given that your model is still very small, it may be more efficient to debug this manually.)
You can read the data from the Excel file however you like. For simply reading xls files, xlrd is a viable option. pandas is also a good choice.
0
Post is closed for comments.
Comments
2 comments