Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch minorant-trait Excluding Merge-Ins
This is equivalent to a diff from 98774dd6e6 to 76f1c7f25f
|
2020-07-20
| ||
| 18:11 | Merge minorant-trait check-in: fe82c5787c user: fifr tags: trunk | |
| 18:03 | master: allow only adding of new variables (no moving) Closed-Leaf check-in: 76f1c7f25f user: fifr tags: minorant-trait | |
| 17:43 | minorant: add a debug assertion to `move_center` check-in: 3a337c0eec user: fifr tags: minorant-trait | |
|
2020-07-19
| ||
| 20:47 | Make `Minorant` a trait check-in: 095240b3e2 user: fifr tags: minorant-trait | |
|
2020-07-18
| ||
| 18:49 | Merge trunk check-in: e12bd4bd5d user: fifr tags: async | |
| 14:59 | Merge minorant-primal check-in: 98774dd6e6 user: fifr tags: trunk | |
| 14:56 | master: remove callback from `compress` method Closed-Leaf check-in: baa49a9473 user: fifr tags: minorant-primal | |
|
2020-07-15
| ||
| 19:52 | Update ordered-float to version 2.0 check-in: f53f2d0005 user: fifr tags: trunk | |
Changes to examples/cflp.rs.
| ︙ | |||
29 30 31 32 33 34 35 | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | - + + + |
use env_logger::{self, fmt::Color};
use ordered_float::NotNan;
use threadpool::ThreadPool;
use bundle::problem::{FirstOrderProblem as ParallelProblem, ResultSender};
use bundle::solver::sync::{DefaultSolver, NoBundleSolver};
|
| ︙ | |||
67 68 69 70 71 72 73 | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | - + - - + - - - - - - - + - - + - - - - - - - + |
impl CFLProblem {
fn new() -> CFLProblem {
CFLProblem { pool: None }
}
}
|
| ︙ |
Changes to examples/mmcf.rs.
| ︙ | |||
21 22 23 24 25 26 27 | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | - + + + - - + + - - + + |
use rustop::opts;
use std::io::Write;
use bundle::master::{Builder, FullMasterBuilder, MasterProblem, MinimalMasterBuilder};
use bundle::mcf::MMCFProblem;
use bundle::solver::asyn::Solver as AsyncSolver;
use bundle::solver::sync::Solver as SyncSolver;
|
| ︙ |
Changes to examples/quadratic.rs.
| ︙ | |||
24 25 26 27 28 29 30 | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | - + - + + |
use std::error::Error;
use std::io::Write;
use std::sync::Arc;
use std::thread;
use bundle::problem::{FirstOrderProblem as ParallelProblem, ResultSender};
use bundle::solver::sync::{DefaultSolver, NoBundleSolver};
|
| ︙ | |||
81 82 83 84 85 86 87 | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | - + - - - - - |
}
debug!("Evaluation at {:?}", x);
debug!(" objective={}", objective);
debug!(" subgradient={}", g);
tx.objective(objective).unwrap();
|
| ︙ |
Changes to src/data/aggregatable.rs.
| ︙ | |||
17 18 19 20 21 22 23 | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | - + - + - + - + | //! Objects that can be combined linearly. use super::Real; use std::borrow::Borrow; /// An aggregatable object. |
| ︙ | |||
68 69 70 71 72 73 74 75 76 77 78 79 80 81 | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |
fn add_scaled<A>(&mut self, _alpha: Real, _other: A)
where
A: Borrow<Self>,
{
}
}
/// Implement for pairs.
impl<T1, T2> Aggregatable for (T1, T2)
where
T1: Aggregatable,
T2: Aggregatable,
{
fn new_scaled<A>(alpha: Real, other: A) -> Self
where
A: Borrow<Self>,
{
let x = other.borrow();
(T1::new_scaled(alpha, &x.0), T2::new_scaled(alpha, &x.1))
}
fn add_scaled<A>(&mut self, alpha: Real, other: A)
where
A: Borrow<Self>,
{
let x = other.borrow();
self.0.add_scaled(alpha, &x.0);
self.1.add_scaled(alpha, &x.1);
}
}
/// Implement for triples.
impl<T1, T2, T3> Aggregatable for (T1, T2, T3)
where
T1: Aggregatable,
T2: Aggregatable,
T3: Aggregatable,
{
fn new_scaled<A>(alpha: Real, other: A) -> Self
where
A: Borrow<Self>,
{
let x = other.borrow();
(
T1::new_scaled(alpha, &x.0),
T2::new_scaled(alpha, &x.1),
T3::new_scaled(alpha, &x.2),
)
}
fn add_scaled<A>(&mut self, alpha: Real, other: A)
where
A: Borrow<Self>,
{
let x = other.borrow();
self.0.add_scaled(alpha, &x.0);
self.1.add_scaled(alpha, &x.1);
self.2.add_scaled(alpha, &x.2);
}
}
/// Implement for scalar values.
impl Aggregatable for Real {
fn new_scaled<A>(alpha: Real, other: A) -> Self
where
A: Borrow<Self>,
{
|
| ︙ |
Changes to src/data/minorant.rs.
| ︙ | |||
13 14 15 16 17 18 19 | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | - + - + + - - - - + + + + + - + - - + - - - - + + - - + - - - - - + + + + + - - + - - - + - - + - - - - - + + + - - + - - - + + + + + + + - - + - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + - - + - - - + + + - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + |
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>
//
//! A linear minorant.
use super::{Aggregatable, DVector, Real};
|
Changes to src/data/mod.rs.
1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | - + + + | /* |
Added src/data/raw.rs.
|
Changes to src/data/vector.rs.
| 1 2 3 4 5 6 7 8 | - + |
|
| ︙ | |||
20 21 22 23 24 25 26 | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | - - + |
use num_traits::Zero;
use std::borrow::Borrow;
use std::fmt;
use std::iter::FromIterator;
use std::ops::{Deref, DerefMut};
use std::vec::IntoIter;
|
| ︙ | |||
135 136 137 138 139 140 141 | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | - - - + - - - - - - - - - + - - - - - - - - - - + - - + - - - - - + + - - - + - - - + - - - - - |
}
/// Return the inner product with another vector.
///
/// The inner product is computed on the smaller of the two
/// dimensions. All other elements are assumed to be zero.
pub fn dot_begin(&self, other: &DVector) -> Real {
|
| ︙ |
Changes to src/master/boxed.rs.
| ︙ | |||
15 16 17 18 19 20 21 | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | - + - + - + | // pub mod unconstrained; use self::unconstrained::UnconstrainedMasterProblem; use super::MasterProblem; use crate::problem::SubgradientExtender; |
| ︙ | |||
65 66 67 68 69 70 71 | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | - + - + - - + + - + |
model_eps: Real,
need_new_candidate: bool,
/// Current number of updates.
cnt_updates: usize,
|
| ︙ | |||
187 188 189 190 191 192 193 | 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | - + - - + + |
* the current box-multipliers $\eta$.
*/
fn get_norm_subg2(&self) -> Real {
self.eta.dot(self.master.dualopt())
}
}
|
| ︙ | |||
228 229 230 231 232 233 234 | 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | - + - - + + + - - - - - - + + - + - - + |
Ok(())
}
fn num_minorants(&self, fidx: usize) -> usize {
self.master.num_minorants(fidx)
}
|
| ︙ | |||
356 357 358 359 360 361 362 | 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | - + |
self.dualoptnorm2
}
fn multiplier(&self, min: Self::MinorantIndex) -> Real {
self.master.multiplier(min)
}
|
| ︙ | |||
382 383 384 385 386 387 388 | 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | - + - - - + + + - + - + | /// Builder for `BoxedMasterProblem`. /// /// `B` is a builder of the underlying `UnconstrainedMasterProblem`. #[derive(Default)] pub struct Builder<B>(B); |
| ︙ |
Changes to src/master/boxed/unconstrained.rs.
| ︙ | |||
14 15 16 17 18 19 20 | 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/> // pub mod cpx; pub mod minimal; use crate::problem::SubgradientExtender; |
| ︙ | |||
43 44 45 46 47 48 49 | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | - + - |
* \alpha_i = 1 \right\\}$. Note, the unconstrained solver is expected
* to compute *dual* optimal solutions, i.e. the solver must compute
* optimal coefficients $\bar{\alpha}$ for the dual problem
*
* \\[ \max_{\alpha \in \Delta} \min_{d \in \mathbb{R}\^n}
* \sum_{i=1}\^k \alpha_i \ell_i(d) + \frac{u}{2} \\| d \\|\^2. \\]
*/
|
| ︙ | |||
78 79 80 81 82 83 84 | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | - + - - - - + - - - + - + - + - + - + |
///
/// When some minorants are compressed, the callback is called with the
/// coefficients and indices of the compressed minorants and the index of
/// the new minorant. The callback may be called several times.
fn compress(&mut self) -> Result<(), Self::Err>;
/// Add a new minorant to the model.
|
Changes to src/master/boxed/unconstrained/cpx.rs.
| ︙ | |||
67 68 69 70 71 72 73 | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | - - + + - + - - - - - - + - - - + - + - + - + - + - + |
CplexMasterError::Cplex(err)
}
}
pub type Result<T> = std::result::Result<T, CplexMasterError>;
/// A minorant and its unique index.
|
| ︙ | |||
153 154 155 156 157 158 159 | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | - + - + - + - + - + - + - + |
/// The additional diagonal term to ensure positive definiteness.
qdiag: Real,
/// The weight of the quadratic term.
weight: Real,
/// The minorants for each subproblem in the model.
|
| ︙ | |||
210 211 212 213 214 215 216 | 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | - + |
qdiag: 0.0,
weight: 1.0,
minorants: vec![],
select_model: Arc::new(|i| i),
submodels: vec![],
in_submodel: vec![],
opt_mults: vec![],
|
| ︙ | |||
268 269 270 271 272 273 274 | 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | - + + + + - + + + - + - - + + - + - - + - + - - - - - - + - - - - |
.collect::<Vec<_>>();
self.aggregate(i, &inds)?;
}
}
Ok(())
}
|
| ︙ | |||
354 355 356 357 358 359 360 | 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | - + |
// update linear costs
{
let mut c = Vec::with_capacity(nvars);
let mut inds = Vec::with_capacity(nvars);
for submodel in &self.submodels {
for i in 0..submodel.num_mins {
let m = &submodel.minorants[i];
|
| ︙ | |||
398 399 400 401 402 403 404 | 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | - + - + - + - - + + - + - + - + |
for &fidx in submodel.iter() {
for mult in &mut self.opt_mults[fidx][submodel.num_mins..] {
*mult = 0.0;
}
}
}
|
| ︙ | |||
510 511 512 513 514 515 516 | 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | - + |
}
let minorants = &self.minorants;
// Compute the number of minorants in each submodel.
for submodel in self.submodels.iter_mut() {
submodel.num_mins = submodel.iter().map(|&fidx| minorants[fidx].len()).min().unwrap_or(0);
|
| ︙ | |||
541 542 543 544 545 546 547 | 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | + - - + + + + + + |
}
})
.collect::<Vec<_>>();
// Compute the aggregated minorants.
for &(_, mod_i, i) in &updateinds {
let submodel = &mut self.submodels[mod_i];
Mn::combine_to_vec(
|
| ︙ | |||
569 570 571 572 573 574 575 | 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | - + - + - + |
// - j is the number of the minorant within the submodel submodel_j
// - idx_j is the unique index of that minorant (of the first subproblem)
for submodel_i in submodels.iter() {
// Compute the minorant g_i for each i
for i in 0..submodel_i.num_mins {
// Store the computed values at the index of the first subproblem in this model.
let idx_i = minorants[submodel_i[0]][i].index;
|
| ︙ | |||
776 777 778 779 780 781 782 | 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | - - + + - + |
Builder {
max_bundle_size: 50,
select_model: Arc::new(|i| i),
}
}
}
|
| ︙ |
Changes to src/master/boxed/unconstrained/minimal.rs.
| ︙ | |||
56 57 58 59 60 61 62 | 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | - + - + - + - + - + - + - - + + + + - - + + + + + + + + - + + + + - + | * is that this model can be solved explicitely and very quickly, but * it is only a very loose approximation of the objective function. * * Because of its properties, it can only be used if the problem to be * solved has a maximal number of minorants of two and only one * subproblem. */ |
| ︙ | |||
186 187 188 189 190 191 192 | 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | - - + - + - - - - - - - - - - - - - - - + - - - - - + - - - - - - - + + + + + + + - + + - + + + - - + + + + + - + - + - + - - + + - + |
_ => unreachable!("Invalid number of minorants in subproblem {}", fidx),
}
}
fn add_vars<SErr>(
&mut self,
nnew: usize,
|
| ︙ | |||
309 310 311 312 313 314 315 | 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | - - + + - + |
impl Default for Builder {
fn default() -> Self {
Builder
}
}
|
Changes to src/master/mod.rs.
| ︙ | |||
36 37 38 39 40 41 42 | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | - + - + |
//! bounds), i.e. replacing $\hat{f}$ by $d \mapsto \hat{f}(d -
//! \hat{d})$ for some given $\hat{d} \in \mathbb{R}\^n$.
pub mod boxed;
pub use self::boxed::BoxedMasterProblem;
use crate::problem::SubgradientExtender;
|
| ︙ | |||
86 87 88 89 90 91 92 | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | - + - - - - - + + - + |
/// Set the maximal number of inner iterations.
fn set_max_updates(&mut self, max_updates: usize) -> Result<(), Self::Err>;
/// Return the current number of inner iterations.
fn cnt_updates(&self) -> usize;
|
| ︙ | |||
132 133 134 135 136 137 138 | 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | - + - + - + - + |
/// $g\^*$ is the optimal aggregated subgradient.
fn get_dualoptnorm2(&self) -> Real;
/// Return the multiplier associated with a minorant.
fn multiplier(&self, min: Self::MinorantIndex) -> Real;
/// Return the aggregated primal.
|
Changes to src/mcf/problem.rs.
| ︙ | |||
417 418 419 420 421 422 423 | 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | - + |
aggr
}
}
impl ParallelProblem for MMCFProblem {
type Err = Error;
|
| ︙ | |||
458 459 460 461 462 463 464 | 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | - + - - - - - - + |
let active_constraints = self.active_constraints.read().unwrap()[0..y.len()].to_vec();
self.pool
.as_ref()
.unwrap()
.execute(move || match sub.write().unwrap().evaluate(&y, active_constraints) {
Ok((objective, subg, primal)) => {
tx.objective(objective).unwrap();
|
| ︙ | |||
525 526 527 528 529 530 531 | 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],
|
Changes to src/problem.rs.
| ︙ | |||
14 15 16 17 18 19 20 | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | - + - + - + | * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/> */ //! An asynchronous first-order oracle. pub use crate::data::minorant::SubgradientExtender; |
| ︙ | |||
90 91 92 93 94 95 96 | 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | - - + + |
///
/// Note that all computations made by an implementation are supposed to be
/// asynchronous.
pub trait FirstOrderProblem {
/// Error raised by this oracle.
type Err;
|
| ︙ | |||
173 174 175 176 177 178 179 | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | - + |
/// information (e.g. adding new variables) to the provided channel.
///
/// The updates might be generated asynchronously.
///
/// The default implementation does nothing.
fn update<U, S>(&mut self, _state: U, _tx: S) -> Result<(), Self::Err>
where
|
Changes to src/solver/asyn.rs.
| ︙ | |||
26 27 28 29 30 31 32 | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | - + | use num_cpus; use num_traits::Float; use std::iter::repeat; use std::sync::Arc; use std::time::Instant; use threadpool::ThreadPool; |
| ︙ | |||
85 86 87 88 89 90 91 | 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | - - + + |
///
/// - `T` is the value type,
/// - `P` is the `FirstOrderProblem` associated with the solver,
/// - `M` is the `MasterBuilder` associated with the solver.
pub type Result<T, P, M> = std::result::Result<
T,
Error<
|
| ︙ | |||
395 396 397 398 399 400 401 | 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | - + |
}
/// Implementation of a parallel bundle method.
pub struct Solver<P, T = StandardTerminator, W = HKWeighter, M = crate::master::FullMasterBuilder>
where
P: FirstOrderProblem,
P::Err: 'static,
|
| ︙ | |||
448 449 450 451 452 453 454 | 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | - + |
impl<P, T, W, M> Solver<P, T, W, M>
where
P: FirstOrderProblem,
P::Err: Send + 'static,
T: Terminator<SolverData> + Default,
W: Weighter<SolverData> + Default,
|
| ︙ | |||
678 679 680 681 682 683 684 | 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 | - + - + |
/// variables), and the master problem is started to compute a new
/// candidate.
///
/// The function returns
/// - `Ok(true)` if the final iteration count has been reached,
/// - `Ok(false)` if the final iteration count has not been reached,
/// - `Err(_)` on error.
|
| ︙ | |||
926 927 928 929 930 931 932 | 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 | - + - + |
}
/// Handles an update response `update` of the problem.
///
/// The method is called if the problem informs the solver about a change of
/// the problem, e.g. adding a new variable. This method updates the other
/// parts of the solver, e.g. the master problem, about the modification.
|
| ︙ | |||
983 984 985 986 987 988 989 | 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 | - + |
self.data.nxt_mod,
self.data.nxt_val,
self.data.cur_val
);
}
/// Return the aggregated primal of the given subproblem.
|
Changes to src/solver/channels.rs.
| ︙ | |||
16 17 18 19 20 21 22 | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 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 | - + - + - + - + - + - + - + - + - + - + - + - + - + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + |
*/
//! Implementation for `ResultSender` using channels.
use super::masterprocess::Response as MasterResponse;
use crate::master::MasterProblem;
use crate::problem::{FirstOrderProblem, ResultSender, SubgradientExtender, UpdateSender};
|
Changes to src/solver/masterprocess.rs.
| ︙ | |||
26 27 28 29 30 31 32 | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | - + |
use log::{debug, warn};
use std::sync::Arc;
use threadpool::ThreadPool;
use super::channels::{ClientSender, Message};
use crate::master::MasterProblem;
use crate::problem::{FirstOrderProblem, SubgradientExtender};
|
| ︙ | |||
104 105 106 107 108 109 110 | 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | - + + - + - - - + + - + - + |
/// The lower bounds on the variables.
pub lower_bounds: Option<DVector>,
/// The lower bounds on the variables.
pub upper_bounds: Option<DVector>,
}
/// A task for the master problem.
|
| ︙ | |||
152 153 154 155 156 157 158 | 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | - + - + - + + - + - + - + |
},
/// An error occurred.
Error(Error<MErr, PErr>),
}
/// Convenient type for `Response`.
pub type MasterResponse<P, M> =
|
| ︙ | |||
204 205 206 207 208 209 210 | 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | - - + + - + |
phantom: std::marker::PhantomData,
}
}
/// Add new variables to the master problem.
pub fn add_vars(
&mut self,
|
| ︙ | |||
248 249 250 251 252 253 254 | 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | - + + + + - + |
/// Sets the new weight of the proximal term in the master problem.
pub fn set_weight(&mut self, weight: Real) -> Result<(), Error<M::Err, P::Err>> {
Ok(self.tx.send(MasterTask::SetWeight { weight })?)
}
/// Get the current aggregated primal for a certain subproblem.
|
| ︙ | |||
294 295 296 297 298 299 300 | 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | - + - - - + - |
MasterTask::AddMinorant(i, mut m) => {
debug!("master: add minorant to subproblem {}", i);
// It may happen the number new minorant belongs to an earlier evaluation
// with less variables (i.e. new variables have been added
// after the start of the evaluation but before the new
// minorant is added, i.e. now). In this case we must add
// extend the minorant accordingly.
|
| ︙ |
Changes to src/solver/sync.rs.
| ︙ | |||
20 21 22 23 24 25 26 | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | - + - + |
#[cfg(feature = "crossbeam")]
use rs_crossbeam::channel::{unbounded as channel, RecvError};
#[cfg(not(feature = "crossbeam"))]
use std::sync::mpsc::{channel, RecvError};
use log::{debug, info, warn};
use num_cpus;
|
| ︙ | |||
84 85 86 87 88 89 90 | 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | - - + + |
///
/// - `T` is the value type,
/// - `P` is the `FirstOrderProblem` associated with the solver,
/// - `M` is the `MasterBuilder` associated with the solver.
pub type Result<T, P, M> = std::result::Result<
T,
Error<
|
| ︙ | |||
393 394 395 396 397 398 399 | 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | - + |
}
}
/// Implementation of a parallel bundle method.
pub struct Solver<P, T = StandardTerminator, W = HKWeighter, M = crate::master::FullMasterBuilder>
where
P: FirstOrderProblem,
|
| ︙ | |||
447 448 449 450 451 452 453 | 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | - + |
impl<P, T, W, M> Solver<P, T, W, M>
where
P: FirstOrderProblem,
P::Err: Send + 'static,
T: Terminator<SolverData> + Default,
W: Weighter<SolverData> + Default,
|
| ︙ | |||
650 651 652 653 654 655 656 | 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 | - + - + |
}
}
}
/// Handle a response from a subproblem evaluation.
///
/// The function returns `Ok(true)` if the final iteration count has been reached.
|
| ︙ | |||
847 848 849 850 851 852 853 | 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 | - - - + + + + - - - - + + - - - + - - - + - - + - - - - - - + + + - + - - - + |
let mut have_update = false;
for msg in update_rx {
if let Message::Update(update) = msg {
match update {
Update::AddVariables { bounds, sgext, .. } => {
have_update = true;
|
| ︙ | |||
922 923 924 925 926 927 928 | 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 | - + |
self.data.nxt_mod,
self.data.nxt_val,
self.data.cur_val
);
}
/// Return the aggregated primal of the given subproblem.
|