Graphviz 13.0.0~dev.20241222.1117
Loading...
Searching...
No Matches
csolve_VPSC.cpp
Go to the documentation of this file.
1
19#include <iostream>
20#include <vpsc/variable.h>
21#include <vpsc/constraint.h>
23#include <vpsc/solve_VPSC.h>
24#include <cstdlib>
25#include <cassert>
26#include <vector>
27#include <vpsc/csolve_VPSC.h>
28Variable* newVariable(int id, double desiredPos, double weight) {
29 return new Variable(id,desiredPos,weight);
30}
32 return new Constraint(left,right,gap);
33}
34VPSC* newIncVPSC(int n, Variable* vs[], int m, Constraint* cs[]) {
35 return new IncVPSC(n,vs,m,cs);
36}
37
38int genXConstraints(int n, boxf *bb, Variable **vs, Constraint ***cs,
39 bool transitiveClosure) {
40 std::vector<Rectangle> rs;
41 for(int i=0;i<n;i++) {
42 rs.emplace_back(bb[i].LL.x,bb[i].UR.x,bb[i].LL.y,bb[i].UR.y);
43 }
44 const int m = generateXConstraints(rs, vs, *cs, transitiveClosure);
45 return m;
46}
47int genYConstraints(int n, boxf* bb, Variable** vs, Constraint*** cs) {
48 std::vector<Rectangle> rs;
49 for(int i=0;i<n;i++) {
50 rs.emplace_back(bb[i].LL.x,bb[i].UR.x,bb[i].LL.y,bb[i].UR.y);
51 }
52 const int m = generateYConstraints(rs, vs, *cs);
53 return m;
54}
55
57 return new Constraint*[m];
58}
59void deleteConstraints(int m, Constraint **cs) {
60 for(int i=0;i<m;i++) {
61 delete cs[i];
62 }
63 delete [] cs;
64}
66 delete c;
67}
69 delete v;
70}
71void satisfyVPSC(VPSC* vpsc) {
72 try {
73 vpsc->satisfy();
74 } catch(const char *e) {
75 std::cerr << e << "\n";
76 std::exit(1);
77 }
78}
79void deleteVPSC(VPSC *vpsc) {
80 assert(vpsc!=nullptr);
81 delete vpsc;
82}
83void solveVPSC(VPSC* vpsc) {
84 vpsc->solve();
85}
86void setVariableDesiredPos(Variable *v, double desiredPos) {
87 v->desiredPosition = desiredPos;
88}
89double getVariablePos(const Variable *v) {
90 return v->position();
91}
92void remapInConstraints(Variable *u, Variable *v, double dgap) {
93 for (Constraint *c : u->in) {
94 c->right=v;
95 c->gap+=dgap;
96 v->in.push_back(c);
97 }
98 u->in.clear();
99}
100void remapOutConstraints(Variable *u, Variable *v, double dgap) {
101 for (Constraint *c : u->out) {
102 c->left=v;
103 c->gap+=dgap;
104 v->out.push_back(c);
105 }
106 u->out.clear();
107}
#define right(i)
Definition closest.c:79
void setVariableDesiredPos(Variable *v, double desiredPos)
Variable * newVariable(int id, double desiredPos, double weight)
Bridge for C programs to access solve_VPSC (which is in C++)
Constraint ** newConstraints(int m)
void deleteConstraint(Constraint *c)
VPSC * newIncVPSC(int n, Variable *vs[], int m, Constraint *cs[])
void deleteVariable(Variable *v)
void deleteConstraints(int m, Constraint **cs)
Constraint * newConstraint(Variable *left, Variable *right, double gap)
void remapInConstraints(Variable *u, Variable *v, double dgap)
int genXConstraints(int n, boxf *bb, Variable **vs, Constraint ***cs, bool transitiveClosure)
void remapOutConstraints(Variable *u, Variable *v, double dgap)
double getVariablePos(const Variable *v)
void satisfyVPSC(VPSC *vpsc)
int genYConstraints(int n, boxf *bb, Variable **vs, Constraint ***cs)
void deleteVPSC(VPSC *vpsc)
void solveVPSC(VPSC *vpsc)
#define left
Definition dthdr.h:12
int generateYConstraints(const vector< Rectangle > &rs, Variable **vars, Constraint **&cs)
int generateXConstraints(const vector< Rectangle > &rs, Variable **vars, Constraint **&cs, const bool useNeighbourLists)
A constraint determines a minimum or exact spacing required between two variables.
Definition constraint.h:25
virtual void solve()
virtual void satisfy()
double desiredPosition
Definition variable.h:30
Constraints out
Definition variable.h:36
Constraints in
Definition variable.h:35
double position() const
Definition variable.h:46
Definition geom.h:41
pointf UR
Definition geom.h:41
pointf LL
Definition geom.h:41
double x
Definition geom.h:29
double y
Definition geom.h:29