| ︙ | | |
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
|
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
|
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
|
+
+
+
|
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;
|
| ︙ | | |
628
629
630
631
632
633
634
635
636
637
638
639
640
641
|
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
|
+
+
+
+
+
|
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
|
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
|
-
+
|
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) {
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
|
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
747
748
749
|
-
+
+
+
|
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>> {
) -> 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
|
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
|
-
+
|
master_proc.add_vars(newvars.iter().map(|v| (v.0, v.1, v.2)).collect(), sgext)?;
}
}
}
}
Ok(())
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.
///
|
| ︙ | | |