RsBundle  Diff

Differences From Artifact [e634f8a692]:

  • File src/mcf/problem.rs — part of check-in [7189c81425] at 2020-07-20 10:29:42 on branch minorant-trait — Master problem convert minorants to some internal representation. (user: fifr size: 18659)

To Artifact [802a398090]:

  • File src/mcf/problem.rs — part of check-in [1f0489f726] at 2020-07-20 15:02:06 on branch minorant-trait — Simplify `Minorant` API and remove `Extendable` (user: fifr size: 18637) [more...]

14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28







-
+







// along with this program.  If not, see  <http://www.gnu.org/licenses/>
//

use crate::mcf;
use crate::problem::{
    FirstOrderProblem as ParallelProblem, ResultSender, UpdateSender, UpdateState as ParallelUpdateState,
};
use crate::{data::minorant::Extendable, DVector, Real};
use crate::{DVector, Minorant, Real};

use log::{debug, warn};
use num_traits::Float;
use threadpool::ThreadPool;

use std::f64::INFINITY;
use std::fmt;
467
468
469
470
471
472
473
474

475
476
477
478
479
480
481
467
468
469
470
471
472
473

474
475
476
477
478
479
480
481







-
+







                Err(err) => tx.error(err).unwrap(),
            });
        Ok(())
    }

    fn update<U, S>(&mut self, state: U, tx: S) -> Result<()>
    where
        U: ParallelUpdateState<<Self::Minorant as Extendable>::Primal>,
        U: ParallelUpdateState<<Self::Minorant as Minorant>::Primal>,
        S: UpdateSender<Self> + 'static,
    {
        if self.inactive_constraints.read().unwrap().is_empty() {
            return Ok(());
        }

        let inactive_constraints = self.inactive_constraints.clone();
520
521
522
523
524
525
526
527

528
529
530



531
532
533
534
535
536
537
538
539
540
541
542
520
521
522
523
524
525
526

527
528


529
530
531

532
533
534
535
536
537
538
539
540
541
542







-
+

-
-
+
+
+
-











            //     }));

            let nnew = active.len() - nold;
            if nnew > 0 {
                let actives = active.clone();
                if let Err(err) = tx.add_variables(
                    vec![(0.0, Real::infinity()); nnew],
                    Box::new(move |fidx: usize, x: &mut dyn Extendable<Primal = DVector>| {
                    Box::new(move |fidx: usize, m: &mut Self::Minorant| {
                        let sub = subs[fidx].read().unwrap();
                        for i in x.dim()..x.dim() + nnew {
                            x.extend(sub.evaluate_constraint(x.primal(), actives[i]));
                        let n = m.dim();
                        let primal = &m.2;
                        m.1.extend((n..n + nnew).map(|i| sub.evaluate_constraint(primal, actives[i])));
                        }
                        Ok(())
                    }),
                ) {
                    warn!("Error sending problem update: {}", err);
                }
            }
        });

        Ok(())
    }
}