def pythoncplex(myTable):
#import numpy and define the distance table as a numpy array called "cost"
import numpy as np
cost = np.array(myTable)
#import cplex
from docplex.mp.model import Model
#create the assignment model
assignment_model = Model('Assignment')
#decision variable
x = assignment_model.binary_var_matrix(cost.shape[0],cost.shape[1],name="x")
#constraints
#we check if we have more rows than columns, namely more tasks than agvs
if(cost.shape[0] > cost.shape[1]):
#1st constraint: an AGV has to have 1 and only 1 task assigned
assignment_model.add_constraints((sum(x[i,j] for i in range(cost.shape[0])) == 1 for j in range(cost.shape[1])), names ='work_load')
#2nd constraint: a tasks cannot have more than 1 AGV assigned to it. But it can have no AGVs assigned
assignment_model.add_constraints((sum(x[i,j] for j in range(cost.shape[1])) <= 1 for i in range(cost.shape[0])), names ='task_completion')
else:
#1st constraint: an AGV has to have 1 and only 1 task assigned
assignment_model.add_constraints((sum(x[i,j] for i in range(cost.shape[0])) <= 1 for j in range(cost.shape[1])), names ='work_load')
#2nd constraint: a tasks cannot have more than 1 AGV assigned to it. But it can have no AGVs assigned
assignment_model.add_constraints((sum(x[i,j] for j in range(cost.shape[1])) == 1 for i in range(cost.shape[0])), names ='task_completion')
#objective function
obj_fn = sum(cost[i,j]*x[i,j] for i in range(cost.shape[0]) for j in range(cost.shape[1]))
assignment_model.set_objective('min',obj_fn)
#print the model
#assignment_model.print_information()
#solve the model
assignment_model.solve()
#write the solution into a python list a return it.
#create a list with all zeros
resultList = [[0 for a in range(cost.shape[1])] for b in range(cost.shape[0])]
#populate the resultList with the solution from the model
sol = assignment_model.solution
for i in range(cost.shape[0]):
for j in range(cost.shape[1]):
if(sol.get_value(x[i,j])==1):
resultList[i][j] = 1
return resultList