def newConstraint(self): # print self.state if self.state < 0: return None c = constraint.Constraint() constant = self.state board = self.board for i in range(self.nx1, self.nx2): for j in range(self.ny1, self.ny2): if board[i][j].state < 0: if board[i][j].state == MARKED: constant -= 1 else: c.add(board[i][j]) board[i][j].setState(CONSTRAINED) c.setConstant(constant) return c
def add_constraint(self, goal_id: str, variable_name: str, predicates: List[List[predicates.Predicate]] = None): """ Adds arc with constraint between nodes. :param variable_name: Variable name :param goal_id: Goal id :param predicates: 2D list of predicates :return: Constraint """ if predicates is None: predicates = [[]] v = self.get_variable(variable_name) g = self.get_goal(goal_id) c = constraint.Constraint(predicates) v.add_neighbor(g, c) g.add_neighbor(v, c) return c
import igl import solver import constraint import transform import open3d as o3d import mesh as m cons = constraint.Constraint() cons.add_constraint(0, [0, 0, 0]) # slvr = solver.Sovler() if __name__ == "__main__": V, F = igl.read_triangle_mesh("cube.obj") mesh = m.Mesh(V, F) slvr = solver.Sovler(mesh, cons) slvr.precompute() V, F = slvr.solve() igl.write_obj("cube_remake", V, F)
def GameBoardToConstraintNetwork(gb): board = gb.board variables = [] value = 0 for i in range(gb.N): for j in range(gb.N): value = board[i][j] domain = [] if value == 0: d = 1 while d <= gb.N: domain.append(d) d += 1 else: domain.append(value) block = int(((floor(i / gb.p) * gb.p) + floor(j / gb.q))) variables.append(variable.Variable(domain, i, j, block)) rows = dict() cols = dict() blocks = dict() for v in variables: row = v.row col = v.col block = v.block if not (row in rows.keys()): rows[row] = [] if not (col in cols.keys()): cols[col] = [] if not (block in blocks.keys()): blocks[block] = [] rows[row].append(v) cols[col].append(v) blocks[block].append(v) cn = constraintnetwork.ConstraintNetwork() for v in variables: cn.addVariable(v) for e in rows: c = constraint.Constraint() for v in rows[e]: c.addVariable(v) cn.addConstraint(c) for e in cols: c = constraint.Constraint() for v in cols[e]: c.addVariable(v) cn.addConstraint(c) for e in blocks: c = constraint.Constraint() for v in blocks[e]: c.addVariable(v) cn.addConstraint(c) return cn
def add_spring_constraint(verts, v_1, v_2, constraints): rest_length = linalg.norm(verts[v_1] - verts[v_2]) number_of_verts = len(verts) constraints.append(constraint.Constraint(number_of_verts, v_1, v_2, rest_length=rest_length))
def add_fixed_constraint(number_of_verts, v_id, vert, constraints): constraints.append(constraint.Constraint(number_of_verts, v_id, fixed_point=vert))
connected_vertex.y) connected_vertex_x = couple[0] connected_vertex_y = couple[1] self.drawing_surface.create_line(position_x, position_y, connected_vertex_x, connected_vertex_y) self.update() def create_circle(self, x, y, r, **kwargs): """ Print a circle on the screen """ return self.drawing_surface.create_oval(x - r, y - r, x + r, y + r, **kwargs) if __name__ == "__main__": input_file = sys.argv[1] parser_instance = parser.Parser(input_file) vertex_list = parser_instance.parse() problem_instance = constraint.Constraint(vertex_list, 4) algo = GAC.GAC() algo.variable_domain = problem_instance.variable_domain algo.constraint = problem_instance.constraint_list app = my_interface(None) app.title('GAC') app.calculate_display_settings(parser_instance.min_x, parser_instance.max_x, parser_instance.min_y, parser_instance.max_x) app.print_graph(vertex_list) app.mainloop()