Updating Lists Under Conditional Statements
回答済みHello,
I know that that if function is not using that way in de code snipet below.
However i created a binary Z varible to satisfy newWarehouse[year] == 1.
In that way i got: m.addConstr((z[i,j,year] == 1) >> newWarehouse[year] == 1).
But i also need to apply:
numWarehouses +=1
storageCapacity.append(newStorage)
palletCapacity.append(newPallet)
operationCapacity.append(newOperation)
these operations when z[i,j,year] or newWarehouse[year] equals to 1. I just couldn't find a way to do it.
Thanks for your help.
for i in range(numWarehouses):
for j in range(numCustomers):
if remainingStorage[i,year] <= updatedStorageDemand[year][j] or remainingPallet[i,year] <= updatedPalletDemand[year][j] or remainingOperation[i,year] <= updatedOperationDemand[year][j]:
numWarehouses +=1
storageCapacity.append(newStorage)
palletCapacity.append(newPallet)
operationCapacity.append(newOperation)
break
-
But i also need to apply:
numWarehouses +=1
storageCapacity.append(newStorage)
palletCapacity.append(newPallet)
operationCapacity.append(newOperation)It is not possible to alter the model data during optimization in this way. Thus, what you are trying to achieve is not possible.
The optimization model and all constraints have to be present and fixed when starting the optimization.
In order to model your scheme, you have to define optimization variables and constraints which describe the behavior you want. This is similar to the \(\texttt{if}\)-clause, which has to be modeled via binary variables and additional (indicator) constraints, because optimization variables don't have any value prior to an optimization run.
Alternatively, maybe you can achieve what you want through callbacks. You can access incumbent values from the MIPSOL callback and then you can add lazy constraints and/or user cuts to the model. Note that you cannot change constraints or variables which are already present in the model. You also cannot add new variables in a callback.
Best regards,
Jaromił0
サインインしてコメントを残してください。
コメント
1件のコメント