| ︙ | | | ︙ | |
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
|
let mut problem = &mut self.problem;
let minorants = &self.minorants;
self.master.add_vars(&newvars.iter().map(|v| (v.0, v.1, v.2)).collect::<Vec<_>>(),
&mut move |fidx, minidx, vars| {
problem.extend_subgradient(minorants[fidx][minidx].primal.as_ref().unwrap(), vars)
.map(DVector)
.unwrap()
});
// modify moved variables
for (index, val) in newvars.iter().filter_map(|v| v.0.map(|i| (i, v.3))) {
self.cur_y[index] = val;
self.nxt_y[index] = val;
self.nxt_d[index] = 0.0;
}
// add new variables
|
|
|
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
|
let mut problem = &mut self.problem;
let minorants = &self.minorants;
self.master.add_vars(&newvars.iter().map(|v| (v.0, v.1, v.2)).collect::<Vec<_>>(),
&mut move |fidx, minidx, vars| {
problem.extend_subgradient(minorants[fidx][minidx].primal.as_ref().unwrap(), vars)
.map(DVector)
.unwrap()
})?;
// modify moved variables
for (index, val) in newvars.iter().filter_map(|v| v.0.map(|i| (i, v.3))) {
self.cur_y[index] = val;
self.nxt_y[index] = val;
self.nxt_d[index] = 0.0;
}
// add new variables
|
| ︙ | | | ︙ | |
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
|
if let Some(ref x) = lb {
if x.len() != self.problem.num_variables() {
return Err(SolverError::Dimension.into());
}
}
try!(self.master.set_num_subproblems(m));
self.master.set_vars(self.problem.num_variables(), lb, ub);
self.master.set_max_updates(self.params.max_updates);
self.minorants = Vec::with_capacity(m);
for _ in 0..m {
self.minorants.push(vec![]);
}
self.cur_val = 0.0;
|
|
|
|
|
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
|
if let Some(ref x) = lb {
if x.len() != self.problem.num_variables() {
return Err(SolverError::Dimension.into());
}
}
self.master.set_num_subproblems(m)?;
self.master.set_vars(self.problem.num_variables(), lb, ub)?;
self.master.set_max_updates(self.params.max_updates)?;
self.minorants = Vec::with_capacity(m);
for _ in 0..m {
self.minorants.push(vec![]);
}
self.cur_val = 0.0;
|
| ︙ | | | ︙ | |
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
|
// subgradient.
//
// We could compute that subgradient directly by
// adding up the initial minorants, but this would not include
// the eta terms. However, this is a heuristic anyway because
// we assume an initial weight of 1.0, which, in general, will
// *not* be the initial weight for the first iteration.
self.master.set_weight(1.0);
try!(self.master.solve(self.cur_val));
self.sgnorm = self.master.get_dualoptnorm2().sqrt();
// Compute the real initial weight.
let state = current_state!(self, Step::Term);
let new_weight = self.weighter.weight(&state, &self.params);
self.master.set_weight(new_weight);
debug!("Init master completed");
Ok(())
}
|
|
|
|
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
|
// subgradient.
//
// We could compute that subgradient directly by
// adding up the initial minorants, but this would not include
// the eta terms. However, this is a heuristic anyway because
// we assume an initial weight of 1.0, which, in general, will
// *not* be the initial weight for the first iteration.
self.master.set_weight(1.0)?;
try!(self.master.solve(self.cur_val));
self.sgnorm = self.master.get_dualoptnorm2().sqrt();
// Compute the real initial weight.
let state = current_state!(self, Step::Term);
let new_weight = self.weighter.weight(&state, &self.params);
self.master.set_weight(new_weight)?;
debug!("Init master completed");
Ok(())
}
|
| ︙ | | | ︙ | |
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
|
});
}
}
Ok(())
}
/// Perform a descent step.
fn descent_step(&mut self) {
let new_weight = self.weighter.weight(¤t_state!(self, Step::Descent), &self.params);
self.master.set_weight(new_weight);
self.cnt_descent += 1;
swap(&mut self.cur_y, &mut self.nxt_y);
swap(&mut self.cur_val, &mut self.nxt_val);
swap(&mut self.cur_mod, &mut self.nxt_mod);
swap(&mut self.cur_vals, &mut self.nxt_vals);
swap(&mut self.cur_mods, &mut self.nxt_mods);
self.master.move_center(1.0, &self.nxt_d);
debug!("Descent Step");
debug!(" dir ={}", self.nxt_d);
debug!(" newy={}", self.cur_y);
}
/// Perform a null step.
fn null_step(&mut self) {
let new_weight = self.weighter.weight(¤t_state!(self, Step::Null), &self.params);
self.master.set_weight(new_weight);
self.cnt_null += 1;
debug!("Null Step");
}
/// Perform one bundle iteration.
#[cfg_attr(feature = "cargo-clippy", allow(collapsible_if))]
pub fn step(&mut self) -> Result<Step, Error> {
self.iterinfos.clear();
|
|
|
>
|
|
>
|
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
|
});
}
}
Ok(())
}
/// Perform a descent step.
fn descent_step(&mut self) -> Result<(), Error> {
let new_weight = self.weighter.weight(¤t_state!(self, Step::Descent), &self.params);
self.master.set_weight(new_weight)?;
self.cnt_descent += 1;
swap(&mut self.cur_y, &mut self.nxt_y);
swap(&mut self.cur_val, &mut self.nxt_val);
swap(&mut self.cur_mod, &mut self.nxt_mod);
swap(&mut self.cur_vals, &mut self.nxt_vals);
swap(&mut self.cur_mods, &mut self.nxt_mods);
self.master.move_center(1.0, &self.nxt_d);
debug!("Descent Step");
debug!(" dir ={}", self.nxt_d);
debug!(" newy={}", self.cur_y);
Ok(())
}
/// Perform a null step.
fn null_step(&mut self) -> Result<(), Error> {
let new_weight = self.weighter.weight(¤t_state!(self, Step::Null), &self.params);
self.master.set_weight(new_weight)?;
self.cnt_null += 1;
debug!("Null Step");
Ok(())
}
/// Perform one bundle iteration.
#[cfg_attr(feature = "cargo-clippy", allow(collapsible_if))]
pub fn step(&mut self) -> Result<Step, Error> {
self.iterinfos.clear();
|
| ︙ | | | ︙ | |
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
|
debug!(" cur_val ={}", self.cur_val);
debug!(" nxt_mod ={}", self.nxt_mod);
debug!(" nxt_ub ={}", self.nxt_val);
debug!(" descent_bnd={}", descent_bnd);
// do a descent step or null step
if nxt_ub <= descent_bnd {
self.descent_step();
Ok(Step::Descent)
} else {
self.null_step();
Ok(Step::Null)
}
}
/**
* Return the bound on the function value that enforces a
* nullstep.
|
|
|
|
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
|
debug!(" cur_val ={}", self.cur_val);
debug!(" nxt_mod ={}", self.nxt_mod);
debug!(" nxt_ub ={}", self.nxt_val);
debug!(" descent_bnd={}", descent_bnd);
// do a descent step or null step
if nxt_ub <= descent_bnd {
self.descent_step()?;
Ok(Step::Descent)
} else {
self.null_step()?;
Ok(Step::Null)
}
}
/**
* Return the bound on the function value that enforces a
* nullstep.
|
| ︙ | | | ︙ | |