Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch mcf-trait Excluding Merge-Ins
This is equivalent to a diff from aebb10d81f to 39a415c170
|
2021-06-30
| ||
| 09:45 | Merge mcf-trait check-in: bbbb1c6ab6 user: fifr tags: trunk | |
| 09:44 | examples/mmcf: add options to select the network flow solver Closed-Leaf check-in: 39a415c170 user: fifr tags: mcf-trait | |
| 09:43 | mmcf: allow to select network flow solver when reading mnetgen instances check-in: 736a0d7893 user: fifr tags: mcf-trait | |
| 09:42 | MCF solvers now implement the trait `mcf::Solver` check-in: 76363b77bc user: fifr tags: mcf-trait | |
|
2021-06-29
| ||
| 07:14 | Merge release check-in: aebb10d81f user: fifr tags: trunk | |
| 07:13 | mcf::problem: use format version of `assert!` check-in: 3f333f2454 user: fifr tags: release | |
| 07:12 | Update blas to 0.22 and openblas-src to 0.10 check-in: 846f32c5fc user: fifr tags: trunk | |
Changes to examples/mmcf.rs.
1 | 1 2 3 4 5 6 7 8 9 | - + | /* |
| ︙ | |||
18 19 20 21 22 23 24 | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | - + |
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};
|
| ︙ | |||
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | + + + + - + + + + + |
opt aggregated:bool, desc:"Use aggregated model";
opt sync:bool, desc:"Use synchronized solver";
opt bundle_size:usize = 0, name:"NUM", desc:"The bundle size";
opt nearest_guess:bool, desc:"Use nearest guess model (default: cut-model)";
opt descent_factor:Real = 0.5, name:"ρ", desc:"Descent parameter in (0,1)";
opt imprecision_factor:Real = 0.9, name:"α", desc:"Imprecision parameter in (0,1)";
opt l_guess_factor:Real = 0.1, name:"β", desc:"Lipschitz-guess increase factor in (0,1]";
opt cpx:bool, desc:"Use Cplex as network flow solver";
opt netspx:bool, desc:"Use network simplex implementation as network flow solver (default)";
param file:String, desc:"Input file in MNetGen format";
}
.parse_or_exit();
let filename = args.file;
info!("Reading instance: {}", filename);
if !args.minimal {
let mut mmcf = if args.netspx || !args.cpx {
info!("Use rs-graph network simplex solver");
|
| ︙ |
Changes to src/mcf/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 | - + + + |
|
Changes to src/mcf/problem.rs.
| ︙ | |||
10 11 12 13 14 15 16 | 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/> // |
| ︙ | |||
97 98 99 100 101 102 103 | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | - + |
ind: usize,
val: Real,
}
/// A single MMCF subproblem, i.e. one network.
struct Subproblem {
/// The (net, cost) pair.
|
| ︙ | |||
185 186 187 188 189 190 191 192 193 194 195 196 197 198 | 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | + + + + + + + |
impl MMCFProblem {
pub fn num_subproblems(&self) -> usize {
self.subs.len()
}
pub fn read_mnetgen(basename: &str) -> std::result::Result<MMCFProblem, MMCFReadError> {
MMCFProblem::read_mnetgen_with_solver::<mcf::NetSpxSolver>(basename)
}
pub fn read_mnetgen_with_solver<S>(basename: &str) -> std::result::Result<MMCFProblem, MMCFReadError>
where
S: Solver + 'static,
{
use MMCFReadError::*;
let mut buffer = String::new();
{
let mut f = File::open(&format!("{}.nod", basename))?;
f.read_to_string(&mut buffer)?;
}
|
| ︙ | |||
212 213 214 215 216 217 218 | 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | - + |
return Err(ExtraNodField);
}
}
// read nodes
let mut nets = Vec::with_capacity(ncom);
for i in 0..ncom {
|
| ︙ |
Changes to src/mcf/solver/cpx.rs.
| ︙ | |||
14 15 16 17 18 19 20 21 22 23 24 25 | 14 15 16 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | + - + - - - - - - - - - - - + + + + + + + - + - - + + |
// along with this program. If not, see <http://www.gnu.org/licenses/>
//
//! Solver for MCF-problems based on Cplex.
#![allow(unused_unsafe)]
use super::{Error, Result, Solver};
use crate::{DVector, Real};
use c_str_macro::c_str;
use cplex_sys as cpx;
use cplex_sys::trycpx;
|
| ︙ | |||
101 102 103 104 105 106 107 | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | - + - + - + - + - + - + - + - + - + - + |
code: status,
msg: CString::from_raw(msg).to_string_lossy().into_owned(),
}
.into());
}
}
|
Changes to src/mcf/solver/mod.rs.
| ︙ | |||
10 11 12 13 14 15 16 17 18 | 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - + + |
* 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/>
*/
use thiserror::Error;
use crate::{DVector, Real};
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
#[error("MCF problem is infeasible")]
Infeasible,
#[error("MCF problem is unbounded")]
Unbounded,
#[error("MCF problem has not been solved")]
Unsolved,
#[error("The mcf network cannot be modified after is has been solved")]
NotInBuildState,
#[error("An unknown error has been raised by the backend solver")]
Unknown(Box<dyn std::error::Error + Send + 'static>),
}
pub type Result<T> = std::result::Result<T, Error>;
/// Generic trait for MCF solvers.
pub trait Solver {
/// Create a new solver.
fn new(id: usize, nnodes: usize) -> Result<Self>
where
Self: Sized;
/// Return the number of nodes.
fn num_nodes(&self) -> usize;
/// Return the number of arcs.
fn num_arcs(&self) -> usize;
/// Set the supply (balance) of a node.
fn set_balance(&mut self, node: usize, supply: Real) -> Result<()>;
/// Set the objective coefficients for each arg.
fn set_objective(&mut self, obj: &DVector) -> Result<()>;
/// Add an arc to the network.
fn add_arc(&mut self, src: usize, snk: usize, cost: Real, cap: Real) -> Result<()>;
/// Solve the network-flow problem.
fn solve(&mut self) -> Result<()>;
/// Return the optimal objective value.
fn objective(&self) -> Result<Real>;
/// Return the optimal flow on each arc.
fn get_solution(&self) -> Result<DVector>;
/// Write an LP representation of the problem to the given file.
fn writelp(&self, _filename: &str) -> Result<()> {
unimplemented!("writelp is not implemented for this solver")
}
}
pub mod cpx;
|
Changes to src/mcf/solver/netspx.rs.
| ︙ | |||
23 24 25 26 27 28 29 | 23 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | - - - - - - - - - - - - - - + - - + - - + + - + - + - + - + - + - + - + - + - + - - - - - - - |
use num_traits::{Float, Zero};
use rs_graph::{
mcf::{MinCostFlow, NetworkSimplex, SolutionState},
traits::{GraphSize, IndexGraph, Indexable},
Buildable, Builder, Net,
};
|
| ︙ |