def checkSubTour(vals): vals = { keyOpMVRPD(var): vals[var] for var in vals.keys() if var[0] == 'x' and vals[var] >= 0.999 } errorcnt = 0 for t in range(1, self.H + 1): edges = [(key[1], key[2]) for key in vals.keys() if key[3] == t and key[0] == 'x'] if len(edges) > 0: subsets = getSubsets(edges, self.V + 1) if len(subsets) > 0: print(t, subsets) print('---------- ERROR! ----------') errorcnt += 1 if errorcnt == 0: print('[TEST] SUBTOUR CORRECT MODEL') return True else: print('[TEST] SUBTOUR ERRORS') return False
def checkSubTour(vals): vals = { keyOpVRP(var): vals[var] for var in vals.keys() if var[0] == 'y' and vals[var] > 0 } errorcnt = 0 for k in range(1, self.trucks + 1): edges = [(key[1], key[2]) for key in vals.keys() if key[3] == k and key[0] == 'y'] if len(edges) > 0: #visualize(edges) subsets = getSubsets(edges, self.totalNodes) if len(subsets) > 0: print(k, subsets) print('---------- ERROR! ----------') errorcnt += 1 if errorcnt == 0: print('[TEST] SUBTOUR CORRECT MODEL') return True else: print('[TEST] SUBTOUR ERRORS') return False
def f1(solValues): cuts = [] solValues = { keyOperator(key) : solValues[key] for key in solValues.keys()} for k in range(1, K + 1): for t in range(1, H + 1): edges = [] for i in range(n + 1): for j in range(n + 1): if i < j: if solValues[(mainStVarName, i, j, k, t)] > 0.5: edges.append((i, j)) subsets = getSubsets(edges, n) if len(edges) > 0: for subset in subsets: for element in subset: newCut = Cut() nonzeros = {} nonzeros.update({ '{}_{}_{}_{}_{}'.format(mainStVarName, i, j, k, t) : 1 for i in subset for j in subset if i < j }) nonzeros.update({'{}_{}_{}_{}'.format(secondStVarName, i, k, t) : -1 for i in subset if i != element }) newCut.nonzero = nonzeros newCut.sense = '<=' newCut.rhs = 0 cuts.append(newCut) return cuts
def f1(solValues): cuts = [] solValues = {(key.split('_')[0], int(key.split('_')[1]), int(key.split('_')[2])): solValues[key] for key in solValues.keys()} edges = [] for i in range(self.n): for j in range(self.n): if i < j: if solValues[('x', i, j)] > 0.5: edges.append((i, j)) subsets = getSubsets(edges, self.n) if len(edges) > 0: for subset in subsets: newCut = Cut() nonzeros = {} nonzeros.update({ 'x_{}_{}'.format(i, j): 1 for i in subset for j in subset if i < j }) newCut.nonzero = nonzeros newCut.sense = '<=' newCut.rhs = len(subset) - 1 cuts.append(newCut) return cuts
def sepFunctionTSP(solValues): # List of cuts is initialized as empty cuts = [] # A new dictionary can be created, formating the keys as tuples (string 'x', int i, int j) instead of strings # The values are the same of course as those of solValues and contain the binary variables x_i_j with i < j. solValues = {(key.split('_')[0], int(key.split('_')[1]), int(key.split('_')[2])): solValues[key] for key in solValues.keys()} # A list stores with tuples of integers the active edges. edges = [] for i in range(nodes): for j in range(nodes): if i < j: # Numerical precaution, this cn be set to >= 1 as well. if solValues[('x', i, j)] >= 0.99: edges.append((i, j)) #This function returns through a list of lists of integers # all connected components in case there is more than one. subsets = getSubsets(edges, nodes) if len(edges) > 0: for subset in subsets: # A new Cut object is created newCut = Cut() nonzeros = {} # The coefficients are always 1, we add all edges associated to the elements of the subset. nonzeros.update({ 'x_{}_{}'.format(i, j): 1 for i in subset for j in subset if i < j }) newCut.nonzero = nonzeros # The sense is added as a string '<=' newCut.sense = '<=' # The cardinality of subset S can be computed as the length of the subset list newCut.rhs = len(subset) - 1 # We append the new cut to the list cuts.append(newCut) return cuts
def checkSubTour(vals): vals = { keyOperator(var) : vals[var] for var in vals.keys() if var[0] == stVarName and vals[var] >= 0.001 } errorcnt = 0 for k in range(1, K + 1): for t in range(1, H + 1): edges = [(key[1], key[2]) for key in vals.keys() if (key[3], key[4]) == (k, t) and key[0] == stVarName] if len(edges) > 0: #visualize(edges) subsets = getSubsets(edges, n) if len(subsets) > 0: print(k, t, subsets) print('---------- ERROR! ----------') errorcnt += 1 if errorcnt == 0: print('[TEST] SUBTOUR CORRECT MODEL') return True else: print('[TEST] SUBTOUR ERRORS') return False
def checkSubTour(vals): vals = { keyOpTSP(var): vals[var] for var in vals.keys() if var[0] == 'x' and vals[var] > 0 } errorcnt = 0 edges = [(key[1], key[2]) for key in vals.keys() if key[0] == 'x'] if len(edges) > 0: #visualize(edges) subsets = getSubsets(edges, self.n) if len(subsets) > 0: print(subsets) print('---------- ERROR! ----------') errorcnt += 1 if errorcnt == 0: print('[TEST] SUBTOUR CORRECT MODEL') return True else: print('[TEST] SUBTOUR ERRORS') return False