RsBundle  Diff

Differences From Artifact [245d4179ba]:

  • File src/mcf/problem.rs — part of check-in [358bb8efe2] at 2017-01-20 20:34:12 on branch trunk — problem: refactor some loops using iterators. (user: fifr size: 10925)

To Artifact [ead0953468]:

  • File src/mcf/problem.rs — part of check-in [d7ed56f9b3] at 2017-02-22 16:32:29 on branch trunk — Remove `DVector` from external API. The use of `[Real]` or `Vec<Real>` is sufficient in most cases. (user: fifr size: 10905)

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 {Real, Vector, DVector, Minorant, FirstOrderProblem, SimpleEvaluation};
use mcf;

use std::fs::File;
use std::io::{self, Read};
use std::result;
use std::num::{ParseIntError, ParseFloatError};
use std::f64::INFINITY;







|







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 {Real, DVector, Minorant, FirstOrderProblem, SimpleEvaluation};
use mcf;

use std::fs::File;
use std::io::{self, Read};
use std::result;
use std::num::{ParseIntError, ParseFloatError};
use std::f64::INFINITY;
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

    type EvalResult = SimpleEvaluation<Vec<DVector>>;

    fn num_variables(&self) -> usize {
        self.lhs.len()
    }

    fn lower_bounds(&self) -> Option<Vector> {
        Some(Vector::new_sparse(self.lhs.len(), &[], &[]))
    }

    fn upper_bounds(&self) -> Option<Vector> {
        None
    }

    fn num_subproblems(&self) -> usize {
        if self.multimodel { self.nets.len() } else { 1 }
    }

    #[allow(unused_variables)]
    fn evaluate(&'a mut self, fidx: usize, y: &DVector, nullstep_bound: Real, relprec: Real) -> result::Result<Self::EvalResult, Self::Error> {
        // compute costs
        self.rhsval = 0.0;
        for i in 0..self.c.len() {
            self.c[i].clear();
            self.c[i].extend(self.cbase[i].iter());
        }

        for (i, &y) in y.iter().enumerate().filter(|&(i,&y)| y != 0.0) {
            self.rhsval += self.rhs[i] * y;
            for (fidx, c) in self.c.iter_mut().enumerate() {
                for elem in &self.lhs[i][fidx] {
                    c[elem.ind] += y * elem.val;
                }
            }
        }

        debug!("y={}", y);
        for i in 0..self.nets.len() {
            debug!("c[{}]={}", i, self.c[i]);
            try!(self.nets[i].set_objective(&self.c[i]));
        }

        // solve subproblems
        for (i, net) in self.nets.iter_mut().enumerate() {







|
|


|








|
















|







232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

    type EvalResult = SimpleEvaluation<Vec<DVector>>;

    fn num_variables(&self) -> usize {
        self.lhs.len()
    }

    fn lower_bounds(&self) -> Option<Vec<Real>> {
        Some(vec![0.0; self.lhs.len()])
    }

    fn upper_bounds(&self) -> Option<Vec<Real>> {
        None
    }

    fn num_subproblems(&self) -> usize {
        if self.multimodel { self.nets.len() } else { 1 }
    }

    #[allow(unused_variables)]
    fn evaluate(&'a mut self, fidx: usize, y: &[Real], nullstep_bound: Real, relprec: Real) -> result::Result<Self::EvalResult, Self::Error> {
        // compute costs
        self.rhsval = 0.0;
        for i in 0..self.c.len() {
            self.c[i].clear();
            self.c[i].extend(self.cbase[i].iter());
        }

        for (i, &y) in y.iter().enumerate().filter(|&(i,&y)| y != 0.0) {
            self.rhsval += self.rhs[i] * y;
            for (fidx, c) in self.c.iter_mut().enumerate() {
                for elem in &self.lhs[i][fidx] {
                    c[elem.ind] += y * elem.val;
                }
            }
        }

        debug!("y={:?}", y);
        for i in 0..self.nets.len() {
            debug!("c[{}]={}", i, self.c[i]);
            try!(self.nets[i].set_objective(&self.c[i]));
        }

        // solve subproblems
        for (i, net) in self.nets.iter_mut().enumerate() {