RsBundle  Artifact [176082e056]

Artifact 176082e056e74f9dcb224eb5e122c72170a94c60:

  • File examples/mmcf.rs — part of check-in [1318918860] at 2016-10-01 20:44:09 on branch trunk — Make `aggregate_primals` take ownership of minorants. This makes sure the problem can track exactly when minorants are not used anymore. (user: fifr size: 2047)

/*
 * Copyright (c) 2016 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/>
 */

extern crate bundle;
#[macro_use]
extern crate log;
extern crate env_logger;

use bundle::{Solver, SolverParams, StandardTerminator, FirstOrderProblem};
use bundle::mcf;
use std::env;

fn main() {
    env_logger::init().unwrap();

    let mut args = env::args();
    let program = args.next().unwrap();

    if let Some(filename) = args.next() {
        info!("Reading instance: {}", filename);
        let mut mmcf = mcf::MMCFProblem::read_mnetgen(&filename).unwrap();
        mmcf.multimodel = false;

        let mut solver = Solver::new_params(mmcf, SolverParams {
            max_bundle_size: 25,
            min_weight: 1e-3,
            max_weight: 100.0,
            ..Default::default()
        }).unwrap();
        solver.terminator = Box::new(StandardTerminator{
            termination_precision: 1e-6
        });
        solver.solve().unwrap();

        let costs : f64 = (0..solver.problem().num_subproblems()).map(|i| {
            let (coeffs, primals) : (Vec<_>, Vec<_>) = solver.aggregated_primals(i).into_iter().unzip();
            let aggr_primals = solver.problem().aggregate_primals_ref(&coeffs, &primals);
            solver.problem().get_primal_costs(i, &aggr_primals)
        }).sum();
        info!("Primal costs: {}", costs);
    } else {
        panic!("Usage: {} FILENAME", program);
    }
}