RsBundle  Diff

Differences From Artifact [1b69b2b864]:

  • File src/mcf/problem.rs — part of check-in [78b057dcc9] at 2021-07-01 07:18:26 on branch trunk — mmcf: add some doc comments (user: fifr size: 19040)

To Artifact [d1725d5d42]:

  • File src/mcf/problem.rs — part of check-in [fa31409d9b] at 2021-07-01 07:27:12 on branch trunk — mmcf: remove now unsupported `multimodel` option (user: fifr size: 18709)

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/// The current implementation always keeps a list of all potential
/// coupling constraints but, depending on the separation choice, the
/// may not be in the model. If separation is used a list of "active"
/// constraints is maintained holding the list of those constraints
/// that are in the model. "inactive" constraints may be separated
/// later on.
pub struct MMCFProblem {
    pub multimodel: bool,

    /// The list of subproblems (single network flows)
    subs: Vec<Arc<RwLock<Subproblem>>>,
    /// The coupling constraints for each subproblem.
    subdatas: Vec<Arc<SubData>>,
    /// The list of currently active constraints
    active_constraints: Arc<RwLock<Vec<usize>>>,
    /// The list of inactive constraints







<
<







133
134
135
136
137
138
139


140
141
142
143
144
145
146
/// The current implementation always keeps a list of all potential
/// coupling constraints but, depending on the separation choice, the
/// may not be in the model. If separation is used a list of "active"
/// constraints is maintained holding the list of those constraints
/// that are in the model. "inactive" constraints may be separated
/// later on.
pub struct MMCFProblem {


    /// The list of subproblems (single network flows)
    subs: Vec<Arc<RwLock<Subproblem>>>,
    /// The coupling constraints for each subproblem.
    subdatas: Vec<Arc<SubData>>,
    /// The list of currently active constraints
    active_constraints: Arc<RwLock<Vec<usize>>>,
    /// The list of inactive constraints
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
            .into_iter()
            .map(|net| Subproblem { net, c: dvec![] })
            .map(RwLock::new)
            .map(Arc::new)
            .collect();

        Ok(MMCFProblem {
            multimodel: false,
            subs: subproblems,
            subdatas,
            active_constraints: Arc::new(RwLock::new((0..ncaps).collect())),
            inactive_constraints: Arc::new(RwLock::new(vec![])),
            pool: None,
        })
    }







<







345
346
347
348
349
350
351

352
353
354
355
356
357
358
            .into_iter()
            .map(|net| Subproblem { net, c: dvec![] })
            .map(RwLock::new)
            .map(Arc::new)
            .collect();

        Ok(MMCFProblem {

            subs: subproblems,
            subdatas,
            active_constraints: Arc::new(RwLock::new((0..ncaps).collect())),
            inactive_constraints: Arc::new(RwLock::new(vec![])),
            pool: None,
        })
    }
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
        } else {
            self.active_constraints = Arc::new(RwLock::new((0..nconstrs).collect()));
            self.inactive_constraints.write().unwrap().clear();
        }
    }

    /// Compute costs for a primal solution.
    pub fn get_primal_costs(&self, fidx: usize, primals: &[DVector]) -> Real {
        let sub = &self.subdatas[fidx];
        if self.multimodel {
            primals[0].iter().enumerate().map(|(i, x)| x * sub.cbase[i]).sum()
        } else {
            let mut sum = 0.0;
            for p in primals {
                for (i, x) in p.iter().enumerate() {
                    sum += x * sub.cbase[i];
                }
            }
            sum
        }
    }

    /// Aggregate primal vectors.
    pub fn aggregate_primals_ref(&self, primals: &[(Real, &Vec<DVector>)]) -> Vec<DVector> {
        let mut aggr = primals[0]
            .1
            .iter()







|

<
|
<
<
<
<
<
<
<
<
<







369
370
371
372
373
374
375
376
377

378









379
380
381
382
383
384
385
        } else {
            self.active_constraints = Arc::new(RwLock::new((0..nconstrs).collect()));
            self.inactive_constraints.write().unwrap().clear();
        }
    }

    /// Compute costs for a primal solution.
    pub fn get_primal_costs(&self, fidx: usize, primals: &DVector) -> Real {
        let sub = &self.subdatas[fidx];

        primals.iter().enumerate().map(|(i, x)| x * sub.cbase[i]).sum()









    }

    /// Aggregate primal vectors.
    pub fn aggregate_primals_ref(&self, primals: &[(Real, &Vec<DVector>)]) -> Vec<DVector> {
        let mut aggr = primals[0]
            .1
            .iter()