'How to handle variable in matrix form which is of binary type in scipy to optimize with differential evolution
I am experimenting to solve an optimization problem using differential evolution. I want to make use of scipy package in Python. The objective function I am trying to optimize with constraints is as below:
Xki is a binary decision variable I am trying to solve for. I have it as a matrix of size n*n. Rest of the parts of the eqn are defined values. My code for solving this optimization problem
summation_1 = 0
for k in range(1,n):
for i in range(0,n):
for j in range(0,n):
summation_1 = summation_1 + calculate_p(demands_list,k-1,vehicle_capacity)*x[k-1][i]*x[k][j]*dist_df[i][j]
summation_2 = 0
for k in range(1,n):
for i in range(1,n):
summation_2 = summation_2 + (x[k][i]*phi*penalty(k)) + (calculate_po(demands_list,k,vehicle_capacity)*x[k][i]*dist_df[i][0])
objective = summation_1 + summation_2
from scipy.optimize import differential_evolution, LinearConstraint
bounds = [] #to be defined
result = differential_evolution(objective, bounds, updating='deferred', workers=2)
I have defined the objective function. The challenges I am facing are:
- How to define the constraints and pass the constraints to objective function ?
- My X variable is in matrix form.. How to handle the variable which is in matrix form?
- since
Xkiis binary variable. How to handle such that only binary values are considered?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

