RsBundle  Diff

Differences From Artifact [cd6b0d77ae]:

  • File src/solver/sync.rs — part of check-in [016889768f] at 2022-09-01 08:21:55 on branch cvx-constraint — solver: verify that convexity constrained variables are in [0,∞) (user: fifr size: 34056)

To Artifact [47a28edb62]:

  • File src/solver/sync.rs — part of check-in [61d6399085] at 2022-09-01 09:00:20 on branch cvx-constraint — solver: initialize y variables in convexity constraints correctly (user: fifr size: 34387)

22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36







-
+







#[cfg(feature = "serialize")]
use serde::{Deserialize, Serialize};

#[cfg(not(feature = "crossbeam"))]
use std::sync::mpsc::{channel, RecvError};

use log::{debug, info, warn};
use num_traits::{Float, Zero};
use num_traits::{Float, FromPrimitive, One, Zero};
use std::collections::HashMap;
use std::fmt::Debug;
use std::sync::Arc;
use std::time::Instant;
use thiserror::Error;
use threadpool::ThreadPool;

476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
476
477
478
479
480
481
482





483
484
485
486
487
488
489







-
-
-
-
-







    /// This function is automatically called by [`Solver::solve`].
    pub fn init(&mut self) -> Result<(), P, M> {
        debug!("Initialize solver");

        let n = self.problem.num_variables();
        let m = self.problem.num_subproblems();

        self.data.init(dvec![0.0; n]);
        self.cnt_descent = 0;
        self.cnt_null = 0;
        self.cnt_evals = 0;

        let (tx, rx) = channel();
        self.client_tx = Some(tx.clone());
        self.client_rx = Some(rx);

        let lower_bounds = self.problem.lower_bounds().map(DVector);
        if lower_bounds.as_ref().map(|lb| lb.len() != n).unwrap_or(false) {
            return Err(Error::Dimension {
515
516
517
518
519
520
521














522
523
524
525
526
527
528
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537







+
+
+
+
+
+
+
+
+
+
+
+
+
+







                    .unwrap_or(false)
                {
                    return Err(Error::InvalidConvexityUpperBound(i));
                }
                constraint_sets.entry(k).or_insert_with(|| vec![]).push(i);
            }
        }

        // compute initial y
        let mut init_y = dvec![Real::zero(); n];
        for convexity_set in constraint_sets.values() {
            let value = Real::one() / Real::from_usize(convexity_set.len()).unwrap();
            for &i in convexity_set {
                init_y[i] = value;
            }
        }

        self.data.init(init_y);
        self.cnt_descent = 0;
        self.cnt_null = 0;
        self.cnt_evals = 0;

        debug!("Start master process");

        // Initialize the master problem.
        let mut master = self.master.build().map_err(Error::BuildMaster)?;
        master.set_num_subproblems(m).map_err(Error::BuildMaster)?;
        master