def cplex_solver(coeff, sources, adjacency):
    N = len(sources)
    open('tmp.lp', 'w').write(to_cplex_lp_file(coeff, sources, adjacency))
    variables, sols = cplex_interface.solve_from_file('tmp.lp', 'o')
    # reconstruct flow matrix from 'sols' returned by cplex solver
    non_zeros = np.where(sols)
    flow = np.zeros((N,N))
    for i in non_zeros[0]:
        a,b = [int(j) for j in variables[i][2:].split('_')]
        flow[a,b] = sols[i]
    return flow
 def cplex_solver(self):
     open('tmp.lp', 'w').write(self.to_cplex_lp_file())
     variables, sols = cplex_interface.solve_from_file('tmp.lp', 'o')
     # reconstruct flow matrix from 'sols' returned by cplex solver
     non_zeros = np.where(sols)
     flow = np.zeros((self.N, self.N))
     for i in non_zeros[0]:
         if variables[i][0] == 'a': continue
         a, b = [int(j) for j in variables[i][2:].split('_')]
         flow[a, b] = sols[i]
     return flow
 def cplex_solver(self):
     open('tmp.lp', 'w').write(self.to_cplex_lp_file())
     variables, sols = cplex_interface.solve_from_file('tmp.lp', 'o')
     # reconstruct flow matrix from 'sols' returned by cplex solver
     non_zeros = np.where(sols)
     flow = np.zeros((self.N, self.N))
     for i in non_zeros[0]:
         if variables[i][0] == 'a': continue
         a,b = [int(j) for j in variables[i][2:].split('_')]
         flow[a,b] = sols[i]
     return flow
Esempio n. 4
0
def cplex_solver(coeff, sources, adjacency):
    N = len(sources)
    open('tmp.lp', 'w').write(to_cplex_lp_file(coeff, sources, adjacency))
    variables, sols = cplex_interface.solve_from_file('tmp.lp', 'o')
    # reconstruct flow matrix from 'sols' returned by cplex solver
    non_zeros = np.where(sols)
    flow = np.zeros((N, N))
    for i in non_zeros[0]:
        a, b = [int(j) for j in variables[i][2:].split('_')]
        flow[a, b] = sols[i]
    return flow