RsBundle  Diff

Differences From Artifact [310a4e8cd2]:

  • File src/parallel/solver.rs — part of check-in [ad5ec1d73d] at 2019-07-24 19:49:58 on branch problem-update — Cleanup types for `SubgradientExtender` callback (user: fifr size: 27462)

To Artifact [334a87326b]:

  • File src/parallel/solver.rs — part of check-in [3227c3bd0c] at 2019-07-25 14:08:50 on branch problem-update — parallel::solver: ensure solver is not terminated if the problem has been changed (user: fifr size: 27797) [more...]

216
217
218
219
220
221
222


223
224
225
226
227
228
229
230
231
232
233
234
235
236

237
238
239
240
241
242
243
    cnt_updates: usize,
    nxt_ubs: Vec<Real>,
    cnt_remaining_ubs: usize,
    nxt_cutvals: Vec<Real>,
    cnt_remaining_mins: usize,
    nxt_d: Arc<DVector>,
    nxt_y: Arc<DVector>,


}

impl IterData {
    fn new(num_subproblems: usize, num_variables: usize, max_iter: usize) -> Self {
        IterData {
            max_iter,
            cnt_iter: 0,
            cnt_updates: 0,
            nxt_ubs: vec![Real::infinity(); num_subproblems],
            cnt_remaining_ubs: num_subproblems,
            nxt_cutvals: vec![-Real::infinity(); num_subproblems],
            cnt_remaining_mins: num_subproblems,
            nxt_d: Arc::new(dvec![0.0; num_variables]),
            nxt_y: Arc::new(dvec![]),

        }
    }
}

/// Data providing access for updating the problem.
struct UpdateData<'a, P, M>
where







>
>














>







216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
    cnt_updates: usize,
    nxt_ubs: Vec<Real>,
    cnt_remaining_ubs: usize,
    nxt_cutvals: Vec<Real>,
    cnt_remaining_mins: usize,
    nxt_d: Arc<DVector>,
    nxt_y: Arc<DVector>,
    /// True if the problem has been updated after the last evaluation.
    updated: bool,
}

impl IterData {
    fn new(num_subproblems: usize, num_variables: usize, max_iter: usize) -> Self {
        IterData {
            max_iter,
            cnt_iter: 0,
            cnt_updates: 0,
            nxt_ubs: vec![Real::infinity(); num_subproblems],
            cnt_remaining_ubs: num_subproblems,
            nxt_cutvals: vec![-Real::infinity(); num_subproblems],
            cnt_remaining_mins: num_subproblems,
            nxt_d: Arc::new(dvec![0.0; num_variables]),
            nxt_y: Arc::new(dvec![]),
            updated: true,
        }
    }
}

/// Data providing access for updating the problem.
struct UpdateData<'a, P, M>
where
578
579
580
581
582
583
584

585
586
587
588
589
590
591
592
593
594
595


596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612

        debug!("Step");
        debug!("  cur_val    ={}", self.data.cur_val);
        debug!("  nxt_mod    ={}", self.data.nxt_mod);
        debug!("  nxt_ub     ={}", nxt_ub);
        debug!("  descent_bnd={}", descent_bnd);


        let step;
        if self.data.cur_val.is_infinite() {
            // This is the first evaluation. We effectively get
            // the function value at the current center but
            // we do not have a model estimate yet. Hence, we do not know
            // a good guess for the weight.
            step = Step::Descent;
            self.data.cur_val = nxt_ub;
            self.data.cur_weight = Real::infinity();
            master.set_weight(1.0)?;



            debug!("First Step");
            debug!("  cur_val={}", self.data.cur_val);
            debug!("  cur_y={}", self.data.cur_y);
        } else if nxt_ub <= descent_bnd {
            step = Step::Descent;
            self.cnt_descent += 1;

            // Update problem.
            Self::update_problem(&mut self.problem, step, &mut self.data, itdata, master)?;

            // Note that we must update the weight *before* we
            // change the internal data, so the old information
            // that caused the descent step is still available.
            self.data.cur_weight = self.weighter.descent_weight(&self.data);
            self.data.cur_y = itdata.nxt_y.as_ref().clone();
            self.data.cur_val = nxt_ub;








>











>
>







<
<
<







581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608



609
610
611
612
613
614
615

        debug!("Step");
        debug!("  cur_val    ={}", self.data.cur_val);
        debug!("  nxt_mod    ={}", self.data.nxt_mod);
        debug!("  nxt_ub     ={}", nxt_ub);
        debug!("  descent_bnd={}", descent_bnd);

        itdata.updated = false;
        let step;
        if self.data.cur_val.is_infinite() {
            // This is the first evaluation. We effectively get
            // the function value at the current center but
            // we do not have a model estimate yet. Hence, we do not know
            // a good guess for the weight.
            step = Step::Descent;
            self.data.cur_val = nxt_ub;
            self.data.cur_weight = Real::infinity();
            master.set_weight(1.0)?;

            itdata.updated = true;

            debug!("First Step");
            debug!("  cur_val={}", self.data.cur_val);
            debug!("  cur_y={}", self.data.cur_y);
        } else if nxt_ub <= descent_bnd {
            step = Step::Descent;
            self.cnt_descent += 1;




            // Note that we must update the weight *before* we
            // change the internal data, so the old information
            // that caused the descent step is still available.
            self.data.cur_weight = self.weighter.descent_weight(&self.data);
            self.data.cur_y = itdata.nxt_y.as_ref().clone();
            self.data.cur_val = nxt_ub;

628
629
630
631
632
633
634





635
636
637
638
639
640
641
            step,
            &self.data,
            self.cnt_descent,
            self.cnt_null,
            itdata.cnt_updates,
        );
        itdata.cnt_iter += 1;






        // Compute the new candidate. The main loop will wait for the result of
        // this solution process of the master problem.
        master.solve(self.data.cur_val)?;

        Ok(itdata.cnt_iter >= itdata.max_iter)
    }







>
>
>
>
>







631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
            step,
            &self.data,
            self.cnt_descent,
            self.cnt_null,
            itdata.cnt_updates,
        );
        itdata.cnt_iter += 1;

        // Update problem.
        if Self::update_problem(&mut self.problem, Step::Descent, &mut self.data, itdata, master)? {
            itdata.updated = true;
        }

        // Compute the new candidate. The main loop will wait for the result of
        // this solution process of the master problem.
        master.solve(self.data.cur_val)?;

        Ok(itdata.cnt_iter >= itdata.max_iter)
    }
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
        if self.data.cur_weight.is_infinite() {
            self.data.cur_weight = self.weighter.initial_weight(&self.data);
            master.set_weight(self.data.cur_weight)?;
            master.solve(self.data.cur_val)?;
            return Ok(false);
        }

        if self.terminator.terminate(&self.data) {
            Self::show_info(
                &self.start_time,
                Step::Term,
                &self.data,
                self.cnt_descent,
                self.cnt_null,
                itdata.cnt_updates,







|







666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
        if self.data.cur_weight.is_infinite() {
            self.data.cur_weight = self.weighter.initial_weight(&self.data);
            master.set_weight(self.data.cur_weight)?;
            master.solve(self.data.cur_val)?;
            return Ok(false);
        }

        if self.terminator.terminate(&self.data) && !itdata.updated {
            Self::show_info(
                &self.start_time,
                Step::Term,
                &self.data,
                self.cnt_descent,
                self.cnt_null,
                itdata.cnt_updates,
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727

728
729

730
731
732
733
734
735
736

    fn update_problem(
        problem: &mut P,
        step: Step,
        data: &mut SolverData,
        itdata: &mut IterData,
        master_proc: &mut MasterProcess<P, M::MasterProblem>,
    ) -> Result<(), Error<P::Err>> {
        let (update_tx, update_rx) = channel();
        problem
            .update(
                &UpdateData {
                    cur_y: &data.cur_y,
                    nxt_y: &itdata.nxt_y,
                    step: step,
                    master_proc: master_proc,
                },
                itdata.cnt_iter,
                update_tx,
            )
            .map_err(Error::Update)?;


        for update in update_rx {
            let update = update.map_err(Error::Update)?;

            match update {
                Update::AddVariables { bounds, sgext, .. } => {
                    let mut newvars = Vec::with_capacity(bounds.len());
                    for (lower, upper) in bounds {
                        if lower > upper {
                            return Err(Error::InvalidBounds { lower, upper });
                        }







|














>


>







714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746

    fn update_problem(
        problem: &mut P,
        step: Step,
        data: &mut SolverData,
        itdata: &mut IterData,
        master_proc: &mut MasterProcess<P, M::MasterProblem>,
    ) -> Result<bool, Error<P::Err>> {
        let (update_tx, update_rx) = channel();
        problem
            .update(
                &UpdateData {
                    cur_y: &data.cur_y,
                    nxt_y: &itdata.nxt_y,
                    step: step,
                    master_proc: master_proc,
                },
                itdata.cnt_iter,
                update_tx,
            )
            .map_err(Error::Update)?;

        let mut have_update = false;
        for update in update_rx {
            let update = update.map_err(Error::Update)?;
            have_update = true;
            match update {
                Update::AddVariables { bounds, sgext, .. } => {
                    let mut newvars = Vec::with_capacity(bounds.len());
                    for (lower, upper) in bounds {
                        if lower > upper {
                            return Err(Error::InvalidBounds { lower, upper });
                        }
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769

                        master_proc.add_vars(newvars.iter().map(|v| (v.0, v.1, v.2)).collect(), sgext)?;
                    }
                }
            }
        }

        Ok(())
    }

    /// Return the bound the function value must be below of to enforce a descent step.
    ///
    /// If the oracle guarantees that $f(\bar{y}) \le$ this bound, the
    /// bundle method will perform a descent step.
    ///







|







765
766
767
768
769
770
771
772
773
774
775
776
777
778
779

                        master_proc.add_vars(newvars.iter().map(|v| (v.0, v.1, v.2)).collect(), sgext)?;
                    }
                }
            }
        }

        Ok(have_update)
    }

    /// Return the bound the function value must be below of to enforce a descent step.
    ///
    /// If the oracle guarantees that $f(\bar{y}) \le$ this bound, the
    /// bundle method will perform a descent step.
    ///