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-2019 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, 0);
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  // slufactor_rational
509  uptype = old.uptype;
513 
514  // clufactor_rational
515  stat = old.stat;
516  thedim = old.thedim;
517  nzCnt = old.nzCnt;
518  initMaxabs = old.initMaxabs;
519  maxabs = old.maxabs;
520  rowMemMult = old.rowMemMult;
521  colMemMult = old.colMemMult;
522  lMemMult = old.lMemMult;
523  factorCount = old.factorCount;
524  factorTime = old.factorTime;
525  timeLimit = old.timeLimit;
526 
531 
532  memcpy(row.perm, old.row.perm, (unsigned int)thedim * sizeof(*row.perm));
533  memcpy(row.orig, old.row.orig, (unsigned int)thedim * sizeof(*row.orig));
534  memcpy(col.perm, old.col.perm, (unsigned int)thedim * sizeof(*col.perm));
535  memcpy(col.orig, old.col.orig, (unsigned int)thedim * sizeof(*col.orig));
536  diag = old.diag;
537 
538  work = vec.get_ptr();
539 
540  /* setup U
541  */
542  u.row.used = old.u.row.used;
543 
545  spx_alloc(u.row.idx, u.row.val.dim());
546  spx_alloc(u.row.start, thedim + 1);
547  spx_alloc(u.row.len, thedim + 1);
548  spx_alloc(u.row.max, thedim + 1);
549 
550  memcpy(u.row.elem, old.u.row.elem, (unsigned int)thedim * sizeof(*u.row.elem));
551  u.row.val = old.u.row.val;
552  memcpy(u.row.idx, old.u.row.idx, (unsigned int)u.row.val.dim() * sizeof(*u.row.idx));
553  memcpy(u.row.start, old.u.row.start, (unsigned int)(thedim + 1) * sizeof(*u.row.start));
554  memcpy(u.row.len, old.u.row.len, (unsigned int)(thedim + 1) * sizeof(*u.row.len));
555  memcpy(u.row.max, old.u.row.max, (unsigned int)(thedim + 1) * sizeof(*u.row.max));
556 
557  // need to make row list ok ?
558  if(thedim > 0 && stat == OK)
559  {
560  u.row.list.idx = old.u.row.list.idx; // .idx neu
561 
562  const Dring* oring = &old.u.row.list;
563  Dring* ring = &u.row.list;
564 
565  while(oring->next != &old.u.row.list)
566  {
567  ring->next = &u.row.elem[oring->next->idx];
568  ring->next->prev = ring;
569  oring = oring->next;
570  ring = ring->next;
571  }
572 
573  ring->next = &u.row.list;
574  ring->next->prev = ring;
575  }
576 
577  u.col.size = old.u.col.size;
578  u.col.used = old.u.col.used;
579 
581  spx_alloc(u.col.idx, u.col.size);
582  spx_alloc(u.col.start, thedim + 1);
583  spx_alloc(u.col.len, thedim + 1);
584  spx_alloc(u.col.max, thedim + 1);
585  u.col.val = old.u.col.val;
586 
587  memcpy(u.col.elem, old.u.col.elem, (unsigned int)thedim * sizeof(*u.col.elem));
588  memcpy(u.col.idx, old.u.col.idx, (unsigned int)u.col.size * sizeof(*u.col.idx));
589  memcpy(u.col.start, old.u.col.start, (unsigned int)(thedim + 1) * sizeof(*u.col.start));
590  memcpy(u.col.len, old.u.col.len, (unsigned int)(thedim + 1) * sizeof(*u.col.len));
591  memcpy(u.col.max, old.u.col.max, (unsigned int)(thedim + 1) * sizeof(*u.col.max));
592 
593  // need to make col list ok
594  if(thedim > 0 && stat == OK)
595  {
596  u.col.list.idx = old.u.col.list.idx; // .idx neu
597 
598  const Dring* oring = &old.u.col.list;
599  Dring* ring = &u.col.list;
600 
601  while(oring->next != &old.u.col.list)
602  {
603  ring->next = &u.col.elem[oring->next->idx];
604  ring->next->prev = ring;
605  oring = oring->next;
606  ring = ring->next;
607  }
608 
609  ring->next = &u.col.list;
610  ring->next->prev = ring;
611  }
612 
613  /* Setup L
614  */
615  l.startSize = old.l.startSize;
616  l.firstUpdate = old.l.firstUpdate;
617  l.firstUnused = old.l.firstUnused;
618  l.updateType = old.l.updateType;
619 
620  l.val = old.l.val;
621  spx_alloc(l.idx, l.val.dim());
624 
625  memcpy(l.idx, old.l.idx, (unsigned int)l.val.dim() * sizeof(*l.idx));
626  memcpy(l.start, old.l.start, (unsigned int)l.startSize * sizeof(*l.start));
627  memcpy(l.row, old.l.row, (unsigned int)l.startSize * sizeof(*l.row));
628 
629  if(l.rval.dim() != 0)
630  {
631  assert(old.l.ridx != 0);
632  assert(old.l.rbeg != 0);
633  assert(old.l.rorig != 0);
634  assert(old.l.rperm != 0);
635 
636  int memsize = l.start[l.firstUpdate];
637 
638  l.rval = old.l.rval;
639  spx_alloc(l.ridx, memsize);
640  spx_alloc(l.rbeg, thedim + 1);
643 
644  memcpy(l.ridx, old.l.ridx, (unsigned int)memsize * sizeof(*l.ridx));
645  memcpy(l.rbeg, old.l.rbeg, (unsigned int)(thedim + 1) * sizeof(*l.rbeg));
646  memcpy(l.rorig, old.l.rorig, (unsigned int)thedim * sizeof(*l.rorig));
647  memcpy(l.rperm, old.l.rperm, (unsigned int)thedim * sizeof(*l.rperm));
648  }
649  else
650  {
651  assert(old.l.ridx == 0);
652  assert(old.l.rbeg == 0);
653  assert(old.l.rorig == 0);
654  assert(old.l.rperm == 0);
655 
656  l.rval.reDim(0);
657  l.ridx = 0;
658  l.rbeg = 0;
659  l.rorig = 0;
660  l.rperm = 0;
661  }
662 
663  assert(row.perm != 0);
664  assert(row.orig != 0);
665  assert(col.perm != 0);
666  assert(col.orig != 0);
667 
668  assert(u.row.elem != 0);
669  assert(u.row.idx != 0);
670  assert(u.row.start != 0);
671  assert(u.row.len != 0);
672  assert(u.row.max != 0);
673 
674  assert(u.col.elem != 0);
675  assert(u.col.idx != 0);
676  assert(u.col.start != 0);
677  assert(u.col.len != 0);
678  assert(u.col.max != 0);
679 
680  assert(l.idx != 0);
681  assert(l.start != 0);
682  assert(l.row != 0);
683 
684 }
685 
687 {
688 
689  if(this != &old)
690  {
691  // we don't need to copy them, because they are temporary vectors
692  vec.clear();
693  ssvec.clear();
694 
695  eta = old.eta;
696  forest = old.forest;
697 
698  freeAll();
699 
700  try
701  {
702  assign(old);
703  }
704  catch(const SPxMemoryException& x)
705  {
706  freeAll();
707  throw x;
708  }
709 
710  assert(isConsistent());
711  }
712 
713  return *this;
714 }
715 
718  , vec(1)
719  , ssvec(1)
720  , usetup(false)
722  , eta(1)
723  , forest(1)
724  , minThreshold(0.01)
725  , timerType(Timer::USER_TIME)
726 {
727  row.perm = 0;
728  row.orig = 0;
729  col.perm = 0;
730  col.orig = 0;
731  u.row.elem = 0;
732  u.row.idx = 0;
733  u.row.start = 0;
734  u.row.len = 0;
735  u.row.max = 0;
736  u.col.elem = 0;
737  u.col.idx = 0;
738  u.col.start = 0;
739  u.col.len = 0;
740  u.col.max = 0;
741  l.idx = 0;
742  l.start = 0;
743  l.row = 0;
744  l.ridx = 0;
745  l.rbeg = 0;
746  l.rorig = 0;
747  l.rperm = 0;
748 
749  nzCnt = 0;
750  thedim = 0;
751 
752  try
753  {
760  diag.reDim(thedim);
761 
762  work = vec.get_ptr();
763 
764  u.row.used = 0;
766  u.row.val.reDim(1);
767  spx_alloc(u.row.idx, u.row.val.dim());
768  spx_alloc(u.row.start, thedim + 1);
769  spx_alloc(u.row.len, thedim + 1);
770  spx_alloc(u.row.max, thedim + 1);
771 
772  u.row.list.idx = thedim;
773  u.row.start[thedim] = 0;
774  u.row.max [thedim] = 0;
775  u.row.len [thedim] = 0;
776 
777  u.col.size = 1;
778  u.col.used = 0;
780  spx_alloc(u.col.idx, u.col.size);
781  spx_alloc(u.col.start, thedim + 1);
782  spx_alloc(u.col.len, thedim + 1);
783  spx_alloc(u.col.max, thedim + 1);
784  u.col.val.reDim(0);
785 
786  u.col.list.idx = thedim;
787  u.col.start[thedim] = 0;
788  u.col.max[thedim] = 0;
789  u.col.len[thedim] = 0;
790 
791  l.val.reDim(1);
792  spx_alloc(l.idx, l.val.dim());
793 
794  l.startSize = 1;
795  l.firstUpdate = 0;
796  l.firstUnused = 0;
797 
800  }
801  catch(const SPxMemoryException& x)
802  {
803  freeAll();
804  throw x;
805  }
806 
807  l.rval.reDim(0);
808  l.ridx = 0;
809  l.rbeg = 0;
810  l.rorig = 0;
811  l.rperm = 0;
812 
813  SLUFactorRational::clear(); // clear() is virtual
814 
815  factorCount = 0;
816  timeLimit = -1.0;
817  solveCount = 0;
818 
819  assert(row.perm != 0);
820  assert(row.orig != 0);
821  assert(col.perm != 0);
822  assert(col.orig != 0);
823 
824  assert(u.row.elem != 0);
825  assert(u.row.idx != 0);
826  assert(u.row.start != 0);
827  assert(u.row.len != 0);
828  assert(u.row.max != 0);
829 
830  assert(u.col.elem != 0);
831  assert(u.col.idx != 0);
832  assert(u.col.start != 0);
833  assert(u.col.len != 0);
834  assert(u.col.max != 0);
835 
836  assert(l.idx != 0);
837  assert(l.start != 0);
838  assert(l.row != 0);
839 
841 }
842 
844  : SLinSolverRational(old)
846  , vec(1) // we don't need to copy it, because they are temporary vectors
847  , ssvec(1) // we don't need to copy it, because they are temporary vectors
848  , usetup(old.usetup)
849  , eta(old.eta)
850  , forest(old.forest)
851  , timerType(old.timerType)
852 {
853  row.perm = 0;
854  row.orig = 0;
855  col.perm = 0;
856  col.orig = 0;
857  u.row.elem = 0;
858  u.row.idx = 0;
859  u.row.start = 0;
860  u.row.len = 0;
861  u.row.max = 0;
862  u.col.elem = 0;
863  u.col.idx = 0;
864  u.col.start = 0;
865  u.col.len = 0;
866  u.col.max = 0;
867  l.idx = 0;
868  l.start = 0;
869  l.row = 0;
870  l.ridx = 0;
871  l.rbeg = 0;
872  l.rorig = 0;
873  l.rperm = 0;
874 
875  solveCount = 0;
878 
879  try
880  {
881  assign(old);
882  }
883  catch(const SPxMemoryException& x)
884  {
885  freeAll();
886  throw x;
887  }
888 
890 }
891 
893 {
894 
895  if(row.perm)
896  spx_free(row.perm);
897 
898  if(row.orig)
899  spx_free(row.orig);
900 
901  if(col.perm)
902  spx_free(col.perm);
903 
904  if(col.orig)
905  spx_free(col.orig);
906 
907  if(u.row.elem)
908  spx_free(u.row.elem);
909 
910  u.row.val.reDim(0);
911 
912  if(u.row.idx)
913  spx_free(u.row.idx);
914 
915  if(u.row.start)
916  spx_free(u.row.start);
917 
918  if(u.row.len)
919  spx_free(u.row.len);
920 
921  if(u.row.max)
922  spx_free(u.row.max);
923 
924  if(u.col.elem)
925  spx_free(u.col.elem);
926 
927  if(u.col.idx)
928  spx_free(u.col.idx);
929 
930  if(u.col.start)
931  spx_free(u.col.start);
932 
933  if(u.col.len)
934  spx_free(u.col.len);
935 
936  if(u.col.max)
937  spx_free(u.col.max);
938 
939  if(l.idx)
940  spx_free(l.idx);
941 
942  if(l.start)
943  spx_free(l.start);
944 
945  if(l.row)
946  spx_free(l.row);
947 
948  diag.reDim(0);
949  u.col.val.reDim(0);
950  l.val.reDim(0);
951 
952  l.rval.reDim(0);
953 
954  if(l.ridx)
955  spx_free(l.ridx);
956 
957  if(l.rbeg)
958  spx_free(l.rbeg);
959 
960  if(l.rorig)
961  spx_free(l.rorig);
962 
963  if(l.rperm)
964  spx_free(l.rperm);
965 
968 }
969 
971 {
972  freeAll();
973 }
974 
976 {
977  assert(th < 1);
978 
979  if(10 * th < 1)
980  th *= 10;
981  else if(10 * th < 8)
982  th = (th + 1) / 2;
983  else if(th < 0.999)
984  th = 0.99999;
985 
986  assert(th < 1);
987 
988  return th;
989 }
990 
992 {
993  assert(dm >= 0);
994  assert(matrix != 0);
995 
996  Rational lastStability = stability();
997 
998  initDR(u.row.list);
999  initDR(u.col.list);
1000 
1001  usetup = false;
1002  l.updateType = uptype;
1003  l.firstUpdate = 0;
1004  l.firstUnused = 0;
1005 
1006  if(dm != thedim)
1007  {
1008  clear();
1009 
1010  thedim = dm;
1011  vec.reDim(thedim);
1012  ssvec.reDim(thedim);
1013  eta.reDim(thedim);
1014  forest.reDim(thedim);
1015  work = vec.get_ptr();
1016 
1021  diag.reDim(thedim);
1022 
1024  spx_realloc(u.row.len, thedim + 1);
1025  spx_realloc(u.row.max, thedim + 1);
1026  spx_realloc(u.row.start, thedim + 1);
1027 
1029  spx_realloc(u.col.len, thedim + 1);
1030  spx_realloc(u.col.max, thedim + 1);
1031  spx_realloc(u.col.start, thedim + 1);
1032 
1034 
1037  }
1038  // the last factorization was reasonably stable, so we decrease the Markowitz threshold (stored in lastThreshold) in
1039  // order favour sparsity
1040  else if(lastStability > 2.0 * minStability)
1041  {
1042  // we reset lastThreshold to its previous value in the sequence minThreshold, betterThreshold(minThreshold),
1043  // betterThreshold(betterThreshold(minThreshold)), ...
1044  Rational last = minThreshold;
1045  Rational better = betterThreshold(last);
1046 
1047  while(better < lastThreshold)
1048  {
1049  last = better;
1050  better = betterThreshold(last);
1051  }
1052 
1053  lastThreshold = last;
1054 
1055  // we reset the minimum stability (which might have been decreased below) to ensure that the increased sparsity
1056  // does not hurt the stability
1057  minStability = 2 * MINSTABILITY;
1058  }
1059 
1060  u.row.list.idx = thedim;
1061  u.row.start[thedim] = 0;
1062  u.row.max[thedim] = 0;
1063  u.row.len[thedim] = 0;
1064 
1065  u.col.list.idx = thedim;
1066  u.col.start[thedim] = 0;
1067  u.col.max[thedim] = 0;
1068  u.col.len[thedim] = 0;
1069 
1070  stat = OK;
1071  factor(matrix, lastThreshold);
1072 
1073  MSG_DEBUG(std::cout << "DSLUFA02 threshold = " << lastThreshold
1074  << "\tstability = " << stability()
1075  << "\tminStability = " << minStability << std::endl;)
1076  MSG_DEBUG(
1077  int i;
1078  FILE* fl = fopen("dump.lp", "w");
1079  std::cout << "DSLUFA03 Basis:\n";
1080  int j = 0;
1081 
1082  for(i = 0; i < dim(); ++i)
1083  j += matrix[i]->size();
1084  for(i = 0; i < dim(); ++i)
1085  {
1086  for(j = 0; j < matrix[i]->size(); ++j)
1087  fprintf(fl, "%8d %8d %s\n",
1088  i + 1, matrix[i]->index(j) + 1, rationalToString(matrix[i]->value(j)).c_str());
1089  }
1090  fclose(fl);
1091  std::cout << "DSLUFA04 LU-Factors:" << std::endl;
1092  dump();
1093 
1094  std::cout << "DSLUFA05 threshold = " << lastThreshold
1095  << "\tstability = " << stability() << std::endl;
1096  )
1097 
1098  assert(isConsistent());
1099  return Status(stat);
1100 }
1101 
1102 
1104 {
1105 #ifdef ENABLE_CONSISTENCY_CHECKS
1107 #else
1108  return true;
1109 #endif
1110 }
1111 
1113 {
1115 }
1116 } // 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:253
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:857
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:153
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:127
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:44
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.
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: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:446
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: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:603
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: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:569
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:584
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:100
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:217
void setup_and_assign(SSVectorBase< S > &rhs)
Sets up rhs vector, and assigns it.
Definition: ssvectorbase.h:722
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
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:262
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: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:3645
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:110
static Real betterThreshold(Real th)
Definition: slufactor.cpp:1341
void solve2right4update(SSVectorRational &x, VectorRational &y, const SVectorRational &b, SSVectorRational &d)
Solves and .
DVectorRational vec
Temporary vector.
SLinSolverRational::Status stat
Status indicator.