Scippy

SoPlex

Sequential object-oriented simPlex

slufactor_rational.cpp
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the class library */
4 /* SoPlex --- the Sequential object-oriented simPlex. */
5 /* */
6 /* Copyright (C) 1996-2017 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SoPlex is distributed under the terms of the ZIB Academic Licence. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file slufactor_rational.cpp
17  * @todo SLUFactorRational seems to be partly an wrapper for CLUFactorRational (was C).
18  * This should be properly integrated and demangled.
19  * @todo Does is make sense, to call x.clear() when next x.altValues()
20  * is called.
21  */
22 
23 #include <assert.h>
24 #include <sstream>
25 
26 #include "spxdefines.h"
27 #include "slufactor_rational.h"
28 #include "cring.h"
29 #include "spxalloc.h"
30 #include "spxout.h"
31 #include "exceptions.h"
32 #include "rational.h"
33 
34 #ifdef SOPLEX_DEBUG
35 #include <stdio.h>
36 #endif
37 
38 namespace soplex
39 {
40 #define MINSTABILITY REAL(4e-2)
41 
43 {
44 
45  solveTime->start();
46 
47  vec = b;
49 
50  solveCount++;
51  solveTime->stop();
52 }
53 
55 {
56 
57  solveTime->start();
58 
59  vec.assign(b);
60  x.clear();
62 
63  solveCount++;
64  solveTime->stop();
65 }
66 
68 {
69 
70  solveTime->start();
71 
72  int m;
73  int n;
74  int f;
75 
76  x.clear();
77  ssvec = b;
78  n = ssvec.size();
79  if (l.updateType == ETA)
80  {
82  ssvec.altValues(), ssvec.altIndexMem(), n, 0, 0, 0);
83  x.setSize(m);
84  //x.forceSetup();
85  x.unSetup();
87  }
88  else
89  {
90  forest.clear();
94  forest.setSize(f);
96  x.setSize(m);
97  x.forceSetup();
98  }
99  usetup = true;
100 
101  solveCount++;
102  solveTime->stop();
103 }
104 
106  SSVectorRational& x,
107  VectorRational& y,
108  const SVectorRational& b,
109  SSVectorRational& rhs)
110 {
111 
112  solveTime->start();
113 
114  int m;
115  int n;
116  int f;
117  int* sidx = ssvec.altIndexMem();
118  int rsize = rhs.size();
119  int* ridx = rhs.altIndexMem();
120 
121  x.clear();
122  y.clear();
123  usetup = true;
124  ssvec = b;
125 
126  if (l.updateType == ETA)
127  {
128  n = ssvec.size();
130  ssvec.get_ptr(), sidx, n, y.get_ptr(),
131  rhs.altValues(), ridx, rsize, 0, 0, 0);
132  x.setSize(m);
133  // x.forceSetup();
134  x.unSetup();
136  }
137  else
138  {
139  forest.clear();
140  n = ssvec.size();
142  ssvec.get_ptr(), sidx, n, y.get_ptr(),
143  rhs.altValues(), ridx, rsize,
145  x.setSize(m);
146  x.forceSetup();
147  forest.setSize(f);
148  forest.forceSetup();
149  }
150  solveCount++;
151  solveTime->stop();
152 }
153 
155  SSVectorRational& x,
156  VectorRational& y,
157  VectorRational& y2,
158  const SVectorRational& b,
159  SSVectorRational& rhs,
160  SSVectorRational& rhs2)
161 {
162 
163  solveTime->start();
164 
165  int m;
166  int n;
167  int f;
168  int* sidx = ssvec.altIndexMem();
169  int rsize = rhs.size();
170  int* ridx = rhs.altIndexMem();
171  int rsize2 = rhs2.size();
172  int* ridx2 = rhs2.altIndexMem();
173 
174  x.clear();
175  y.clear();
176  y2.clear();
177  usetup = true;
178  ssvec = b;
179 
180  if (l.updateType == ETA)
181  {
182  n = ssvec.size();
183  m = vSolveRight4update3(x.altValues(), x.altIndexMem(), ssvec.get_ptr(), sidx, n,
184  y.get_ptr(), rhs.altValues(), ridx, rsize,
185  y2.get_ptr(), rhs2.altValues(), ridx2, rsize2,
186  0, 0, 0);
187  x.setSize(m);
188  // x.forceSetup();
189  x.unSetup();
191  }
192  else
193  {
194  forest.clear();
195  n = ssvec.size();
196  m = vSolveRight4update3(x.altValues(), x.altIndexMem(), ssvec.get_ptr(), sidx, n,
197  y.get_ptr(), rhs.altValues(), ridx, rsize,
198  y2.get_ptr(), rhs2.altValues(), ridx2, rsize2,
200  x.setSize(m);
201  x.forceSetup();
202  forest.setSize(f);
203  forest.forceSetup();
204  }
205  solveCount++;
206  solveTime->stop();
207 }
208 
210 {
211 
212  solveTime->start();
213 
214  vec = b;
215  ///@todo Why is x.clear() here used and not with solveRight() ?
216  x.clear();
218 
219  solveCount++;
220  solveTime->stop();
221 }
222 
224 {
225 
226  solveTime->start();
227 
228  ssvec.assign(b);
229 
230  x.clear();
231  int sz = ssvec.size(); // see .altValues()
232  int n = vSolveLeft(x.altValues(), x.altIndexMem(),
233  ssvec.altValues(), ssvec.altIndexMem(), sz);
234 
235  if (n > 0)
236  {
237  x.setSize(n);
238  x.forceSetup();
239  }
240  else
241  x.unSetup();
242 
243  ssvec.setSize(0);
244  ssvec.forceSetup();
245 
246  solveCount++;
247  solveTime->stop();
248 }
249 
251  SSVectorRational& x,
252  VectorRational& y,
253  const SVectorRational& rhs1,
254  SSVectorRational& rhs2) //const
255 {
256 
257  solveTime->start();
258 
259  int n;
260  Rational* svec = ssvec.altValues();
261  int* sidx = ssvec.altIndexMem();
262  int rn = rhs2.size();
263  int* ridx = rhs2.altIndexMem();
264 
265  x.clear();
266  y.clear();
267  ssvec.assign(rhs1);
268  n = ssvec.size(); // see altValues();
269  n = vSolveLeft2(x.altValues(), x.altIndexMem(), svec, sidx, n,
270  y.get_ptr(), rhs2.altValues(), ridx, rn);
271 
272  x.setSize(n);
273 
274  if (n > 0)
275  x.forceSetup();
276  else
277  x.unSetup();
278 
279  rhs2.setSize(0);
280  rhs2.forceSetup();
281  ssvec.setSize(0);
282  ssvec.forceSetup();
283 
284  solveCount++;
285  solveTime->stop();
286 }
287 
289  SSVectorRational& x,
290  VectorRational& y,
291  VectorRational& z,
292  const SVectorRational& rhs1,
293  SSVectorRational& rhs2,
294  SSVectorRational& rhs3)
295 {
296 
297  solveTime->start();
298 
299  int n;
300  Rational* svec = ssvec.altValues();
301  int* sidx = ssvec.altIndexMem();
302 
303  x.clear();
304  y.clear();
305  z.clear();
306  ssvec.assign(rhs1);
307  n = ssvec.size(); // see altValues();
308  n = vSolveLeft3(x.altValues(), x.altIndexMem(), svec, sidx, n,
309  y.get_ptr(), rhs2.altValues(), rhs2.altIndexMem(), rhs2.size(),
310  z.get_ptr(), rhs3.altValues(), rhs3.altIndexMem(), rhs3.size());
311 
312  x.setSize(n);
313 
314  if (n > 0)
315  x.forceSetup();
316  else
317  x.unSetup();
318 
319  ssvec.setSize(0);
320  ssvec.forceSetup();
321 
322  solveCount++;
323  solveTime->stop();
324 }
325 
327 {
328 
329  if (status() != OK)
330  return 0;
331 
332  if (maxabs < initMaxabs)
333  return 1;
334 
335  return initMaxabs / maxabs;
336 }
337 
338 std::string SLUFactorRational::statistics() const
339 {
340  std::stringstream s;
341  s << "Factorizations : " << std::setw(10) << getFactorCount() << std::endl
342  << " Time spent : " << std::setw(10) << std::fixed << std::setprecision(2) << getFactorTime() << std::endl
343  << "Solves : " << std::setw(10) << getSolveCount() << std::endl
344  << " Time spent : " << std::setw(10) << getSolveTime() << std::endl;
345 
346  return s.str();
347 }
348 
350 {
351 
352  int es = et.size(); // see altValues()
353  update(idx, et.altValues(), et.altIndexMem(), es);
354  et.setSize(0);
355  et.forceSetup();
356 }
357 
359  int idx,
360  const SVectorRational& subst,
361  const SSVectorRational* e)
362 {
363 
364  // BH 2005-08-23: The boolean usetup indicates that an "update vector"
365  // has been set up. I suppose that SSVectorRational forest is this
366  // update vector, which is set up by solveRight4update() and
367  // solve2right4update() in order to optimize the basis update.
368 
369  if (usetup)
370  {
371  if (l.updateType == FOREST_TOMLIN) // FOREST_TOMLIN updates
372  {
373  // BH 2005-08-19: The size of a SSVectorRational is the size of the
374  // index set, i.e. the number of nonzeros which is only
375  // defined if the SSVectorRational is set up. Since
376  // SSVectorRational::altValues() calls unSetup() the size needs to be
377  // stored before the following call.
378  int fsize = forest.size(); // see altValues()
379  forestUpdate(idx, forest.altValues(), fsize, forest.altIndexMem());
380  forest.setSize(0);
381  forest.forceSetup();
382  }
383  else
384  {
385  assert(l.updateType == ETA);
386  changeEta(idx, eta);
387  }
388  }
389  else if (e != 0) // ETA updates
390  {
391  l.updateType = ETA;
392  updateNoClear(idx, e->values(), e->indexMem(), e->size());
393  l.updateType = uptype;
394  }
395  else if (l.updateType == FOREST_TOMLIN) // FOREST_TOMLIN updates
396  {
397  assert(0); // probably this part is never called.
398  // forestUpdate() with the last parameter set to NULL should fail.
399  forest = subst;
401  forestUpdate(idx, forest.altValues(), 0, 0);
402  forest.setSize(0);
403  forest.forceSetup();
404  }
405  else // ETA updates
406  {
407  assert(l.updateType == ETA);
408  vec = subst;
409  eta.clear();
411  changeEta(idx, eta);
412  }
413  usetup = false;
414 
415  MSG_DEBUG( std::cout << "DSLUFA01\tupdated\t\tstability = " << stability()
416  << std::endl; )
417 
418  return status();
419 }
420 
422 {
423 
424  rowMemMult = 5; /* factor of minimum Memory * #of nonzeros */
425  colMemMult = 5; /* factor of minimum Memory * #of nonzeros */
426  lMemMult = 1; /* factor of minimum Memory * #of nonzeros */
427 
428  l.firstUpdate = 0;
429  l.firstUnused = 0;
430  thedim = 0;
431 
432  usetup = false;
433  maxabs = 1;
434  initMaxabs = 1;
437  stat = UNLOADED;
438 
439  vec.clear();
440  eta.clear();
441  ssvec.clear();
442  forest.clear();
443 
444  u.col.size = 100;
445  l.startSize = 100;
446 
447  l.rval.reDim(0);
448  if(l.ridx)
449  spx_free(l.ridx);
450  if(l.rbeg)
451  spx_free(l.rbeg);
452  if(l.rorig)
453  spx_free(l.rorig);
454  if(l.rperm)
455  spx_free(l.rperm);
456 
457  if(u.row.idx)
458  spx_free(u.row.idx);
459  if(u.col.idx)
460  spx_free(u.col.idx);
461  if(l.idx)
462  spx_free(l.idx);
463  if(l.start)
464  spx_free(l.start);
465  if(l.row)
466  spx_free(l.row);
467 
468  // G clear() is used in constructor of SLUFactorRational so we have to
469  // G clean up if anything goes wrong here
470  try
471  {
472  u.row.val.reDim(100);
473  spx_alloc(u.row.idx, u.row.val.dim());
474  spx_alloc(u.col.idx, u.col.size);
475 
476  l.val.reDim(100);
477  spx_alloc(l.idx, l.val.dim());
480  }
481  catch(const SPxMemoryException& x)
482  {
483  freeAll();
484  throw x;
485  }
486 }
487 
488 /** assignment used to implement operator=() and copy constructor.
489  * If this is initialised, freeAll() has to be called before.
490  * Class objects from SLUFactorRational are not copied here.
491  */
493 {
494  // slufactor_rational
495  uptype = old.uptype;
499 
500  // clufactor_rational
501  stat = old.stat;
502  thedim = old.thedim;
503  nzCnt = old.nzCnt;
504  initMaxabs = old.initMaxabs;
505  maxabs = old.maxabs;
506  rowMemMult = old.rowMemMult;
507  colMemMult = old.colMemMult;
508  lMemMult = old.lMemMult;
509  factorCount = old.factorCount;
510  factorTime = old.factorTime;
511  timeLimit = old.timeLimit;
512 
517 
518  memcpy(row.perm, old.row.perm, (unsigned int)thedim * sizeof(*row.perm));
519  memcpy(row.orig, old.row.orig, (unsigned int)thedim * sizeof(*row.orig));
520  memcpy(col.perm, old.col.perm, (unsigned int)thedim * sizeof(*col.perm));
521  memcpy(col.orig, old.col.orig, (unsigned int)thedim * sizeof(*col.orig));
522  diag = old.diag;
523 
524  work = vec.get_ptr();
525 
526  /* setup U
527  */
528  u.row.used = old.u.row.used;
529 
531  spx_alloc(u.row.idx, u.row.val.dim());
532  spx_alloc(u.row.start, thedim + 1);
533  spx_alloc(u.row.len, thedim + 1);
534  spx_alloc(u.row.max, thedim + 1);
535 
536  memcpy(u.row.elem, old.u.row.elem, (unsigned int)thedim * sizeof(*u.row.elem));
537  u.row.val = old.u.row.val;
538  memcpy(u.row.idx, old.u.row.idx, (unsigned int)u.row.val.dim() * sizeof(*u.row.idx));
539  memcpy(u.row.start, old.u.row.start, (unsigned int)(thedim + 1) * sizeof(*u.row.start));
540  memcpy(u.row.len, old.u.row.len, (unsigned int)(thedim + 1) * sizeof(*u.row.len));
541  memcpy(u.row.max, old.u.row.max, (unsigned int)(thedim + 1) * sizeof(*u.row.max));
542 
543  // need to make row list ok ?
544  if (thedim > 0 && stat == OK)
545  {
546  u.row.list.idx = old.u.row.list.idx; // .idx neu
547 
548  const Dring* oring = &old.u.row.list;
549  Dring* ring = &u.row.list;
550 
551  while(oring->next != &old.u.row.list)
552  {
553  ring->next = &u.row.elem[oring->next->idx];
554  ring->next->prev = ring;
555  oring = oring->next;
556  ring = ring->next;
557  }
558  ring->next = &u.row.list;
559  ring->next->prev = ring;
560  }
561 
562  u.col.size = old.u.col.size;
563  u.col.used = old.u.col.used;
564 
566  spx_alloc(u.col.idx, u.col.size);
567  spx_alloc(u.col.start, thedim + 1);
568  spx_alloc(u.col.len, thedim + 1);
569  spx_alloc(u.col.max, thedim + 1);
570  u.col.val = old.u.col.val;
571 
572  memcpy(u.col.elem, old.u.col.elem, (unsigned int)thedim * sizeof(*u.col.elem));
573  memcpy(u.col.idx, old.u.col.idx, (unsigned int)u.col.size * sizeof(*u.col.idx));
574  memcpy(u.col.start, old.u.col.start, (unsigned int)(thedim + 1) * sizeof(*u.col.start));
575  memcpy(u.col.len, old.u.col.len, (unsigned int)(thedim + 1) * sizeof(*u.col.len));
576  memcpy(u.col.max, old.u.col.max, (unsigned int)(thedim + 1) * sizeof(*u.col.max));
577 
578  // need to make col list ok
579  if (thedim > 0 && stat == OK)
580  {
581  u.col.list.idx = old.u.col.list.idx; // .idx neu
582 
583  const Dring* oring = &old.u.col.list;
584  Dring* ring = &u.col.list;
585 
586  while(oring->next != &old.u.col.list)
587  {
588  ring->next = &u.col.elem[oring->next->idx];
589  ring->next->prev = ring;
590  oring = oring->next;
591  ring = ring->next;
592  }
593  ring->next = &u.col.list;
594  ring->next->prev = ring;
595  }
596 
597  /* Setup L
598  */
599  l.startSize = old.l.startSize;
600  l.firstUpdate = old.l.firstUpdate;
601  l.firstUnused = old.l.firstUnused;
602  l.updateType = old.l.updateType;
603 
604  l.val = old.l.val;
605  spx_alloc(l.idx, l.val.dim());
608 
609  memcpy(l.idx, old.l.idx, (unsigned int)l.val.dim() * sizeof(*l.idx));
610  memcpy(l.start, old.l.start, (unsigned int)l.startSize * sizeof(*l.start));
611  memcpy(l.row, old.l.row, (unsigned int)l.startSize * sizeof(*l.row));
612 
613  if (l.rval.dim() != 0)
614  {
615  assert(old.l.ridx != 0);
616  assert(old.l.rbeg != 0);
617  assert(old.l.rorig != 0);
618  assert(old.l.rperm != 0);
619 
620  int memsize = l.start[l.firstUpdate];
621 
622  l.rval= old.l.rval;
623  spx_alloc(l.ridx, memsize);
624  spx_alloc(l.rbeg, thedim + 1);
627 
628  memcpy(l.ridx, old.l.ridx, (unsigned int)memsize * sizeof(*l.ridx));
629  memcpy(l.rbeg, old.l.rbeg, (unsigned int)(thedim + 1) * sizeof(*l.rbeg));
630  memcpy(l.rorig, old.l.rorig, (unsigned int)thedim * sizeof(*l.rorig));
631  memcpy(l.rperm, old.l.rperm, (unsigned int)thedim * sizeof(*l.rperm));
632  }
633  else
634  {
635  assert(old.l.ridx == 0);
636  assert(old.l.rbeg == 0);
637  assert(old.l.rorig == 0);
638  assert(old.l.rperm == 0);
639 
640  l.rval.reDim(0);
641  l.ridx = 0;
642  l.rbeg = 0;
643  l.rorig = 0;
644  l.rperm = 0;
645  }
646 
647  assert(row.perm != 0);
648  assert(row.orig != 0);
649  assert(col.perm != 0);
650  assert(col.orig != 0);
651 
652  assert(u.row.elem != 0);
653  assert(u.row.idx != 0);
654  assert(u.row.start != 0);
655  assert(u.row.len != 0);
656  assert(u.row.max != 0);
657 
658  assert(u.col.elem != 0);
659  assert(u.col.idx != 0);
660  assert(u.col.start != 0);
661  assert(u.col.len != 0);
662  assert(u.col.max != 0);
663 
664  assert(l.idx != 0);
665  assert(l.start != 0);
666  assert(l.row != 0);
667 
668 }
669 
671 {
672 
673  if (this != &old)
674  {
675  // we don't need to copy them, because they are temporary vectors
676  vec.clear();
677  ssvec.clear();
678 
679  eta = old.eta;
680  forest = old.forest;
681 
682  freeAll();
683  try
684  {
685  assign(old);
686  }
687  catch(const SPxMemoryException& x)
688  {
689  freeAll();
690  throw x;
691  }
692  assert(isConsistent());
693  }
694  return *this;
695 }
696 
699  , vec (1)
700  , ssvec (1)
701  , usetup (false)
703  , eta (1)
704  , forest (1)
705  , minThreshold (0.01)
706  , timerType(Timer::USER_TIME)
707 {
708  row.perm = 0;
709  row.orig = 0;
710  col.perm = 0;
711  col.orig = 0;
712  u.row.elem = 0;
713  u.row.idx = 0;
714  u.row.start = 0;
715  u.row.len = 0;
716  u.row.max = 0;
717  u.col.elem = 0;
718  u.col.idx = 0;
719  u.col.start = 0;
720  u.col.len = 0;
721  u.col.max = 0;
722  l.idx = 0;
723  l.start = 0;
724  l.row = 0;
725  l.ridx = 0;
726  l.rbeg = 0;
727  l.rorig = 0;
728  l.rperm = 0;
729 
730  nzCnt = 0;
731  thedim = 0;
732  try
733  {
740  diag.reDim(thedim);
741 
742  work = vec.get_ptr();
743 
744  u.row.used = 0;
746  u.row.val.reDim(1);
747  spx_alloc(u.row.idx, u.row.val.dim());
748  spx_alloc(u.row.start, thedim + 1);
749  spx_alloc(u.row.len, thedim + 1);
750  spx_alloc(u.row.max, thedim + 1);
751 
752  u.row.list.idx = thedim;
753  u.row.start[thedim] = 0;
754  u.row.max [thedim] = 0;
755  u.row.len [thedim] = 0;
756 
757  u.col.size = 1;
758  u.col.used = 0;
760  spx_alloc(u.col.idx, u.col.size);
761  spx_alloc(u.col.start, thedim + 1);
762  spx_alloc(u.col.len, thedim + 1);
763  spx_alloc(u.col.max, thedim + 1);
764  u.col.val.reDim(0);
765 
766  u.col.list.idx = thedim;
767  u.col.start[thedim] = 0;
768  u.col.max[thedim] = 0;
769  u.col.len[thedim] = 0;
770 
771  l.val.reDim(1);
772  spx_alloc(l.idx, l.val.dim());
773 
774  l.startSize = 1;
775  l.firstUpdate = 0;
776  l.firstUnused = 0;
777 
780  }
781  catch(const SPxMemoryException& x)
782  {
783  freeAll();
784  throw x;
785  }
786 
787  l.rval.reDim(0);
788  l.ridx = 0;
789  l.rbeg = 0;
790  l.rorig = 0;
791  l.rperm = 0;
792 
793  SLUFactorRational::clear(); // clear() is virtual
794 
795  factorCount = 0;
796  timeLimit = -1.0;
797  solveCount = 0;
798 
799  assert(row.perm != 0);
800  assert(row.orig != 0);
801  assert(col.perm != 0);
802  assert(col.orig != 0);
803 
804  assert(u.row.elem != 0);
805  assert(u.row.idx != 0);
806  assert(u.row.start != 0);
807  assert(u.row.len != 0);
808  assert(u.row.max != 0);
809 
810  assert(u.col.elem != 0);
811  assert(u.col.idx != 0);
812  assert(u.col.start != 0);
813  assert(u.col.len != 0);
814  assert(u.col.max != 0);
815 
816  assert(l.idx != 0);
817  assert(l.start != 0);
818  assert(l.row != 0);
819 
821 }
822 
824  : SLinSolverRational( old )
826  , vec(1) // we don't need to copy it, because they are temporary vectors
827  , ssvec(1) // we don't need to copy it, because they are temporary vectors
828  , usetup(old.usetup)
829  , eta (old.eta)
830  , forest(old.forest)
831  , timerType(old.timerType)
832 {
833  row.perm = 0;
834  row.orig = 0;
835  col.perm = 0;
836  col.orig = 0;
837  u.row.elem = 0;
838  u.row.idx = 0;
839  u.row.start = 0;
840  u.row.len = 0;
841  u.row.max = 0;
842  u.col.elem = 0;
843  u.col.idx = 0;
844  u.col.start = 0;
845  u.col.len = 0;
846  u.col.max = 0;
847  l.idx = 0;
848  l.start = 0;
849  l.row = 0;
850  l.ridx = 0;
851  l.rbeg = 0;
852  l.rorig = 0;
853  l.rperm = 0;
854 
855  solveCount = 0;
858 
859  try
860  {
861  assign(old);
862  }
863  catch(const SPxMemoryException& x)
864  {
865  freeAll();
866  throw x;
867  }
869 }
870 
872 {
873 
874  if(row.perm) spx_free(row.perm);
875  if(row.orig) spx_free(row.orig);
876  if(col.perm) spx_free(col.perm);
877  if(col.orig) spx_free(col.orig);
878  if(u.row.elem) spx_free(u.row.elem);
879  u.row.val.reDim(0);
880  if(u.row.idx) spx_free(u.row.idx);
881  if(u.row.start) spx_free(u.row.start);
882  if(u.row.len) spx_free(u.row.len);
883  if(u.row.max) spx_free(u.row.max);
884  if(u.col.elem) spx_free(u.col.elem);
885  if(u.col.idx) spx_free(u.col.idx);
886  if(u.col.start) spx_free(u.col.start);
887  if(u.col.len) spx_free(u.col.len);
888  if(u.col.max) spx_free(u.col.max);
889  if(l.idx) spx_free(l.idx);
890  if(l.start) spx_free(l.start);
891  if(l.row) spx_free(l.row);
892 
893  diag.reDim(0);
894  u.col.val.reDim(0);
895  l.val.reDim(0);
896 
897  l.rval.reDim(0);
898  if(l.ridx) spx_free(l.ridx);
899  if(l.rbeg) spx_free(l.rbeg);
900  if(l.rorig) spx_free(l.rorig);
901  if(l.rperm) spx_free(l.rperm);
902 
905 }
906 
908 {
909  freeAll();
910 }
911 
913 {
914  assert(th < 1);
915 
916  if ( 10 * th < 1 )
917  th *= 10;
918  else if ( 10 * th < 8 )
919  th = (th + 1) / 2;
920  else if ( th < 0.999 )
921  th = 0.99999;
922 
923  assert(th < 1);
924 
925  return th;
926 }
927 
929 {
930  assert(dm >= 0);
931  assert(matrix != 0);
932 
933  Rational lastStability = stability();
934 
935  initDR(u.row.list);
936  initDR(u.col.list);
937 
938  usetup = false;
939  l.updateType = uptype;
940  l.firstUpdate = 0;
941  l.firstUnused = 0;
942 
943  if (dm != thedim)
944  {
945  clear();
946 
947  thedim = dm;
948  vec.reDim(thedim);
949  ssvec.reDim(thedim);
950  eta.reDim(thedim);
952  work = vec.get_ptr();
953 
958  diag.reDim(thedim);
959 
961  spx_realloc(u.row.len, thedim + 1);
962  spx_realloc(u.row.max, thedim + 1);
963  spx_realloc(u.row.start, thedim + 1);
964 
966  spx_realloc(u.col.len, thedim + 1);
967  spx_realloc(u.col.max, thedim + 1);
968  spx_realloc(u.col.start, thedim + 1);
969 
971 
974  }
975  // the last factorization was reasonably stable, so we decrease the Markowitz threshold (stored in lastThreshold) in
976  // order favour sparsity
977  else if (lastStability > 2.0 * minStability)
978  {
979  // we reset lastThreshold to its previous value in the sequence minThreshold, betterThreshold(minThreshold),
980  // betterThreshold(betterThreshold(minThreshold)), ...
981  Rational last = minThreshold;
982  Rational better = betterThreshold(last);
983  while (better < lastThreshold)
984  {
985  last = better;
986  better = betterThreshold(last);
987  }
988  lastThreshold = last;
989 
990  // we reset the minimum stability (which might have been decreased below) to ensure that the increased sparsity
991  // does not hurt the stability
993  }
994 
995  u.row.list.idx = thedim;
996  u.row.start[thedim] = 0;
997  u.row.max[thedim] = 0;
998  u.row.len[thedim] = 0;
999 
1000  u.col.list.idx = thedim;
1001  u.col.start[thedim] = 0;
1002  u.col.max[thedim] = 0;
1003  u.col.len[thedim] = 0;
1004 
1005  stat = OK;
1006  factor(matrix, lastThreshold);
1007 
1008  MSG_DEBUG( std::cout << "DSLUFA02 threshold = " << lastThreshold
1009  << "\tstability = " << stability()
1010  << "\tminStability = " << minStability << std::endl; )
1011  MSG_DEBUG(
1012  int i;
1013  FILE* fl = fopen("dump.lp", "w");
1014  std::cout << "DSLUFA03 Basis:\n";
1015  int j = 0;
1016  for (i = 0; i < dim(); ++i)
1017  j += matrix[i]->size();
1018  for (i = 0; i < dim(); ++i)
1019  {
1020  for (j = 0; j < matrix[i]->size(); ++j)
1021  fprintf(fl, "%8d %8d %s\n",
1022  i + 1, matrix[i]->index(j) + 1, rationalToString(matrix[i]->value(j)).c_str());
1023  }
1024  fclose(fl);
1025  std::cout << "DSLUFA04 LU-Factors:" << std::endl;
1026  dump();
1027 
1028  std::cout << "DSLUFA05 threshold = " << lastThreshold
1029  << "\tstability = " << stability() << std::endl;
1030  )
1031 
1032  assert(isConsistent());
1033  return Status(stat);
1034 }
1035 
1036 
1038 {
1039 #ifdef ENABLE_CONSISTENCY_CHECKS
1041 #else
1042  return true;
1043 #endif
1044 }
1045 
1047 {
1049 }
1050 } // namespace soplex
Real lMemMult
factor of minimum Memory * number of nonzeros
int * start
starting positions in val and idx
int firstUpdate
number of first update L vector
int * ridx
indices of rows of L
int used
used entries of array idx
int * max
maximum available nonzeros per colunn: start[i] + max[i] == start[elem[i].next->idx] len[i] <= max[i]...
void reDim(int newdim, const bool setZero=true)
Resets DVectorBase&#39;s dimension to newdim.
Definition: dvectorbase.h:249
No matrix has yet been loaded.
Implementation of Sparse Linear Solver with Rational precision.This class implements a SLinSolverRati...
Rational * work
Working array: must always be left as 0!
Memory allocation routines.
SSVectorBase< R > & assign(const SVectorBase< S > &rhs)
Assigns only the elements of rhs.
Definition: basevectors.h:882
int * max
maximum available nonzeros per row: start[i] + max[i] == start[elem[i].next->idx] len[i] <= max[i]...
Dring list
Double linked ringlist of vector indices in the order they appear in the column file.
Real colMemMult
factor of minimum Memory * number of nonzeros
int firstUnused
number of first unused L vector
struct soplex::CLUFactorRational::U::Col col
int size() const
Number of used indices.
Definition: svectorbase.h:152
void changeEta(int idx, SSVectorRational &eta)
Exception classes for SoPlex.
int thedim
dimension of factorized matrix
int getFactorCount() const
number of factorizations performed
int * row
column indices of L vectors
DVectorRational diag
Array of pivot elements.
void unSetup()
Makes SSVectorBase not setup.
Definition: ssvectorbase.h:126
int getSolveCount() const
number of solves performed
Implementation of Sparse Linear Solver with Rational precision.
void update(int p_col, Rational *p_work, const int *p_idx, int num)
int used
used entries of arrays idx and val
void factor(const SVectorRational **vec, const Rational &threshold)
pivoting threshold
SLUFactorRational()
default constructor.
Real timeLimit
Time limit on factorization or solves.
Wrapper for GMP type mpq_class.We wrap mpq_class so that we can replace it by a double type if GMP is...
Definition: rational.h:45
int updateType
type of updates to be used.
SSVectorRational ssvec
Temporary semi-sparse vector.
int * altIndexMem()
Returns array indices.
Definition: ssvectorbase.h:311
int vSolveLeft(Rational *vec, int *idx, Rational *rhs, int *ridx, int rn)
UpdateType uptype
the current UpdateType.
DVectorRational val
hold nonzero values: this is only initialized in the end of the factorization with DEFAULT updates...
void assign(const SLUFactorRational &old)
used to implement the assignment operator
Rational initMaxabs
maximum abs number in initail Matrix
Wrapper for different output streams and verbosity levels.
void solveRight(Rational *vec, Rational *rhs)
Exception class for out of memory exceptions.This class is derived from the SoPlex exception base cla...
Definition: exceptions.h:70
virtual void start()=0
start timer, resume accounting user, system and real time.
virtual Real stop()=0
stop timer, return accounted user time.
void spx_alloc(T &p, int n=1)
Allocate memory.
Definition: spxalloc.h:48
R * altValues()
Returns array values.
Definition: ssvectorbase.h:318
Sparse Linear Solver virtual base class with Rational precision.Class SLinSolverRational provides a c...
Rational minStability
minimum stability to achieve by setting threshold.
SLinSolverRational::Status Status
for convenience
int * start
starting positions in val and idx
R * get_ptr()
Conversion to C-style pointer.
Definition: vectorbase.h:444
Rational minThreshold
minimum threshold to use.
int vSolveRight4update(Rational *vec, int *idx, Rational *rhs, int *ridx, int rn, Rational *forest, int *forestNum, int *forestIdx)
Real getSolveTime() const
time spent in solves
const R * values() const
Returns array values.
Definition: ssvectorbase.h:299
#define MSG_DEBUG(x)
Definition: spxdefines.h:132
int vSolveLeft2(Rational *vec, int *idx, Rational *rhs, int *ridx, int rn, Rational *vec2, Rational *rhs2, int *ridx2, int rn2)
Real rowMemMult
factor of minimum Memory * number of nonzeros
void solveLeft(Rational *vec, Rational *rhs)
Wrapper for GMP types.
Rational lastThreshold
pivoting threshold of last factorization
DVectorRational val
values of L vectors
void solveRight(VectorRational &x, const VectorRational &b)
Solves .
Dring list
Double linked ringlist of vector indices in the order they appear in the row file.
void solveRight4update(SSVectorRational &x, const SVectorRational &b)
Solves .
Perm row
row permutation matrices
void clear()
Clears vector.
Definition: ssvectorbase.h:600
int * rorig
original row permutation
int solveCount
Number of solves.
SSVectorRational forest
? Update vector set up by solveRight4update() and solve2right4update()
DVectorRational rval
values of rows of L
static Timer * createTimer(Timer::TYPE ttype)
create timers and allocate memory for them
Definition: timerfactory.h:43
Timer * factorTime
Time spent in factorizations.
Status load(const SVectorRational *vec[], int dim)
bool isConsistent() const
consistency check.
const int * indexMem() const
Returns array indices.
Definition: ssvectorbase.h:293
virtual ~SLUFactorRational()
destructor.
void reDim(int newdim)
Resets dimension to newdim.
Definition: ssvectorbase.h:566
bool usetup
TRUE iff update vector has been setup.
Debugging, floating point type and parameter definitions.
void setSize(int n)
Sets number of nonzeros (thereby unSetup SSVectorBase).
Definition: ssvectorbase.h:581
void dump() const
prints the LU factorization to stdout.
int * idx
array of size val.dim() storing indices of L vectors
R * get_ptr()
Only used in slufactor.cpp.
Definition: ssvectorbase.h:99
void spx_realloc(T &p, int n)
Change amount of allocated memory.
Definition: spxalloc.h:79
Real getFactorTime() const
time spent in factorizations
Status change(int idx, const SVectorRational &subst, const SSVectorRational *eta=0)
int dim() const
Dimension of vector.
Definition: vectorbase.h:215
void setup_and_assign(SSVectorBase< S > &rhs)
Sets up rhs vector, and assigns it.
Definition: ssvectorbase.h:718
int size() const
Returns the number of nonzeros.
Definition: ssvectorbase.h:199
Implementation of sparse LU factorization with Rational precision.This class implements a sparse LU f...
Everything should be within this namespace.
struct soplex::CLUFactorRational::U::Row row
int * perm
perm[i] permuted index from i
Timer * solveTime
Time spent in solves.
int * len
used nonzeros per column vector
int * len
used nonzeros per row vectors
std::string statistics() const
DVectorRational val
hold nonzero values
int * idx
hold row indices of nonzeros
int * start
starting positions in val and idx
Dring * elem
Array of ring elements.
int vSolveLeft3(Rational *vec, int *idx, Rational *rhs, int *ridx, int rn, Rational *vec2, Rational *rhs2, int *ridx2, int rn2, Rational *vec3, Rational *rhs3, int *ridx3, int rn3)
int factorCount
Number of factorizations.
int startSize
size of array start
void clear()
Set vector to 0.
Definition: vectorbase.h:260
void forestUpdate(int col, Rational *work, int num, int *nonz)
Performs the Forrest-Tomlin update of the LU factorization.
void forceSetup()
Forces setup status.
Definition: ssvectorbase.h:162
#define initDR(ring)
Definition: cring.h:23
void solve3right4update(SSVectorRational &x, VectorRational &y, VectorRational &z, const SVectorRational &b, SSVectorRational &d, SSVectorRational &e)
Solves , and .
int vSolveRight4update2(Rational *vec, int *idx, Rational *rhs, int *ridx, int rn, Rational *vec2, Rational *rhs2, int *ridx2, int rn2, Rational *forest, int *forestNum, int *forestIdx)
#define MAXUPDATES
maximum nr. of factorization updates allowed before refactorization.
Definition: slufactor.h:33
#define MINSTABILITY
SLUFactorRational & operator=(const SLUFactorRational &old)
assignment operator.
Rational maxabs
maximum abs number in L and U
Perm col
column permutation matrices
int * rperm
original row permutation
VectorBase< R > & assign(const SVectorBase< S > &vec)
Assign values of vec.
Definition: basevectors.h:80
void updateNoClear(int p_col, const Rational *p_work, const int *p_idx, int num)
int * rbeg
start of rows in rval and ridx
std::string rationalToString(const Rational &r, const int precision)
convert rational number to string
Definition: rational.cpp:3452
Dring * elem
Array of ring elements.
int * idx
array of length val.dim() to hold column indices of nonzeros in val
void solveLeft(VectorRational &x, const VectorRational &b)
Solves .
Status
status flags of the SLinSolverRational class.
Wrapper for the system time query methods.
Definition: timer.h:76
int * orig
orig[p] original index from p
int vSolveRight4update3(Rational *vec, int *idx, Rational *rhs, int *ridx, int rn, Rational *vec2, Rational *rhs2, int *ridx2, int rn2, Rational *vec3, Rational *rhs3, int *ridx3, int rn3, Rational *forest, int *forestNum, int *forestIdx)
int nzCnt
number of nonzeros in U
void spx_free(T &p)
Release memory.
Definition: spxalloc.h:109
static Real betterThreshold(Real th)
Definition: slufactor.cpp:1253
void solve2right4update(SSVectorRational &x, VectorRational &y, const SVectorRational &b, SSVectorRational &d)
Solves and .
DVectorRational vec
Temporary vector.
SLinSolverRational::Status stat
Status indicator.