RsBundle  Check-in [62c311d2a4]

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

Overview
Comment:Move `parallel` to `solver::sync`
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | restructure
Files: files | file ages | folders
SHA1: 62c311d2a4533203087023457738e13702fa74c0
User & Date: fifr 2019-07-30 07:40:07.612
Context
2019-07-30
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
07:25
Remove old sequential solver check-in: b194454b53 user: fifr tags: restructure
Changes
Unified Diff Ignore Whitespace Patch
Changes to examples/cflp.rs.
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::io::Write as _;
use std::sync::Arc;

use env_logger::{self, fmt::Color};
use ordered_float::NotNan;
use threadpool::ThreadPool;

use bundle::parallel::{
    DefaultSolver as ParallelSolver, EvalResult, FirstOrderProblem as ParallelProblem,
    NoBundleSolver as NoParallelSolver, ResultSender,
};
use bundle::{dvec, DVector, Minorant, Real};

const Nfac: usize = 3;
const Ncus: usize = 5;
const F: [Real; Nfac] = [1000.0, 1000.0, 1000.0];
const CAP: [Real; Nfac] = [500.0, 500.0, 500.0];
const C: [[Real; Ncus]; Nfac] = [







<
|
|
<







27
28
29
30
31
32
33

34
35

36
37
38
39
40
41
42
use std::io::Write as _;
use std::sync::Arc;

use env_logger::{self, fmt::Color};
use ordered_float::NotNan;
use threadpool::ThreadPool;


use bundle::problem::{EvalResult, FirstOrderProblem as ParallelProblem, ResultSender};
use bundle::solver::sync::{DefaultSolver, NoBundleSolver};

use bundle::{dvec, DVector, Minorant, Real};

const Nfac: usize = 3;
const Ncus: usize = 5;
const F: [Real; Nfac] = [1000.0, 1000.0, 1000.0];
const CAP: [Real; Nfac] = [500.0, 500.0, 500.0];
const C: [[Real; Ncus]; Nfac] = [
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272

    let (args, _) = opts! {
        synopsis "Solver a simple capacitated facility location problem";
        opt minimal:bool, desc:"Use the minimal master model";
    }
    .parse_or_exit();
    if !args.minimal {
        let mut slv = ParallelSolver::<_>::new(CFLProblem::new());
        slv.terminator.termination_precision = 1e-9;
        slv.master.max_bundle_size = 5;
        slv.solve()?;

        show_primals(|i| slv.aggregated_primal(i).unwrap())?;
    } else {
        let mut slv = NoParallelSolver::<_>::new(CFLProblem::new());
        slv.terminator.termination_precision = 1e-5;
        slv.solve()?;

        show_primals(|i| slv.aggregated_primal(i).unwrap())?;
    }

    Ok(())
}







|






|








248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270

    let (args, _) = opts! {
        synopsis "Solver a simple capacitated facility location problem";
        opt minimal:bool, desc:"Use the minimal master model";
    }
    .parse_or_exit();
    if !args.minimal {
        let mut slv = DefaultSolver::<_>::new(CFLProblem::new());
        slv.terminator.termination_precision = 1e-9;
        slv.master.max_bundle_size = 5;
        slv.solve()?;

        show_primals(|i| slv.aggregated_primal(i).unwrap())?;
    } else {
        let mut slv = NoBundleSolver::<_>::new(CFLProblem::new());
        slv.terminator.termination_precision = 1e-5;
        slv.solve()?;

        show_primals(|i| slv.aggregated_primal(i).unwrap())?;
    }

    Ok(())
}
Changes to examples/mmcf.rs.
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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::parallel;
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 = parallel::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()?;

    let costs: f64 = (0..slv.problem().num_subproblems())
        .map(|i| {
            let aggr_primals = slv.aggregated_primal(i).unwrap();







|











|







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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()?;

    let costs: f64 = (0..slv.problem().num_subproblems())
        .map(|i| {
            let aggr_primals = slv.aggregated_primal(i).unwrap();
Changes to examples/quadratic.rs.
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use env_logger::fmt::Color;
use log::{debug, Level};
use rustop::opts;
use std::io::Write;
use std::sync::Arc;
use std::thread;

use bundle::parallel::{
    DefaultSolver as ParallelSolver, EvalResult, FirstOrderProblem as ParallelProblem,
    NoBundleSolver as NoParallelSolver, ResultSender,
};
use bundle::{DVector, Minorant, Real};

#[derive(Clone)]
struct QuadraticProblem {
    a: [[Real; 2]; 2],
    b: [Real; 2],
    c: Real,







<
|
|
<







23
24
25
26
27
28
29

30
31

32
33
34
35
36
37
38
use env_logger::fmt::Color;
use log::{debug, Level};
use rustop::opts;
use std::io::Write;
use std::sync::Arc;
use std::thread;


use bundle::problem::{EvalResult, FirstOrderProblem as ParallelProblem, ResultSender};
use bundle::solver::sync::{DefaultSolver, NoBundleSolver};

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

#[derive(Clone)]
struct QuadraticProblem {
    a: [[Real; 2]; 2],
    b: [Real; 2],
    c: Real,
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
        synopsis "Solver a simple quadratic optimization problem";
        opt minimal:bool, desc:"Use the minimal master model";
    }
    .parse_or_exit();

    let f = QuadraticProblem::new();
    if !args.minimal {
        let mut solver = ParallelSolver::<_>::new(f);
        solver.solve().map_err(|e| format!("{}", e))?;
    } else {
        let mut solver = NoParallelSolver::<_>::new(f);
        solver.solve().map_err(|e| format!("{}", e))?;
    }

    Ok(())
}







|


|





137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
        synopsis "Solver a simple quadratic optimization problem";
        opt minimal:bool, desc:"Use the minimal master model";
    }
    .parse_or_exit();

    let f = QuadraticProblem::new();
    if !args.minimal {
        let mut solver = DefaultSolver::<_>::new(f);
        solver.solve().map_err(|e| format!("{}", e))?;
    } else {
        let mut solver = NoBundleSolver::<_>::new(f);
        solver.solve().map_err(|e| format!("{}", e))?;
    }

    Ok(())
}
Changes to src/lib.rs.
28
29
30
31
32
33
34
35


36
37
38
39
40
41
42

pub mod vector;
pub use crate::vector::{DVector, Vector};

pub mod minorant;
pub use crate::minorant::{Aggregatable, Minorant};

pub mod parallel;



pub mod weighter;

pub mod terminator;

pub mod master;








|
>
>







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

pub mod vector;
pub use crate::vector::{DVector, Vector};

pub mod minorant;
pub use crate::minorant::{Aggregatable, Minorant};

pub mod problem;

pub mod solver;

pub mod weighter;

pub mod terminator;

pub mod master;

Changes to src/master/primalmaster.rs.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see  <http://www.gnu.org/licenses/>
 */

//! A wrapper around master problems to handle primal information.

use super::MasterProblem;
use crate::parallel::SubgradientExtender;
use crate::{Aggregatable, Minorant, Real};

use std::collections::HashMap;
use std::ops::{Deref, DerefMut};

/// A wrapper around `MasterProblem` to handle primal information.
///







|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see  <http://www.gnu.org/licenses/>
 */

//! A wrapper around master problems to handle primal information.

use super::MasterProblem;
use crate::problem::SubgradientExtender;
use crate::{Aggregatable, Minorant, Real};

use std::collections::HashMap;
use std::ops::{Deref, DerefMut};

/// A wrapper around `MasterProblem` to handle primal information.
///
Changes to src/mcf/problem.rs.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// 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::mcf;
use crate::parallel::{
    EvalResult, FirstOrderProblem as ParallelProblem, ResultSender, Update as ParallelUpdate, UpdateSender,
    UpdateState as ParallelUpdateState,
};
use crate::{DVector, Minorant, Real};

use itertools::izip;
use log::{debug, warn};







|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// 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::mcf;
use crate::problem::{
    EvalResult, FirstOrderProblem as ParallelProblem, ResultSender, Update as ParallelUpdate, UpdateSender,
    UpdateState as ParallelUpdateState,
};
use crate::{DVector, Minorant, Real};

use itertools::izip;
use log::{debug, warn};
Deleted src/parallel/mod.rs.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
 * 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/>
 */

//! Implementation of a asynchronous parallel proximal bundle method.

mod problem;
pub use self::problem::{
    EvalResult, FirstOrderProblem, ResultSender, SubgradientExtender, Update, UpdateSender, UpdateState,
};

mod solver;
pub use self::solver::Solver;

/// The default bundle solver with general master problem.
pub type DefaultSolver<P> =
    Solver<P, crate::terminator::StandardTerminator, crate::weighter::HKWeighter, crate::FullMasterBuilder>;

/// A bundle solver with a minimal cutting plane model.
pub type NoBundleSolver<P> =
    Solver<P, crate::terminator::StandardTerminator, crate::weighter::HKWeighter, crate::MinimalMasterBuilder>;

mod masterprocess;
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<








































































Name change from src/parallel/problem.rs to src/problem.rs.
Name change from src/parallel/masterprocess.rs to src/solver/masterprocess.rs.
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
//! Asynchronous process solving a master problem.

use crossbeam::channel::{unbounded as channel, Receiver, Sender};
use log::{debug, warn};
use std::sync::Arc;
use threadpool::ThreadPool;

use super::problem::{FirstOrderProblem, SubgradientExtender};
use super::solver::Error;
use crate::master::primalmaster::PrimalMaster;
use crate::master::MasterProblem;

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

/// Configuration information for setting up a master problem.
pub struct MasterConfig {
    /// The number of subproblems.
    pub num_subproblems: usize,
    /// The number of variables.







<
|


>







18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
//! Asynchronous process solving a master problem.

use crossbeam::channel::{unbounded as channel, Receiver, Sender};
use log::{debug, warn};
use std::sync::Arc;
use threadpool::ThreadPool;


use super::sync::Error;
use crate::master::primalmaster::PrimalMaster;
use crate::master::MasterProblem;
use crate::problem::{FirstOrderProblem, SubgradientExtender};
use crate::{DVector, Minorant, Real};

/// Configuration information for setting up a master problem.
pub struct MasterConfig {
    /// The number of subproblems.
    pub num_subproblems: usize,
    /// The number of variables.
Name change from src/parallel/solver.rs to src/solver/sync.rs.
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38






39
40
41
42
43
44
45
use std::sync::Arc;
use std::time::Instant;
use threadpool::ThreadPool;

use crate::{DVector, Real};

use super::masterprocess::{MasterConfig, MasterProcess, MasterResponse};
use super::problem::{EvalResult, FirstOrderProblem, Update, UpdateState};
use crate::master::{self, MasterProblem};

use crate::terminator::{StandardTerminatable, StandardTerminator, Terminator};
use crate::weighter::{HKWeightable, HKWeighter, Weighter};

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







/// 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.
    Master(Box<dyn std::error::Error>),







<

>






>
>
>
>
>
>







24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use std::sync::Arc;
use std::time::Instant;
use threadpool::ThreadPool;

use crate::{DVector, Real};

use super::masterprocess::{MasterConfig, MasterProcess, MasterResponse};

use crate::master::{self, MasterProblem};
use crate::problem::{EvalResult, FirstOrderProblem, Update, UpdateState};
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.
    Master(Box<dyn std::error::Error>),