@@ -166,6 +166,9 @@ void print_repn(fmt::ostream& ostr, const QuadraticExpr& repn,
166
166
167
167
class LPWriter {
168
168
public:
169
+ #ifdef COEK_WITH_COMPACT_MODEL
170
+ Model model_handle;
171
+ #endif
169
172
bool one_var_constant;
170
173
std::unordered_map<size_t , size_t > vid;
171
174
std::vector<Variable> variables;
@@ -250,9 +253,8 @@ void LPWriter::print_objectives(StreamType& ostr, CompactModel& model)
250
253
print_objective (ostr, obj);
251
254
++n_obj;
252
255
}
253
- else {
254
- auto & seq = std::get<ObjectiveSequence>(val);
255
- for (auto & jt : seq) {
256
+ else if (auto eval = std::get_if<ObjectiveSequence>(&val)) {
257
+ for (auto & jt : *eval) {
256
258
print_objective (ostr, jt);
257
259
++n_obj;
258
260
}
@@ -290,14 +292,21 @@ void LPWriter::print_constraints(StreamType& ostr, CompactModel& model)
290
292
print_constraint (ostr, c, ctr);
291
293
++ctr;
292
294
}
293
- else {
294
- auto & seq = std::get<ConstraintSequence>(val);
295
- for (auto & jt : seq) {
295
+ else if (auto cval = std::get_if<ConstraintSequence>(&val)) {
296
+ for (auto & jt : *cval) {
296
297
invconmap[jt.id ()] = ctr;
297
298
print_constraint (ostr, jt, ctr);
298
299
++ctr;
299
300
}
300
301
}
302
+ else if (auto cval = std::get_if<ConstraintMap>(&val)) {
303
+ // for (auto jt=cval->begin(); jt != cval->end(); ++jt) {
304
+ for (auto & [k,v] : *cval) {
305
+ invconmap[v.id ()] = ctr;
306
+ print_constraint (ostr, v, ctr);
307
+ ++ctr;
308
+ }
309
+ }
301
310
}
302
311
}
303
312
#endif
@@ -328,6 +337,7 @@ void LPWriter::collect_variables(Model& model)
328
337
#ifdef COEK_WITH_COMPACT_MODEL
329
338
void LPWriter::collect_variables (CompactModel& model)
330
339
{
340
+ model_handle = model.expand_data ();
331
341
size_t ctr = 0 ;
332
342
for (auto & val : model.repn ->variables ) {
333
343
if (auto eval = std::get_if<Variable>(&val)) {
@@ -351,9 +361,40 @@ void LPWriter::collect_variables(CompactModel& model)
351
361
invvarmap[ctr] = variables.size ();
352
362
++ctr;
353
363
}
354
- else {
355
- auto & seq = std::get<VariableSequence>(val);
356
- for (auto & jt : seq) {
364
+ else if (auto eval = std::get_if<VariableSequence>(&val)) {
365
+ for (auto & jt : *eval) {
366
+ if (jt.fixed ())
367
+ continue ;
368
+ variables.push_back (jt);
369
+ if (jt.is_binary ())
370
+ bvars[vid[jt.id ()]] = jt.repn ;
371
+ if (jt.is_integer ())
372
+ ivars[vid[jt.id ()]] = jt.repn ;
373
+
374
+ vid[jt.id ()] = ctr;
375
+ invvarmap[ctr] = variables.size ();
376
+ ++ctr;
377
+ }
378
+ }
379
+ else if (auto eval = std::get_if<VariableMap>(&val)) {
380
+ eval->expand ();
381
+ for (auto & jt : *eval) {
382
+ if (jt.fixed ())
383
+ continue ;
384
+ variables.push_back (jt);
385
+ if (jt.is_binary ())
386
+ bvars[vid[jt.id ()]] = jt.repn ;
387
+ if (jt.is_integer ())
388
+ ivars[vid[jt.id ()]] = jt.repn ;
389
+
390
+ vid[jt.id ()] = ctr;
391
+ invvarmap[ctr] = variables.size ();
392
+ ++ctr;
393
+ }
394
+ }
395
+ else if (auto eval = std::get_if<VariableArray>(&val)) {
396
+ eval->expand ();
397
+ for (auto & jt : *eval) {
357
398
if (jt.fixed ())
358
399
continue ;
359
400
variables.push_back (jt);
0 commit comments