RsBundle  Diff

Differences From Artifact [ee0e357dc6]:

  • File src/solver.rs — part of check-in [7b213efa22] at 2016-10-01 07:49:00 on branch trunk — Aggregate primal information. For this, master problems must return the coefficients and the problem trait needs to implement an `aggregate` method. (user: fifr size: 25959)

To Artifact [08a7218298]:

  • File src/solver.rs — part of check-in [39420cd8e3] at 2016-10-01 20:03:46 on branch trunk — Implement computation of aggregated primals. (user: fifr size: 26814)

277
278
279
280
281
282
283
284

285
286
287
288
289
290
291
277
278
279
280
281
282
283

284
285
286
287
288
289
290
291







-
+








/// Information about a minorant.
#[derive(Debug, Clone)]
struct MinorantInfo<Pr> {
    /// The minorant's index in the master problem
    index: usize,
    /// Current multiplier.
    multiplier: usize,
    multiplier: Real,
    /// Primal associated with this minorant.
    primal: Option<Pr>,
}

/**
 * Implementation of a bundle method.
 */
484
485
486
487
488
489
490













491
492
493
494
495
496
497
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510







+
+
+
+
+
+
+
+
+
+
+
+
+







            self.show_info(term);
            if term == Step::Term {
                break;
            }
        }
        Ok(())
    }

    /// Return the current aggregated primal information for a subproblem.
    ///
    /// This function returns all currently used minorants $x_i$ along
    /// with their coefficients $\alpha_i$. The aggregated primal can
    /// be computed by combining the minorants $\bar{x} =
    /// \sum_{i=1}\^m \alpha_i x_i$.
    pub fn aggregated_primals(&mut self, subproblem : usize) -> Pr {
        let (coeffs, primals) : (Vec<_>, Vec<_>) = self.minorants[subproblem].iter().map(|m| {
            (m.multiplier, m.primal.as_ref().unwrap())
        }).unzip();
        self.problem.aggregate_primals(&coeffs, &primals)
    }

    fn show_info(&self, step: Step) {
        let time = self.start_time.elapsed();
        info!("{} {:0>2}:{:0>2}:{:0>2}.{:0>2} {:4} {:4} {:4}{:1}  {:9.4} {:9.4} {:12.6e}({:12.6e}) {:12.6e}",
              if step == Step::Term { "_endit" } else { "endit " },
              time.as_secs() / 3600,
              (time.as_secs() / 60) % 60,
553
554
555
556
557
558
559
560

561
562
563
564
565
566
567
566
567
568
569
570
571
572

573
574
575
576
577
578
579
580







-
+








            let mut minorants = result.into_iter();
            if let Some((minorant, primal)) = minorants.next() {
                self.cur_mods[i] = minorant.constant;
                self.cur_mod += self.cur_mods[i];
                self.minorants[i].push(MinorantInfo {
                    index: try!(self.master.add_minorant(i, minorant)),
                    multiplier: 0,
                    multiplier: 0.0,
                    primal: Some(primal),
                });
            } else {
                return Err(Error::NoMinorant);
            }
        }

606
607
608
609
610
611
612
613

614
615
616
617
618







619

620
621


622
623

624
625
626
627


628
629
630
631
632
633
634
619
620
621
622
623
624
625

626





627
628
629
630
631
632
633
634
635


636
637
638
639
640
641
642


643
644
645
646
647
648
649
650
651







-
+
-
-
-
-
-
+
+
+
+
+
+
+

+
-
-
+
+


+


-
-
+
+







        Ok(())
    }


    /// Reduce size of bundle.
    fn compress_bundle(&mut self) -> Result<()> {
        for i in 0..self.problem.num_subproblems() {
            let n = self.master.num_minorants(i);
            // update multiplier from master solution
            if n >= self.params.max_bundle_size {
                for m in self.minorants[i].iter_mut() {
                    m.multiplier = (1e6 * self.master.multiplier(m.index)) as usize;
                }
                self.minorants[i].sort_by_key(|m| -(m.multiplier as isize));
            for m in self.minorants[i].iter_mut() {
                m.multiplier = self.master.multiplier(m.index);
            }
            let n = self.master.num_minorants(i);
            if n >= self.params.max_bundle_size {
                // aggregate minorants with smallest coefficients
                self.minorants[i].sort_by_key(|m| -((1e6 * m.multiplier) as isize));
                let aggr = self.minorants[i].split_off(self.params.max_bundle_size-2);
                let aggr_sum = aggr.iter().map(|m| m.multiplier).sum();
                let (aggr_mins, aggr_primals) : (Vec<_>, Vec<_>) = aggr.into_iter().map(|m| {
                    (m.index, m.primal.unwrap())
                let (aggr_mins, aggr_primals) : (Vec<_>, Vec<_>) = aggr.iter().map(|m| {
                    (m.index, m.primal.as_ref().unwrap())
                }).unzip();
                let (aggr_min, aggr_coeffs) = try!(self.master.aggregate(i, &aggr_mins));
                // append aggregated minorant
                self.minorants[i].push(MinorantInfo{
                    index: aggr_min,
                    multiplier: 0,
                    primal: Some(self.problem.aggregate_primals(&aggr_coeffs, aggr_primals)),
                    multiplier: aggr_sum,
                    primal: Some(self.problem.aggregate_primals(&aggr_coeffs, &aggr_primals)),
                });
            }
        }
        Ok(())
    }

    /// Perform a descent step.
703
704
705
706
707
708
709
710

711
712
713
714
715
716
717
720
721
722
723
724
725
726

727
728
729
730
731
732
733
734







-
+







            self.nxt_vals[fidx] = fun_ub;

            // move center of minorant to cur_y
            nxt_minorant.move_center(-1.0, &self.nxt_d);
            self.new_cutval += nxt_minorant.constant;
            self.minorants[fidx].push(MinorantInfo{
                index: try!(self.master.add_minorant(fidx, nxt_minorant)),
                multiplier: 0,
                multiplier: 0.0,
                primal: Some(nxt_primal),
            });
        }

        if self.new_cutval > self.cur_val + 1e-3 {
            warn!("New minorant has higher value in center new:{} old:{}", self.new_cutval, self.cur_val);
            self.cur_val = self.new_cutval;