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-2020 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 "soplex/spxdefines.h"
28 #include "soplex/cring.h"
29 #include "soplex/spxalloc.h"
30 #include "soplex/spxout.h"
31 #include "soplex/exceptions.h"
32 #include "soplex/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 
80  if(l.updateType == ETA)
81  {
83  ssvec.altValues(), ssvec.altIndexMem(), n, 0, 0, 0);
84  x.setSize(m);
85  //x.forceSetup();
86  x.unSetup();
88  }
89  else
90  {
91  forest.clear();
95  forest.setSize(f);
97  x.setSize(m);
98  x.forceSetup();
99  }
100 
101  usetup = true;
102 
103  solveCount++;
104  solveTime->stop();
105 }
106 
108  SSVectorRational& x,
109  VectorRational& y,
110  const SVectorRational& b,
111  SSVectorRational& rhs)
112 {
113 
114  solveTime->start();
115 
116  int m;
117  int n;
118  int f;
119  int* sidx = ssvec.altIndexMem();
120  int rsize = rhs.size();
121  int* ridx = rhs.altIndexMem();
122 
123  x.clear();
124  y.clear();
125  usetup = true;
126  ssvec = b;
127 
128  if(l.updateType == ETA)
129  {
130  n = ssvec.size();
132  ssvec.get_ptr(), sidx, n, y.get_ptr(),
133  rhs.altValues(), ridx, rsize, 0, 0, 0);
134  x.setSize(m);
135  // x.forceSetup();
136  x.unSetup();
138  }
139  else
140  {
141  forest.clear();
142  n = ssvec.size();
144  ssvec.get_ptr(), sidx, n, y.get_ptr(),
145  rhs.altValues(), ridx, rsize,
147  x.setSize(m);
148  x.forceSetup();
149  forest.setSize(f);
150  forest.forceSetup();
151  }
152 
153  solveCount++;
154  solveTime->stop();
155 }
156 
158  SSVectorRational& x,
159  VectorRational& y,
160  VectorRational& y2,
161  const SVectorRational& b,
162  SSVectorRational& rhs,
163  SSVectorRational& rhs2)
164 {
165 
166  solveTime->start();
167 
168  int m;
169  int n;
170  int f;
171  int* sidx = ssvec.altIndexMem();
172  int rsize = rhs.size();
173  int* ridx = rhs.altIndexMem();
174  int rsize2 = rhs2.size();
175  int* ridx2 = rhs2.altIndexMem();
176 
177  x.clear();
178  y.clear();
179  y2.clear();
180  usetup = true;
181  ssvec = b;
182 
183  if(l.updateType == ETA)
184  {
185  n = ssvec.size();
186  m = vSolveRight4update3(x.altValues(), x.altIndexMem(), ssvec.get_ptr(), sidx, n,
187  y.get_ptr(), rhs.altValues(), ridx, rsize,
188  y2.get_ptr(), rhs2.altValues(), ridx2, rsize2,
189  0, 0, 0);
190  x.setSize(m);
191  // x.forceSetup();
192  x.unSetup();
194  }
195  else
196  {
197  forest.clear();
198  n = ssvec.size();
199  m = vSolveRight4update3(x.altValues(), x.altIndexMem(), ssvec.get_ptr(), sidx, n,
200  y.get_ptr(), rhs.altValues(), ridx, rsize,
201  y2.get_ptr(), rhs2.altValues(), ridx2, rsize2,
203  x.setSize(m);
204  x.forceSetup();
205  forest.setSize(f);
206  forest.forceSetup();
207  }
208 
209  solveCount++;
210  solveTime->stop();
211 }
212 
214 {
215 
216  solveTime->start();
217 
218  vec = b;
219  ///@todo Why is x.clear() here used and not with solveRight() ?
220  x.clear();
222 
223  solveCount++;
224  solveTime->stop();
225 }
226 
228 {
229 
230  solveTime->start();
231 
232  ssvec.assign(b);
233 
234  x.clear();
235  int sz = ssvec.size(); // see .altValues()
236  int n = vSolveLeft(x.altValues(), x.altIndexMem(),
237  ssvec.altValues(), ssvec.altIndexMem(), sz);
238 
239  if(n > 0)
240  {
241  x.setSize(n);
242  x.forceSetup();
243  }
244  else
245  x.unSetup();
246 
247  ssvec.setSize(0);
248  ssvec.forceSetup();
249 
250  solveCount++;
251  solveTime->stop();
252 }
253 
255  SSVectorRational& x,
256  VectorRational& y,
257  const SVectorRational& rhs1,
258  SSVectorRational& rhs2) //const
259 {
260 
261  solveTime->start();
262 
263  int n;
264  Rational* svec = ssvec.altValues();
265  int* sidx = ssvec.altIndexMem();
266  int rn = rhs2.size();
267  int* ridx = rhs2.altIndexMem();
268 
269  x.clear();
270  y.clear();
271  ssvec.assign(rhs1);
272  n = ssvec.size(); // see altValues();
273  n = vSolveLeft2(x.altValues(), x.altIndexMem(), svec, sidx, n,
274  y.get_ptr(), rhs2.altValues(), ridx, rn);
275 
276  x.setSize(n);
277 
278  if(n > 0)
279  x.forceSetup();
280  else
281  x.unSetup();
282 
283  rhs2.setSize(0);
284  rhs2.forceSetup();
285  ssvec.setSize(0);
286  ssvec.forceSetup();
287 
288  solveCount++;
289  solveTime->stop();
290 }
291 
293  SSVectorRational& x,
294  VectorRational& y,
295  VectorRational& z,
296  const SVectorRational& rhs1,
297  SSVectorRational& rhs2,
298  SSVectorRational& rhs3)
299 {
300 
301  solveTime->start();
302 
303  int n;
304  Rational* svec = ssvec.altValues();
305  int* sidx = ssvec.altIndexMem();
306 
307  x.clear();
308  y.clear();
309  z.clear();
310  ssvec.assign(rhs1);
311  n = ssvec.size(); // see altValues();
312  n = vSolveLeft3(x.altValues(), x.altIndexMem(), svec, sidx, n,
313  y.get_ptr(), rhs2.altValues(), rhs2.altIndexMem(), rhs2.size(),
314  z.get_ptr(), rhs3.altValues(), rhs3.altIndexMem(), rhs3.size());
315 
316  x.setSize(n);
317 
318  if(n > 0)
319  x.forceSetup();
320  else
321  x.unSetup();
322 
323  ssvec.setSize(0);
324  ssvec.forceSetup();
325 
326  solveCount++;
327  solveTime->stop();
328 }
329 
331 {
332 
333  if(status() != OK)
334  return 0;
335 
336  if(maxabs < initMaxabs)
337  return 1;
338 
339  return initMaxabs / maxabs;
340 }
341 
342 std::string SLUFactorRational::statistics() const
343 {
344  std::stringstream s;
345  s << "Factorizations : " << std::setw(10) << getFactorCount() << std::endl
346  << " Time spent : " << std::setw(10) << std::fixed << std::setprecision(
347  2) << getFactorTime() << std::endl
348  << "Solves : " << std::setw(10) << getSolveCount() << std::endl
349  << " Time spent : " << std::setw(10) << getSolveTime() << std::endl;
350 
351  return s.str();
352 }
353 
355 {
356 
357  int es = et.size(); // see altValues()
358  update(idx, et.altValues(), et.altIndexMem(), es);
359  et.setSize(0);
360  et.forceSetup();
361 }
362 
364  int idx,
365  const SVectorRational& subst,
366  const SSVectorRational* e)
367 {
368 
369  // BH 2005-08-23: The boolean usetup indicates that an "update vector"
370  // has been set up. I suppose that SSVectorRational forest is this
371  // update vector, which is set up by solveRight4update() and
372  // solve2right4update() in order to optimize the basis update.
373 
374  if(usetup)
375  {
376  if(l.updateType == FOREST_TOMLIN) // FOREST_TOMLIN updates
377  {
378  // BH 2005-08-19: The size of a SSVectorRational is the size of the
379  // index set, i.e. the number of nonzeros which is only
380  // defined if the SSVectorRational is set up. Since
381  // SSVectorRational::altValues() calls unSetup() the size needs to be
382  // stored before the following call.
383  int fsize = forest.size(); // see altValues()
384  forestUpdate(idx, forest.altValues(), fsize, forest.altIndexMem());
385  forest.setSize(0);
386  forest.forceSetup();
387  }
388  else
389  {
390  assert(l.updateType == ETA);
391  changeEta(idx, eta);
392  }
393  }
394  else if(e != 0) // ETA updates
395  {
396  l.updateType = ETA;
397  updateNoClear(idx, e->values(), e->indexMem(), e->size());
398  l.updateType = uptype;
399  }
400  else if(l.updateType == FOREST_TOMLIN) // FOREST_TOMLIN updates
401  {
402  assert(0); // probably this part is never called.
403  // forestUpdate() with the last parameter set to NULL should fail.
404  forest = subst;
406  forestUpdate(idx, forest.altValues(), 0, nullptr);
407  forest.setSize(0);
408  forest.forceSetup();
409  }
410  else // ETA updates
411  {
412  assert(l.updateType == ETA);
413  vec = subst;
414  eta.clear();
416  changeEta(idx, eta);
417  }
418 
419  usetup = false;
420 
421  MSG_DEBUG(std::cout << "DSLUFA01\tupdated\t\tstability = " << stability()
422  << std::endl;)
423 
424  return status();
425 }
426 
428 {
429 
430  rowMemMult = 5; /* factor of minimum Memory * #of nonzeros */
431  colMemMult = 5; /* factor of minimum Memory * #of nonzeros */
432  lMemMult = 1; /* factor of minimum Memory * #of nonzeros */
433 
434  l.firstUpdate = 0;
435  l.firstUnused = 0;
436  thedim = 0;
437 
438  usetup = false;
439  maxabs = 1;
440  initMaxabs = 1;
443  stat = UNLOADED;
444 
445  vec.clear();
446  eta.clear();
447  ssvec.clear();
448  forest.clear();
449 
450  u.col.size = 100;
451  l.startSize = 100;
452 
453  l.rval.reDim(0);
454 
455  if(l.ridx)
456  spx_free(l.ridx);
457 
458  if(l.rbeg)
459  spx_free(l.rbeg);
460 
461  if(l.rorig)
462  spx_free(l.rorig);
463 
464  if(l.rperm)
465  spx_free(l.rperm);
466 
467  if(u.row.idx)
468  spx_free(u.row.idx);
469 
470  if(u.col.idx)
471  spx_free(u.col.idx);
472 
473  if(l.idx)
474  spx_free(l.idx);
475 
476  if(l.start)
477  spx_free(l.start);
478 
479  if(l.row)
480  spx_free(l.row);
481 
482  // G clear() is used in constructor of SLUFactorRational so we have to
483  // G clean up if anything goes wrong here
484  try
485  {
486  u.row.val.reDim(100);
487  spx_alloc(u.row.idx, u.row.val.dim());
488  spx_alloc(u.col.idx, u.col.size);
489 
490  l.val.reDim(100);
491  spx_alloc(l.idx, l.val.dim());
494  }
495  catch(const SPxMemoryException& x)
496  {
497  freeAll();
498  throw x;
499  }
500 }
501 
502 /** assignment used to implement operator=() and copy constructor.
503  * If this is initialised, freeAll() has to be called before.
504  * Class objects from SLUFactorRational are not copied here.
505  */
507 {
508  unsigned int thediminc;
509 
510  // slufactor_rational
511  uptype = old.uptype;
515 
516  // clufactor_rational
517  stat = old.stat;
518  thedim = old.thedim;
519  nzCnt = old.nzCnt;
520  initMaxabs = old.initMaxabs;
521  maxabs = old.maxabs;
522  rowMemMult = old.rowMemMult;
523  colMemMult = old.colMemMult;
524  lMemMult = old.lMemMult;
525  factorCount = old.factorCount;
526  factorTime = old.factorTime;
527  timeLimit = old.timeLimit;
528 
533 
534  memcpy(row.perm, old.row.perm, (unsigned int)thedim * sizeof(*row.perm));
535  memcpy(row.orig, old.row.orig, (unsigned int)thedim * sizeof(*row.orig));
536  memcpy(col.perm, old.col.perm, (unsigned int)thedim * sizeof(*col.perm));
537  memcpy(col.orig, old.col.orig, (unsigned int)thedim * sizeof(*col.orig));
538  diag = old.diag;
539 
540  work = vec.get_ptr();
541 
542  /* setup U
543  */
544  thediminc = (unsigned int)(thedim + 1);
545  u.row.used = old.u.row.used;
546 
548  spx_alloc(u.row.idx, u.row.val.dim());
549  spx_alloc(u.row.start, thediminc);
550  spx_alloc(u.row.len, thediminc);
551  spx_alloc(u.row.max, thediminc);
552 
553  memcpy(u.row.elem, old.u.row.elem, (unsigned int)thedim * sizeof(*u.row.elem));
554  u.row.val = old.u.row.val;
555  memcpy(u.row.idx, old.u.row.idx, (unsigned int)u.row.val.dim() * sizeof(*u.row.idx));
556  memcpy(u.row.start, old.u.row.start, thediminc * sizeof(*u.row.start));
557  memcpy(u.row.len, old.u.row.len, thediminc * sizeof(*u.row.len));
558  memcpy(u.row.max, old.u.row.max, thediminc * sizeof(*u.row.max));
559 
560  // need to make row list ok ?
561  if(thedim > 0 && stat == OK)
562  {
563  u.row.list.idx = old.u.row.list.idx; // .idx neu
564 
565  const Dring* oring = &old.u.row.list;
566  Dring* ring = &u.row.list;
567 
568  while(oring->next != &old.u.row.list)
569  {
570  ring->next = &u.row.elem[oring->next->idx];
571  ring->next->prev = ring;
572  oring = oring->next;
573  ring = ring->next;
574  }
575 
576  ring->next = &u.row.list;
577  ring->next->prev = ring;
578  }
579 
580  u.col.size = old.u.col.size;
581  u.col.used = old.u.col.used;
582 
584  spx_alloc(u.col.idx, u.col.size);
585  spx_alloc(u.col.start, thediminc);
586  spx_alloc(u.col.len, thediminc);
587  spx_alloc(u.col.max, thediminc);
588  u.col.val = old.u.col.val;
589 
590  memcpy(u.col.elem, old.u.col.elem, (unsigned int)thedim * sizeof(*u.col.elem));
591  memcpy(u.col.idx, old.u.col.idx, (unsigned int)u.col.size * sizeof(*u.col.idx));
592  memcpy(u.col.start, old.u.col.start, thediminc * sizeof(*u.col.start));
593  memcpy(u.col.len, old.u.col.len, thediminc * sizeof(*u.col.len));
594  memcpy(u.col.max, old.u.col.max, thediminc * sizeof(*u.col.max));
595 
596  // need to make col list ok
597  if(thedim > 0 && stat == OK)
598  {
599  u.col.list.idx = old.u.col.list.idx; // .idx neu
600 
601  const Dring* oring = &old.u.col.list;
602  Dring* ring = &u.col.list;
603 
604  while(oring->next != &old.u.col.list)
605  {
606  ring->next = &u.col.elem[oring->next->idx];
607  ring->next->prev = ring;
608  oring = oring->next;
609  ring = ring->next;
610  }
611 
612  ring->next = &u.col.list;
613  ring->next->prev = ring;
614  }
615 
616  /* Setup L
617  */
618  l.startSize = old.l.startSize;
619  l.firstUpdate = old.l.firstUpdate;
620  l.firstUnused = old.l.firstUnused;
621  l.updateType = old.l.updateType;
622 
623  l.val = old.l.val;
624  spx_alloc(l.idx, l.val.dim());
627 
628  memcpy(l.idx, old.l.idx, (unsigned int)l.val.dim() * sizeof(*l.idx));
629  memcpy(l.start, old.l.start, (unsigned int)l.startSize * sizeof(*l.start));
630  memcpy(l.row, old.l.row, (unsigned int)l.startSize * sizeof(*l.row));
631 
632  if(l.rval.dim() != 0)
633  {
634  assert(old.l.ridx != 0);
635  assert(old.l.rbeg != 0);
636  assert(old.l.rorig != 0);
637  assert(old.l.rperm != 0);
638 
639  int memsize = l.start[l.firstUpdate];
640 
641  l.rval = old.l.rval;
642  spx_alloc(l.ridx, memsize);
643  spx_alloc(l.rbeg, thediminc);
646 
647  memcpy(l.ridx, old.l.ridx, (unsigned int)memsize * sizeof(*l.ridx));
648  memcpy(l.rbeg, old.l.rbeg, thediminc * sizeof(*l.rbeg));
649  memcpy(l.rorig, old.l.rorig, (unsigned int)thedim * sizeof(*l.rorig));
650  memcpy(l.rperm, old.l.rperm, (unsigned int)thedim * sizeof(*l.rperm));
651  }
652  else
653  {
654  assert(old.l.ridx == 0);
655  assert(old.l.rbeg == 0);
656  assert(old.l.rorig == 0);
657  assert(old.l.rperm == 0);
658 
659  l.rval.reDim(0);
660  l.ridx = 0;
661  l.rbeg = 0;
662  l.rorig = 0;
663  l.rperm = 0;
664  }
665 
666  assert(row.perm != 0);
667  assert(row.orig != 0);
668  assert(col.perm != 0);
669  assert(col.orig != 0);
670 
671  assert(u.row.elem != 0);
672  assert(u.row.idx != 0);
673  assert(u.row.start != 0);
674  assert(u.row.len != 0);
675  assert(u.row.max != 0);
676 
677  assert(u.col.elem != 0);
678  assert(u.col.idx != 0);
679  assert(u.col.start != 0);
680  assert(u.col.len != 0);
681  assert(u.col.max != 0);
682 
683  assert(l.idx != 0);
684  assert(l.start != 0);
685  assert(l.row != 0);
686 
687 }
688 
690 {
691 
692  if(this != &old)
693  {
694  // we don't need to copy them, because they are temporary vectors
695  vec.clear();
696  ssvec.clear();
697 
698  eta = old.eta;
699  forest = old.forest;
700 
701  freeAll();
702 
703  try
704  {
705  assign(old);
706  }
707  catch(const SPxMemoryException& x)
708  {
709  freeAll();
710  throw x;
711  }
712 
713  assert(isConsistent());
714  }
715 
716  return *this;
717 }
718 
721  , vec(1)
722  , ssvec(1)
723  , usetup(false)
725  , eta(1)
726  , forest(1)
727  , minThreshold(0.01)
728  , timerType(Timer::USER_TIME)
729 {
730  row.perm = 0;
731  row.orig = 0;
732  col.perm = 0;
733  col.orig = 0;
734  u.row.elem = 0;
735  u.row.idx = 0;
736  u.row.start = 0;
737  u.row.len = 0;
738  u.row.max = 0;
739  u.col.elem = 0;
740  u.col.idx = 0;
741  u.col.start = 0;
742  u.col.len = 0;
743  u.col.max = 0;
744  l.idx = 0;
745  l.start = 0;
746  l.row = 0;
747  l.ridx = 0;
748  l.rbeg = 0;
749  l.rorig = 0;
750  l.rperm = 0;
751 
752  nzCnt = 0;
753  thedim = 0;
754 
755  try
756  {
763  diag.reDim(thedim);
764 
765  work = vec.get_ptr();
766 
767  u.row.used = 0;
769  u.row.val.reDim(1);
770  spx_alloc(u.row.idx, u.row.val.dim());
771  spx_alloc(u.row.start, thedim + 1);
772  spx_alloc(u.row.len, thedim + 1);
773  spx_alloc(u.row.max, thedim + 1);
774 
775  u.row.list.idx = thedim;
776  u.row.start[thedim] = 0;
777  u.row.max [thedim] = 0;
778  u.row.len [thedim] = 0;
779 
780  u.col.size = 1;
781  u.col.used = 0;
783  spx_alloc(u.col.idx, u.col.size);
784  spx_alloc(u.col.start, thedim + 1);
785  spx_alloc(u.col.len, thedim + 1);
786  spx_alloc(u.col.max, thedim + 1);
787  u.col.val.reDim(0);
788 
789  u.col.list.idx = thedim;
790  u.col.start[thedim] = 0;
791  u.col.max[thedim] = 0;
792  u.col.len[thedim] = 0;
793 
794  l.val.reDim(1);
795  spx_alloc(l.idx, l.val.dim());
796 
797  l.startSize = 1;
798  l.firstUpdate = 0;
799  l.firstUnused = 0;
800 
803  }
804  catch(const SPxMemoryException& x)
805  {
806  freeAll();
807  throw x;
808  }
809 
810  l.rval.reDim(0);
811  l.ridx = 0;
812  l.rbeg = 0;
813  l.rorig = 0;
814  l.rperm = 0;
815 
816  SLUFactorRational::clear(); // clear() is virtual
817 
818  factorCount = 0;
819  timeLimit = -1.0;
820  solveCount = 0;
821 
822  assert(row.perm != 0);
823  assert(row.orig != 0);
824  assert(col.perm != 0);
825  assert(col.orig != 0);
826 
827  assert(u.row.elem != 0);
828  assert(u.row.idx != 0);
829  assert(u.row.start != 0);
830  assert(u.row.len != 0);
831  assert(u.row.max != 0);
832 
833  assert(u.col.elem != 0);
834  assert(u.col.idx != 0);
835  assert(u.col.start != 0);
836  assert(u.col.len != 0);
837  assert(u.col.max != 0);
838 
839  assert(l.idx != 0);
840  assert(l.start != 0);
841  assert(l.row != 0);
842 
844 }
845 
847  : SLinSolverRational(old)
849  , vec(1) // we don't need to copy it, because they are temporary vectors
850  , ssvec(1) // we don't need to copy it, because they are temporary vectors
851  , usetup(old.usetup)
852  , eta(old.eta)
853  , forest(old.forest)
854  , timerType(old.timerType)
855 {
856  row.perm = 0;
857  row.orig = 0;
858  col.perm = 0;
859  col.orig = 0;
860  u.row.elem = 0;
861  u.row.idx = 0;
862  u.row.start = 0;
863  u.row.len = 0;
864  u.row.max = 0;
865  u.col.elem = 0;
866  u.col.idx = 0;
867  u.col.start = 0;
868  u.col.len = 0;
869  u.col.max = 0;
870  l.idx = 0;
871  l.start = 0;
872  l.row = 0;
873  l.ridx = 0;
874  l.rbeg = 0;
875  l.rorig = 0;
876  l.rperm = 0;
877 
878  solveCount = 0;
881 
882  try
883  {
884  assign(old);
885  }
886  catch(const SPxMemoryException& x)
887  {
888  freeAll();
889  throw x;
890  }
891 
893 }
894 
896 {
897 
898  if(row.perm)
899  spx_free(row.perm);
900 
901  if(row.orig)
902  spx_free(row.orig);
903 
904  if(col.perm)
905  spx_free(col.perm);
906 
907  if(col.orig)
908  spx_free(col.orig);
909 
910  if(u.row.elem)
911  spx_free(u.row.elem);
912 
913  if(u.row.idx)
914  spx_free(u.row.idx);
915 
916  if(u.row.start)
917  spx_free(u.row.start);
918 
919  if(u.row.len)
920  spx_free(u.row.len);
921 
922  if(u.row.max)
923  spx_free(u.row.max);
924 
925  if(u.col.elem)
926  spx_free(u.col.elem);
927 
928  if(u.col.idx)
929  spx_free(u.col.idx);
930 
931  if(u.col.start)
932  spx_free(u.col.start);
933 
934  if(u.col.len)
935  spx_free(u.col.len);
936 
937  if(u.col.max)
938  spx_free(u.col.max);
939 
940  if(l.idx)
941  spx_free(l.idx);
942 
943  if(l.start)
944  spx_free(l.start);
945 
946  if(l.row)
947  spx_free(l.row);
948 
949  if(l.ridx)
950  spx_free(l.ridx);
951 
952  if(l.rbeg)
953  spx_free(l.rbeg);
954 
955  if(l.rorig)
956  spx_free(l.rorig);
957 
958  if(l.rperm)
959  spx_free(l.rperm);
960 
963 }
964 
966 {
967  freeAll();
968 }
969 
971 {
972  assert(th < 1);
973 
974  if(10 * th < 1)
975  th *= 10;
976  else if(10 * th < 8)
977  th = (th + 1) / 2;
978  else if(th < 0.999)
979  th = 0.99999;
980 
981  assert(th < 1);
982 
983  return th;
984 }
985 
987 {
988  assert(dm >= 0);
989  assert(matrix != 0);
990 
991  Rational lastStability = stability();
992 
993  initDR(u.row.list);
994  initDR(u.col.list);
995 
996  usetup = false;
997  l.updateType = uptype;
998  l.firstUpdate = 0;
999  l.firstUnused = 0;
1000 
1001  if(dm != thedim)
1002  {
1003  clear();
1004 
1005  thedim = dm;
1006  vec.reDim(thedim);
1007  ssvec.reDim(thedim);
1008  eta.reDim(thedim);
1009  forest.reDim(thedim);
1010  work = vec.get_ptr();
1011 
1016  diag.reDim(thedim);
1017 
1019  spx_realloc(u.row.len, thedim + 1);
1020  spx_realloc(u.row.max, thedim + 1);
1021  spx_realloc(u.row.start, thedim + 1);
1022 
1024  spx_realloc(u.col.len, thedim + 1);
1025  spx_realloc(u.col.max, thedim + 1);
1026  spx_realloc(u.col.start, thedim + 1);
1027 
1029 
1032  }
1033  // the last factorization was reasonably stable, so we decrease the Markowitz threshold (stored in lastThreshold) in
1034  // order favour sparsity
1035  else if(lastStability > 2.0 * minStability)
1036  {
1037  // we reset lastThreshold to its previous value in the sequence minThreshold, betterThreshold(minThreshold),
1038  // betterThreshold(betterThreshold(minThreshold)), ...
1039  Rational last = minThreshold;
1040  Rational better = betterThreshold(last);
1041 
1042  while(better < lastThreshold)
1043  {
1044  last = better;
1045  better = betterThreshold(last);
1046  }
1047 
1048  lastThreshold = last;
1049 
1050  // we reset the minimum stability (which might have been decreased below) to ensure that the increased sparsity
1051  // does not hurt the stability
1052  minStability = 2 * MINSTABILITY;
1053  }
1054 
1055  u.row.list.idx = thedim;
1056  u.row.start[thedim] = 0;
1057  u.row.max[thedim] = 0;
1058  u.row.len[thedim] = 0;
1059 
1060  u.col.list.idx = thedim;
1061  u.col.start[thedim] = 0;
1062  u.col.max[thedim] = 0;
1063  u.col.len[thedim] = 0;
1064 
1065  stat = OK;
1066  factor(matrix, lastThreshold);
1067 
1068  MSG_DEBUG(std::cout << "DSLUFA02 threshold = " << lastThreshold
1069  << "\tstability = " << stability()
1070  << "\tminStability = " << minStability << std::endl;)
1071  MSG_DEBUG(
1072  int i;
1073  FILE* fl = fopen("dump.lp", "w");
1074  std::cout << "DSLUFA03 Basis:\n";
1075  int j = 0;
1076 
1077  for(i = 0; i < dim(); ++i)
1078  j += matrix[i]->size();
1079  for(i = 0; i < dim(); ++i)
1080  {
1081  for(j = 0; j < matrix[i]->size(); ++j)
1082  fprintf(fl, "%8d %8d %s\n",
1083  i + 1, matrix[i]->index(j) + 1, rationalToString(matrix[i]->value(j)).c_str());
1084  }
1085  fclose(fl);
1086  std::cout << "DSLUFA04 LU-Factors:" << std::endl;
1087  dump();
1088 
1089  std::cout << "DSLUFA05 threshold = " << lastThreshold
1090  << "\tstability = " << stability() << std::endl;
1091  )
1092 
1093  assert(isConsistent());
1094  return Status(stat);
1095 }
1096 
1097 
1099 {
1100 #ifdef ENABLE_CONSISTENCY_CHECKS
1102 #else
1103  return true;
1104 #endif
1105 }
1106 
1108 {
1110 }
1111 } // namespace soplex
Real lMemMult
factor of minimum Memory * number of nonzeros
VectorRational val
hold nonzero values
int * start
starting positions in val and idx
int firstUpdate
number of first update L vector
int * ridx
indices of rows of L
VectorRational vec
Temporary vector.
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]...
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!
static Rational betterThreshold(Rational th)
Memory allocation routines.
SSVectorBase< R > & assign(const SVectorBase< S > &rhs)
Assigns only the elements of rhs.
Definition: basevectors.h:855
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:155
VectorRational diag
Array of pivot elements.
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
VectorRational val
hold nonzero values: this is only initialized in the end of the factorization with DEFAULT updates...
void unSetup()
Makes SSVectorBase not setup.
Definition: ssvectorbase.h:127
int getSolveCount() const
number of solves performed
Implementation of Sparse Linear Solver with Rational precision.
VectorRational val
values of L vectors
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:62
int updateType
type of updates to be used.
SSVectorRational ssvec
Temporary semi-sparse vector.
int * altIndexMem()
Returns array indices.
Definition: ssvectorbase.h:312
int vSolveLeft(Rational *vec, int *idx, Rational *rhs, int *ridx, int rn)
UpdateType uptype
the current UpdateType.
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:49
R * altValues()
Returns array values.
Definition: ssvectorbase.h:319
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:485
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:300
#define MSG_DEBUG(x)
Definition: spxdefines.h:141
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
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:604
int * rorig
original row permutation
int solveCount
Number of solves.
SSVectorRational forest
? Update vector set up by solveRight4update() and solve2right4update()
static Timer * createTimer(Timer::TYPE ttype)
create timers and allocate memory for them
Definition: timerfactory.h:44
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:294
virtual ~SLUFactorRational()
destructor.
void reDim(int newdim)
Resets dimension to newdim.
Definition: ssvectorbase.h:570
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:585
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.hpp.
Definition: ssvectorbase.h:100
void spx_realloc(T &p, int n)
Change amount of allocated memory.
Definition: spxalloc.h:80
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:261
void setup_and_assign(SSVectorBase< S > &rhs)
Sets up rhs vector, and assigns it.
Definition: ssvectorbase.h:723
int size() const
Returns the number of nonzeros.
Definition: ssvectorbase.h:200
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
int * idx
hold row indices of nonzeros
int * start
starting positions in val and idx
Dring * elem
Array of ring elements.
void reDim(int newdim, const bool setZero=true)
Resets VectorBase&#39;s dimension to newdim.
Definition: vectorbase.h:532
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 contain all-zeros (keeping the same length)
Definition: vectorbase.h:299
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:163
#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:32
#define MINSTABILITY
SLUFactorRational & operator=(const SLUFactorRational &old)
assignment operator.
Rational maxabs
maximum abs number in L and U
Perm col
column permutation matrices
VectorRational rval
values of rows of L
int * rperm
original row permutation
VectorBase< R > & assign(const SVectorBase< S > &vec)
Assign values of vec.
Definition: basevectors.h:78
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:1858
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:111
void solve2right4update(SSVectorRational &x, VectorRational &y, const SVectorRational &b, SSVectorRational &d)
Solves and .
SLinSolverRational::Status stat
Status indicator.