RsBundle  Changes On Branch bundle-compression

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch bundle-compression Excluding Merge-Ins

This is equivalent to a diff from 7d19b86676 to fcd1979efd

2019-07-23
07:57
Merge bundle-compression check-in: 9cac21baad user: fifr tags: async
07:55
cpx: add assertion for maximal bundle size to `compress` Closed-Leaf check-in: fcd1979efd user: fifr tags: bundle-compression
07:53
examples/cflp: adjust maximal bundle size check-in: 09bef0cf18 user: fifr tags: bundle-compression
07:50
boxed: impl `Deref` for the builder type. check-in: e1e0d664de user: fifr tags: bundle-compression
07:23
Use `better_panic` for examples check-in: 7d19b86676 user: fifr tags: async
2019-07-22
13:58
Add `MasterProblem::compress` method check-in: bbd32bf565 user: fifr tags: async

Changes to examples/cflp.rs.
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
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







-
-
-
-




















-
+
+

+







        });
        Ok(())
    }
}

fn main() -> Result<(), Box<dyn Error>> {
    better_panic::install();
    // env_logger::builder()
    //     .default_format_timestamp(false)
    //     .default_format_module_path(false)
    //     .init();
    env_logger::builder()
        .format(|buf, record| {
            let mut style = buf.style();
            let color = match record.level() {
                Level::Error | Level::Warn => Color::Red,
                Level::Trace => Color::Blue,
                Level::Debug => Color::Yellow,
                _ => Color::White,
            };
            style.set_color(color);
            writeln!(
                buf,
                "{}{:5}{} {}",
                style.value("["),
                style.value(record.level()),
                style.value("]"),
                style.value(record.args())
            )
        })
        .init();
    {

    {
        let mut slv = DefaultSolver::new(CFLProblem::new())?;
        slv.params.max_bundle_size = 5;
        slv.terminator.termination_precision = 1e-9;
        slv.solve()?;

        for i in 0..Ncus {
            let x = slv.aggregated_primals(Nfac + i);
            let mut obj = 0.0;
            let mut s = String::new();
291
292
293
294
295
296
297

298
299
300
301
302
289
290
291
292
293
294
295
296
297
298
299
300
301







+





        write!(s, "  objval = {:.2}", obj)?;
        info!("{}", s);
    }

    {
        let mut slv = ParallelSolver::<_>::new(CFLProblem::new());
        slv.terminator.termination_precision = 1e-9;
        slv.master_builder.max_bundle_size = 5;
        slv.solve()?;
    }

    Ok(())
}
Changes to src/master/boxed.rs.
378
379
380
381
382
383
384














378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398







+
+
+
+
+
+
+
+
+
+
+
+
+
+
{
    type MasterProblem = BoxedMasterProblem<B::MasterProblem>;

    fn build(&mut self) -> Result<Self::MasterProblem, <Self::MasterProblem as MasterProblem>::Err> {
        self.0.build().map(BoxedMasterProblem::with_master)
    }
}

impl<B> std::ops::Deref for Builder<B> {
    type Target = B;

    fn deref(&self) -> &B {
        &self.0
    }
}

impl<B> std::ops::DerefMut for Builder<B> {
    fn deref_mut(&mut self) -> &mut B {
        &mut self.0
    }
}
Changes to src/master/cpx.rs.
97
98
99
100
101
102
103



104
105
106
107
108
109
110
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113







+
+
+








    /// The minorants for each subproblem in the model.
    minorants: Vec<Vec<Minorant>>,
    /// Optimal multipliers for each subproblem in the model.
    opt_mults: Vec<DVector>,
    /// Optimal aggregated minorant.
    opt_minorant: Minorant,

    /// Maximal bundle size.
    pub max_bundle_size: usize,
}

unsafe impl Send for CplexMaster {}

impl Drop for CplexMaster {
    fn drop(&mut self) {
        unsafe { cpx::freeprob(self.env, &mut self.lp) };
135
136
137
138
139
140
141

142
143
144
145
146
147
148
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152







+







            min2index: vec![],
            index2min: vec![],
            qterm: vec![],
            weight: 1.0,
            minorants: vec![],
            opt_mults: vec![],
            opt_minorant: Minorant::default(),
            max_bundle_size: 50,
        })
    }

    fn num_subproblems(&self) -> usize {
        self.minorants.len()
    }

174
175
176
177
178
179
180








181







182
183
184
185
186
187
188
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







+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+







    }

    fn num_minorants(&self, fidx: usize) -> usize {
        self.minorants[fidx].len()
    }

    fn compress(&mut self) -> Result<()> {
        assert!(self.max_bundle_size >= 2, "Maximal bundle size must be >= 2");
        for i in 0..self.num_subproblems() {
            let n = self.num_minorants(i);
            if n >= self.max_bundle_size {
                // aggregate minorants with smallest coefficients
                let mut inds = (0..n).collect::<Vec<_>>();
                inds.sort_by_key(|&j| -((1e6 * self.opt_mults[i][j]) as isize));
                let inds = inds[self.max_bundle_size - 2..]
        unimplemented!()
                    .iter()
                    .map(|&j| self.min2index[i][j])
                    .collect::<Vec<_>>();
                self.aggregate(i, &inds)?;
            }
        }
        Ok(())
    }

    fn add_minorant(&mut self, fidx: usize, minorant: Minorant) -> Result<usize> {
        debug!("Add minorant");
        debug!("  fidx={} index={}: {}", fidx, self.minorants[fidx].len(), minorant);

        let min_idx = self.minorants[fidx].len();
547
548
549
550
551
552
553
554




555
556
557
558
559
560



561
562








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







-
+
+
+
+





-
+
+
+


+
+
+
+
+
+
+
+
        self.force_update = false;

        Ok(())
    }
}

#[derive(Default)]
pub struct Builder;
pub struct Builder {
    /// The maximal bundle size used in the master problem.
    pub max_bundle_size: usize,
}

impl unconstrained::Builder for Builder {
    type MasterProblem = CplexMaster;

    fn build(&mut self) -> Result<CplexMaster> {
        CplexMaster::new()
        let mut cpx = CplexMaster::new()?;
        cpx.max_bundle_size = self.max_bundle_size;
        Ok(cpx)
    }
}

impl Builder {
    pub fn max_bundle_size(&mut self, s: usize) -> &mut Self {
        assert!(s >= 2, "The maximal bundle size must be >= 2");
        self.max_bundle_size = s;
        self
    }
}
Changes to src/parallel/masterprocess.rs.
207
208
209
210
211
212
213
214

215
216
217
218
219
220
221
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221







-
+







                }
                MasterTask::MoveCenter(alpha, d) => {
                    debug!("master: move center");
                    master.move_center(alpha, &d);
                }
                MasterTask::Compress => {
                    debug!("Compress bundle");
                    warn!("Bundle compression not yet implemented");
                    master.compress()?;
                }
                MasterTask::Solve { center_value } => {
                    debug!("master: solve with center_value {}", center_value);
                    master.solve(center_value)?;
                    let master_response = MasterResponse {
                        nxt_d: master.get_primopt(),
                        nxt_mod: master.get_primoptval(),
Changes to src/parallel/solver.rs.
205
206
207
208
209
210
211



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221



222
223
224
225
226
227
228







+
+
+







-
-
-







    pub terminator: T,

    /// Weighter heuristic.
    pub weighter: W,

    /// The threadpool of the solver.
    pub threadpool: ThreadPool,

    /// The master problem builder.
    pub master_builder: M,

    /// The first order problem.
    problem: P,

    /// The algorithm data.
    data: SolverData,

    /// The master problem builder.
    master_builder: M,

    /// The master problem process.
    master: Option<MasterProcess<P, M::MasterProblem>>,

    /// The channel to receive the evaluation results from subproblems.
    client_tx: Option<ClientSender<P>>,

    /// The channel to receive the evaluation results from subproblems.