107 {
108
109
110
112 const int num_of_extra_constraints =
113 static_cast<int>(extra_constraints_.size());
114 const int num_of_vertex_constraints =
115 static_cast<int>(vertex_constraints_.size());
116 const int num_of_variables = 3 * n;
117 const int num_of_constraints = num_of_variables + 3 * (n - 1) + 3 +
118 num_of_extra_constraints +
119 num_of_vertex_constraints;
120 lower_bounds->resize(num_of_constraints);
121 upper_bounds->resize(num_of_constraints);
122
123 std::vector<std::vector<std::pair<c_int, c_float>>> variables(
124 num_of_variables);
125
126 int constraint_index = 0;
127
128 for (int i = 0; i < num_of_variables; ++i) {
129 if (i < n) {
130 variables[i].emplace_back(constraint_index, 1.0);
131 lower_bounds->at(constraint_index) =
133 upper_bounds->at(constraint_index) =
135 } else if (i < 2 * n) {
136 variables[i].emplace_back(constraint_index, 1.0);
137
138 lower_bounds->at(constraint_index) =
140 upper_bounds->at(constraint_index) =
142 } else {
143 variables[i].emplace_back(constraint_index, 1.0);
144 lower_bounds->at(constraint_index) =
146 upper_bounds->at(constraint_index) =
148 }
149 ++constraint_index;
150 }
151 CHECK_EQ(constraint_index, num_of_variables);
152 for (int i = 0; i < num_of_extra_constraints; ++i) {
153 auto& left_index = extra_constraints_[i].left_index;
154 auto& right_index = extra_constraints_[i].right_index;
155 auto& left_weight = extra_constraints_[i].left_weight;
156 auto& right_weight = extra_constraints_[i].right_weight;
157
158 variables[left_index].emplace_back(constraint_index,
160 variables[right_index].emplace_back(constraint_index,
162 lower_bounds->at(constraint_index) = extra_constraints_[i].lower_bound;
163 upper_bounds->at(constraint_index) = extra_constraints_[i].upper_bound;
164 ++constraint_index;
165 }
166 for (int i = 0; i < num_of_vertex_constraints; ++i) {
167 auto& left_index = vertex_constraints_[i].left_index;
168 auto& right_index = vertex_constraints_[i].right_index;
169 auto& left_weight = vertex_constraints_[i].left_weight;
170 auto& right_weight = vertex_constraints_[i].right_weight;
171
172 variables[left_index].emplace_back(constraint_index,
174 variables[right_index].emplace_back(constraint_index,
176 variables[n + left_index].emplace_back(
179 variables[n + right_index].emplace_back(
182 lower_bounds->at(constraint_index) = vertex_constraints_[i].lower_bound;
183 upper_bounds->at(constraint_index) = vertex_constraints_[i].upper_bound;
184 ++constraint_index;
185 }
186
187 for (int i = 0; i + 1 < n; ++i) {
188 variables[2 * n + i].emplace_back(constraint_index, -1.0);
189 variables[2 * n + i + 1].emplace_back(constraint_index, 1.0);
190 lower_bounds->at(constraint_index) =
192 upper_bounds->at(constraint_index) =
194 ++constraint_index;
195 }
196
197 for (int i = 0; i + 1 < n; ++i) {
198 variables[n + i].emplace_back(constraint_index, -1.0 *
scale_factor_[2]);
199 variables[n + i + 1].emplace_back(constraint_index, 1.0 *
scale_factor_[2]);
200 variables[2 * n + i].emplace_back(constraint_index,
202 variables[2 * n + i + 1].emplace_back(constraint_index,
204 lower_bounds->at(constraint_index) = 0.0;
205 upper_bounds->at(constraint_index) = 0.0;
206 ++constraint_index;
207 }
208
209
211 for (int i = 0; i + 1 < n; ++i) {
212 variables[i].emplace_back(constraint_index,
214 variables[i + 1].emplace_back(constraint_index,
216 variables[n + i].emplace_back(
218 variables[2 * n + i].emplace_back(
219 constraint_index,
221 variables[2 * n + i + 1].emplace_back(
222 constraint_index,
224
225 lower_bounds->at(constraint_index) = 0.0;
226 upper_bounds->at(constraint_index) = 0.0;
227 ++constraint_index;
228 }
229
230 variables[0].emplace_back(constraint_index, 1.0);
233 ++constraint_index;
234
235 variables[n].emplace_back(constraint_index, 1.0);
238 ++constraint_index;
239
240 variables[2 * n].emplace_back(constraint_index, 1.0);
243 ++constraint_index;
244
245 CHECK_EQ(constraint_index, num_of_constraints);
246 int ind_p = 0;
247 for (int i = 0; i < num_of_variables; ++i) {
248 A_indptr->push_back(ind_p);
249 for (const auto& variable_nz : variables[i]) {
250
251 A_data->push_back(variable_nz.second);
252
253
254 A_indices->push_back(variable_nz.first);
255 ++ind_p;
256 }
257 }
258
259
260 A_indptr->push_back(ind_p);
261}
double front_edge_to_center
std::pair< double, double > dddx_bound_
std::vector< std::pair< double, double > > x_bounds_
std::array< double, 3 > x_init_
std::vector< std::pair< double, double > > ddx_bounds_
std::array< double, 3 > scale_factor_
std::vector< std::pair< double, double > > dx_bounds_