def solve(self): X = [] V = {} C = {} # initialize variable and domain for i in range(0, len(self.Components)): X.append(i) component_width = self.Components[i][0] component_height = self.Components[i][1] # possible lower left point of a component for x in range(0, self.width): for y in range(0, self.height): # if legal, append to V if x + component_width <= self.width and y + component_height <= self.height: if i in V: V[i].append((x, y)) else: V[i] = [(x, y)] # initialize constraints for i in range(0, len(X)): for j in range(0, len(X)): if not i == j: if not (i, j) in C and not (j, i) in C: C[(i, j)] = self.get_cons(i, j, V) #print(X) #print(V) #print(C) problem = CSP(X, V, C) # solve if self.bt_mc == 1: solution = problem.solve() else: solution = problem.min_conflicts(1000) result = {} if solution == None: return None for idx in solution: result[tuple(self.Components[idx])] = solution[idx] return result
def solve(self): X = [] V = {} C = {} # get a list of different color pairs color_pairs = get_color_pairs(self.Color) # initialize variable and domain for i in range(0, len(self.T)): X.append(i) V[i] = [] for c in self.Color: V[i].append(c) #V[i] = self.Color # initialize constraints for t in self.Neighbors: for n in self.Neighbors[t]: ti = self.T.index(t) ni = self.T.index(n) if not (ti, ni) in C and not (ni, ti) in C: C[(ti, ni)] = color_pairs #print(X) #print(V) #print(C) problem = CSP(X, V, C) # solve if self.bt_mc == 1: solution = problem.solve() else: solution = problem.min_conflicts(101) result = {} if solution == None: return None for idx in solution: result[self.T[idx]] = solution[idx] return result