def exactMatch(A, resolution=1e-8, cython=True):
    # via tha LAPJV algorithm
    A = np.array(A)
    if cython:
        [pi, cost, v, u, costMat] = LAPJV.fast_lapjv(A, resolution)
    else:
        [pi, cost, v, u, costMat] = LAPJV.lapjv(A, resolution)
    N = len(pi)
    edge_cost = A[xrange(N), pi]
    return cost, np.array(pi), np.array(edge_cost)
 def best_ss_lapjv(self,cost_matrix):
   a          = numpy.array(cost_matrix)
   jv_results = LAPJV.lap(a)
   max_val    = self.max_val
   multiplier = self.multiplier
   wip_ss     = 0
   for p_idx, c_idx in enumerate(jv_results[1]):
     cost     = cost_matrix[p_idx][c_idx]
     ss       = max_val - cost
     wip_ss  += ss
   match_ss   = float(wip_ss) / float(multiplier)
   return match_ss
 def best_ss_lapjv(self, cost_matrix):
     a = numpy.array(cost_matrix)
     jv_results = LAPJV.lap(a)
     max_val = self.max_val
     multiplier = self.multiplier
     wip_ss = 0
     for p_idx, c_idx in enumerate(jv_results[1]):
         cost = cost_matrix[p_idx][c_idx]
         ss = max_val - cost
         wip_ss += ss
     match_ss = float(wip_ss) / float(multiplier)
     return match_ss
Exemple #4
0
#!/usr/bin/env python

## Thanks to Dr N.D. van Foreest for providing this example code. ##


"""
The cost matrix is based on Balas and Toth, 1985, Branch and bound
# methods, in Lawler, E.L, et al., The TSP, John Wiley & Sons,
Chischester, pp 361--401.
"""

import numpy
import LAPJV

inf = 1000

a = numpy.array( [[inf,2,11,10,8,7,6,5],
                  [6,inf,1,8,8,4,6,7],
                  [5,12,inf,11,8,12,3,11],
                  [11,9,10,inf,1,9,8,10],
                  [11,11,9,4,inf,2,10,9],
                  [12,8,5,2,11,inf,11,9],
                  [10,11,12,10,9,12,inf,3],
                  [10,10,10,10,6,3,1,inf]] )

print  LAPJV.lap(a)[1]

Exemple #5
0
#!/usr/bin/env python

## Thanks to Dr N.D. van Foreest for providing this example code. ##


"""
The cost matrix is based on Balas and Toth, 1985, Branch and bound
# methods, in Lawler, E.L, et al., The TSP, John Wiley & Sons,
Chischester, pp 361--401.
"""

import numpy
import LAPJV

inf = 1000

a = numpy.array( [[inf,2,11,10,8,7,6,5],
                  [6,inf,1,8,8,4,6,7],
                  [5,12,inf,11,8,12,3,11],
                  [11,9,10,inf,1,9,8,10],
                  [11,11,9,4,inf,2,10,9],
                  [12,8,5,2,11,inf,11,9],
                  [10,11,12,10,9,12,inf,3],
                  [10,10,10,10,6,3,1,inf]] )

print LAPJV.lap(a)[0]