14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
// along with this program. If not, see <http://www.gnu.org/licenses/>
//
use crate::mcf;
use crate::problem::{
FirstOrderProblem as ParallelProblem, ResultSender, UpdateSender, UpdateState as ParallelUpdateState,
};
use crate::{data::minorant::Extendable, DVector, Real};
use log::{debug, warn};
use num_traits::Float;
use threadpool::ThreadPool;
use std::f64::INFINITY;
use std::fmt;
|
|
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
// along with this program. If not, see <http://www.gnu.org/licenses/>
//
use crate::mcf;
use crate::problem::{
FirstOrderProblem as ParallelProblem, ResultSender, UpdateSender, UpdateState as ParallelUpdateState,
};
use crate::{DVector, Minorant, Real};
use log::{debug, warn};
use num_traits::Float;
use threadpool::ThreadPool;
use std::f64::INFINITY;
use std::fmt;
|
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
Err(err) => tx.error(err).unwrap(),
});
Ok(())
}
fn update<U, S>(&mut self, state: U, tx: S) -> Result<()>
where
U: ParallelUpdateState<<Self::Minorant as Extendable>::Primal>,
S: UpdateSender<Self> + 'static,
{
if self.inactive_constraints.read().unwrap().is_empty() {
return Ok(());
}
let inactive_constraints = self.inactive_constraints.clone();
|
|
|
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
Err(err) => tx.error(err).unwrap(),
});
Ok(())
}
fn update<U, S>(&mut self, state: U, tx: S) -> Result<()>
where
U: ParallelUpdateState<<Self::Minorant as Minorant>::Primal>,
S: UpdateSender<Self> + 'static,
{
if self.inactive_constraints.read().unwrap().is_empty() {
return Ok(());
}
let inactive_constraints = self.inactive_constraints.clone();
|
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
|
// }));
let nnew = active.len() - nold;
if nnew > 0 {
let actives = active.clone();
if let Err(err) = tx.add_variables(
vec![(0.0, Real::infinity()); nnew],
Box::new(move |fidx: usize, x: &mut dyn Extendable<Primal = DVector>| {
let sub = subs[fidx].read().unwrap();
for i in x.dim()..x.dim() + nnew {
x.extend(sub.evaluate_constraint(x.primal(), actives[i]));
}
Ok(())
}),
) {
warn!("Error sending problem update: {}", err);
}
}
});
Ok(())
}
}
|
|
|
>
|
<
|
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
|
// }));
let nnew = active.len() - nold;
if nnew > 0 {
let actives = active.clone();
if let Err(err) = tx.add_variables(
vec![(0.0, Real::infinity()); nnew],
Box::new(move |fidx: usize, m: &mut Self::Minorant| {
let sub = subs[fidx].read().unwrap();
let n = m.dim();
let primal = &m.2;
m.1.extend((n..n + nnew).map(|i| sub.evaluate_constraint(primal, actives[i])));
Ok(())
}),
) {
warn!("Error sending problem update: {}", err);
}
}
});
Ok(())
}
}
|