RsBundle  Check-in [d5eed55bb2]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Rearrange master problem module
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | restructure
Files: files | file ages | folders
SHA1: d5eed55bb2e57f598a82468dddc82b6e6e8dd205
User & Date: fifr 2019-07-30 08:01:24.714
Context
2019-07-30
08:11
Move data structures like `DVector` and `Minorant` to `data` submodule Closed-Leaf check-in: bda0e2d65c user: fifr tags: restructure
08:01
Rearrange master problem module check-in: d5eed55bb2 user: fifr tags: restructure
07:40
Move `parallel` to `solver::sync` check-in: 62c311d2a4 user: fifr tags: restructure
Changes
Unified Diff Ignore Whitespace Patch
Changes to examples/mmcf.rs.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

use env_logger;
use env_logger::fmt::Color;
use log::{info, Level};
use rustop::opts;
use std::io::Write;

use bundle::master::{Builder as MasterBuilder, MasterProblem};
use bundle::mcf::MMCFProblem;
use bundle::solver::sync::Solver;
use bundle::{terminator::StandardTerminator, weighter::HKWeighter};
use bundle::{FullMasterBuilder, MinimalMasterBuilder};

use std::error::Error;
use std::result::Result;

fn solve_parallel<M>(master: M, mmcf: MMCFProblem) -> Result<(), Box<dyn Error>>
where
    M: MasterBuilder,
    M::MasterProblem: MasterProblem<MinorantIndex = usize>,
{
    let mut slv = Solver::<_, StandardTerminator, HKWeighter, M>::with_master(mmcf, master);
    slv.weighter.set_weight_bounds(1e-1, 100.0);
    slv.terminator.termination_precision = 1e-6;
    slv.solve()?;








|



<






|







17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41

use env_logger;
use env_logger::fmt::Color;
use log::{info, Level};
use rustop::opts;
use std::io::Write;

use bundle::master::{Builder, FullMasterBuilder, MasterProblem, MinimalMasterBuilder};
use bundle::mcf::MMCFProblem;
use bundle::solver::sync::Solver;
use bundle::{terminator::StandardTerminator, weighter::HKWeighter};


use std::error::Error;
use std::result::Result;

fn solve_parallel<M>(master: M, mmcf: MMCFProblem) -> Result<(), Box<dyn Error>>
where
    M: Builder,
    M::MasterProblem: MasterProblem<MinorantIndex = usize>,
{
    let mut slv = Solver::<_, StandardTerminator, HKWeighter, M>::with_master(mmcf, master);
    slv.weighter.set_weight_bounds(1e-1, 100.0);
    slv.terminator.termination_precision = 1e-6;
    slv.solve()?;

Changes to src/lib.rs.
39
40
41
42
43
44
45
46
47
48
49
50
51
pub mod weighter;

pub mod terminator;

pub mod master;

pub mod mcf;

/// The minimal bundle builder.
pub type FullMasterBuilder = master::boxed::Builder<master::cpx::Builder>;

/// The minimal bundle builder.
pub type MinimalMasterBuilder = master::boxed::Builder<master::minimal::Builder>;







<
<
<
<
<
<
39
40
41
42
43
44
45






pub mod weighter;

pub mod terminator;

pub mod master;

pub mod mcf;






Changes to src/master/boxed.rs.
10
11
12
13
14
15
16

17



18
19
20
21
22
23
24
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see  <http://www.gnu.org/licenses/>
//


use crate::master::{self, MasterProblem, SubgradientExtension, UnconstrainedMasterProblem};



use crate::{DVector, Minorant, Real};

use itertools::multizip;
use log::debug;
use std::f64::{EPSILON, INFINITY, NEG_INFINITY};

/**







>
|
>
>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see  <http://www.gnu.org/licenses/>
//

pub mod unconstrained;
use self::unconstrained::UnconstrainedMasterProblem;

use super::MasterProblem;
pub use super::SubgradientExtension;
use crate::{DVector, Minorant, Real};

use itertools::multizip;
use log::debug;
use std::f64::{EPSILON, INFINITY, NEG_INFINITY};

/**
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390

/// Builder for `BoxedMasterProblem`.
///
/// `B` is a builder of the underlying `UnconstrainedMasterProblem`.
#[derive(Default)]
pub struct Builder<B>(B);

impl<B> master::Builder for Builder<B>
where
    B: master::unconstrained::Builder,
    B::MasterProblem: UnconstrainedMasterProblem,
{
    type MasterProblem = BoxedMasterProblem<B::MasterProblem>;

    fn build(&mut self) -> Result<Self::MasterProblem, <Self::MasterProblem as MasterProblem>::Err> {
        self.0.build().map(BoxedMasterProblem::with_master)
    }







|

|







378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

/// Builder for `BoxedMasterProblem`.
///
/// `B` is a builder of the underlying `UnconstrainedMasterProblem`.
#[derive(Default)]
pub struct Builder<B>(B);

impl<B> super::Builder for Builder<B>
where
    B: unconstrained::Builder,
    B::MasterProblem: UnconstrainedMasterProblem,
{
    type MasterProblem = BoxedMasterProblem<B::MasterProblem>;

    fn build(&mut self) -> Result<Self::MasterProblem, <Self::MasterProblem as MasterProblem>::Err> {
        self.0.build().map(BoxedMasterProblem::with_master)
    }
Name change from src/master/unconstrained.rs to src/master/boxed/unconstrained.rs.
10
11
12
13
14
15
16



17
18
19
20
21
22
23
24
25
26
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see  <http://www.gnu.org/licenses/>
//




use crate::{DVector, Minorant, Real};

use super::SubgradientExtension;

use std::error::Error;

/**
 * Trait for master problems without box constraints.
 *
 * Implementors of this trait are supposed to solve quadratic







>
>
>


|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see  <http://www.gnu.org/licenses/>
//

pub mod cpx;
pub mod minimal;

use crate::{DVector, Minorant, Real};

pub use super::SubgradientExtension;

use std::error::Error;

/**
 * Trait for master problems without box constraints.
 *
 * Implementors of this trait are supposed to solve quadratic
Name change from src/master/cpx.rs to src/master/boxed/unconstrained/cpx.rs.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// along with this program.  If not, see  <http://www.gnu.org/licenses/>
//

//! Master problem implementation using CPLEX.

#![allow(unused_unsafe)]

use crate::master::unconstrained::{self, UnconstrainedMasterProblem};
use crate::master::SubgradientExtension;
use crate::{Aggregatable, DVector, Minorant, Real};

use c_str_macro::c_str;
use cplex_sys as cpx;
use cplex_sys::trycpx;
use log::debug;








|
<







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/>
//

//! Master problem implementation using CPLEX.

#![allow(unused_unsafe)]

use super::{SubgradientExtension, UnconstrainedMasterProblem};

use crate::{Aggregatable, DVector, Minorant, Real};

use c_str_macro::c_str;
use cplex_sys as cpx;
use cplex_sys::trycpx;
use log::debug;

759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
        Builder {
            max_bundle_size: 50,
            select_model: Arc::new(|i| i),
        }
    }
}

impl unconstrained::Builder for Builder {
    type MasterProblem = CplexMaster;

    fn build(&mut self) -> Result<CplexMaster> {
        let mut cpx = CplexMaster::new()?;
        cpx.max_bundle_size = self.max_bundle_size;
        cpx.select_model = self.select_model.clone();
        cpx.update_submodels();







|







758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
        Builder {
            max_bundle_size: 50,
            select_model: Arc::new(|i| i),
        }
    }
}

impl super::Builder for Builder {
    type MasterProblem = CplexMaster;

    fn build(&mut self) -> Result<CplexMaster> {
        let mut cpx = CplexMaster::new()?;
        cpx.max_bundle_size = self.max_bundle_size;
        cpx.select_model = self.select_model.clone();
        cpx.update_submodels();
Name change from src/master/minimal.rs to src/master/boxed/unconstrained/minimal.rs.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see  <http://www.gnu.org/licenses/>
//

use crate::master::unconstrained;
use crate::master::{SubgradientExtension, UnconstrainedMasterProblem};
use crate::{Aggregatable, DVector, Minorant, Real};

use log::debug;

use std::error::Error;
use std::f64::NEG_INFINITY;
use std::fmt;







<
|







10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see  <http://www.gnu.org/licenses/>
//


use super::{SubgradientExtension, UnconstrainedMasterProblem};
use crate::{Aggregatable, DVector, Minorant, Real};

use log::debug;

use std::error::Error;
use std::f64::NEG_INFINITY;
use std::fmt;
389
390
391
392
393
394
395
396
397
398
399
400
401
402

impl Default for Builder {
    fn default() -> Self {
        Builder
    }
}

impl unconstrained::Builder for Builder {
    type MasterProblem = MinimalMaster;

    fn build(&mut self) -> Result<MinimalMaster, MinimalMasterError> {
        MinimalMaster::new()
    }
}







|






388
389
390
391
392
393
394
395
396
397
398
399
400
401

impl Default for Builder {
    fn default() -> Self {
        Builder
    }
}

impl super::Builder for Builder {
    type MasterProblem = MinimalMaster;

    fn build(&mut self) -> Result<MinimalMaster, MinimalMasterError> {
        MinimalMaster::new()
    }
}
Changes to src/master/mod.rs.
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! * moving the center of the linear functions $\ell_i$ (and the
//!   bounds), i.e. replacing $\hat{f}$ by $d \mapsto \hat{f}(d -
//!   \hat{d})$ for some given $\hat{d} \in \mathbb{R}\^n$.

pub mod boxed;
pub use self::boxed::BoxedMasterProblem;

pub mod unconstrained;
pub use self::unconstrained::UnconstrainedMasterProblem;

pub mod minimal;
pub use self::minimal::MinimalMaster;

// pub mod grb;
// pub use master::grb::GurobiMaster;

pub mod cpx;

pub(crate) mod primalmaster;

use crate::{DVector, Minorant, Real};
use std::error::Error;
use std::result::Result;

/// Callback for subgradient extensions.







<
<
<
<
<
<
<
<
<
<
<







35
36
37
38
39
40
41











42
43
44
45
46
47
48
//! * moving the center of the linear functions $\ell_i$ (and the
//!   bounds), i.e. replacing $\hat{f}$ by $d \mapsto \hat{f}(d -
//!   \hat{d})$ for some given $\hat{d} \in \mathbb{R}\^n$.

pub mod boxed;
pub use self::boxed::BoxedMasterProblem;












pub(crate) mod primalmaster;

use crate::{DVector, Minorant, Real};
use std::error::Error;
use std::result::Result;

/// Callback for subgradient extensions.
173
174
175
176
177
178
179






pub trait Builder {
    /// The master problem to be build.
    type MasterProblem: MasterProblem;

    /// Create a new master problem.
    fn build(&mut self) -> Result<Self::MasterProblem, <Self::MasterProblem as MasterProblem>::Err>;
}













>
>
>
>
>
>
162
163
164
165
166
167
168
169
170
171
172
173
174
pub trait Builder {
    /// The master problem to be build.
    type MasterProblem: MasterProblem;

    /// Create a new master problem.
    fn build(&mut self) -> Result<Self::MasterProblem, <Self::MasterProblem as MasterProblem>::Err>;
}

/// The minimal bundle builder.
pub type FullMasterBuilder = boxed::Builder<boxed::unconstrained::cpx::Builder>;

/// The minimal bundle builder.
pub type MinimalMasterBuilder = boxed::Builder<boxed::unconstrained::minimal::Builder>;
Added src/solver.rs.














































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
 * Copyright (c) 2019 Frank Fischer <frank-fischer@shadow-soft.de>
 *
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see  <http://www.gnu.org/licenses/>
 */

//! The basic solver implementation.

pub mod sync;
pub use sync::{DefaultSolver, NoBundleSolver};

mod masterprocess;
Changes to src/solver/sync.rs.
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use crate::terminator::{StandardTerminatable, StandardTerminator, Terminator};
use crate::weighter::{HKWeightable, HKWeighter, Weighter};

/// The default iteration limit.
pub const DEFAULT_ITERATION_LIMIT: usize = 10_000;

/// The default solver.
pub type DefaultSolver<P> = Solver<P, StandardTerminator, HKWeighter, crate::FullMasterBuilder>;

/// The minimal bundle solver.
pub type NoBundleSolver<P> = Solver<P, StandardTerminator, HKWeighter, crate::MinimalMasterBuilder>;

/// Error raised by the parallel bundle [`Solver`].
#[derive(Debug)]
pub enum Error<E> {
    /// An error raised when creating a new master problem solver.
    BuildMaster(Box<dyn std::error::Error>),
    /// An error raised by the master problem process.







|


|







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use crate::terminator::{StandardTerminatable, StandardTerminator, Terminator};
use crate::weighter::{HKWeightable, HKWeighter, Weighter};

/// The default iteration limit.
pub const DEFAULT_ITERATION_LIMIT: usize = 10_000;

/// The default solver.
pub type DefaultSolver<P> = Solver<P, StandardTerminator, HKWeighter, crate::master::FullMasterBuilder>;

/// The minimal bundle solver.
pub type NoBundleSolver<P> = Solver<P, StandardTerminator, HKWeighter, crate::master::MinimalMasterBuilder>;

/// Error raised by the parallel bundle [`Solver`].
#[derive(Debug)]
pub enum Error<E> {
    /// An error raised when creating a new master problem solver.
    BuildMaster(Box<dyn std::error::Error>),
    /// An error raised by the master problem process.
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
            .get_aggregated_primal(i)
            .map_err(|_| "get_aggregated_primal".to_string())
            .expect("Cannot get aggregated primal from master process")
    }
}

/// Implementation of a parallel bundle method.
pub struct Solver<P, T = StandardTerminator, W = HKWeighter, M = crate::FullMasterBuilder>
where
    P: FirstOrderProblem,
    M: master::Builder,
{
    /// Parameters for the solver.
    pub params: Parameters,








|







326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
            .get_aggregated_primal(i)
            .map_err(|_| "get_aggregated_primal".to_string())
            .expect("Cannot get aggregated primal from master process")
    }
}

/// Implementation of a parallel bundle method.
pub struct Solver<P, T = StandardTerminator, W = HKWeighter, M = crate::master::FullMasterBuilder>
where
    P: FirstOrderProblem,
    M: master::Builder,
{
    /// Parameters for the solver.
    pub params: Parameters,