My Project
OSMatrix.cpp
Go to the documentation of this file.
1 /* $Id: OSMatrix.cpp 3186 2010-02-06 23:38:35Z Gassmann $ */
16 #include "OSMatrix.h"
17 #include "OSGeneral.h"
18 #include "OSParameters.h"
19 #include "OSErrorClass.h"
20 #include "OSMathUtil.h"
21 #include "OSBase64.h"
22 #include "OSOutput.h"
23 #include "OSgLWriter.h"
24 
25 #include <iostream>
26 #include <sstream>
27 
28 
29 using namespace std;
30 using std::endl;
31 
32 
33 /***************************************************************
34  * *
35  * Implementations of methods for various matrix classes *
36  * *
37  ***************************************************************/
38 
41  matrixType(ENUM_MATRIX_TYPE_unknown),
43  inumberOfChildren(),
44  m_mChildren(NULL){
45 #ifndef NDEBUG
46  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "in MatrixNode constructor");
47 #endif
48 }
49 
51 {
52 #ifndef NDEBUG
53  std::ostringstream outStr;
54  outStr << "inside MatrixNode destructor" << std::endl;
55  outStr << "number of kids = " << inumberOfChildren << std::endl;
57 #endif
58  if (inumberOfChildren > 0 && m_mChildren != NULL)
59  {
60  for (unsigned int i=0; i<inumberOfChildren; i++)
61  {
62  if (m_mChildren[i] != NULL)
63  {
64 #ifndef NDEBUG
65  outStr.str("");
66  outStr.clear();
67  outStr << "deleting Matrixnode->m_mChildren[" << i << "] at "
68  << &m_mChildren[i] << std::endl;
70  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
71 #endif
72  delete m_mChildren[i];
73  }
74  m_mChildren[i] = NULL;
75  }
76  delete [] m_mChildren;
77  m_mChildren = NULL;
79  }
80  else if (inumberOfChildren > 0 || m_mChildren != NULL)
81  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_warning, "Warning: Possible memory leak");
82 }
83 
85 {
86  return nType;
87 }// end of OSMatrix::getNodeType()
88 
90 {
91  return "";
92 }// end of MatrixNode::getMatrixNodeInXML()
93 
94 bool MatrixNode::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
95 {
96  return false;
97 }// end of MatrixNode::alignsOnBlockBoundary()
98 
100 {
101 #ifndef NDEBUG
102  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in MatrixNode");
103 #endif
104  if (this == NULL)
105  {
106  if (that == NULL)
107  return true;
108  else
109  {
110 #ifndef NDEBUG
112  "First object is NULL, second is not");
113 #endif
114  return false;
115  }
116  }
117  else
118  {
119  if (that == NULL)
120  {
121 #ifndef NDEBUG
123  "Second object is NULL, first is not");
124 #endif
125  return false;
126  }
127  else
128  {
129  if (this->inumberOfChildren != that->inumberOfChildren) return false;
130  if (this->matrixType != that->matrixType) return false;
131  if (this->nType != that->nType) return false;
132 
133  for (unsigned int i=0; i < inumberOfChildren; i++)
134  if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
135  return false;
136 
137  return true;
138  }
139  }
140 }// end of MatrixNode::IsEqual()
141 // end of methods for MatrixNode
142 
143 
146 {
147 #ifndef NDEBUG
148  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixConstructor Constructor");
149 #endif
150 }
151 
153 {
154 #ifndef NDEBUG
155  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixConstructor Destructor");
156 #endif
157 }//end of MatrixConstructor::~MatrixConstructor
158 // end of methods for MatrixConstructor
159 
160 
162 // methods for MatrixType
164  MatrixNode(),
165  symmetry(ENUM_MATRIX_SYMMETRY_none),
167  numberOfRows(0),
168  numberOfColumns(0),
169  ExpandedMatrixInRowMajorForm(NULL),
170  ExpandedMatrixInColumnMajorForm(NULL),
171  m_miRowPartition(NULL),
172  m_iRowPartitionSize(0),
173  m_miColumnPartition(NULL),
174  m_iColumnPartitionSize(0),
175  m_bHaveRowPartition(false),
176  m_bHaveColumnPartition(false)
177 {
178 #ifndef NDEBUG
179  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixType Constructor");
180 #endif
181 } // end of MatrixType
182 
184 {
185 #ifndef NDEBUG
186  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixType Destructor");
187 #endif
188 }// end of ~MatrixType
189 
190 bool MatrixType::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
191 {
192  return false;
193 }// end of MatrixType::alignsOnBlockBoundary()
194 
196 {
197  return (inumberOfChildren > 0 && m_mChildren != NULL
199 }// end of matrixHasBase
200 
202 {
203  if (inumberOfChildren == 0 || m_mChildren == NULL) return false;
204  for (unsigned int i=0; i < inumberOfChildren; i++)
205  {
212  }
213  return false;
214 }// end of matrixHasElements
215 
217 {
218  if (inumberOfChildren == 0 || m_mChildren == NULL) return false;
219  for (unsigned int i=0; i < inumberOfChildren; i++)
220  {
222  }
223  return false;
224 }// end of matrixHasTransformations
225 
227 {
228  if (inumberOfChildren == 0 || m_mChildren == NULL) return false;
229  for (unsigned int i=0; i < inumberOfChildren; i++)
230  {
231  if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks) return true;
232  }
233  return false;
234 }// end of matrixHasBlocks
235 
237 {
238  int k = 0;
239  if (inumberOfChildren == 0 || m_mChildren == NULL) return 0;
240  for (unsigned int i=0; i < inumberOfChildren; i++)
241  {
248  }
249  return k++;
250 }// end of getNumberOfElementConstructors
251 
253 {
254  int k = 0;
255  if (inumberOfChildren == 0 || m_mChildren == NULL) return 0;
256  for (unsigned int i=0; i < inumberOfChildren; i++)
257  {
259  }
260  return k++;
261 }// end of getNumberOfTransformationConstructors
262 
264 {
265  int k = 0;
266  if (inumberOfChildren == 0 || m_mChildren == NULL) return 0;
267  for (unsigned int i=0; i < inumberOfChildren; i++)
268  {
270  }
271  return k++;
272 }// end of getNumberOfBlocksConstructors
273 
275 {
276 #ifndef NDEBUG
277  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside getMatrixCoefficientsInColumnMajor()");
278 #endif
279  try
280  {
281  //Check if previous expansion available
284  if (ExpandedMatrixInRowMajorForm != NULL)
285  {
288  }
289 
290  // The complexity increases with the number of constructors
291  // Start by checking for empty matrix
292  if (inumberOfChildren == 0)
293  {
299  for (int i=0; i <= numberOfColumns; i++)
302  }
303 
304  // single constructor --- process by type
305  else if (inumberOfChildren == 1)
306  {
308  {
309  int baseMtxIdx = ((BaseMatrix*)m_mChildren[0])->baseMatrixIdx;
310  OSMatrix* baseMtxPtr = ((BaseMatrix*)m_mChildren[0])->baseMatrix;
311 
312  int iroff = ((BaseMatrix*)m_mChildren[0])->targetMatrixFirstRow;
313  int icoff = ((BaseMatrix*)m_mChildren[0])->targetMatrixFirstCol;
314 
315  int base_r0, base_c0, base_rN, base_cN;
316 
317  GeneralSparseMatrix* baseMtx;
318  if (((BaseMatrix*)m_mChildren[0])->baseTranspose)
319  {
320  baseMtx = baseMtxPtr->getMatrixCoefficientsInRowMajor();
321  base_r0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartCol;
322  base_c0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartRow;
323  base_rN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndCol;
324  base_cN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndRow;
325  if (base_cN < 0)
326  base_cN = baseMtxPtr->numberOfRows - 1;
327  if (base_rN < 0)
328  base_rN = baseMtxPtr->numberOfColumns - 1;
329  }
330  else
331  {
332  baseMtx = baseMtxPtr->getMatrixCoefficientsInColumnMajor();
333  base_r0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartRow;
334  base_c0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartCol;
335  base_rN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndRow;
336  base_cN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndCol;
337  if (base_rN < 0)
338  base_rN = baseMtxPtr->numberOfRows - 1;
339  if (base_cN < 0)
340  base_cN = baseMtxPtr->numberOfColumns - 1;
341  }
342 
343  double scaleMult = ((BaseMatrix*)m_mChildren[0])->scalarMultiplier;
344 
348 
349  // position and other options can affect what arrays need to be duplicated
350  bool isShifted = (iroff > 0 || icoff > 0);
351  bool isCropped = (base_c0 > 0 || base_r0 > 0 ||
352  base_rN < baseMtxPtr->numberOfRows - 1 ||
353  base_cN < baseMtxPtr->numberOfColumns - 1);
354  bool isClipped = (iroff + base_rN - base_r0 >= numberOfRows ||
355  icoff + base_cN - base_c0 >= numberOfColumns);
356  bool isScaled = (scaleMult != 1);
357  bool reTyped = (getMatrixType() != baseMtx->vType);
358  bool hasGap = (icoff + base_cN - base_c0 < numberOfColumns - 1);
359 
360  //default position without cropping, scaling or retyping is easiest
361  if ( !isShifted && !isCropped && !isClipped && !isScaled && !reTyped )
362  {
371 
372  // even in default layout the baseMatrix may still have different dimensions...
373  if (!hasGap)
375  else
376  {
380  for (int i=0; i < baseMtx->startSize; i++)
381  ExpandedMatrixInColumnMajorForm->start[i] = baseMtx->start[i];
382  int lastStart = baseMtx->valueSize;
383  for (int i=baseMtx->startSize;
384  i < ExpandedMatrixInColumnMajorForm->startSize; i++)
385  ExpandedMatrixInColumnMajorForm->start[i] = lastStart;
386  }
387 
389  }
390  else
391  {
392  // cropping, positioning or scaling all require a deep copy
393  if ( !isShifted && !isCropped && !isClipped )
394  {
395  // it's a bit easier if we are just scaling
403 
404  // even in default layout the baseMatrix may still have different dimensions...
405  if (!hasGap)
407  else
408  {
412  for (int i=0; i < baseMtx->startSize; i++)
413  ExpandedMatrixInColumnMajorForm->start[i] = baseMtx->start[i];
414  int lastStart = baseMtx->valueSize;
415  for (int i=baseMtx->startSize;
416  i < ExpandedMatrixInColumnMajorForm->startSize; i++)
417  ExpandedMatrixInColumnMajorForm->start[i] = lastStart;
418  }
419 
420  // the values are a bit more difficult ...
421  if ( baseMtx->vType == ENUM_MATRIX_TYPE_constant)
422  {
425  = new double[baseMtx->valueSize];
426  for (int i = 0; i < baseMtx->valueSize; i++)
428  = scaleMult*((ConstantMatrixValues*)baseMtx->value)->el[i];
429  }
430  else if (baseMtx->vType == ENUM_MATRIX_TYPE_varReference)
431  {
432  // must convert to linear elements
433  LinearMatrixValues* tmpValues = new LinearMatrixValues();
434  tmpValues->el = new LinearMatrixElement*[baseMtx->valueSize];
435  for (int i = 0; i < baseMtx->valueSize; i++)
436  {
437  tmpValues->el[i] = new LinearMatrixElement();
438  tmpValues->el[i]->numberOfVarIdx = 1;
439  tmpValues->el[i]->varIdx = new LinearMatrixElementTerm*[1];
440  tmpValues->el[i]->varIdx[0] = new LinearMatrixElementTerm();
441  tmpValues->el[i]->varIdx[0]->coef = scaleMult;
442  tmpValues->el[i]->varIdx[0]->idx
443  = ((VarReferenceMatrixValues*)baseMtx->value)->el[i];
444  }
446  }
447  else if (baseMtx->vType == ENUM_MATRIX_TYPE_linear)
448  {
449  LinearMatrixValues* tmpValues = new LinearMatrixValues();
450  tmpValues->el = new LinearMatrixElement*[baseMtx->valueSize];
451  for (int i = 0; i < baseMtx->valueSize; i++)
452  {
453  tmpValues->el[i] = new LinearMatrixElement();
454  if (!(tmpValues->el[i]
455  ->deepCopyFrom(((LinearMatrixValues*)baseMtx->value)->el[i])))
456  throw ErrorClass("failed copying linear element values in method getMatrixCoefficientsInColumnMajor()");
457  for (int j=0; j<tmpValues->el[i]->numberOfVarIdx; j++)
458  tmpValues->el[i]->varIdx[j]->coef *= scaleMult;
459  }
461  }
462  else if (baseMtx->vType == ENUM_MATRIX_TYPE_general)
463  {
464  // add scalar multiple as a product
465  GeneralMatrixValues* tmpValues = new GeneralMatrixValues();
466  tmpValues->el = new ScalarExpressionTree*[baseMtx->valueSize];
467  for (int i = 0; i < baseMtx->valueSize; i++)
468  {
469  tmpValues->el[i] = new ScalarExpressionTree();
470  tmpValues->el[i]->m_treeRoot = new OSnLNodeTimes();
471  tmpValues->el[i]->m_treeRoot->m_mChildren[0] = new OSnLNodeNumber();
472  ((OSnLNodeNumber*)tmpValues->el[i]->m_treeRoot->m_mChildren[0])->value = scaleMult;
473  tmpValues->el[i]->m_treeRoot->m_mChildren[1]
474  = ((GeneralMatrixValues*)baseMtx->value)->el[i]->m_treeRoot
476  }
478  }
479  else if (baseMtx->vType == ENUM_MATRIX_TYPE_objReference)
480  {
481  throw ErrorClass("scalar multiple not defined for objReference elements in getMatrixCoefficientsInColumnMajor()");
482  }
483  else if (baseMtx->vType == ENUM_MATRIX_TYPE_conReference)
484  {
485  throw ErrorClass("scalar multiple not defined for conReference elements in getMatrixCoefficientsInColumnMajor()");
486  }
488  }
489  else // repositioned Basematrix with cropping
490  {
497 
498  int startSize = numberOfColumns + 1;
499  int* tmpStarts = new int[startSize];
500  for (int i=0; i < startSize; i++)
501  tmpStarts[i] = 0;
502 
503  int adjc = icoff - base_c0;
504  int lastcol = icoff + base_cN - base_c0 + 1;
505  if (lastcol > numberOfColumns)
506  lastcol = numberOfColumns;
507 
508  // count elements in each column and calculate starts
509  for (int i=icoff; i<lastcol; i++)
510  for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
511  {
512  if (baseMtx->index[j] >= base_r0 &&
513  baseMtx->index[j] <= base_rN &&
514  baseMtx->index[j] < numberOfRows + base_r0 - iroff)
515  tmpStarts[i+1]++;
516  }
517  for (int i=icoff+1; i < startSize; i++)
518  tmpStarts[i] += tmpStarts[i-1];
519 
520  int valueSize = tmpStarts[startSize-1];
521  int* tmpIndexes = new int[valueSize];
522 
525 
526  // to get the values, go through the base matrix a second time
527  if ( baseMtx->vType == ENUM_MATRIX_TYPE_constant)
528  {
529  MatrixElementValues* tmpValues = new ConstantMatrixValues();
530  ((ConstantMatrixValues*)tmpValues)->el = new double[valueSize];
531 
532  int ival = 0;
533  for (int i=icoff; i<lastcol; i++)
534  for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
535  {
536  if (baseMtx->index[j] >= base_r0 &&
537  baseMtx->index[j] <= base_rN &&
538  baseMtx->index[j] < numberOfRows + base_r0 - iroff)
539  {
540  tmpIndexes[ival] = baseMtx->index[j] - base_r0 + iroff;
541  ((ConstantMatrixValues*)tmpValues)->el[ival]
542  = scaleMult*((ConstantMatrixValues*)baseMtx->value)->el[j];
543  ival++;
544  }
545  }
548  }
549 
550  else if (baseMtx->vType == ENUM_MATRIX_TYPE_varReference)
551  {
552  if (scaleMult == 1)
553  {
555  ((VarReferenceMatrixValues*)tmpValues)->el = new int[valueSize];
556 
557  int ival = 0;
558  for (int i=icoff; i<lastcol; i++)
559  for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
560  {
561  if (baseMtx->index[j] >= base_r0 &&
562  baseMtx->index[j] < numberOfRows + base_r0 - iroff)
563  {
564  tmpIndexes[ival] = baseMtx->index[j] - base_r0 + iroff;
565  ((VarReferenceMatrixValues*)tmpValues)->el[ival]
566  = ((VarReferenceMatrixValues*)baseMtx->value)->el[j];
567  ival++;
568  }
569  }
572  }
573  else
574  {
575  // must convert to linear elements
576  MatrixElementValues* tmpValues = new LinearMatrixValues();
577  ((LinearMatrixValues*)tmpValues)->el
578  = new LinearMatrixElement*[valueSize];
579 
580  int ival = 0;
581  for (int i=icoff; i<lastcol; i++)
582  for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
583  {
584  if (baseMtx->index[j] >= base_r0 &&
585  baseMtx->index[j] < numberOfRows + base_r0 - iroff)
586  {
587  ((LinearMatrixValues*)tmpValues)->el[ival]
588  = new LinearMatrixElement();
589  ((LinearMatrixValues*)tmpValues)->el[ival]->numberOfVarIdx = 1;
590  ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx
591  = new LinearMatrixElementTerm*[1];
592  ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx[0]
593  = new LinearMatrixElementTerm();
594  ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx[0]->coef
595  = scaleMult;
596  ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx[0]->idx
597  = ((VarReferenceMatrixValues*)baseMtx->value)->el[j];
598  ival++;
599  }
600  }
603  }
604  }
605  else if (baseMtx->vType == ENUM_MATRIX_TYPE_linear)
606  {
607  LinearMatrixValues* tmpValues = new LinearMatrixValues();
608  tmpValues->el = new LinearMatrixElement*[baseMtx->valueSize];
609 
610  int ival = 0;
611  for (int i=icoff; i<lastcol; i++)
612  for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
613  {
614  if (baseMtx->index[j] >= base_r0 &&
615  baseMtx->index[j] < numberOfRows + base_r0 - iroff)
616  {
617  tmpValues->el[ival] = new LinearMatrixElement();
618  if (!(tmpValues->el[ival]
619  ->deepCopyFrom(((LinearMatrixValues*)baseMtx->value)->el[j])))
620  throw ErrorClass("failed copying linear element values in method getMatrixCoefficientsInColumnMajor()");
621  for (int k=0; k<tmpValues->el[ival]->numberOfVarIdx; k++)
622  tmpValues->el[ival]->varIdx[k]->coef *= scaleMult;
623  ival++;
624  }
625  }
628  }
629  else if (baseMtx->vType == ENUM_MATRIX_TYPE_general)
630  {
631  if (scaleMult == 1)
632  {
633  GeneralMatrixValues* tmpValues = new GeneralMatrixValues();
634  tmpValues->el = new ScalarExpressionTree*[baseMtx->valueSize];
635 
636  int ival = 0;
637  for (int i=icoff; i<lastcol; i++)
638  for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
639  {
640  if (baseMtx->index[j] >= base_r0 &&
641  baseMtx->index[j] < numberOfRows + base_r0 - iroff)
642  {
643  ((GeneralMatrixValues*)tmpValues)->el[ival]
644  = new ScalarExpressionTree();
645 // ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot
646 // = new OSnLNode();
647  ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot
648  = ((GeneralMatrixValues*)baseMtx->value)->el[j]->m_treeRoot
649  ->copyNodeAndDescendants();
650  ival++;
651  }
652  }
655  }
656  else
657  {
658  // add scalar multiple as a product
659  GeneralMatrixValues* tmpValues = new GeneralMatrixValues();
660  tmpValues->el = new ScalarExpressionTree*[baseMtx->valueSize];
661  int ival = 0;
662  for (int i=icoff; i<lastcol; i++)
663  for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
664  {
665  if (baseMtx->index[j] >= base_r0 &&
666  baseMtx->index[j] < numberOfRows + base_r0 - iroff)
667  {
668  ((GeneralMatrixValues*)tmpValues)->el[ival]
669  = new ScalarExpressionTree();
670  ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot
671  = new OSnLNodeTimes();
672  ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot->m_mChildren[0]
673  = new OSnLNodeNumber();
674  ((OSnLNodeNumber*)tmpValues->el[ival]->m_treeRoot->m_mChildren[0])->value = scaleMult;
675  ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot->m_mChildren[1]
676  = ((GeneralMatrixValues*)baseMtx->value)->el[j]->m_treeRoot->copyNodeAndDescendants();
677  ival++;
678 
679  }
680  }
683  }
684  }
685  else if (baseMtx->vType == ENUM_MATRIX_TYPE_objReference)
686  {
687  throw ErrorClass("scalar multiple not defined for objReference elements in getMatrixCoefficientsInColumnMajor()");
688  }
689  else if (baseMtx->vType == ENUM_MATRIX_TYPE_conReference)
690  {
691  throw ErrorClass("scalar multiple not defined for conReference elements in getMatrixCoefficientsInColumnMajor()");
692  }
693  }
695  }
696  }
697 
699  {
700  //make sure the blocks have been expanded, then retrieve them
701  if (!processBlocks(false, symmetry))
702  throw ErrorClass("error processing blocks in getMatrixCoefficientsInColumnMajor()");
703 
704  ExpandedMatrixBlocks* currentBlocks
706  m_iColumnPartitionSize, false, true);
707  //ExpandedMatrixByBlocks.push_back(currentBlocks);
708 
718  for (int i=0; i <= numberOfColumns; i++)
720 
721  // augment column lengths block by block
722  for (int i=0; i < currentBlocks->blockNumber; i++)
723  {
724  int c0 = currentBlocks->colOffset[currentBlocks->blockColumns[i]];
725  int cN = currentBlocks->colOffset[currentBlocks->blockColumns[i]+1];
726  for (int j = c0; j < cN; j++)
727  {
729  ( currentBlocks->blocks[i]->start[j+1-c0]
730  - currentBlocks->blocks[i]->start[j -c0] );
731  }
732  }
733 
734  for (int i=1; i <= numberOfColumns; i++)
739  int* tmpIndexes = new int[ExpandedMatrixInColumnMajorForm->valueSize];
740 
741  // go through the blocks a second time to store values --- based on type
742  if (currentBlocks->blocks[0]->vType == ENUM_MATRIX_TYPE_constant)
743  {
744  ConstantMatrixValues* tmpValues = new ConstantMatrixValues();
745  tmpValues->el
747 
748  for (int i=0; i < currentBlocks->blockNumber; i++)
749  {
750  int c0 = currentBlocks->colOffset[currentBlocks->blockColumns[i]];
751  int cN = currentBlocks->colOffset[currentBlocks->blockColumns[i]+1];
752  int row_adj = currentBlocks->rowOffset[currentBlocks->blockRows[i]];
753 
754  for (int j = c0; j < cN; j++)
755  {
757  for (int k = currentBlocks->blocks[i]->start[j-c0];
758  k < currentBlocks->blocks[i]->start[j-c0+1]; k++)
759  {
760  tmpIndexes[loc] = currentBlocks->blocks[i]->index[k] + row_adj;
761  ((ConstantMatrixValues*)tmpValues)->el[loc]
762  = ((ConstantMatrixValues*)currentBlocks->blocks[i]->value)->el[k];
763  loc++;
764  }
766  }
767  }
770  }
771  else
772  throw ErrorClass("getMatrixCoefficientsInColumnMajor: Can only handle constant values so far in blocks");
773  for (int i=numberOfColumns; i > 0; i--)
778  }
779 
781  {
782 // transformation: see if we can do at least AB, A'B, AB'
783 // for now:
784  throw ErrorClass("transformations not yet implemented in getMatrixCoefficientsInColumnMajor()");
785  }
786  else // some kind of elements --- if given column-wise, just copy pointers
787  {
788  if (!((MatrixElements*)m_mChildren[0])->rowMajor)
789  {
798  = ((MatrixElements*)m_mChildren[0])->numberOfValues;
800  = ((MatrixElements*)m_mChildren[0])->start->el;
802  = getMatrixType();
804  = ((MatrixElements*)m_mChildren[0])->index->el;
807  = ((ConstantMatrixElements*)m_mChildren[0])->value;
810  = ((VarReferenceMatrixElements*)m_mChildren[0])->value;
813  = ((LinearMatrixElements*)m_mChildren[0])->value;
816  = ((GeneralMatrixElements*)m_mChildren[0])->value;
819  = ((ObjReferenceMatrixElements*)m_mChildren[0])->value;
822  = ((ConReferenceMatrixElements*)m_mChildren[0])->value;
823  else
824  throw ErrorClass("Unknown element type in getMatrixCoefficientsInColumnMajor()");
825 
827  }
828  else // elements are given row-wise and must be "turned"
829  {
831 
837  for (int i=0; i <= numberOfColumns; i++)
839 
840  //if <value> is empty, return an empty matrix
841  if (refMtx == NULL || refMtx->numberOfValues == 0)
842  {
845  }
846 
849 
850  int i, j, iTemp;
851  int iNumSource = numberOfRows;
852 
853  for (i = 0; i < numberOfRows; i++)
854  {
855  for (j = refMtx->start->el[i]; j < refMtx->start->el[i + 1]; j++)
856  {
857  ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j] + 1] ++;
858  }
859  }
861 
862  for (i = 1; i <= numberOfColumns; i++ )
863  {
866  }
867 
868  // store the elements, by type
870  {
873  = new double[refMtx->numberOfValues];
874 
875  for (i = 0; i < numberOfRows; i++)
876  {
877  // get row indices and values of the matrix
878  for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
879  {
880  iTemp = ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]];
883  = ((ConstantMatrixValues*)((ConstantMatrixElements*)refMtx)->value)->el[j];
885  }
886  }
887  }
889  {
892  = new int[refMtx->numberOfValues];
893 
894  for (i = 0; i < numberOfRows; i++)
895  {
896  // get row indices and values of the matrix
897  for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
898  {
899  iTemp = ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]];
902  = ((VarReferenceMatrixValues*)((VarReferenceMatrixElements*)refMtx)->value)->el[j];
904  }
905  }
906  }
908  {
911  = new LinearMatrixElement*[refMtx->numberOfValues];
912  for (i = 0; i < refMtx->numberOfValues; i++)
914  = new LinearMatrixElement();
915 
916  for (i = 0; i < numberOfRows; i++)
917  {
918  // get row indices and values of the matrix
919  for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
920  {
921  iTemp = ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]];
924  el[ iTemp]->deepCopyFrom(((LinearMatrixValues*)
925  ((LinearMatrixElements*)refMtx)->value)->el[j]))
926  return NULL;
928  }
929  }
930  }
932  {
935  = new ScalarExpressionTree*[refMtx->numberOfValues];
936  for (i = 0; i < refMtx->numberOfValues; i++)
937  {
939  = new ScalarExpressionTree();
940  }
941 
942  for (i = 0; i < numberOfRows; i++)
943  {
944  // get row indices and values of the matrix
945  for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
946  {
947  iTemp = ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]];
949  ((GeneralMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el[ iTemp]->m_treeRoot
950  = ((GeneralMatrixValues*)((GeneralMatrixElements*)refMtx)->value)->el[j]->m_treeRoot->copyNodeAndDescendants();
952  }
953  }
954  }
956  {
959  = new int[refMtx->numberOfValues];
960 
961  for (i = 0; i < numberOfRows; i++)
962  {
963  // get row indices and values of the matrix
964  for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
965  {
966  iTemp = ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]];
969  = ((ObjReferenceMatrixValues*)((ObjReferenceMatrixElements*)refMtx)->value)->el[j];
971  }
972  }
973  }
975  {
979  for (i = 0; i < refMtx->numberOfValues; i++)
981  = new ConReferenceMatrixElement();
982 
983  for (i = 0; i < numberOfRows; i++)
984  {
985  // get row indices and values of the matrix
986  for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
987  {
988  iTemp = ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]];
991  return NULL;
993  }
994  }
995  }
996 
997  // readjust the starts
998  for (i = numberOfColumns; i >= 1; i--)
999  {
1002  }
1003 
1006  }
1007  }
1008  }
1009 
1010  else // two or more constructors --- worry about overwriting and number of elements
1011  {
1012 /*
1013  (basematrix plus) elements should be ok
1014  maybe transformation (product) plus elements
1015  others: throw error
1016 */
1017  throw ErrorClass("Multiple constructors not yet implemented in getMatrixCoefficientsInColumnMajor()");
1018  }
1019  return NULL;
1020  }
1021  catch(const ErrorClass& eclass)
1022  {
1023  throw ErrorClass( eclass.errormsg);
1024  }
1025 }// end of getMatrixCoefficientsInColumnMajor
1026 
1028 {
1029 #ifndef NDEBUG
1030  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside getMatrixCoefficientsInRowMajor()");
1031 #endif
1032  try
1033  {
1034  //Check if previous expansion available
1035  if (ExpandedMatrixInRowMajorForm != NULL)
1037  if (ExpandedMatrixInColumnMajorForm != NULL)
1038  {
1041  }
1042 
1043  // The complexity increases with the number of constructors
1044  // Start by checking for empty matrix
1045  if (inumberOfChildren == 0)
1046  {
1052  for (int i=0; i <= numberOfRows; i++)
1055  }
1056 
1057  // single constructor --- process by type
1058  else if (inumberOfChildren == 1)
1059  {
1061  {
1062  int baseMtxIdx = ((BaseMatrix*)m_mChildren[0])->baseMatrixIdx;
1063  OSMatrix* baseMtxPtr = ((BaseMatrix*)m_mChildren[0])->baseMatrix;
1064 
1065  int iroff = ((BaseMatrix*)m_mChildren[0])->targetMatrixFirstRow;
1066  int icoff = ((BaseMatrix*)m_mChildren[0])->targetMatrixFirstCol;
1067  int base_r0, base_c0, base_rN, base_cN;
1068 
1069  GeneralSparseMatrix* baseMtx;
1070  if (((BaseMatrix*)m_mChildren[0])->baseTranspose)
1071  {
1072  baseMtx = baseMtxPtr->getMatrixCoefficientsInColumnMajor();
1073  base_c0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartCol;
1074  base_r0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartRow;
1075  base_cN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndCol;
1076  base_rN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndRow;
1077  if (base_cN < 0)
1078  base_cN = baseMtxPtr->numberOfColumns - 1;
1079  if (base_rN < 0)
1080  base_rN = baseMtxPtr->numberOfRows - 1;
1081  }
1082  else
1083  {
1084  baseMtx = baseMtxPtr->getMatrixCoefficientsInRowMajor();
1085  base_c0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartRow;
1086  base_r0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartCol;
1087  base_cN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndRow;
1088  base_rN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndCol;
1089  if (base_cN < 0)
1090  base_cN = baseMtxPtr->numberOfRows - 1;
1091  if (base_rN < 0)
1092  base_rN = baseMtxPtr->numberOfColumns - 1;
1093  }
1094 
1095  double scaleMult = ((BaseMatrix*)m_mChildren[0])->scalarMultiplier;
1096 
1100 
1101  // position and other options can affect what arrays need to be duplicated
1102  bool isShifted = (iroff > 0 || icoff > 0);
1103  bool isCropped = (base_c0 > 0 || base_r0 > 0 ||
1104  base_rN < baseMtxPtr->numberOfRows - 1 ||
1105  base_cN < baseMtxPtr->numberOfColumns - 1);
1106  bool isClipped = (iroff + base_rN - base_r0 >= numberOfRows ||
1107  icoff + base_cN - base_c0 >= numberOfColumns);
1108  bool isScaled = (scaleMult != 1);
1109  bool reTyped = (getMatrixType() != baseMtx->vType);
1110  bool hasGap = (icoff + base_cN - base_c0 < numberOfColumns - 1);
1111 
1112  //default position without cropping, scaling or retyping is easiest
1113  if ( !isShifted && !isCropped && !isClipped && !isScaled && !reTyped )
1114  {
1123 
1124  // even in default layout the baseMatrix may still have different dimensions...
1125  if (!hasGap)
1127  else
1128  {
1132  for (int i=0; i < baseMtx->startSize; i++)
1133  ExpandedMatrixInRowMajorForm->start[i] = baseMtx->start[i];
1134  int lastStart = baseMtx->valueSize;
1135  for (int i=baseMtx->startSize;
1136  i < ExpandedMatrixInRowMajorForm->startSize; i++)
1137  ExpandedMatrixInRowMajorForm->start[i] = lastStart;
1138  }
1140  }
1141  else
1142  {
1143  // cropping, positioning or scaling all require a deep copy
1144  if ( !isShifted && !isCropped && !isClipped )
1145  {
1146  // it's a bit easier if we are just scaling
1154 
1155  // even in default layout the baseMatrix may still have different dimensions...
1156  if (!hasGap)
1158  else
1159  {
1163  for (int i=0; i < baseMtx->startSize; i++)
1164  ExpandedMatrixInRowMajorForm->start[i] = baseMtx->start[i];
1165  int lastStart = baseMtx->valueSize;
1166  for (int i=baseMtx->startSize;
1167  i < ExpandedMatrixInRowMajorForm->startSize; i++)
1168  ExpandedMatrixInRowMajorForm->start[i] = lastStart;
1169  }
1170 
1171  // the values are a bit more difficult ...
1172  if ( baseMtx->vType == ENUM_MATRIX_TYPE_constant)
1173  {
1176  = new double[baseMtx->valueSize];
1177  for (int i = 0; i < baseMtx->valueSize; i++)
1179  = scaleMult*((ConstantMatrixValues*)baseMtx->value)->el[i];
1180  }
1181  else if (baseMtx->vType == ENUM_MATRIX_TYPE_varReference)
1182  {
1183  // must convert to linear elements
1184  LinearMatrixValues* tmpValues = new LinearMatrixValues();
1185  tmpValues->el = new LinearMatrixElement*[baseMtx->valueSize];
1186  for (int i = 0; i < baseMtx->valueSize; i++)
1187  {
1188  tmpValues->el[i] = new LinearMatrixElement();
1189  tmpValues->el[i]->numberOfVarIdx = 1;
1190  tmpValues->el[i]->varIdx = new LinearMatrixElementTerm*[1];
1191  tmpValues->el[i]->varIdx[0] = new LinearMatrixElementTerm();
1192  tmpValues->el[i]->varIdx[0]->coef = scaleMult;
1193  tmpValues->el[i]->varIdx[0]->idx
1194  = ((VarReferenceMatrixValues*)baseMtx->value)->el[i];
1195  }
1196  ExpandedMatrixInRowMajorForm->value = tmpValues;
1197  }
1198  else if (baseMtx->vType == ENUM_MATRIX_TYPE_linear)
1199  {
1200  LinearMatrixValues* tmpValues = new LinearMatrixValues();
1201  tmpValues->el = new LinearMatrixElement*[baseMtx->valueSize];
1202  for (int i = 0; i < baseMtx->valueSize; i++)
1203  {
1204  tmpValues->el[i] = new LinearMatrixElement();
1205  if (!(tmpValues->el[i]
1206  ->deepCopyFrom(((LinearMatrixValues*)baseMtx->value)->el[i])))
1207  throw ErrorClass("failed copying linear element values in method getMatrixCoefficientsInRowMajor()");
1208  for (int j=0; j<tmpValues->el[i]->numberOfVarIdx; j++)
1209  tmpValues->el[i]->varIdx[j]->coef *= scaleMult;
1210  }
1211  ExpandedMatrixInRowMajorForm->value = tmpValues;
1212  }
1213  else if (baseMtx->vType == ENUM_MATRIX_TYPE_general)
1214  {
1215  // add scalar multiple as a product
1216  GeneralMatrixValues* tmpValues = new GeneralMatrixValues();
1217  tmpValues->el = new ScalarExpressionTree*[baseMtx->valueSize];
1218  for (int i = 0; i < baseMtx->valueSize; i++)
1219  {
1220  tmpValues->el[i] = new ScalarExpressionTree();
1221  tmpValues->el[i]->m_treeRoot = new OSnLNodeTimes();
1222  tmpValues->el[i]->m_treeRoot->m_mChildren[0] = new OSnLNodeNumber();
1223  ((OSnLNodeNumber*)tmpValues->el[i]->m_treeRoot->m_mChildren[0])->value = scaleMult;
1224  tmpValues->el[i]->m_treeRoot->m_mChildren[1]
1225  = ((GeneralMatrixValues*)baseMtx->value)->el[i]->m_treeRoot
1227  }
1228  ExpandedMatrixInRowMajorForm->value = tmpValues;
1229  }
1230  else if (baseMtx->vType == ENUM_MATRIX_TYPE_objReference)
1231  {
1232  throw ErrorClass("scalar multiple not defined for objReference elements in getMatrixCoefficientsInRowMajor()");
1233  }
1234  else if (baseMtx->vType == ENUM_MATRIX_TYPE_conReference)
1235  {
1236  throw ErrorClass("scalar multiple not defined for conReference elements in getMatrixCoefficientsInRowMajor()");
1237  }
1239  }
1240  else // repositioned Basematrix with cropping
1241  {
1248 
1249  int startSize = numberOfRows + 1;
1250  int* tmpStarts = new int[startSize];
1251  for (int i=0; i < startSize; i++)
1252  tmpStarts[i] = 0;
1253 
1254  int adjc = icoff - base_c0;
1255  int lastcol = icoff + base_cN - base_c0 + 1;
1256  if (lastcol > numberOfRows)
1257  lastcol = numberOfRows;
1258 
1259  // count elements in each column and calculate starts
1260  for (int i=icoff; i<lastcol; i++)
1261  for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
1262  {
1263  if (baseMtx->index[j] >= base_r0 &&
1264  baseMtx->index[j] <= base_rN &&
1265  baseMtx->index[j] < numberOfColumns + base_r0 - iroff)
1266  tmpStarts[i+1]++;
1267  }
1268  for (int i=icoff+1; i <= startSize; i++)
1269  tmpStarts[i] += tmpStarts[i-1];
1270 
1271  int valueSize = tmpStarts[startSize-1];
1272  int* tmpIndexes = new int[valueSize];
1273 
1275  ExpandedMatrixInRowMajorForm->start = tmpStarts;
1276 
1277  // to get the values, go through the base matrix a second time
1278  if ( baseMtx->vType == ENUM_MATRIX_TYPE_constant)
1279  {
1280  MatrixElementValues* tmpValues = new ConstantMatrixValues();
1281  ((ConstantMatrixValues*)tmpValues)->el = new double[valueSize];
1282 
1283  int ival = 0;
1284  for (int i=icoff; i<lastcol; i++)
1285  for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
1286  {
1287  if (baseMtx->index[j] >= base_r0 &&
1288  baseMtx->index[j] <= base_rN &&
1289  baseMtx->index[j] < numberOfColumns + base_r0 - iroff)
1290  {
1291  tmpIndexes[ival] = baseMtx->index[j] - base_r0 + iroff;
1292  ((ConstantMatrixValues*)tmpValues)->el[ival]
1293  = scaleMult*((ConstantMatrixValues*)baseMtx->value)->el[j];
1294  ival++;
1295  }
1296  }
1297  ExpandedMatrixInRowMajorForm->index = tmpIndexes;
1298  ExpandedMatrixInRowMajorForm->value = tmpValues;
1299  }
1300 
1301  else if (baseMtx->vType == ENUM_MATRIX_TYPE_varReference)
1302  {
1303  if (scaleMult == 1)
1304  {
1305  MatrixElementValues* tmpValues = new VarReferenceMatrixValues();
1306  ((VarReferenceMatrixValues*)tmpValues)->el = new int[valueSize];
1307 
1308  int ival = 0;
1309  for (int i=icoff; i<lastcol; i++)
1310  for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
1311  {
1312  if (baseMtx->index[j] >= base_r0 &&
1313  baseMtx->index[j] < numberOfColumns + base_r0 - iroff)
1314  {
1315  tmpIndexes[ival] = baseMtx->index[j] + base_r0 - iroff;
1317  = scaleMult*((ConstantMatrixValues*)baseMtx->value)->el[j];
1318  ival++;
1319  }
1320  }
1321  ExpandedMatrixInRowMajorForm->index = tmpIndexes;
1322  ExpandedMatrixInRowMajorForm->value = tmpValues;
1323  }
1324  else
1325  {
1326  // must convert to linear elements
1327  MatrixElementValues* tmpValues = new LinearMatrixValues();
1328  ((LinearMatrixValues*)tmpValues)->el
1329  = new LinearMatrixElement*[valueSize];
1330 
1331  int ival = 0;
1332  for (int i=icoff; i<lastcol; i++)
1333  for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
1334  {
1335  if (baseMtx->index[j] >= base_r0 &&
1336  baseMtx->index[j] < numberOfColumns + base_r0 - iroff)
1337  {
1338  ((LinearMatrixValues*)tmpValues)->el[ival]
1339  = new LinearMatrixElement();
1340  ((LinearMatrixValues*)tmpValues)->el[ival]->numberOfVarIdx = 1;
1341  ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx
1342  = new LinearMatrixElementTerm*[1];
1343  ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx[0]
1344  = new LinearMatrixElementTerm();
1345  ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx[0]->coef
1346  = scaleMult;
1347  ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx[0]->idx
1348  = ((VarReferenceMatrixValues*)baseMtx->value)->el[j];
1349  ival++;
1350  }
1351  }
1352  ExpandedMatrixInRowMajorForm->index = tmpIndexes;
1353  ExpandedMatrixInRowMajorForm->value = tmpValues;
1354  }
1355  }
1356  else if (baseMtx->vType == ENUM_MATRIX_TYPE_linear)
1357  {
1358  LinearMatrixValues* tmpValues = new LinearMatrixValues();
1359  tmpValues->el = new LinearMatrixElement*[baseMtx->valueSize];
1360 
1361  int ival = 0;
1362  for (int i=icoff; i<lastcol; i++)
1363  for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
1364  {
1365  if (baseMtx->index[j] >= base_r0 &&
1366  baseMtx->index[j] < numberOfColumns + base_r0 - iroff)
1367  {
1368  tmpValues->el[ival] = new LinearMatrixElement();
1369  if (!(tmpValues->el[ival]
1370  ->deepCopyFrom(((LinearMatrixValues*)baseMtx->value)->el[j])))
1371  throw ErrorClass("failed copying linear element values in method getMatrixCoefficientsInRowMajor()");
1372  for (int k=0; k<tmpValues->el[ival]->numberOfVarIdx; k++)
1373  tmpValues->el[ival]->varIdx[k]->coef *= scaleMult;
1374  ival++;
1375  }
1376  }
1377  ExpandedMatrixInRowMajorForm->index = tmpIndexes;
1378  ExpandedMatrixInRowMajorForm->value = tmpValues;
1379  }
1380  else if (baseMtx->vType == ENUM_MATRIX_TYPE_general)
1381  {
1382  if (scaleMult == 1)
1383  {
1384  GeneralMatrixValues* tmpValues = new GeneralMatrixValues();
1385  tmpValues->el = new ScalarExpressionTree*[baseMtx->valueSize];
1386 
1387  int ival = 0;
1388  for (int i=icoff; i<lastcol; i++)
1389  for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
1390  {
1391  if (baseMtx->index[j] >= base_r0 &&
1392  baseMtx->index[j] < numberOfColumns + base_r0 - iroff)
1393  {
1394  ((GeneralMatrixValues*)tmpValues)->el[ival]
1395  = new ScalarExpressionTree();
1396 // ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot
1397 // = new OSnLNode();
1398  ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot
1399  = ((GeneralMatrixValues*)baseMtx->value)->el[j]->m_treeRoot
1400  ->copyNodeAndDescendants();
1401  ival++;
1402  }
1403  }
1404  ExpandedMatrixInRowMajorForm->index = tmpIndexes;
1405  ExpandedMatrixInRowMajorForm->value = tmpValues;
1406  }
1407  else
1408  {
1409  // add scalar multiple as a product
1410  GeneralMatrixValues* tmpValues = new GeneralMatrixValues();
1411  tmpValues->el = new ScalarExpressionTree*[baseMtx->valueSize];
1412  int ival = 0;
1413  for (int i=icoff; i<lastcol; i++)
1414  for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
1415  {
1416  if (baseMtx->index[j] >= base_r0 &&
1417  baseMtx->index[j] < numberOfColumns + base_r0 - iroff)
1418  {
1419  ((GeneralMatrixValues*)tmpValues)->el[ival]
1420  = new ScalarExpressionTree();
1421  ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot
1422  = new OSnLNodeTimes();
1423  ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot->m_mChildren[0]
1424  = new OSnLNodeNumber();
1425  ((OSnLNodeNumber*)tmpValues->el[ival]->m_treeRoot->m_mChildren[0])->value = scaleMult;
1426  ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot->m_mChildren[1]
1427  = ((GeneralMatrixValues*)baseMtx->value)->el[j]->m_treeRoot->copyNodeAndDescendants();
1428  ival++;
1429 
1430  }
1431  }
1432  ExpandedMatrixInRowMajorForm->index = tmpIndexes;
1433  ExpandedMatrixInRowMajorForm->value = tmpValues;
1434  }
1435  }
1436  else if (baseMtx->vType == ENUM_MATRIX_TYPE_objReference)
1437  {
1438  throw ErrorClass("scalar multiple not defined for objReference elements in getMatrixCoefficientsInRowMajor()");
1439  }
1440  else if (baseMtx->vType == ENUM_MATRIX_TYPE_conReference)
1441  {
1442  throw ErrorClass("scalar multiple not defined for conReference elements in getMatrixCoefficientsInRowMajor()");
1443  }
1444  }
1446  }
1447  }
1448 
1450  {
1451  //make sure the blocks have been expanded, then retrieve them
1452  if (!processBlocks(true, symmetry))
1453  throw ErrorClass("error processing blocks in getMatrixCoefficientsInRowMajor()");
1454 
1455  ExpandedMatrixBlocks* currentBlocks
1457  m_iColumnPartitionSize, true, true);
1458  //ExpandedMatrixByBlocks.push_back(currentBlocks);
1459 
1469  for (int i=0; i <= numberOfRows; i++)
1471 
1472  // augment column lengths block by block
1473  for (int i=0; i < currentBlocks->blockNumber; i++)
1474  {
1475  int c0 = currentBlocks->colOffset[currentBlocks->blockColumns[i]];
1476  int cN = currentBlocks->colOffset[currentBlocks->blockColumns[i]+1];
1477  for (int j = c0; j < cN; j++)
1478  {
1480  ( currentBlocks->blocks[i]->start[j+1-c0]
1481  - currentBlocks->blocks[i]->start[j -c0] );
1482  }
1483  }
1484 
1485  for (int i=1; i <= numberOfRows; i++)
1490  int* tmpIndexes = new int[ExpandedMatrixInRowMajorForm->valueSize];
1491 
1492  // go through the blocks a second time to store values --- based on type
1493  if (currentBlocks->blocks[0]->vType == ENUM_MATRIX_TYPE_constant)
1494  {
1495  ConstantMatrixValues* tmpValues = new ConstantMatrixValues();
1496  tmpValues->el
1497  = new double[ExpandedMatrixInRowMajorForm->valueSize];
1498 
1499  for (int i=0; i < currentBlocks->blockNumber; i++)
1500  {
1501  int c0 = currentBlocks->rowOffset[currentBlocks->blockRows[i]];
1502  int cN = currentBlocks->rowOffset[currentBlocks->blockRows[i]+1];
1503  int row_adj = currentBlocks->colOffset[currentBlocks->blockColumns[i]];
1504 
1505  for (int j = c0; j < cN; j++)
1506  {
1507  int loc = ExpandedMatrixInRowMajorForm->start[j];
1508  for (int k = currentBlocks->blocks[i]->start[j-c0];
1509  k < currentBlocks->blocks[i]->start[j-c0+1]; k++)
1510  {
1511  tmpIndexes[loc] = currentBlocks->blocks[i]->index[k] + row_adj;
1512  ((ConstantMatrixValues*)tmpValues)->el[loc]
1513  = ((ConstantMatrixValues*)currentBlocks->blocks[i]->value)->el[k];
1514  loc++;
1515  }
1517  }
1518  }
1519  ExpandedMatrixInRowMajorForm->index = tmpIndexes;
1520  ExpandedMatrixInRowMajorForm->value = tmpValues;
1521  }
1522  else
1523  throw ErrorClass("getMatrixCoefficientsInRowMajor: Can only handle constant values so far in blocks");
1524  for (int i=numberOfColumns; i > 0; i--)
1529  }
1530 
1532  {
1533 // transformation: see if we can do at least AB, A'B, AB'
1534 // for now:
1535  throw ErrorClass("transformations not yet implemented in getMatrixCoefficientsInColumnMajor()");
1536  }
1537  else // some kind of elements --- if given row-wise, just copy pointers
1538  {
1539  if (((MatrixElements*)m_mChildren[0])->rowMajor)
1540  {
1549  = ((MatrixElements*)m_mChildren[0])->numberOfValues;
1551  = ((MatrixElements*)m_mChildren[0])->start->el;
1553  = getMatrixType();
1555  = ((MatrixElements*)m_mChildren[0])->index->el;
1558  = ((ConstantMatrixElements*)m_mChildren[0])->value;
1561  = ((VarReferenceMatrixElements*)m_mChildren[0])->value;
1564  = ((LinearMatrixElements*)m_mChildren[0])->value;
1567  = ((GeneralMatrixElements*)m_mChildren[0])->value;
1570  = ((ObjReferenceMatrixElements*)m_mChildren[0])->value;
1573  = ((ConReferenceMatrixElements*)m_mChildren[0])->value;
1574  else
1575  throw ErrorClass("Unknown element type in getMatrixCoefficientsInRowMajor()");
1576 
1578  }
1579 
1580  else // elements are given column-wise and must be "turned"
1581  {
1582  MatrixElements* refMtx = (MatrixElements*)m_mChildren[0];
1583 
1589  for (int i=0; i <= numberOfRows; i++)
1591 
1592  //if <values> is empty, return an empty matrix
1593  if (refMtx == NULL || refMtx->numberOfValues == 0)
1594  {
1597  }
1598 
1601 
1602  int i, j, iTemp;
1603  int iNumSource = numberOfColumns;
1604 
1605  for (i = 0; i < numberOfColumns; i++)
1606  {
1607  for (j = refMtx->start->el[i]; j < refMtx->start->el[i + 1]; j++)
1608  {
1609  ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j] + 1] ++;
1610  }
1611  }
1613 
1614  for (i = 1; i <= numberOfRows; i++ )
1615  {
1617  += ExpandedMatrixInRowMajorForm->start [i - 1] ;
1618  }
1619 
1620  // store the elements, by type
1622  {
1625  = new double[refMtx->numberOfValues];
1626 
1627  for (i = 0; i < numberOfColumns; i++)
1628  {
1629  // get column indices and values of the matrix
1630  for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
1631  {
1632  iTemp = ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]];
1633  ExpandedMatrixInRowMajorForm->index[ iTemp] = i;
1635  = ((ConstantMatrixValues*)((ConstantMatrixElements*)refMtx)->value)->el[j];
1636  ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]] ++;
1637  }
1638  }
1639  }
1641  {
1644  = new int[refMtx->numberOfValues];
1645 
1646  for (i = 0; i < numberOfColumns; i++)
1647  {
1648  // get column indices and values of the matrix
1649  for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
1650  {
1651  iTemp = ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]];
1652  ExpandedMatrixInRowMajorForm->index[ iTemp] = i;
1654  = ((VarReferenceMatrixValues*)((VarReferenceMatrixElements*)refMtx)->value)->el[j];
1655  ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]] ++;
1656  }
1657  }
1658  }
1660  {
1663  = new LinearMatrixElement*[refMtx->numberOfValues];
1664  for (i = 0; i < refMtx->numberOfValues; i++)
1666  = new LinearMatrixElement();
1667 
1668  for (i = 0; i < numberOfColumns; i++)
1669  {
1670  // get column indices and values of the matrix
1671  for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
1672  {
1673  iTemp = ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]];
1674  ExpandedMatrixInRowMajorForm->index[ iTemp] = i;
1676  el[ iTemp]->deepCopyFrom(((LinearMatrixValues*)
1677  ((LinearMatrixElements*)refMtx)->value)->el[j]))
1678  return NULL;
1679  ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]] ++;
1680  }
1681  }
1682  }
1684  {
1687  = new ScalarExpressionTree*[refMtx->numberOfValues];
1688  for (i = 0; i < refMtx->numberOfValues; i++)
1689  {
1691  = new ScalarExpressionTree();
1692  }
1693 
1694  for (i = 0; i < numberOfColumns; i++)
1695  {
1696  // get column indices and values of the matrix
1697  for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
1698  {
1699  iTemp = ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]];
1700  ExpandedMatrixInRowMajorForm->index[ iTemp] = i;
1701  ((GeneralMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el[ iTemp]->m_treeRoot
1702  = ((GeneralMatrixValues*)((GeneralMatrixElements*)refMtx)->value)->el[j]->m_treeRoot->copyNodeAndDescendants();
1703  ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]] ++;
1704  }
1705  }
1706  }
1708  {
1711  = new int[refMtx->numberOfValues];
1712 
1713  for (i = 0; i < numberOfColumns; i++)
1714  {
1715  // get column indices and values of the matrix
1716  for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
1717  {
1718  iTemp = ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]];
1719  ExpandedMatrixInRowMajorForm->index[ iTemp] = i;
1721  = ((ObjReferenceMatrixValues*)((ObjReferenceMatrixElements*)refMtx)->value)->el[j];
1722  ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]] ++;
1723  }
1724  }
1725  }
1727  {
1730  = new ConReferenceMatrixElement*[refMtx->numberOfValues];
1731  for (i = 0; i < refMtx->numberOfValues; i++)
1733  = new ConReferenceMatrixElement();
1734 
1735  for (i = 0; i < numberOfColumns; i++)
1736  {
1737  // get column indices and values of the matrix
1738  for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
1739  {
1740  iTemp = ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]];
1741  ExpandedMatrixInRowMajorForm->index[ iTemp] = i;
1743  return NULL;
1744  ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]] ++;
1745  }
1746  }
1747  }
1748 
1749  // readjust the starts
1750  for (i = numberOfRows; i >= 1; i-- )
1751  {
1754  }
1755 
1758  }
1759  }
1760  }
1761 
1762  else // two or more constructors --- worry about overwriting and number of elements
1763  {
1764 /*
1765  (basematrix plus) elements should be ok
1766  maybe transformation (product) plus elements
1767  others: throw error
1768 */
1769  throw ErrorClass("Multiple constructors not yet implemented in getMatrixCoefficientsInRowMajor()");
1770  }
1771  return NULL;
1772  }
1773  catch(const ErrorClass& eclass)
1774  {
1775  throw ErrorClass( eclass.errormsg);
1776  }
1777 }// end of getMatrixCoefficientsInRowMajor
1778 
1779 bool MatrixType::expandElements(bool rowMajor)
1780 {
1781  return NULL;
1782 }// end of expandElements
1783 
1785 {
1786  try
1787  {
1788  GeneralSparseMatrix* tmp;
1789 
1790  if (rowMajor_)
1791  {
1792  if (ExpandedMatrixInRowMajorForm == NULL)
1793  return false;
1795  }
1796  else
1797  {
1798  if (ExpandedMatrixInColumnMajorForm == NULL)
1799  return false;
1801  }
1802 
1803  std::ostringstream outStr;
1804 
1806 
1808  {
1809  outStr << "matrix " << ((OSMatrix*)this)->idx;
1810  if (((OSMatrix*)this)->name != "")
1811  outStr << " (" << ((OSMatrix*)this)->name << ")";
1812  outStr << std::endl;
1813  }
1815  outStr << "matrix block" << std::endl;
1816  else
1817  throw ErrorClass("matrix type unknown or not set");
1818 
1819  outStr << "number of rows " << numberOfRows << std::endl;
1820  outStr << "number of columns " << numberOfColumns << std::endl;
1821  outStr << "number of nonzeros " << tmp->valueSize << std::endl;
1822  outStr << "type of nonzeros " << returnMatrixTypeString(tmp->vType) << std::endl;
1823  outStr << "symmetry " << returnMatrixSymmetryString(symmetry) << std::endl;
1824 
1825  outStr << std::endl << "These matrix arrays are organized ";
1826  if (rowMajor_)
1827  outStr << "by rows" << std::endl;
1828  else
1829  outStr << "by columns" << std::endl;
1830 
1831  outStr << std::endl << "starts:";
1832  for (int i=0; i < tmp->startSize; i++)
1833  outStr << " " << tmp->start[i];
1834  outStr << std::endl;
1835 
1836  outStr << std::endl << "indexes:";
1837  for (int i=0; i < tmp->valueSize; i++)
1838  outStr << " " << tmp->index[i];
1839  outStr << std::endl;
1840 
1841  outStr << std::endl << "values:";
1843  {
1844  for (int i=0; i < tmp->valueSize; i++)
1845  outStr << " " << ((ConstantMatrixValues*)tmp->value)->el[i];
1846  outStr << std::endl;
1847  }
1848  else if (tmp->vType == ENUM_MATRIX_TYPE_varReference)
1849  {
1850  for (int i=0; i < tmp->valueSize; i++)
1851  outStr << " " << ((VarReferenceMatrixValues*)tmp->value)->el[i];
1852  outStr << std::endl;
1853  }
1854  else if (tmp->vType == ENUM_MATRIX_TYPE_objReference)
1855  {
1856  for (int i=0; i < tmp->valueSize; i++)
1857  outStr << " " << ((ObjReferenceMatrixValues*)tmp->value)->el[i];
1858  outStr << std::endl;
1859  }
1860  else if (tmp->vType == ENUM_MATRIX_TYPE_conReference)
1861  {
1862  for (int i=0; i < tmp->valueSize; i++)
1863  outStr << " " << ((ConReferenceMatrixValues*)tmp->value)->el[i]->conReference;
1864  outStr << std::endl;
1865  }
1866  else if (tmp->vType == ENUM_MATRIX_TYPE_general)
1867  {
1868  outStr << std::endl;
1869  for (int i=0; i < tmp->valueSize; i++)
1870  outStr << "element " << i << ": (general expression; not yet implemented)" << std::endl;
1871  outStr << std::endl;
1872  }
1873  else if (tmp->vType == ENUM_MATRIX_TYPE_linear)
1874  {
1875  outStr << std::endl;
1876  for (int i=0; i < tmp->valueSize; i++)
1877  {
1878  outStr << "element " << i << ": ";
1879 
1880  double c = ((LinearMatrixElement*)((LinearMatrixValues*)tmp->value)->el[i])->constant;
1881  int m = ((LinearMatrixElement*)((LinearMatrixValues*)tmp->value)->el[i])->numberOfVarIdx;
1882  if (c != 0)
1883  {
1884  outStr << c;
1885  if (m > 0)
1886  outStr << " + ";
1887  }
1888 
1890  for (int j=0; j<m; j++)
1891  {
1892  if (j > 0)
1893  outStr << " + ";
1894  temp = ((LinearMatrixElement*)((LinearMatrixValues*)tmp->value)->el[i])->varIdx[j];
1895  if (temp->coef != 1)
1896  outStr << temp->coef << "*";
1897  outStr << "x[" << temp->idx << "]";
1898  }
1899  outStr << std::endl;
1900  }
1901  outStr << std::endl;
1902  }
1904 
1905  return true;
1906  }
1907  catch(const ErrorClass& eclass)
1908  {
1909  throw ErrorClass( eclass.errormsg);
1910  }
1911 }// end of printExpandedMatrix
1912 
1914 // bool isColumnMajor, int startSize, int valueSize, int* start, int* index,
1915 // double* value, int dimension)
1916 {
1917 #ifndef NDEBUG
1918  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside convertToOtherMajor()");
1919 #endif
1920  GeneralSparseMatrix* refMtx;
1921  if (isColumnMajor)
1922  {
1925  }
1926  else
1927  {
1930  }
1931  if (refMtx == NULL ) return NULL;
1932  if (refMtx->start == NULL || refMtx->startSize <= 1 ) return NULL;
1933 
1934  int iStartSize = isColumnMajor ? numberOfRows+1 : numberOfColumns+1;
1935  GeneralSparseMatrix *matrix
1936  = new GeneralSparseMatrix( !isColumnMajor, iStartSize, refMtx->valueSize, refMtx->vType);
1937 
1938  int i,j, iTemp;
1939  int iNumSource = refMtx->startSize - 1;
1940 
1941  int* miStart = matrix->start;
1942  int* miIndex = matrix->index;
1943 
1944  for ( i = 1; i < iStartSize; i++)
1945  {
1946  miStart [ i ] = 0;
1947  }
1948  // for illustration assume we are converting from column to row major
1949  // i is indexing columns and j is indexing row numbers
1950  for (i = 0; i < iNumSource; i++)
1951  {
1952  for (j = refMtx->start[i]; j < refMtx->start[ i + 1 ]; j++)
1953  {
1954  // index[ j] is a row index, we have just found an occurance of row index[j]
1955  // therefore we increase by 1 (or push back) the start of the row indexed by index[j] + 1,
1956  // i.e. the start of the next row
1957  miStart[refMtx->index[j] + 1] ++;
1958  }
1959  }
1960  // at this point, miStart[ i] holds the number of columns with a nonzero in row i - 1
1961  // if we knew the correct starting point of row i -1, the correct starting point
1962  // for row i is miStart[i] + miStart [i - 1]
1963  miStart[0] = 0;
1964  for (i = 1; i < iStartSize; i++ )
1965  {
1966  miStart[i] += miStart [i - 1] ;
1967  }
1968 
1969  // now get the correct values
1970  // again assume we are converting column major to row major
1971  // loop over columns
1972  // this is a bit tedious, since different types of elements need to be treated differently
1973  if ( refMtx->vType == ENUM_MATRIX_TYPE_constant)
1974  {
1975  matrix->value = new ConstantMatrixValues();
1976  ((ConstantMatrixValues*)matrix->value)->el = new double[refMtx->valueSize];
1977 
1978  for (i = 0; i < iNumSource; i++)
1979  {
1980  // get row indices and values of the matrix
1981  for (j = refMtx->start[i]; j < refMtx->start[ i + 1 ]; j++)
1982  {
1983  iTemp = miStart[refMtx->index[j]];
1984  miIndex [ iTemp] = i;
1985  ((ConstantMatrixValues*)matrix->value)->el[ iTemp]
1986  = ((ConstantMatrixValues*)refMtx->value)->el[j];
1987  miStart[refMtx->index[j]] ++;
1988  }
1989  }
1990  }
1991  else if (refMtx->vType == ENUM_MATRIX_TYPE_varReference)
1992  {
1993  matrix->value = new VarReferenceMatrixValues();
1994  ((VarReferenceMatrixValues*)matrix->value)->el = new int[refMtx->valueSize];
1995 
1996  for (i = 0; i < iNumSource; i++)
1997  {
1998  // get row indices and values of the matrix
1999  for (j = refMtx->start[i]; j < refMtx->start[ i + 1 ]; j++)
2000  {
2001  iTemp = miStart[refMtx->index[j]];
2002  miIndex [ iTemp] = i;
2003  ((VarReferenceMatrixValues*)matrix->value)->el[ iTemp]
2004  = ((VarReferenceMatrixValues*)refMtx->value)->el[j];
2005  miStart[refMtx->index[j]] ++;
2006  }
2007  }
2008  }
2009  else if (refMtx->vType == ENUM_MATRIX_TYPE_linear)
2010  {
2011  matrix->value = new LinearMatrixValues();
2012  ((LinearMatrixValues*)matrix->value)->el = new LinearMatrixElement*[refMtx->valueSize];
2013  for (i = 0; i < refMtx->valueSize; i++)
2014  ((LinearMatrixValues*)matrix->value)->el[i] = new LinearMatrixElement();
2015 
2016  for (i = 0; i < iNumSource; i++)
2017  {
2018  // get row indices and values of the matrix
2019  for (j = refMtx->start[i]; j < refMtx->start[ i + 1 ]; j++)
2020  {
2021  iTemp = miStart[refMtx->index[j]];
2022  miIndex [ iTemp] = i;
2023  if (!((LinearMatrixValues*)matrix->value)->el[ iTemp]->deepCopyFrom(((LinearMatrixValues*)refMtx->value)->el[j]))
2024  return NULL;
2025  miStart[refMtx->index[j]] ++;
2026  }
2027  }
2028  }
2029  else if (refMtx->vType == ENUM_MATRIX_TYPE_general)
2030  {
2031  matrix->value = new GeneralMatrixValues();
2032  ((GeneralMatrixValues*)matrix->value)->el = new ScalarExpressionTree*[refMtx->valueSize];
2033  for (i = 0; i < refMtx->valueSize; i++)
2034  {
2035  ((GeneralMatrixValues*)matrix->value)->el[i] = new ScalarExpressionTree();
2036  }
2037  for (i = 0; i < iNumSource; i++)
2038  {
2039  // get row indices and values of the matrix
2040  for (j = refMtx->start[i]; j < refMtx->start[ i + 1 ]; j++)
2041  {
2042  iTemp = miStart[refMtx->index[j]];
2043  miIndex [ iTemp] = i;
2044  ((GeneralMatrixValues*)matrix->value)->el[ iTemp]->m_treeRoot
2045  = ((GeneralMatrixValues*)refMtx->value)->el[j]->m_treeRoot->copyNodeAndDescendants();
2046  miStart[refMtx->index[j]] ++;
2047  }
2048  }
2049  }
2050  else if (refMtx->vType == ENUM_MATRIX_TYPE_objReference)
2051  {
2052  matrix->value = new ObjReferenceMatrixValues();
2053  ((ObjReferenceMatrixValues*)matrix->value)->el = new int[refMtx->valueSize];
2054 
2055  for (i = 0; i < iNumSource; i++)
2056  {
2057  // get row indices and values of the matrix
2058  for (j = refMtx->start[i]; j < refMtx->start[ i + 1 ]; j++)
2059  {
2060  iTemp = miStart[refMtx->index[j]];
2061  miIndex [ iTemp] = i;
2062  ((ObjReferenceMatrixValues*)matrix->value)->el[ iTemp]
2063  = ((ObjReferenceMatrixValues*)refMtx->value)->el[j];
2064  miStart[refMtx->index[j]] ++;
2065  }
2066  }
2067  }
2068  else if (refMtx->vType == ENUM_MATRIX_TYPE_conReference)
2069  {
2070  matrix->value = new ConReferenceMatrixValues();
2071  ((ConReferenceMatrixValues*)matrix->value)->el
2072  = new ConReferenceMatrixElement*[refMtx->valueSize];
2073  for (i = 0; i < refMtx->valueSize; i++)
2074  ((ConReferenceMatrixValues*)matrix->value)->el[i] = new ConReferenceMatrixElement();
2075 
2076  for (i = 0; i < iNumSource; i++)
2077  {
2078  // get row indices and values of the matrix
2079  for (j = refMtx->start[i]; j < refMtx->start[ i + 1 ]; j++)
2080  {
2081  iTemp = miStart[refMtx->index[j]];
2082  miIndex [ iTemp] = i;
2083  if (!((ConReferenceMatrixValues*)matrix->value)->el[ iTemp]->deepCopyFrom(((ConReferenceMatrixValues*)refMtx->value)->el[j]))
2084  return NULL;
2085  miStart[refMtx->index[j]] ++;
2086  }
2087  }
2088  }
2089 
2090  // miStart[ i] is now equal to miStart[ i + 1], so readjust
2091  for (i = iStartSize - 1; i >= 1; i-- )
2092  {
2093  miStart[i] = miStart [i - 1] ;
2094  }
2095 
2096  miStart[0] = 0;
2097  return matrix;
2098 }//end of MatrixType::convertToOtherMajor
2099 
2101 {
2102  if (!m_bHaveRowPartition)
2103  {
2104  bool OK = processBlockPartition();
2105  if (!OK) throw ErrorClass("Error processing blocks");
2106  }
2107  return m_iRowPartitionSize;
2108 }// end of MatrixType::getRowPartitionSize()
2109 
2111 {
2112  if (!m_bHaveRowPartition)
2113  {
2114  bool OK = processBlockPartition();
2115  if (!OK) throw ErrorClass("Error processing blocks");
2116  }
2117  return m_miRowPartition;
2118 }// end of MatrixType::getRowPartition()
2119 
2121 {
2122  if (!m_bHaveColumnPartition)
2123  {
2124  bool OK = processBlockPartition();
2125  if (!OK) throw ErrorClass("Error processing blocks");
2126  }
2127  return m_iColumnPartitionSize;
2128 }// end of MatrixType::getColumnPartitionSize()
2129 
2131 {
2132  if (!m_bHaveColumnPartition)
2133  {
2134  bool OK = processBlockPartition();
2135  if (!OK) throw ErrorClass("Error processing blocks");
2136  }
2137  return m_miColumnPartition;
2138 }// end of MatrixType::getColumnPartition()
2139 
2140 
2142 {
2143 #ifndef NDEBUG
2144  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside processBlockPartition()");
2145 #endif
2146  if (matrixHasBlocks())
2147  {
2148  int nPartitions = 0;
2149  int imerge_R;
2150  int imerge_C;
2151 
2152  for (unsigned int i=0; i < inumberOfChildren; i++)
2153  {
2155  {
2156  if (nPartitions == 0)
2157  {
2158  // first blocks constructor. Set up data structures
2159  nPartitions++;
2160  m_iRowPartitionSize = ((MatrixBlocks*)m_mChildren[i])->rowOffset->numberOfEl;
2162  for (int j=0; j<m_iRowPartitionSize; j++)
2163  m_miRowPartition[j] = ((MatrixBlocks*)m_mChildren[i])->rowOffset->el[j];
2164  m_iColumnPartitionSize = ((MatrixBlocks*)m_mChildren[i])->colOffset->numberOfEl;
2166  for (int j=0; j<m_iColumnPartitionSize; j++)
2167  m_miColumnPartition[j] = ((MatrixBlocks*)m_mChildren[i])->colOffset->el[j];
2168  }
2169  else
2170  {
2171  //another block constructor. merge row partitions
2172  nPartitions++;
2173  int i0 = 0;
2174  int itemp = 0;
2175  imerge_R = 0;
2176  for (;;)
2177  {
2178  if (m_miRowPartition[i0] == ((MatrixBlocks*)m_mChildren[i])->rowOffset->el[itemp])
2179  {
2180  if (imerge_R != i0) m_miRowPartition[imerge_R] = m_miRowPartition[i0];
2181  i0++;
2182  itemp++;
2183  imerge_R++;
2184  }
2185  else
2186  {
2187  if (m_miRowPartition[i0] <
2188  ((MatrixBlocks*)m_mChildren[i])->rowOffset->el[itemp])
2189  i0++;
2190  else
2191  itemp++;
2192  }
2193  if (i0 >= m_iRowPartitionSize ||
2194  itemp >= ((MatrixBlocks*)m_mChildren[i])->rowOffset->numberOfEl)
2195  break;
2196  }
2197  m_iRowPartitionSize = imerge_R;
2198 
2199  // merge column partitions
2200  i0 = 0;
2201  itemp = 0;
2202  imerge_C = 0;
2203  for (;;)
2204  {
2205  if (m_miColumnPartition[i0] ==
2206  ((MatrixBlocks*)m_mChildren[i])->colOffset->el[itemp])
2207  {
2208  if (imerge_C != i0) m_miColumnPartition[imerge_C] = m_miColumnPartition[i0];
2209  i0++;
2210  itemp++;
2211  imerge_C++;
2212  }
2213  else
2214  {
2215  if (m_miColumnPartition[i0] <
2216  ((MatrixBlocks*)m_mChildren[i])->colOffset->el[itemp])
2217  i0++;
2218  else
2219  itemp++;
2220  }
2221  if (i0 >= m_iColumnPartitionSize ||
2222  itemp >= ((MatrixBlocks*)m_mChildren[i])->colOffset->numberOfEl)
2223  break;
2224  }
2225  m_iColumnPartitionSize = imerge_C;
2226  }
2227  }
2228  }
2229  if (nPartitions > 1)
2230  {
2231  int* tempPartition = new int[imerge_R];
2232  for (int i=0; i < imerge_R; i++)
2233  tempPartition[i] = m_miRowPartition[i];
2234  delete [] m_miRowPartition;
2235  m_miRowPartition = tempPartition;
2236 
2237  tempPartition = new int[imerge_C];
2238  for (int i=0; i < imerge_C; i++)
2239  tempPartition[i] = m_miColumnPartition[i];
2240  delete [] m_miColumnPartition;
2241  m_miColumnPartition = tempPartition;
2242  }
2243  }
2244  else
2245  {
2246  m_iRowPartitionSize = 2;
2247  m_miRowPartition = new int[2];
2248  m_miRowPartition[0] = 0;
2251  m_miColumnPartition = new int[2];
2252  m_miColumnPartition[0] = 0;
2254  }
2255  m_bHaveRowPartition = true;
2256  m_bHaveColumnPartition = true;
2257  return true;
2258 }// end of processBlockPartition
2259 
2261 {
2262 #ifndef NDEBUG
2263  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside getMatrixBlockInColumnMajorForm()");
2264 #endif
2265  return NULL;
2266 }// end of MatrixType::getMatrixBlockInColumnMajorForm
2267 
2268 ExpandedMatrixBlocks* MatrixType::getBlocks(int* rowPartition, int rowPartitionSize,
2269  int* colPartition, int colPartitionSize,
2270  bool rowMajor, bool appendToBlockArray)
2271 {
2272 #ifndef NDEBUG
2273  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside getBlocks()");
2274 #endif
2275 
2276  // Try to find a collection of blocks that matches the criteria
2277  for (size_t kount = 0; kount < ExpandedMatrixByBlocks.size(); kount++)
2278  {
2279  if (rowPartitionSize != ExpandedMatrixByBlocks[kount]->rowOffsetSize ||
2280  colPartitionSize != ExpandedMatrixByBlocks[kount]->colOffsetSize ||
2281  rowMajor != ExpandedMatrixByBlocks[kount]->isRowMajor)
2282  continue;
2283 
2284  for (int i=0; i < rowPartitionSize; i++)
2285  if (rowPartition[i] != ExpandedMatrixByBlocks[kount]->rowOffset[i])
2286  continue;
2287  for (int i=0; i < colPartitionSize; i++)
2288  if (colPartition[i] != ExpandedMatrixByBlocks[kount]->colOffset[i])
2289  continue;
2290 
2291  return ExpandedMatrixByBlocks[kount];
2292  }
2293 
2294  // not found; create a new collection
2295  if (!appendToBlockArray) return NULL;
2296 
2297  if (!processBlocks(rowPartition, rowPartitionSize,
2298  colPartition, colPartitionSize, false, symmetry))
2299  return NULL;
2300  return ExpandedMatrixByBlocks.back();
2301 }// end of MatrixType::getBlocks
2302 
2304 {
2305  int cSize = getColumnPartitionSize();
2306  int rSize = getRowPartitionSize();
2307  int* cPartition = getColumnPartition();
2308  int* rPartition = getRowPartition();
2309  return processBlocks(rPartition, rSize, cPartition, cSize, rowMajor, symmetry);
2310 }// end of MatrixType::processBlocks
2311 
2312 bool MatrixType::processBlocks(int* rowOffset, int rowOffsetSize, int* colOffset,
2313  int colOffsetSize, bool rowMajor, ENUM_MATRIX_SYMMETRY symmetry)
2314 {
2315 #ifndef NDEBUG
2316  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside processBlocks()");
2317 #endif
2318  try
2319  {
2320  ENUM_MATRIX_TYPE elType = getMatrixType();
2321 
2322  // check for blocks constructor with matching partition
2323  if (inumberOfChildren == 1)
2324  {
2326  {
2327  if (((MatrixBlocks*)m_mChildren[0])->rowOffset->numberOfEl != rowOffsetSize ||
2328  ((MatrixBlocks*)m_mChildren[0])->colOffset->numberOfEl != colOffsetSize)
2329  goto none_found;
2330 
2331  for (int j=0; j < rowOffsetSize; j++)
2332  if (((MatrixBlocks*)m_mChildren[0])->rowOffset->el[j] != rowOffset[j])
2333  goto none_found;
2334 
2335  for (int j=0; j < colOffsetSize; j++)
2336  if (((MatrixBlocks*)m_mChildren[0])->colOffset->el[j] != colOffset[j])
2337  goto none_found;
2338 
2339  // Here we have matching block partitions
2340  ExpandedMatrixBlocks* tmpBlocks = new ExpandedMatrixBlocks();
2341 
2342  tmpBlocks->bDeleteArrays = false;
2343  tmpBlocks->vType = elType;
2344  tmpBlocks->isRowMajor = rowMajor;
2345  tmpBlocks->rowOffsetSize = rowOffsetSize;
2346  tmpBlocks->colOffsetSize = colOffsetSize;
2347  tmpBlocks->rowOffset = rowOffset;
2348  tmpBlocks->colOffset = colOffset;
2349 
2350  // access each block; expand and convert if necessary, count (and suppress if empty)
2351  MatrixBlock* tmpChild;
2352  int tmpBlockNumber = 0;
2353  int tmpBlockSize;
2354  for (unsigned int j=0; j<((MatrixBlocks*)m_mChildren[0])->inumberOfChildren; j++)
2355  {
2356  tmpChild = (MatrixBlock*)((MatrixBlocks*)m_mChildren[0])->m_mChildren[j];
2357  if (rowMajor)
2358  {
2359  tmpChild->getMatrixCoefficientsInRowMajor();
2360  if (tmpChild->ExpandedMatrixInRowMajorForm->valueSize > 0)
2361  tmpBlockNumber++;
2362  }
2363  else
2364  {
2366  if (tmpChild->ExpandedMatrixInColumnMajorForm->valueSize > 0)
2367  tmpBlockNumber++;
2368  }
2369  }
2370 
2371  // We know the number of blocks; allocate memory
2372  tmpBlocks->blockNumber = tmpBlockNumber;
2373  tmpBlocks->blocks = new GeneralSparseMatrix*[tmpBlockNumber];
2374  tmpBlocks->blockRows = new int[tmpBlockNumber];
2375  tmpBlocks->blockColumns = new int[tmpBlockNumber];
2376 
2377  // go through blocks again and store pointers
2378  tmpBlockNumber = 0;
2379  for (unsigned int j=0; j<((MatrixBlocks*)m_mChildren[0])->inumberOfChildren; j++)
2380  {
2381  tmpChild = (MatrixBlock*)((MatrixBlocks*)m_mChildren[0])->m_mChildren[j];
2382  if (rowMajor)
2383  {
2384  if (tmpChild->ExpandedMatrixInRowMajorForm->valueSize == 0)
2385  continue;
2386  tmpBlocks->blocks[tmpBlockNumber] = tmpChild->ExpandedMatrixInRowMajorForm;
2387  }
2388  else
2389  {
2390  if (tmpChild->ExpandedMatrixInColumnMajorForm->valueSize == 0)
2391  continue;
2392  tmpBlocks->blocks[tmpBlockNumber] = tmpChild->ExpandedMatrixInColumnMajorForm;
2393  }
2394  tmpBlocks->blockRows[tmpBlockNumber] = tmpChild->blockRowIdx;
2395  tmpBlocks->blockColumns[tmpBlockNumber] = tmpChild->blockColIdx;
2396 
2397 #ifndef NDEBUG
2398  tmpChild->printExpandedMatrix(rowMajor);
2399 #endif
2400 
2401  tmpBlockNumber++;
2402  }
2403  ExpandedMatrixByBlocks.push_back(tmpBlocks);
2404  return true;
2405  }
2406  }
2407 
2408 none_found:
2409  if (inumberOfChildren == 0)
2410  {
2411  // empty matrix -- return empty collection
2412  ExpandedMatrixBlocks* tmpBlocks = new ExpandedMatrixBlocks();
2413 
2414  tmpBlocks->bDeleteArrays = false;
2415  tmpBlocks->vType = elType;
2416  tmpBlocks->isRowMajor = rowMajor;
2417  tmpBlocks->rowOffsetSize = rowOffsetSize;
2418  tmpBlocks->colOffsetSize = colOffsetSize;
2419  tmpBlocks->rowOffset = rowOffset;
2420  tmpBlocks->colOffset = colOffset;
2421  tmpBlocks->blockNumber = 0;
2422  tmpBlocks->blocks = NULL;
2423  tmpBlocks->blockRows = NULL;
2424  tmpBlocks->blockColumns = NULL;
2425  ExpandedMatrixByBlocks.push_back(tmpBlocks);
2426  return true;
2427  }
2428 
2429  // unless there is a block partition already, separate the expanded matrix into blocks
2430  if ( (ExpandedMatrixInColumnMajorForm != NULL && !rowMajor) ||
2431  (ExpandedMatrixInRowMajorForm != NULL && rowMajor) ||
2432  ExpandedMatrixByBlocks.size() == 0)
2433  {
2434  ExpandedMatrixByBlocks.push_back(disassembleMatrix(rowOffset, rowOffsetSize, colOffset,
2435  colOffsetSize, rowMajor, symmetry));
2436  return true;
2437  }
2438 
2439  // If a different block partition is available, it is less wasteful to disassemble it
2440  // rather than making a full expansion first
2441  // Refinements and coarser partitions are easier to handle, so check for those first
2442 
2443  int refinement = -1;
2444  int coarsening = -1;
2445  bool refinementCandidate;
2446  bool coarseningCandidate;
2447  int k = 0;
2448 
2449  for (size_t k = 0; k < ExpandedMatrixByBlocks.size(); k++)
2450  {
2451  refinementCandidate = true;
2452  int itarget = 0;
2453  int itest = 0;
2454  for (;;)
2455  {
2456  if (rowOffset[itarget] == ExpandedMatrixByBlocks[k]->rowOffset[itest])
2457  {
2458  itest++;
2459  itarget++;
2460  }
2461  else
2462  {
2463  if (rowOffset[itarget] < ExpandedMatrixByBlocks[k]->rowOffset[itest])
2464  {
2465  itarget++;
2466  }
2467  else
2468  {
2469  refinementCandidate = false;
2470  continue;
2471  }
2472  }
2473  if (itarget >= rowOffsetSize || itest >= ExpandedMatrixByBlocks[k]->rowOffsetSize)
2474  break;
2475  }
2476 
2477  if (refinementCandidate)
2478  {
2479  itarget = 0;
2480  itest = 0;
2481  for (;;)
2482  {
2483  if (colOffset[itarget] == ExpandedMatrixByBlocks[k]->colOffset[itest])
2484  {
2485  itest++;
2486  itarget++;
2487  }
2488  else
2489  {
2490  if (colOffset[itarget] < ExpandedMatrixByBlocks[k]->colOffset[itest])
2491  {
2492  itarget++;
2493  }
2494  else
2495  {
2496  refinementCandidate = false;
2497  continue;
2498  }
2499  }
2500  if (itarget >= colOffsetSize || itest >= ExpandedMatrixByBlocks[k]->colOffsetSize)
2501  break;
2502  }
2503  }
2504 
2505  if (refinementCandidate)
2506  {
2507  refinement = k;
2508  break;
2509  }
2510 
2511  coarseningCandidate = false;
2512  itarget = 0;
2513  itest = 0;
2514  for (;;)
2515  {
2516  if (rowOffset[itarget] == ExpandedMatrixByBlocks[k]->rowOffset[itest])
2517  {
2518  itest++;
2519  itarget++;
2520  }
2521  else
2522  {
2523  if (rowOffset[itarget] < ExpandedMatrixByBlocks[k]->rowOffset[itest])
2524  {
2525  itarget++;
2526  continue;
2527  }
2528  else
2529  {
2530  coarseningCandidate = true;
2531  itest++;
2532  }
2533  }
2534  if (itarget >= rowOffsetSize || itest >= ExpandedMatrixByBlocks[k]->rowOffsetSize)
2535  break;
2536  }
2537 
2538  itarget = 0;
2539  itest = 0;
2540  for (;;)
2541  {
2542  if (colOffset[itarget] == ExpandedMatrixByBlocks[k]->colOffset[itest])
2543  {
2544  itest++;
2545  itarget++;
2546  }
2547  else
2548  {
2549  if (colOffset[itarget] < ExpandedMatrixByBlocks[k]->colOffset[itest])
2550  {
2551  itarget++;
2552  continue;
2553  }
2554  else
2555  {
2556  coarseningCandidate = true;
2557  itest++;
2558  }
2559  }
2560  if (itarget >= colOffsetSize || itest >= ExpandedMatrixByBlocks[k]->colOffsetSize)
2561  break;
2562  }
2563 
2564  if (coarseningCandidate)
2565  {
2566  refinement = k;
2567  }
2568  }
2569 
2570  if (refinement >= 0)
2571  {
2572  throw ErrorClass ("Not yet implemented: obtaining one block partition from a different one");
2573  return false;
2574  }
2575 
2576  if (coarsening >= 0)
2577  {
2578  throw ErrorClass ("Not yet implemented: obtaining one block partition from a different one");
2579  return false;
2580  }
2581 
2582  // here we have previous partitions that all overlap with the current one
2583  throw ErrorClass ("Not yet implemented: obtaining one block partition from a different one");
2584 
2585 
2586  return false;
2587  }
2588  catch(const ErrorClass& eclass)
2589  {
2590  throw ErrorClass( eclass.errormsg);
2591  }
2592 }// end of alternate MatrixType::processBlocks
2593 
2594 ExpandedMatrixBlocks* MatrixType::disassembleMatrix(int* rowPartition, int rowPartitionSize,
2595  int* colPartition, int colPartitionSize,
2596  bool rowMajor, ENUM_MATRIX_SYMMETRY symmetry)
2597 {
2598 /*
2599  We go through the nonzeros of the matrix to determine both the number of nonzero blocks
2600  and the number of elements in each block.
2601  We do not know how many blocks there are, so we have to store them temporarily in a vector.
2602  As each block is detected, we extend the vector.
2603  This keeps the blocks ordered by colIdx (assuming column major) and probably also
2604  by rowIdx within each column (assuming "normal" ordering of nonzeros).
2605  (This affects only the efficiency of the search routines, not the validity of the algorithm.)
2606  After the counts have been established, we have to go through the nonzeros again to store values.
2607  Finally we convert the vector to an array and return.
2608  */
2609 #ifndef NDEBUG
2610  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside disassembleMatrix()");
2611 #endif
2612  int currBlockRow, currBlockCol, lastBlock, currRow;
2613  int blockCount, firstBlockInCol, blockTotal;
2614  std::vector<GeneralSparseMatrix*> tmpBlocks;
2615  int* tmpBlockRows;
2616  int* tmpBlockColumns;
2617  bool found;
2618  int i, j, k;
2619  int* elCount;
2620  ENUM_MATRIX_TYPE vType = getMatrixType();
2621 
2622  //This section is for column-wise representations --- row-wise will work analogously
2623  if (!rowMajor)
2624  {
2625  firstBlockInCol = -1;
2626  if (ExpandedMatrixInColumnMajorForm == NULL)
2628 
2629  // OK. Start counting
2630  blockCount = 0;
2631  elCount = new int[rowPartitionSize-1];
2632 
2633  for (i=0; i < colPartitionSize-1; i++) // i indexes a block of columns
2634  {
2635 // blk0 = blockCount;
2636  for (j=0; j<rowPartitionSize-1; j++)
2637  elCount[j] = 0;
2638  lastBlock = i;
2639  if (lastBlock >= rowPartitionSize)
2640  lastBlock = rowPartitionSize - 1;
2641 
2642  for (j=colPartition[i]; j<colPartition[i+1]; j++) // j indexes a column within this block
2643  {
2644  for ( k = ExpandedMatrixInColumnMajorForm->start[j];
2645  k < ExpandedMatrixInColumnMajorForm->start[j+1];
2646  k++ ) // k indexes the elements in this column
2647  {
2648  currRow = ExpandedMatrixInColumnMajorForm->index[k];
2649  if (currRow < rowPartition[lastBlock] || currRow >= rowPartition[lastBlock+1])
2650  {
2651  found = false;
2652  int n = lastBlock + 1;
2653  while (!found && n < rowPartitionSize - 1)
2654  {
2655 // for (k=lastBlock+1; k < rowPartitionSize - 1; k++)
2656  if (currRow >= rowPartition[n+1])
2657  n++;
2658  else
2659  {
2660  found = true;
2661  lastBlock = n;
2662  break;
2663  }
2664  }
2665  if (!found)
2666  n = lastBlock - 1;
2667  while (!found && n >= 0)
2668  {
2669 // for (k=lastBlock-1; k >= 0; k--)
2670  if (currRow < rowPartition[n])
2671  n--;
2672  else
2673  {
2674  found = true;
2675  lastBlock = n;
2676  break;
2677  }
2678  }
2679  if (!found)
2680  throw ErrorClass("Invalid row information detected in disassembleMatrix()");
2681 
2682  elCount[lastBlock]++;
2683  if (elCount[lastBlock] == 1)
2684  {
2685  //add a new block
2686  GeneralSparseMatrix* tmpBlock = new GeneralSparseMatrix();
2687  blockCount++;
2688  if (firstBlockInCol < 0)
2689  firstBlockInCol = blockCount - 1;
2690  tmpBlock->b_deleteStartArray = true;
2691  tmpBlock->b_deleteIndexArray = true;
2692  tmpBlock->b_deleteValueArray = true;
2693  tmpBlock->isRowMajor = false;
2694  tmpBlock->symmetry = symmetry;
2695  tmpBlock->vType = vType;
2696  tmpBlock->startSize = colPartition[i+1] - colPartition[i] + 1;
2697  tmpBlock->start = new int[tmpBlock->startSize];
2698 
2699  for (int n=0; n <= j - colPartition[i]; n++)
2700  tmpBlock->start[n] = 0;
2701 
2702  tmpBlocks.push_back(tmpBlock);
2703  if (firstBlockInCol < 0)
2704  firstBlockInCol = blockCount - 1;
2705  }
2706  } // end of element
2707  } // end of column
2708 
2709  //store starts
2710  for (k=firstBlockInCol; k < blockCount; k++)
2711  tmpBlocks[k]->start[j-colPartition[i] + 1] = elCount[k];
2712 
2713  } // end of block of columns
2714 
2715  // allocate space for indexes, values and block location
2716  for (k=firstBlockInCol; k < blockCount; k++)
2717  {
2718  tmpBlocks[k]->valueSize = elCount[k];
2719  tmpBlocks[k]->index = new int[elCount[k]];
2720  tmpBlocks[k]->value = new MatrixElementValues[elCount[k]];
2721  }
2722  tmpBlockRows = new int[blockCount];
2723  tmpBlockColumns = new int[blockCount];
2724  for (j=0; j<blockCount; j++)
2725  {
2726  tmpBlockRows[j] = -1;
2727  }
2728 
2729  lastBlock = i;
2730 
2731  // traverse a second time to get values
2732  for (j=colPartition[i]; j<colPartition[i+1]; j++) // j indexes a column within this block
2733  {
2734  for ( k = ExpandedMatrixInColumnMajorForm->start[j];
2735  k < ExpandedMatrixInColumnMajorForm->start[j+1];
2736  k++ ) // k indexes the elements in this column
2737  {
2738  currRow = ExpandedMatrixInColumnMajorForm->index[k];
2739  if (currRow < rowPartition[lastBlock] || currRow >= rowPartition[lastBlock+1])
2740  {
2741  found = false;
2742  int n;
2743  while (!found)
2744  {
2745  for (n=lastBlock+1; n < rowPartitionSize - 1; n++)
2746  if (currRow >= rowPartition[lastBlock] &&
2747  currRow < rowPartition[lastBlock+1])
2748  {
2749  found = true;
2750  lastBlock = n;
2751  break;
2752  }
2753  }
2754  while (!found)
2755  {
2756  for (n=lastBlock-1; k >= 0; k--)
2757  if (currRow >= rowPartition[lastBlock] &&
2758  currRow < rowPartition[lastBlock+1])
2759  {
2760  found = true;
2761  lastBlock = n;
2762  break;
2763  }
2764  }
2765  }
2766  if (tmpBlockRows[lastBlock] == -1)
2767  {
2768  tmpBlockRows[lastBlock] = j;
2769  tmpBlockColumns[lastBlock] = i;
2770  }
2771  }
2772 
2773  int k0 = 0;
2774  tmpBlocks[lastBlock]->index[k-k0]
2775  = ExpandedMatrixInColumnMajorForm->index[k] - rowPartition[j];
2776  tmpBlocks[lastBlock]->value[k-k0] = ExpandedMatrixInColumnMajorForm->value[k];
2777  }
2778  } // end of entire collection
2779 
2780  } // end of column major
2781  else
2782  throw ErrorClass("Row major not yet implemented in MatrixType::disassembleMatrix()");
2783 
2784  ExpandedMatrixBlocks* returnArray = new ExpandedMatrixBlocks();
2785  returnArray->bDeleteArrays = true;
2786  returnArray->vType = vType;
2787  returnArray->isRowMajor = rowMajor;
2788  returnArray->blockNumber = tmpBlocks.size();
2789  returnArray->rowOffset = rowPartition;
2790  returnArray->colOffset = colPartition;
2791  returnArray->rowOffsetSize = rowPartitionSize;
2792  returnArray->colOffsetSize = colPartitionSize;
2793  returnArray->blocks = new GeneralSparseMatrix*[tmpBlocks.size()];
2794 
2795  for (size_t i=0; i<tmpBlocks.size();i++);
2796  {
2797  returnArray->blocks[i] = tmpBlocks[i];
2798  returnArray->blockRows[i] = tmpBlockRows[i];
2799  returnArray->blockColumns[i] = tmpBlockColumns[i];
2800  }
2801 
2802  return returnArray;
2803 }//end of MatrixType::disassembleMatrix
2804 
2805 
2806 GeneralSparseMatrix* MatrixType::extractBlock(int firstrow, int firstcol, int nrows, int ncols,
2807  bool rowMajor, ENUM_MATRIX_SYMMETRY symmetry)
2808 {
2809 #ifndef NDEBUG
2810  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside extractBlock()");
2811 #endif
2812  bool mustCopy = false;
2813  int n = inumberOfChildren;
2814  if (n > 1)
2815  mustCopy = true;
2816  else
2817  {
2818 
2819  }
2820  for (int i=0; i < n; i++)
2822  {
2823 
2824  break;
2825  }
2826  else
2827  {
2828 // for (int j=0; j <
2829  }
2830 
2831 return NULL;
2832 }// end of MatrixType::extractBlock
2833 // end of methods for MatrixType
2834 
2835 
2838  rowMajor(false),
2839  numberOfValues(-1),
2840  start(NULL),
2841  index(NULL)
2842 {
2843 #ifndef NDEBUG
2844  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixElements Constructor");
2845 #endif
2846 }// end of MatrixElements::MatrixElements()
2847 
2849 {
2850  ostringstream outStr;
2851 #ifndef NDEBUG
2852  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixElements Destructor");
2853 #endif
2854  if (start != NULL)
2855  {
2856 #ifndef NDEBUG
2857  outStr.str("");
2858  outStr.clear();
2859  outStr << "deleting MatrixElements->start at " << &start << std::endl;
2861 #endif
2862  delete start;
2863  start = NULL;
2864  }
2865 
2866  if (index != NULL)
2867  {
2868 #ifndef NDEBUG
2869  outStr.str("");
2870  outStr.clear();
2871  outStr << "deleting MatrixElements->index at " << &index << std::endl;
2873 #endif
2874  delete index;
2875  index = NULL;
2876  }
2877 }// end of MatrixElements::~MatrixElements()
2878 
2880 {
2881  return rowMajor;
2882 }// end of MatrixElements::getRowMajor
2883 
2884 #if 0
2885 bool MatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
2886 {
2887  return false;
2888 }// end of MatrixElements::alignsOnBlockBoundary()
2889 
2890 std::string MatrixElements::getNodeName()
2891 {
2892  return "";
2893 }// end of MatrixElements::getNodeName()
2894 #endif
2895 
2897 {
2898 #ifndef NDEBUG
2899  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in MatrixElements");
2900 #endif
2901  if (this == NULL)
2902  {
2903  if (that == NULL)
2904  return true;
2905  else
2906  {
2907 #ifndef NDEBUG
2909  "First object is NULL, second is not");
2910 #endif
2911  return false;
2912  }
2913  }
2914  else
2915  {
2916  if (that == NULL)
2917  {
2918 #ifndef NDEBUG
2920  "Second object is NULL, first is not");
2921 #endif
2922  return false;
2923  }
2924  else
2925  {
2926  if (this->rowMajor != that->rowMajor) return false;
2927  if (this->numberOfValues != that->numberOfValues) return false;
2928 
2929  if (!this->start->IsEqual(that->start))
2930  return false;
2931 
2932  if (!this->index->IsEqual(that->index))
2933  return false;
2934 
2935  return true;
2936  }
2937  }
2938 }// end of MatrixElements::IsEqual()
2939 // end of methods for MatrixElements
2940 
2941 
2944  numberOfEl(0)
2945 {
2946 #ifndef NDEBUG
2947  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixElementValues Constructor");
2948 #endif
2949 }
2950 
2952 {
2953 #ifndef NDEBUG
2954  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixElementValues Destructor");
2955 #endif
2956 }//end of MatrixElementValues::~MatrixElementValues
2957 
2959 {
2960  return true;
2961 }// end of MatrixElementValues::deepCopyFrom
2962 
2963 // end of methods for MatrixElementValues
2964 
2965 
2968  MatrixType(),
2969  idx(-1),
2970  name("")
2971 {
2972 #ifndef NDEBUG
2973  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrix Constructor");
2974 #endif
2976 }// end of OSMatrix
2977 
2979 {
2980 #ifndef NDEBUG
2981  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrix Destructor");
2982 #endif
2983 }// end of ~OSMatrix
2984 
2985 
2986 OSMatrix* OSMatrix::createConstructorTreeFromPrefix(std::vector<MatrixNode*> mtxConstructorVec)
2987 {
2988  std::vector<MatrixNode*> stackVec;
2989  int kount = mtxConstructorVec.size() - 1;
2990  while(kount >= 0)
2991  {
2992  int numkids = mtxConstructorVec[kount]->inumberOfChildren;
2993  if(numkids > 0)
2994  {
2995  for(int i = 0; i < numkids; i++)
2996  {
2997  mtxConstructorVec[kount]->m_mChildren[i] = stackVec.back();
2998  stackVec.pop_back();
2999  }
3000  }
3001  stackVec.push_back( mtxConstructorVec[kount]);
3002  kount--;
3003  }
3004  stackVec.clear();
3005  return (OSMatrix*)mtxConstructorVec[ 0];
3006 }//end OSMatrix::createExpressionTreeFromPrefix
3007 
3008 
3010 {
3012 }// end of OSMatrix::getNodeType()
3013 
3015 {
3016  return "matrix";
3017 }// end of OSMatrix::getNodeName()
3018 
3020 {
3022  {
3024  for (unsigned int i=0; i<inumberOfChildren; i++)
3026  }
3027  return matrixType;
3028 }// end of OSMatrix::getMatrixType()
3029 
3030 bool OSMatrix::expandElements(bool rowMajor)
3031 {
3032 #if 0
3033  //Check if expanded previously
3034  if (rowMajor)
3035  {
3036  if (ExpandedMatrixInRowMajorForm != NULL) return true;
3037  }
3038  else
3039  {
3040  if (ExpandedMatrixInColumnMajorForm != NULL) return true;
3041  }
3042 
3043  // The complexity increases with the number of constructors
3044  // Start by checking for empty matrix
3045  if (inumberOfChildren == 0)
3046  {
3047  if (rowMajor)
3048  {
3053  ExpandedMatrixInRowMajorForm->starts = new int[numberOfRows + 1];
3054  for (int i=0; i <= numberOfRows; i++)
3055  ExpandedMatrixInRowMajorForm->starts[i] = 0;
3056  return true;
3057  }
3058  else
3059  {
3064  ExpandedMatrixInColumnMajorForm->starts = new int[numberOfColumns + 1];
3065  for (int i=0; i <= numberOfColumns; i++)
3066  ExpandedMatrixInColumnMajorForm->starts[i] = 0;
3067  return true;
3068  }
3069  }
3070 
3071  else if (inumberOfChildren == 1)
3072  {
3074  {
3075  int baseMtxIdx = ((BaseMatrix*)m_mChildren[0])->baseMatrixIdx;
3076  OSMatrix* basematrix =
3077  bool haveRowForm = (baseMtx->ExpandedMatrixInRowMajorForm != NULL);
3078  bool haveColumnForm = (baseMtx->ExpandedMatrixInColumnMajorForm != NULL);
3079 // what about cropping, scaling, transpose???
3080  m_mChildren[0]->expandElements(rowMajor);
3081  if (targetMatrixFirstRow == 0 && targetMatrixFirstCol == 0 &&
3082  baseMatrixStartRow == 0 && baseMatrixStartCol == 0 &&
3083  baseMatrixEndRow == numberOfRows - 1 &&
3084  baseMatrixEndCol == numberOfColumns - 1 &&
3085  scalarMultiplier == 1)
3086  {
3087  if (rowmajor)
3088  {
3090  ExpandedMatrixInRowMajorForm = m_mChildren[0]->ExpandedMatrixInRowMajorForm;
3093  ExpandedMatrixInRowMajorForm->starts = new int[numberOfRows + 1];
3094  }
3095  else
3096  {
3098  ExpandedMatrixInColumnMajorForm = m_mChildren[0]->ExpandedMatrixInColumnMajorForm;
3101  ExpandedMatrixInColumnMajorForm->starts = new int[numberOfColumns + 1];
3102  }
3103  }
3104  return true;
3105  }
3106 
3108  {
3109  ExpandedMatrixBlocks* currentBlocks =
3110  processBlocks(int* rowOffsets, int* colOffsets,
3111  bool rowMajor, ENUM_MATRIX_SYMMETRY symmetry);
3112  ExpandedMatrixByBlocks.push_back(currentBlocks);
3113 
3114  if (rowmajor)
3115  {
3118  ExpandedMatrixInRowMajorForm->starts = new int[numberOfRows + 1];
3119  for (int i=0; i <= numberOfRows; i++)
3120  ExpandedMatrixInRowMajorForm->starts[i] = 0;
3121  }
3122  else
3123  {
3126  ExpandedMatrixInColumnMajorForm->starts = new int[numberOfColumns + 1];
3127  for (int i=0; i <= numberOfColumns; i++)
3128  ExpandedMatrixInColumnMajorForm->starts[i] = 0;
3129  // augment column lengths block by block
3130  for (int j=0; j < currentBlocks->numberOfBlocks; j++)
3131  {
3132  }
3133 
3134  }
3135  }
3136 
3138  {
3139  }
3140  }
3141 
3142  else
3143  {
3144  }
3145 #endif
3146 /*do induction on # of constructors.
3147 if one: blocks: expand
3148  transformation: see if I can do at least AB, A'B, AB'
3149  elements: copy
3150 more than one: tricky
3151  (basematrix plus) elements should be ok
3152  maybe transformation (product) plus elements
3153  others: throw error
3154 */
3155  return false;
3156 }// end of expandElements
3157 
3158 #if 0
3159 bool OSMatrix::processBlocks(int* rowOffsets, int* colOffsets,
3160  bool rowMajor, ENUM_MATRIX_SYMMETRY symmetry)
3161 {
3176  bool haveBlocks;
3177  bool haveTemp;
3178  bool mustSynchronize;
3179  int* temp;
3180  int tempSize;
3181  int iconst;
3182 
3183 //check for duplicates
3184 
3185  // check if empty
3186  if (inumberOfChildren == 0)
3187  {
3188  m_miRowPartition = new int[2];
3189  m_miColumnPartition = new int[2];
3190  m_iRowPartitionSize = 2;
3192  m_miRowPartition[0] = 0;
3194  m_miColumnPartition[0] = 0;
3196  m_bBlockPartitionProcessed = true;
3197  return true;
3198  }
3199 
3200  // initialize for row partition
3201  haveBlocks = false;
3202  haveTemp = false;
3203  mustSynchronize = false;
3204 
3206  {
3207  tempSize = ((BaseMatrix*)m_mChildren[0])->baseMatrix->getRowPartitionSize();
3208  if (tempSize > 2)
3209  {
3210  m_miRowPartition = ((BaseMatrix*)m_mChildren[0])->baseMatrix->getRowPartition();
3211  m_iRowPartitionSize = tempSize;
3212  mustSynchronize = true;
3213  haveBlocks = true;
3214  }
3215  iconst = 1;
3216  }
3217  else
3218  iconst = 0;
3219 
3220  // process remaining constructors
3221  int jproc;
3222  int jcand;
3223  int nsync;
3224 
3225  for (int i=iconst; i < inumberOfChildren; i++)
3226  {
3228  {
3229  if (((MatrixBlocks*)m_mChildren[i])->rowOffsets->el[0] != 0)
3230  return false;
3231 
3232  if (haveBlocks == false)
3233  {
3234  m_miRowPartition = ((MatrixBlocks*)m_mChildren[i])->rowOffsets->el;
3235  m_iRowPartitionSize = ((MatrixBlocks*)m_mChildren[i])->rowOffsets->numberOfEl;
3236  mustSynchronize = true;
3237  haveBlocks = true;
3238  }
3239  else
3240  {
3241  // check if we have to synchronize
3242  jproc = 0;
3243  jcand = 0;
3244  nsync = 0;
3245  for (;;)
3246  {
3247  if (m_miRowPartition[jproc] == ((MatrixBlocks*)m_mChildren[i])->rowOffsets->el[jcand])
3248  {
3249  if (haveTemp)
3250  temp[nsync] = m_miRowPartition[jproc];
3251  jproc++;
3252  jcand++;
3253  nsync++;
3254  }
3255  else
3256  {
3257  if (!haveTemp)
3258  {
3259  haveTemp = true;
3260  tempSize = min (((MatrixBlocks*)m_mChildren[i])->rowOffsets->numberOfEl,
3262  temp = new int[tempSize];
3263  for (int l=0; l < nsync; l++)
3264  temp[l] = m_miRowPartition[l];
3265  }
3266  if (m_miRowPartition[jproc] <
3267  ((MatrixBlocks*)m_mChildren[i])->rowOffsets->el[jcand])
3268  jproc++;
3269  else
3270  jcand++;
3271  }
3272  if (jproc >= m_iRowPartitionSize ||
3273  jcand >= ((MatrixBlocks*)m_mChildren[i])->rowOffsets->numberOfEl)
3274  break;
3275  }
3276  }
3277 
3278  if (haveTemp && temp[nsync-1] < numberOfRows)
3279  {
3280  temp[nsync] = numberOfRows;
3281  nsync++;
3282  }
3283  }
3284 
3285  if (haveTemp)
3286  {
3287  if (m_miRowPartition != NULL) delete m_miRowPartition;
3288  m_miRowPartition = new int[nsync];
3289  for (int l=0; l<nsync; l++)
3290  m_miRowPartition[l] = temp[l];
3291  delete [] temp;
3292  m_iRowPartitionSize = nsync;
3293  if (nsync == 2) break;
3294  }
3295  }
3296 
3297  if (haveBlocks == false)
3298  {
3299  m_miRowPartition = new int[2];
3300  m_iRowPartitionSize = 2;
3301  m_miRowPartition[0] = 0;
3303  }
3304 
3305  // here we do the same thing for the columns
3306  haveBlocks = false;
3307  haveTemp = false;
3308  mustSynchronize = false;
3309 
3311  {
3312  tempSize = ((BaseMatrix*)m_mChildren[0])->baseMatrix->getColumnPartitionSize();
3313  if (tempSize > 2)
3314  {
3315  m_miColumnPartition = ((BaseMatrix*)m_mChildren[0])->baseMatrix->getColumnPartition();
3316  m_iColumnPartitionSize = tempSize;
3317  mustSynchronize = true;
3318  haveBlocks = true;
3319  }
3320  iconst = 1;
3321  }
3322  else
3323  iconst = 0;
3324 
3325  // process remaining constructors
3326  for (int i=iconst; i < inumberOfChildren; i++)
3327  {
3329  {
3330  if (((MatrixBlocks*)m_mChildren[i])->colOffsets->el[0] != 0)
3331  return false;
3332 
3333  if (haveBlocks == false)
3334  {
3335  m_miColumnPartition = ((MatrixBlocks*)m_mChildren[i])->colOffsets->el;
3336  m_iColumnPartitionSize = ((MatrixBlocks*)m_mChildren[i])->colOffsets->numberOfEl;
3337  mustSynchronize = true;
3338  haveBlocks = true;
3339  }
3340  else
3341  {
3342  // check if we have to synchronize
3343  jproc = 0;
3344  jcand = 0;
3345  nsync = 0;
3346  for (;;)
3347  {
3348  if (m_miColumnPartition[jproc] == ((MatrixBlocks*)m_mChildren[i])->colOffsets->el[jcand])
3349  {
3350  if (haveTemp)
3351  temp[nsync] = m_miColumnPartition[jproc];
3352  jproc++;
3353  jcand++;
3354  nsync++;
3355  }
3356  else
3357  {
3358  if (!haveTemp)
3359  {
3360  haveTemp = true;
3361  tempSize = min (((MatrixBlocks*)m_mChildren[i])->colOffsets->numberOfEl,
3363  temp = new int[tempSize];
3364  for (int l=0; l < nsync; l++)
3365  temp[l] = m_miColumnPartition[l];
3366  }
3367  if (m_miColumnPartition[jproc] <
3368  ((MatrixBlocks*)m_mChildren[i])->colOffsets->el[jcand])
3369  jproc++;
3370  else
3371  jcand++;
3372  }
3373  if (jproc >= m_iColumnPartitionSize ||
3374  jcand >= ((MatrixBlocks*)m_mChildren[i])->colOffsets->numberOfEl)
3375  break;
3376  }
3377  }
3378 
3379  if (haveTemp && temp[nsync-1] < numberOfColumns)
3380  {
3381  temp[nsync] = numberOfColumns;
3382  nsync++;
3383  }
3384  }
3385 
3386  if (haveTemp)
3387  {
3388  if (m_miColumnPartition != NULL) delete m_miColumnPartition;
3389  m_miColumnPartition = new int[nsync];
3390  for (int l=0; l<nsync; l++)
3391  m_miColumnPartition[l] = temp[l];
3392  delete [] temp;
3393  m_iColumnPartitionSize = nsync;
3394  if (nsync == 2) break;
3395  }
3396  }
3397 
3398  if (haveBlocks == false)
3399  {
3400  m_miColumnPartition = new int[2];
3402  m_miColumnPartition[0] = 0;
3404  }
3405 
3406  return true;
3407 }// end of OSMatrix::processBlocks()
3408 #endif
3409 
3410 bool OSMatrix::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
3411 {
3412  bool accumulator = true;
3413  for (unsigned int i=0; i < inumberOfChildren; i++)
3415  accumulator &= m_mChildren[i]->alignsOnBlockBoundary(firstRow, firstColumn, nRows, nCols);
3417  accumulator &= m_mChildren[i]->alignsOnBlockBoundary(firstRow, firstColumn, nRows, nCols);
3419  return false;
3420  else return false;
3421  return accumulator;
3422 }// end of OSMatrix::alignsOnBlockBoundary()
3423 
3424 #if 0
3426 {
3427  bool isDiagonal;
3428  int haveBaseBlocks = false;
3429  int nBlocks;
3430  int iconst;
3431 
3432  // check if empty
3433  if (inumberOfChildren == 0)
3434  return true;
3435 
3436  // check for blocks in baseMatrix --- if any
3438  {
3439  int tempSize = ((BaseMatrix*)m_mChildren[0])->baseMatrix->getRowPartitionSize();
3440  if (tempSize > 2)
3441  {
3442  haveBaseBlocks = true;
3443  isDiagonal = ((BaseMatrix*)m_mChildren[0])->baseMatrix->isBlockDiagonal();
3444  if (!isDiagonal) return false;
3445  }
3446  else
3447  isDiagonal = true;
3448  iconst = 1;
3449  }
3450  else
3451  iconst = 0;
3452 
3453  // process remaining constructors
3454  int jproc;
3455  int jcand;
3456  int nsync;
3457  int* rowPartition = getRowPartition();
3458  int rowPartitionSize = getRowPartitionSize();
3459  int* colPartition = getColumnPartition();
3460  int colPartitionSize = getColumnPartitionSize();
3461 
3462  for (int i=iconst; i < inumberOfChildren; i++)
3464  for (int j=0; j < ((MatrixBlocks*)m_mChildren[i])->numberOfBlocks; j++)
3465  if ( ((MatrixBlock*)((MatrixBlocks*)m_mChildren[i])->m_mChildren[j])->blockRowIdx !=
3466  ((MatrixBlock*)((MatrixBlocks*)m_mChildren[i])->m_mChildren[j])->blockColIdx)
3467  return false;
3468 
3469  // Now check if there are other constructors that might introduce elements outside the block diagonal
3470  if (iconst == 1 && !haveBaseBlocks) return false;
3471  for (int i=iconst; i < inumberOfChildren; i++)
3472  if (m_mChildren[i]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_elements)
3473  {
3474  if (((MatrixElements*)m_mChildren[i])->constantElements != NULL)
3475  {
3476  if (((MatrixElements*)m_mChildren[i])->constantElements->rowMajor)
3477  {
3478  for (int j=1; j < colPartitionSize; j++)
3479  for (int k = colPartition[j-1]; k < colPartition[j]; j++)
3480  for (int l = ((MatrixElements*)m_mChildren[i])->constantElements->start->el[k];
3481  l < ((MatrixElements*)m_mChildren[i])->constantElements->start->el[k+1];
3482  l++)
3483  if ( ((MatrixElements*)m_mChildren[i])->constantElements->indexes->el[l]
3484  < rowPartition[j-1] ||
3485  ((MatrixElements*)m_mChildren[i])->constantElements->indexes->el[l]
3486  >= rowPartition[j] )
3487  return false;
3488  }
3489  else
3490  {
3491  for (int j=1; j < rowPartitionSize; j++)
3492  for (int k = rowPartition[j-1]; k < rowPartition[j]; j++)
3493  for (int l = ((MatrixElements*)m_mChildren[i])->constantElements->start->el[k];
3494  l < ((MatrixElements*)m_mChildren[i])->constantElements->start->el[k+1];
3495  l++)
3496  if ( ((MatrixElements*)m_mChildren[i])->constantElements->indexes->el[l]
3497  < colPartition[j-1] ||
3498  ((MatrixElements*)m_mChildren[i])->constantElements->indexes->el[l]
3499  >= colPartition[j] )
3500  return false;
3501  }
3502  }
3503 
3504 
3505  if (((MatrixElements*)m_mChildren[i])->varReferenceElements != NULL)
3506  {
3507  if (((MatrixElements*)m_mChildren[i])->varReferenceElements->rowMajor)
3508  {
3509  for (int j=1; j < colPartitionSize; j++)
3510  for (int k = colPartition[j-1]; k < colPartition[j]; j++)
3511  for (int l = ((MatrixElements*)m_mChildren[i])->varReferenceElements->start->el[k];
3512  l < ((MatrixElements*)m_mChildren[i])->varReferenceElements->start->el[k+1];
3513  l++)
3514  if ( ((MatrixElements*)m_mChildren[i])->varReferenceElements->indexes->el[l]
3515  < rowPartition[j-1] ||
3516  ((MatrixElements*)m_mChildren[i])->varReferenceElements->indexes->el[l]
3517  >= rowPartition[j] )
3518  return false;
3519  }
3520  else
3521  {
3522  for (int j=1; j < rowPartitionSize; j++)
3523  for (int k = rowPartition[j-1]; k < rowPartition[j]; j++)
3524  for (int l = ((MatrixElements*)m_mChildren[i])->varReferenceElements->start->el[k];
3525  l < ((MatrixElements*)m_mChildren[i])->varReferenceElements->start->el[k+1];
3526  l++)
3527  if ( ((MatrixElements*)m_mChildren[i])->varReferenceElements->indexes->el[l]
3528  < colPartition[j-1] ||
3529  ((MatrixElements*)m_mChildren[i])->varReferenceElements->indexes->el[l]
3530  >= colPartition[j] )
3531  return false;
3532  }
3533  }
3534 
3535 
3536  if (((MatrixElements*)m_mChildren[i])->linearElements != NULL)
3537  {
3538  if (((MatrixElements*)m_mChildren[i])->linearElements->rowMajor)
3539  {
3540  for (int j=1; j < colPartitionSize; j++)
3541  for (int k = colPartition[j-1]; k < colPartition[j]; j++)
3542  for (int l = ((MatrixElements*)m_mChildren[i])->linearElements->start->el[k];
3543  l < ((MatrixElements*)m_mChildren[i])->linearElements->start->el[k+1];
3544  l++)
3545  if ( ((MatrixElements*)m_mChildren[i])->linearElements->indexes->el[l]
3546  < rowPartition[j-1] ||
3547  ((MatrixElements*)m_mChildren[i])->linearElements->indexes->el[l]
3548  >= rowPartition[j] )
3549  return false;
3550  }
3551  else
3552  {
3553  for (int j=1; j < rowPartitionSize; j++)
3554  for (int k = rowPartition[j-1]; k < rowPartition[j]; j++)
3555  for (int l = ((MatrixElements*)m_mChildren[i])->linearElements->start->el[k];
3556  l < ((MatrixElements*)m_mChildren[i])->linearElements->start->el[k+1];
3557  l++)
3558  if ( ((MatrixElements*)m_mChildren[i])->linearElements->indexes->el[l]
3559  < colPartition[j-1] ||
3560  ((MatrixElements*)m_mChildren[i])->linearElements->indexes->el[l]
3561  >= colPartition[j] )
3562  return false;
3563  }
3564  }
3565 
3566 
3567  if (((MatrixElements*)m_mChildren[i])->generalElements != NULL)
3568  {
3569  if (((MatrixElements*)m_mChildren[i])->generalElements->rowMajor)
3570  {
3571  for (int j=1; j < colPartitionSize; j++)
3572  for (int k = colPartition[j-1]; k < colPartition[j]; j++)
3573  for (int l = ((MatrixElements*)m_mChildren[i])->generalElements->start->el[k];
3574  l < ((MatrixElements*)m_mChildren[i])->generalElements->start->el[k+1];
3575  l++)
3576  if ( ((MatrixElements*)m_mChildren[i])->generalElements->indexes->el[l]
3577  < rowPartition[j-1] ||
3578  ((MatrixElements*)m_mChildren[i])->generalElements->indexes->el[l]
3579  >= rowPartition[j] )
3580  return false;
3581  }
3582  else
3583  {
3584  for (int j=1; j < rowPartitionSize; j++)
3585  for (int k = rowPartition[j-1]; k < rowPartition[j]; j++)
3586  for (int l = ((MatrixElements*)m_mChildren[i])->generalElements->start->el[k];
3587  l < ((MatrixElements*)m_mChildren[i])->generalElements->start->el[k+1];
3588  l++)
3589  if ( ((MatrixElements*)m_mChildren[i])->generalElements->indexes->el[l]
3590  < colPartition[j-1] ||
3591  ((MatrixElements*)m_mChildren[i])->generalElements->indexes->el[l]
3592  >= colPartition[j] )
3593  return false;
3594  }
3595  }
3596 
3597 
3598  if (((MatrixElements*)m_mChildren[i])->objReferenceElements != NULL)
3599  {
3600  if (((MatrixElements*)m_mChildren[i])->objReferenceElements->rowMajor)
3601  {
3602  for (int j=1; j < colPartitionSize; j++)
3603  for (int k = colPartition[j-1]; k < colPartition[j]; j++)
3604  for (int l = ((MatrixElements*)m_mChildren[i])->objReferenceElements->start->el[k];
3605  l < ((MatrixElements*)m_mChildren[i])->objReferenceElements->start->el[k+1];
3606  l++)
3607  if ( ((MatrixElements*)m_mChildren[i])->objReferenceElements->indexes->el[l]
3608  < rowPartition[j-1] ||
3609  ((MatrixElements*)m_mChildren[i])->objReferenceElements->indexes->el[l]
3610  >= rowPartition[j] )
3611  return false;
3612  }
3613  else
3614  {
3615  for (int j=1; j < rowPartitionSize; j++)
3616  for (int k = rowPartition[j-1]; k < rowPartition[j]; j++)
3617  for (int l = ((MatrixElements*)m_mChildren[i])->objReferenceElements->start->el[k];
3618  l < ((MatrixElements*)m_mChildren[i])->objReferenceElements->start->el[k+1];
3619  l++)
3620  if ( ((MatrixElements*)m_mChildren[i])->objReferenceElements->indexes->el[l]
3621  < colPartition[j-1] ||
3622  ((MatrixElements*)m_mChildren[i])->objReferenceElements->indexes->el[l]
3623  >= colPartition[j] )
3624  return false;
3625  }
3626  }
3627 
3628 
3629  if (((MatrixElements*)m_mChildren[i])->conReferenceElements != NULL)
3630  {
3631  if (((MatrixElements*)m_mChildren[i])->conReferenceElements->rowMajor)
3632  {
3633  for (int j=1; j < colPartitionSize; j++)
3634  for (int k = colPartition[j-1]; k < colPartition[j]; j++)
3635  for (int l = ((MatrixElements*)m_mChildren[i])->conReferenceElements->start->el[k];
3636  l < ((MatrixElements*)m_mChildren[i])->conReferenceElements->start->el[k+1];
3637  l++)
3638  if ( ((MatrixElements*)m_mChildren[i])->conReferenceElements->indexes->el[l]
3639  < rowPartition[j-1] ||
3640  ((MatrixElements*)m_mChildren[i])->conReferenceElements->indexes->el[l]
3641  >= rowPartition[j] )
3642  return false;
3643  }
3644  else
3645  {
3646  for (int j=1; j < rowPartitionSize; j++)
3647  for (int k = rowPartition[j-1]; k < rowPartition[j]; j++)
3648  for (int l = ((MatrixElements*)m_mChildren[i])->conReferenceElements->start->el[k];
3649  l < ((MatrixElements*)m_mChildren[i])->conReferenceElements->start->el[k+1];
3650  l++)
3651  if ( ((MatrixElements*)m_mChildren[i])->conReferenceElements->indexes->el[l]
3652  < colPartition[j-1] ||
3653  ((MatrixElements*)m_mChildren[i])->conReferenceElements->indexes->el[l]
3654  >= colPartition[j] )
3655  return false;
3656  }
3657  }
3658  }
3660  return false;
3661 
3662  return true;
3663 }// end of OSMatrix::isBlockDiagonal()
3664 #endif
3665 
3666 
3667 bool OSMatrix::setMatrix(std::string name, int numberOfRows, int numberOfColumns,
3668  ENUM_MATRIX_SYMMETRY symmetry, ENUM_MATRIX_TYPE matrixType,
3669  unsigned int inumberOfChildren, MatrixNode **m_mChildren)
3670 {
3671  this->name = name;
3672  this->numberOfRows = numberOfRows;
3673  this->numberOfColumns = numberOfColumns;
3674  this->symmetry = symmetry;
3675  this->matrixType = matrixType;
3676  this->inumberOfChildren = inumberOfChildren;
3677  this->m_mChildren = m_mChildren;
3678  return true;
3679 }//setMatrix
3680 
3681 
3683 {
3684  ostringstream outStr;
3685  outStr << "<matrix";
3686  outStr << " numberOfRows=\"" << numberOfRows << "\"";
3687  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
3689  outStr << " symmetry=\"" << returnMatrixSymmetryString(symmetry) << "\"";
3690  if (name != "")
3691  outStr << " name=\"" << name << "\"";
3693  outStr << " type=\"" << returnMatrixTypeString(matrixType) << "\"";
3694 
3695  if (inumberOfChildren > 0)
3696  {
3697  outStr << ">" << std::endl;
3698  for (unsigned int i=0; i < inumberOfChildren; i++)
3699  outStr << m_mChildren[i]->getMatrixNodeInXML();
3700  outStr << "</matrix>" << std::endl;
3701  }
3702  else
3703  outStr << "/>" << std::endl;
3704  return outStr.str();
3705 }// end of OSMatrix::getMatrixNodeInXML()
3706 
3708 {
3709  MatrixType *nodePtr;
3710  nodePtr = new OSMatrix();
3711  return (OSMatrix*)nodePtr;
3712 }// end of OSMatrix::cloneMatrixNode
3713 
3715 {
3716 #ifndef NDEBUG
3717  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in OSMatrix");
3718 #endif
3719  if (this == NULL)
3720  {
3721  if (that == NULL)
3722  return true;
3723  else
3724  {
3725 #ifndef NDEBUG
3727  "First object is NULL, second is not");
3728 #endif
3729  return false;
3730  }
3731  }
3732  else
3733  {
3734  if (that == NULL)
3735  {
3736 #ifndef NDEBUG
3738  "Second object is NULL, first is not");
3739 #endif
3740  return false;
3741  }
3742  else
3743  {
3744  if (this->idx != that->idx) return false;
3745  if (this->name != that->name) return false;
3746  return this->MatrixNode::IsEqual(that);
3747  }
3748  }
3749 }// end of OSMatrix::IsEqual()
3750 // end of methods for OSMatrix
3751 
3752 
3755  OSMatrix(),
3756  matrixVarIdx(-1)
3757 {
3758 #ifndef NDEBUG
3759  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrixWithMatrixVarIdx Constructor");
3760 #endif
3761 }// end of OSMatrixWithMatrixVarIdx
3762 
3764 {
3765 #ifndef NDEBUG
3766  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrixWithMatrixVarIdx Destructor");
3767 #endif
3768 }// end of ~OSMatrixWithMatrixVarIdx
3769 
3770 
3772 {
3773  ostringstream outStr;
3774  outStr << "<matrixVar";
3775  outStr << " numberOfRows=\"" << numberOfRows << "\"";
3776  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
3777  outStr << " matrixVarIdx=\"" << matrixVarIdx << "\"";
3779  outStr << " symmetry=\"" << returnMatrixSymmetryString(symmetry) << "\"";
3780  if (name != "")
3781  outStr << " name=\"" << name << "\"";
3783  outStr << " type=\"" << returnMatrixTypeString(matrixType) << "\"";
3784 
3785  if (inumberOfChildren > 0)
3786  {
3787  outStr << ">" << std::endl;
3788  for (unsigned int i=0; i < inumberOfChildren; i++)
3789  outStr << m_mChildren[i]->getMatrixNodeInXML();
3790  outStr << "</matrixVar>" << std::endl;
3791  }
3792  else
3793  outStr << "/>" << std::endl;
3794  return outStr.str();
3795 }// end of OSMatrixWithMatrixVarIdx::getMatrixNodeInXML()
3796 
3798 {
3799  MatrixType *nodePtr;
3800  nodePtr = new OSMatrixWithMatrixVarIdx();
3801  return (OSMatrixWithMatrixVarIdx*)nodePtr;
3802 }// end of OSMatrixWithMatrixVarIdx::cloneMatrixNode
3803 
3806  OSMatrix(),
3807  matrixObjIdx(-1)
3808 {
3809 #ifndef NDEBUG
3810  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrixWithMatrixObjIdx Constructor");
3811 #endif
3812 }// end of OSMatrixWithMatrixObjIdx
3813 
3815 {
3816 #ifndef NDEBUG
3817  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrixWithMatrixObjIdx Destructor");
3818 #endif
3819 }// end of ~OSMatrixWithMatrixObjIdx
3820 
3821 
3823 {
3824  ostringstream outStr;
3825  outStr << "<matrixObj";
3826  outStr << " numberOfRows=\"" << numberOfRows << "\"";
3827  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
3828  outStr << " matrixObjIdx=\"" << matrixObjIdx << "\"";
3830  outStr << " symmetry=\"" << returnMatrixSymmetryString(symmetry) << "\"";
3831  if (name != "")
3832  outStr << " name=\"" << name << "\"";
3834  outStr << " type=\"" << returnMatrixTypeString(matrixType) << "\"";
3835 
3836  if (inumberOfChildren > 0)
3837  {
3838  outStr << ">" << std::endl;
3839  for (unsigned int i=0; i < inumberOfChildren; i++)
3840  outStr << m_mChildren[i]->getMatrixNodeInXML();
3841  outStr << "</matrixObj>" << std::endl;
3842  }
3843  else
3844  outStr << "/>" << std::endl;
3845  return outStr.str();
3846 }// end of OSMatrixWithMatrixObjIdx::getMatrixNodeInXML()
3847 
3849 {
3850  MatrixType *nodePtr;
3851  nodePtr = new OSMatrixWithMatrixObjIdx();
3852  return (OSMatrixWithMatrixObjIdx*)nodePtr;
3853 }// end of OSMatrixWithMatrixObjIdx::cloneMatrixNode
3854 
3857  OSMatrix(),
3858  matrixConIdx(-1)
3859 {
3860 #ifndef NDEBUG
3861  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrixWithMatrixConIdx Constructor");
3862 #endif
3863 }// end of OSMatrixWithMatrixConIdx
3864 
3866 {
3867 #ifndef NDEBUG
3868  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrixWithMatrixConIdx Destructor");
3869 #endif
3870 }// end of ~OSMatrixWithMatrixConIdx
3871 
3873 {
3874  ostringstream outStr;
3875  outStr << "<matrixCon";
3876  outStr << " numberOfRows=\"" << numberOfRows << "\"";
3877  outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
3878  outStr << " matrixConIdx=\"" << matrixConIdx << "\"";
3880  outStr << " symmetry=\"" << returnMatrixSymmetryString(symmetry) << "\"";
3881  if (name != "")
3882  outStr << " name=\"" << name << "\"";
3884  outStr << " type=\"" << returnMatrixTypeString(matrixType) << "\"";
3885 
3886  if (inumberOfChildren > 0)
3887  {
3888  outStr << ">" << std::endl;
3889  for (unsigned int i=0; i < inumberOfChildren; i++)
3890  outStr << m_mChildren[i]->getMatrixNodeInXML();
3891  outStr << "</matrixCon>" << std::endl;
3892  }
3893  else
3894  outStr << "/>" << std::endl;
3895  return outStr.str();
3896 }// end of OSMatrixWithMatrixConIdx::getMatrixNodeInXML()
3897 
3899 {
3900  MatrixType *nodePtr;
3901  nodePtr = new OSMatrixWithMatrixConIdx();
3902  return (OSMatrixWithMatrixConIdx*)nodePtr;
3903 }// end of OSMatrixWithMatrixConIdx::cloneMatrixNode
3904 
3907  baseMatrixIdx(-1),
3908  baseMatrix(NULL),
3909  targetMatrixFirstRow(0),
3910  targetMatrixFirstCol(0),
3911  baseMatrixStartRow(0),
3912  baseMatrixStartCol(0),
3913  baseMatrixEndRow(-1),
3914  baseMatrixEndCol(-1),
3915  baseTranspose(false),
3916  scalarMultiplier(1.0)
3917 {
3918 #ifndef NDEBUG
3919  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the BaseMatrix Constructor");
3920 #endif
3922 } // end of BaseMatrix
3923 
3925 {
3926 #ifndef NDEBUG
3927  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the BaseMatrix Destructor");
3928 #endif
3929 } // end of ~BaseMatrix
3930 
3932 {
3934 }// end of BaseMatrix::getNodeType()
3935 
3937 {
3938  return "baseMatrix";
3939 }// end of BaseMatrix::getNodeName()
3940 
3942 {
3943  return ((OSMatrix*)baseMatrix)->getMatrixType();
3944 }// end of BaseMatrix::getMatrixType()
3945 
3947 {
3948  ostringstream outStr;
3949  outStr << "<baseMatrix";
3950  outStr << " baseMatrixIdx=\"" << baseMatrixIdx << "\"";
3951  if (baseMatrixStartRow != 0)
3952  outStr << " baseMatrixStartRow=\"" << baseMatrixStartRow << "\"";
3953  if (baseMatrixStartCol != 0)
3954  outStr << " baseMatrixStartCol=\"" << baseMatrixStartCol << "\"";
3955  if (baseMatrixEndRow >= 0)
3956  outStr << " baseMatrixEndRow=\"" << baseMatrixEndRow << "\"";
3957  if (baseMatrixEndCol >= 0)
3958  outStr << " baseMatrixEndCol=\"" << baseMatrixEndCol << "\"";
3959  if (baseTranspose)
3960  outStr << " baseTranspose=\"true\"";
3961  if (scalarMultiplier != 1)
3962  outStr << " scalarMultiplier=\"" << scalarMultiplier << "\"";
3963  if (targetMatrixFirstRow != 0)
3964  outStr << " targetMatrixFirstRow=\"" << targetMatrixFirstRow << "\"";
3965  if (targetMatrixFirstCol != 0)
3966  outStr << " targetMatrixFirstCol=\"" << targetMatrixFirstCol << "\"";
3967  outStr << "/>" << std::endl;
3968  return outStr.str();
3969 }// end of BaseMatrix::getMatrixNodeInXML()
3970 
3971 bool BaseMatrix::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
3972 {
3973  return ((OSMatrix*)baseMatrix)->alignsOnBlockBoundary(firstRow, firstColumn, nRows, nCols);
3974 }// end of BaseMatrix::alignsOnBlockBoundary()
3975 
3977 {
3978  MatrixNode *nodePtr;
3979  nodePtr = new BaseMatrix();
3980  return (BaseMatrix*)nodePtr;
3981 }// end of BaseMatrix::cloneMatrixNode
3982 
3984 {
3985 #ifndef NDEBUG
3986  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in BaseMatrix");
3987 #endif
3988  if (this == NULL)
3989  {
3990  if (that == NULL)
3991  return true;
3992  else
3993  {
3994 #ifndef NDEBUG
3996  "First object is NULL, second is not");
3997 #endif
3998  return false;
3999  }
4000  }
4001  else
4002  {
4003  if (that == NULL)
4004  {
4005 #ifndef NDEBUG
4007  "Second object is NULL, first is not");
4008 #endif
4009  return false;
4010  }
4011  else
4012  {
4013  if (this->baseMatrixIdx != that->baseMatrixIdx) return false;
4014  if (this->targetMatrixFirstRow != that->targetMatrixFirstRow) return false;
4015  if (this->targetMatrixFirstCol != that->targetMatrixFirstCol) return false;
4016  if (this->baseMatrixStartRow != that->baseMatrixStartRow) return false;
4017  if (this->baseMatrixStartCol != that->baseMatrixStartCol) return false;
4018  if (this->baseMatrixEndRow != that->baseMatrixEndRow) return false;
4019  if (this->baseMatrixEndCol != that->baseMatrixEndCol) return false;
4020  if (this->baseTranspose != that->baseTranspose) return false;
4021  if (this->scalarMultiplier != that->scalarMultiplier) return false;
4022 
4023  return true;
4024  }
4025  }
4026 }// end of BaseMatrix::IsEqual()
4027 // end of methods for BaseMatrix
4028 
4029 
4033  transformation(NULL)
4034 {
4035 #ifndef NDEBUG
4036  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixTransformation Constructor");
4037 #endif
4039 }// end of MatrixTransformation::MatrixTransformation()
4040 
4042 {
4043 #ifndef NDEBUG
4044  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixTransformation Destructor");
4045 #endif
4046  if (transformation != NULL)
4047  delete transformation;
4048  transformation = NULL;
4049 }// end of MatrixTransformation::~MatrixTransformation()
4050 
4052 {
4054 }// end of MatrixTransformation::getNodeType()
4055 
4057 {
4058  return "transformation";
4059 }// end of MatrixTransformation::getNodeName()
4060 
4062 {
4065  return matrixType;
4066 }// end of MatrixTransformation::getMatrixType()
4067 
4069 {
4070  ostringstream outStr;
4071  outStr << "<transformation";
4073  outStr << " shape=\"" << returnExprShapeString(shape) << "\"";
4074  outStr << ">" << std::endl;
4075 
4076  outStr << transformation->getNonlinearExpressionInXML() << std::endl;
4077 
4078  outStr << "</transformation>" << std::endl;
4079  return outStr.str();
4080 }// end of MatrixTransformation::getMatrixNodeInXML()
4081 
4082 bool MatrixTransformation::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
4083 {
4084  return false;
4085 }// end of MatrixTransformation::alignsOnBlockBoundary()
4086 
4088 {
4089  MatrixTransformation *nodePtr;
4090  nodePtr = new MatrixTransformation();
4091  return (MatrixTransformation*)nodePtr;
4092 }// end of MatrixTransformation::cloneMatrixNode
4093 
4095 {
4096 #ifndef NDEBUG
4097  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixTransformation");
4098 #endif
4099  if (this == NULL)
4100  {
4101  if (that == NULL)
4102  return true;
4103  else
4104  {
4105 #ifndef NDEBUG
4107  "First object is NULL, second is not");
4108 #endif
4109  return false;
4110  }
4111  }
4112  else
4113  {
4114  if (that == NULL)
4115  {
4116 #ifndef NDEBUG
4118  "Second object is NULL, first is not");
4119 #endif
4120  return false;
4121  }
4122  else
4123  {
4124  if (!this->transformation->IsEqual(that->transformation))
4125  return false;
4126 
4127  return true;
4128  }
4129  }
4130 }// end of MatrixTransformation::IsEqual()
4131 //end of methods for MatrixTransformation
4132 
4133 
4136  value(NULL)
4137 {
4138 #ifndef NDEBUG
4139  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConstantMatrixElements Constructor");
4140 #endif
4141 }// end of ConstantMatrixElements::ConstantMatrixElements()
4142 
4144 {
4145 #ifndef NDEBUG
4147  "Inside the ConstantMatrixElements Destructor");
4148 
4149  ostringstream outStr;
4150  outStr.str("");
4151  outStr.clear();
4152  outStr << "deleting ConstantMatrixElements->value at " << &value << std::endl;
4154  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
4155 #endif
4156  if (value != NULL)
4157  delete value;
4158  value = NULL;
4159 }// end of ConstantMatrixElements::~ConstantMatrixElements()
4160 
4162 {
4164 }// end of ConstantMatrixElements::getNodeType()
4165 
4167 {
4168  return "constantElements";
4169 }// end of ConstantMatrixElements::getNodeName()
4170 
4172 {
4175  return matrixType;
4176 }// end of ConstantMatrixElements::getMatrixType()
4177 
4179 {
4180  ostringstream outStr;
4181  outStr << "<constantElements";
4182  if (rowMajor)
4183  outStr << " rowMajor=\"true\"";
4184  outStr << " numberOfValues=\"" << numberOfValues << "\"";
4185  outStr << ">" << std::endl;
4186 
4187  outStr << "<start>" << std::endl;
4188  outStr << writeIntVectorData(start, true, false);
4189  outStr << "</start>" << std::endl;
4190 
4191  if (numberOfValues > 0)
4192  {
4193  outStr << "<index>" << std::endl;
4194  outStr << writeIntVectorData(index, true, false);
4195  outStr << "</index>" << std::endl;
4196 
4197  outStr << "<value>" << std::endl;
4198 
4199  for(int i = 0; i < numberOfValues;)
4200  {
4201  int mult = getMult(&(value->el[i]), numberOfValues - i);
4202  if (mult == 1)
4203  outStr << "<el>" ;
4204  else
4205  outStr << "<el mult=\"" << mult << "\">";
4206  outStr << os_dtoa_format(value->el[i]);
4207  outStr << "</el>" << std::endl;
4208  i += mult;
4209  }
4210  outStr << "</value>" << std::endl;
4211  }
4212 
4213  outStr << "</constantElements>" << std::endl;
4214  return outStr.str();
4215 }// end of ConstantMatrixElements::getMatrixNodeInXML()
4216 
4217 bool ConstantMatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
4218 {
4219  return false;
4220 }// end of ConstantMatrixElements::alignsOnBlockBoundary()
4221 
4223 {
4224  ConstantMatrixElements *nodePtr;
4225  nodePtr = new ConstantMatrixElements();
4226  return (ConstantMatrixElements*)nodePtr;
4227 }// end of ConstantMatrixElements::cloneMatrixNode
4228 
4230 {
4231 #ifndef NDEBUG
4232  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in BaseMatrix");
4233 #endif
4234  if (this == NULL)
4235  {
4236  if (that == NULL)
4237  return true;
4238  else
4239  {
4240 #ifndef NDEBUG
4242  "First object is NULL, second is not");
4243 #endif
4244  return false;
4245  }
4246  }
4247  else
4248  {
4249  if (that == NULL)
4250  {
4251 #ifndef NDEBUG
4253  "Second object is NULL, first is not");
4254 #endif
4255  return false;
4256  }
4257  else
4258  {
4259  if (this->rowMajor != that->rowMajor) return false;
4260  if (this->numberOfValues != that->numberOfValues) return false;
4261 
4262  if (!this->start->IsEqual(that->start)) return false;
4263  if (!this->index->IsEqual(that->index)) return false;
4264  if (!this->value->IsEqual(that->value)) return false;
4265 
4266  return true;
4267  }
4268  }
4269 }// end of ConstantMatrixElements::IsEqual()
4270 
4271 bool ConstantMatrixElements::setRandom(double density, bool conformant, int iMin, int iMax)
4272 {
4273  return true;
4274 }// end of ConstantMatrixElements::setRandom()
4275 
4277 {
4278  return true;
4279 }// end of ConstantMatrixElements::deepCopyFrom()
4280 
4281 
4284  el(NULL)
4285 {
4286 #ifndef NDEBUG
4287  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConstantMatrixValues Constructor");
4288 #endif
4289 }// end of ConstantMatrixValues::ConstantMatrixValues()
4290 
4292 {
4293 #ifndef NDEBUG
4294  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConstantMatrixValues Destructor");
4295  ostringstream outStr;
4296  outStr.str("");
4297  outStr.clear();
4298  outStr << "deleting ConstantMatrixValues->el at " << &el << std::endl;
4300  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
4301 #endif
4302  if (el != NULL)
4303  delete [] el;
4304  el = NULL;
4305 }// end of ConstantMatrixValues::~ConstantMatrixValues()
4306 
4308 {
4309 #ifndef NDEBUG
4310  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in ConstantMatrixValues");
4311 #endif
4312  if (this == NULL)
4313  {
4314  if (that == NULL)
4315  return true;
4316  else
4317  {
4318 #ifndef NDEBUG
4320  "First object is NULL, second is not");
4321 #endif
4322  return false;
4323  }
4324  }
4325  else
4326  {
4327  if (that == NULL)
4328  {
4329 #ifndef NDEBUG
4331  "Second object is NULL, first is not");
4332 #endif
4333  return false;
4334  }
4335  else
4336  {
4337  if (this->numberOfEl != that->numberOfEl) return false;
4338  for (int i=0; i < numberOfEl; i++)
4339  if (this->el[i] != that->el[i]) return false;
4340 
4341  return true;
4342  }
4343  }
4344 }// end of ConstantMatrixValues::IsEqual()
4345 
4346 bool ConstantMatrixValues::setRandom(double density, bool conformant, int iMin, int iMax)
4347 {
4348  return true;
4349 }// end of ConstantMatrixValues::setRandom()
4350 
4352 {
4353 #ifndef NDEBUG
4354  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of ConstantMatrixValues");
4355 #endif
4356  this->numberOfEl = that->numberOfEl;
4357  this->el = new double[numberOfEl];
4358  for (int i=0; i<numberOfEl; i++)
4359  this->el[i] = that->el[i];
4360 
4361  return true;
4362 }// end of ConstantMatrixValues::deepCopyFrom()
4363 
4364 
4367  value(NULL)
4368 {
4369 #ifndef NDEBUG
4370  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the VarReferenceMatrixElements Constructor");
4371 #endif
4372 }// end of VarReferenceMatrixElements::VarReferenceMatrixElements()
4373 
4375 {
4376 #ifndef NDEBUG
4378  "Inside the VarReferenceMatrixElements Destructor");
4379 
4380  ostringstream outStr;
4381  outStr.str("");
4382  outStr.clear();
4383  outStr << "deleting VarReferenceMatrixElements->value at " << &value << std::endl;
4385  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
4386 #endif
4387  if (value != NULL)
4388  delete value;
4389  value = NULL;
4390 }// end of VarReferenceMatrixElements::~VarReferenceMatrixElements()
4391 
4393 {
4395 }// end of VarReferenceMatrixElements::getNodeType()
4396 
4398 {
4399  return "varReferenceElements";
4400 }// end of VarReferenceMatrixElements::getNodeName()
4401 
4403 {
4406  return matrixType;
4407 }// end of VarReferenceMatrixElements::getMatrixType()
4408 
4410 {
4411  int mult, incr;
4412  ostringstream outStr;
4413  outStr << "<varReferenceElements";
4414  if (rowMajor)
4415  outStr << " rowMajor=\"true\"";
4416  outStr << " numberOfValues=\"" << numberOfValues << "\"";
4417  outStr << ">" << std::endl;
4418 
4419  outStr << "<start>" << std::endl;
4420  outStr << writeIntVectorData(start, true, false);
4421  outStr << "</start>" << std::endl;
4422 
4423  if (numberOfValues > 0)
4424  {
4425  outStr << "<index>" << std::endl;
4426  outStr << writeIntVectorData(index, true, false);
4427  outStr << "</index>" << std::endl;
4428 
4429  outStr << "<value>" << std::endl;
4430 
4431  for(int i = 0; i < numberOfValues;)
4432  {
4433  getMultIncr(&(value->el[i]), &mult, &incr, (value->numberOfEl) - i, 0);
4434  if (mult == 1)
4435  outStr << "<el>";
4436  else if (incr == 0)
4437  outStr << "<el mult=\"" << mult << "\">";
4438  else
4439  outStr << "<el mult=\"" << mult << "\" incr=\"" << incr << "\">";
4440  outStr << value->el[i];
4441  outStr << "</el>" << std::endl;
4442  i += mult;
4443  }
4444  outStr << "</value>" << std::endl;
4445  }
4446 
4447  outStr << "</varReferenceElements>" << std::endl;
4448  return outStr.str();
4449 }// end of VarReferenceMatrixElements::getMatrixNodeInXML()
4450 
4451 bool VarReferenceMatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
4452 {
4453  return false;
4454 }// end of VarReferenceMatrixElements::alignsOnBlockBoundary()
4455 
4457 {
4458  VarReferenceMatrixElements *nodePtr;
4459  nodePtr = new VarReferenceMatrixElements();
4460  return (VarReferenceMatrixElements*)nodePtr;
4461 }// end of VarReferenceMatrixElements::cloneMatrixNode
4462 
4464 {
4465 #ifndef NDEBUG
4466  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in VarReferenceMatrixElements");
4467 #endif
4468  if (this == NULL)
4469  {
4470  if (that == NULL)
4471  return true;
4472  else
4473  {
4474 #ifndef NDEBUG
4476  "First object is NULL, second is not");
4477 #endif
4478  return false;
4479  }
4480  }
4481  else
4482  {
4483  if (that == NULL)
4484  {
4485 #ifndef NDEBUG
4487  "Second object is NULL, first is not");
4488 #endif
4489  return false;
4490  }
4491  else
4492  {
4493  if (this->rowMajor != that->rowMajor) return false;
4494  if (this->numberOfValues != that->numberOfValues) return false;
4495 
4496  if (!this->start->IsEqual(that->start)) return false;
4497  if (!this->index->IsEqual(that->index)) return false;
4498  if (!this->value->IsEqual(that->value)) return false;
4499 
4500  return true;
4501  }
4502  }
4503 }// end of VarReferenceMatrixElements::IsEqual()
4504 
4505 bool VarReferenceMatrixElements::setRandom(double density, bool conformant, int iMin, int iMax)
4506 {
4507  return true;
4508 }// end of VarReferenceMatrixElements::setRandom()
4509 
4511 {
4512  return true;
4513 }// end of VarReferenceMatrixElements::deepCopyFrom()
4514 
4515 
4518  el(NULL)
4519 {
4520 #ifndef NDEBUG
4521  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the VarReferenceMatrixValues Constructor");
4522 #endif
4523 }// end of VarReferenceMatrixValues::VarReferenceMatrixValues()
4524 
4526 {
4527 #ifndef NDEBUG
4529  "Inside the VarReferenceMatrixValues Destructor");
4530  ostringstream outStr;
4531  outStr.str("");
4532  outStr.clear();
4533  outStr << "deleting VarReferenceMatrixValues->el at " << &el << std::endl;
4535  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
4536 #endif
4537  if (el != NULL)
4538  delete [] el;
4539  el = NULL;
4540 }// end of VarReferenceMatrixValues::~VarReferenceMatrixValues()
4541 
4543 {
4544 #ifndef NDEBUG
4545  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in VarReferenceMatrixValues");
4546 #endif
4547  if (this == NULL)
4548  {
4549  if (that == NULL)
4550  return true;
4551  else
4552  {
4553 #ifndef NDEBUG
4555  "First object is NULL, second is not");
4556 #endif
4557  return false;
4558  }
4559  }
4560  else
4561  {
4562  if (that == NULL)
4563  {
4564 #ifndef NDEBUG
4566  "Second object is NULL, first is not");
4567 #endif
4568  return false;
4569  }
4570  else
4571  {
4572  if (this->numberOfEl != that->numberOfEl) return false;
4573  for (int i=0; i < numberOfEl; i++)
4574  if (this->el[i] != that->el[i]) return false;
4575 
4576  return true;
4577  }
4578  }
4579 }// end of VarReferenceMatrixValues::IsEqual()
4580 
4581 bool VarReferenceMatrixValues::setRandom(double density, bool conformant, int iMin, int iMax)
4582 {
4583  return true;
4584 }// end of VarReferenceMatrixValues::setRandom()
4585 
4587 {
4588 #ifndef NDEBUG
4589  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of VarReferenceMatrixValues");
4590 #endif
4591  this->numberOfEl = that->numberOfEl;
4592  this->el = new int[numberOfEl];
4593  for (int i=0; i<numberOfEl; i++)
4594  this->el[i] = that->el[i];
4595 
4596  return true;
4597 }// end of VarReferenceMatrixValues::deepCopyFrom()
4598 
4599 
4602  value(NULL)
4603 {
4604 #ifndef NDEBUG
4605  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the LinearMatrixElements Constructor");
4606 #endif
4607 }// end of LinearMatrixElements::LinearMatrixElements()
4608 
4610 {
4611  std::ostringstream outStr;
4612 #ifndef NDEBUG
4614  "Inside the LinearMatrixElements Destructor");
4615 
4616  outStr.str("");
4617  outStr.clear();
4618  outStr << "deleting LinearMatrixElements->value at " << &value << std::endl;
4620  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
4621 #endif
4622  if (value != NULL)
4623  delete value;
4624  value = NULL;
4625 }// end of LinearMatrixElements::~LinearMatrixElements()
4626 
4628 {
4630 }// end of LinearMatrixElements::getNodeType()
4631 
4633 {
4634  return "linearElements";
4635 }// end of LinearMatrixElements::getNodeName()
4636 
4638 {
4641  return matrixType;
4642 }// end of LinearMatrixElements::getMatrixType()
4643 
4645 {
4646  ostringstream outStr;
4647  outStr << "<linearElements";
4648  if (rowMajor)
4649  outStr << " rowMajor=\"true\"";
4650  outStr << " numberOfValues=\"" << numberOfValues << "\"";
4651  outStr << ">" << std::endl;
4652 
4653  outStr << "<start>" << std::endl;
4654  outStr << writeIntVectorData(start, true, false);
4655  outStr << "</start>" << std::endl;
4656 
4657  if (numberOfValues > 0)
4658  {
4659  outStr << "<index>" << std::endl;
4660  outStr << writeIntVectorData(index, true, false);
4661  outStr << "</index>" << std::endl;
4662 
4663  outStr << "<value>" << std::endl;
4664 
4665  int i,j;
4666  for (i=0; i < numberOfValues; i++)
4667  {
4668  outStr << "<el";
4669  outStr << " numberOfVarIdx=\"" << value->el[i]->numberOfVarIdx << "\"";
4670  if (value->el[i]->constant != 0.0)
4671  outStr << " constant=\"" << value->el[i]->constant << "\"";
4672  outStr << ">" << std::endl;
4673 
4674  for (j=0; j < value->el[i]->numberOfVarIdx; j++)
4675  {
4676  outStr << "<varIdx";
4677  if (value->el[i]->varIdx[j]->coef != 1.0)
4678  outStr << " coef=\"" << value->el[i]->varIdx[j]->coef << "\"";
4679  outStr << ">";
4680  outStr << value->el[i]->varIdx[j]->idx;
4681  outStr << "</varIdx>" << std::endl;
4682  }
4683 
4684  outStr << "</el>" << std::endl;
4685  }
4686  outStr << "</value>" << std::endl;
4687  }
4688  outStr << "</linearElements>" << std::endl;
4689  return outStr.str();
4690 }// end of LinearMatrixElements::getMatrixNodeInXML()
4691 
4692 bool LinearMatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
4693 {
4694  return false;
4695 }// end of LinearMatrixElements::alignsOnBlockBoundary()
4696 
4698 {
4699  LinearMatrixElements *nodePtr;
4700  nodePtr = new LinearMatrixElements();
4701  return (LinearMatrixElements*)nodePtr;
4702 }// end of LinearMatrixElements::cloneMatrixNode
4703 
4705 {
4706 #ifndef NDEBUG
4707  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in LinearMatrixElements");
4708 #endif
4709  if (this == NULL)
4710  {
4711  if (that == NULL)
4712  return true;
4713  else
4714  {
4715 #ifndef NDEBUG
4717  "First object is NULL, second is not");
4718 #endif
4719  return false;
4720  }
4721  }
4722  else
4723  {
4724  if (that == NULL)
4725  {
4726 #ifndef NDEBUG
4728  "Second object is NULL, first is not");
4729 #endif
4730  return false;
4731  }
4732  else
4733  {
4734  if (this->rowMajor != that->rowMajor) return false;
4735  if (this->numberOfValues != that->numberOfValues) return false;
4736 
4737  if (!this->start->IsEqual(that->start)) return false;
4738  if (!this->index->IsEqual(that->index)) return false;
4739  if (!this->value->IsEqual(that->value)) return false;
4740 
4741  return true;
4742  }
4743  }
4744 }// end of LinearMatrixElements::IsEqual()
4745 
4746 bool LinearMatrixElements::setRandom(double density, bool conformant, int iMin, int iMax)
4747 {
4748  return true;
4749 }// end of LinearMatrixElements::setRandom()
4750 
4752 {
4753  return true;
4754 }// end of LinearMatrixElements::deepCopyFrom()
4755 
4756 
4759  el(NULL)
4760 {
4761 #ifndef NDEBUG
4763  "Inside the LinearMatrixValues Constructor");
4764 
4765 #endif
4766 }// end of LinearMatrixValues::LinearMatrixValues()
4767 
4769 {
4770  std::ostringstream outStr;
4771 #ifndef NDEBUG
4773  "Inside the LinearMatrixValues Destructor");
4774 
4775  outStr.str("");
4776  outStr.clear();
4777  outStr << "deleting LinearMatrixValues->el at " << &el << std::endl;
4779  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
4780 #endif
4781 
4782  if (el != NULL)
4783  {
4784  for (int i=0; i < numberOfEl; i++)
4785  {
4786  if (el[i] != NULL)
4787  {
4788 #ifndef NDEBUG
4789  outStr.str("");
4790  outStr.clear();
4791  outStr << "deleting LinearMatrixValues->el [" << i << "] at " << &el[i] << std::endl;
4793  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
4794 #endif
4795  delete el[i];
4796  el[i] = NULL;
4797  }
4798  }
4799  delete [] el;
4800  el = NULL;
4801  }
4802 }// end of LinearMatrixValues::~LinearMatrixValues()
4803 
4805 {
4806 #ifndef NDEBUG
4807  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in LinearMatrixValues");
4808 #endif
4809  if (this == NULL)
4810  {
4811  if (that == NULL || that->numberOfEl == 0)
4812  return true;
4813  else
4814  {
4815 #ifndef NDEBUG
4817  "First object is NULL, second is not");
4818 #endif
4819  return false;
4820  }
4821  }
4822  else
4823  {
4824  if (that == NULL || that->numberOfEl == 0)
4825  {
4826 #ifndef NDEBUG
4828  "Second object is NULL, first is not");
4829 #endif
4830  return false;
4831  }
4832  else
4833  {
4834  if (this->numberOfEl != that->numberOfEl) return false;
4835 
4836  for (int i=0; i < numberOfEl; i++)
4837  if (!this->el[i]->IsEqual(that->el[i])) return false;
4838 
4839  return true;
4840  }
4841  }
4842 }// end of LinearMatrixValues::IsEqual()
4843 
4844 bool LinearMatrixValues::setRandom(double density, bool conformant, int iMin, int iMax)
4845 {
4846  return true;
4847 }// end of LinearMatrixValues::setRandom()
4848 
4850 {
4851 #ifndef NDEBUG
4852  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of LinearMatrixValues");
4853 #endif
4854  this->numberOfEl = that->numberOfEl;
4855  this->el = new LinearMatrixElement*[numberOfEl];
4856  for (int i=0; i<numberOfEl; i++)
4857  {
4858  this->el[i] = new LinearMatrixElement();
4859  ((LinearMatrixValues*)this)->el[i]->deepCopyFrom(that->el[i]);
4860  }
4861  return true;
4862 }// end of LinearMatrixValues::deepCopyFrom()
4863 
4864 
4867  numberOfVarIdx(0),
4868  constant(0.0),
4869  varIdx(NULL)
4870 {
4871 #ifndef NDEBUG
4873  ENUM_OUTPUT_LEVEL_trace, "Inside the LinearMatrixElement Constructor");
4874 #endif
4875 }// end of LinearMatrixElement::LinearMatrixElement()
4876 
4878 {
4879  std::ostringstream outStr;
4880 #ifndef NDEBUG
4882  ENUM_OUTPUT_LEVEL_trace, "Inside the LinearMatrixElement Destructor");
4883  outStr.str("");
4884  outStr.clear();
4885  outStr << "NUMBER OF VARIDX = " << numberOfVarIdx << endl;
4887 #endif
4888  if (varIdx != NULL)
4889  {
4890  for (int i=0; i < numberOfVarIdx; i++)
4891  {
4892 #ifndef NDEBUG
4893  outStr.str("");
4894  outStr.clear();
4895  outStr << "DESTROYING VARIDX " << i << " at " << &varIdx[i] << std::endl;
4897 #endif
4898  if (varIdx[i] != NULL)
4899  delete varIdx[i];
4900  varIdx[i] = NULL;
4901  }
4902  delete [] varIdx;
4903  varIdx = NULL;
4904  }
4905 }// end of LinearMatrixElement::~LinearMatrixElement()
4906 
4908 {
4909 #ifndef NDEBUG
4910  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in LinearMatrixElement");
4911 #endif
4912  if (this == NULL)
4913  {
4914  if (that == NULL || that->numberOfVarIdx == 0)
4915  return true;
4916  else
4917  {
4918 #ifndef NDEBUG
4920  "First object is NULL, second is not");
4921 #endif
4922  return false;
4923  }
4924  }
4925  else
4926  {
4927  if (that == NULL || that->numberOfVarIdx == 0)
4928  {
4929 #ifndef NDEBUG
4931  "Second object is NULL, first is not");
4932 #endif
4933  return false;
4934  }
4935  else
4936  {
4937  if (this->numberOfVarIdx != that->numberOfVarIdx) return false;
4938  if (this->constant != that->constant) return false;
4939 
4940  for (int i=0; i < numberOfVarIdx; i++)
4941  if (!this->varIdx[i]->IsEqual(that->varIdx[i])) return false;
4942 
4943  return true;
4944  }
4945  }
4946 }// end of LinearMatrixElement::IsEqual()
4947 
4948 bool LinearMatrixElement::setRandom(double density, bool conformant, int iMin, int iMax)
4949 {
4950  return true;
4951 }// end of LinearMatrixElement::setRandom()
4952 
4954 {
4955  try
4956  {
4957  this->constant = that->constant;
4958  this->numberOfVarIdx = that->numberOfVarIdx;
4960  for (int i=0; i<numberOfVarIdx; i++)
4961  {
4962  this->varIdx[i] = new LinearMatrixElementTerm();
4963  ((LinearMatrixElement*)this)->varIdx[i]->deepCopyFrom(that->varIdx[i]);
4964  }
4965  return true;
4966  }
4967  catch(const ErrorClass& eclass)
4968  {
4969  throw ErrorClass( eclass.errormsg);
4970  }
4971 }// end of LinearMatrixElement::deepCopyFrom()
4972 
4973 
4976  idx(-1),
4977  coef(1.0)
4978 {
4979 #ifndef NDEBUG
4980  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the LinearMatrixElementTerm Constructor");
4981 #endif
4982 }// end of LinearMatrixElementTerm::LinearMatrixElementTerm()
4983 
4985 {
4986 #ifndef NDEBUG
4987  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the LinearMatrixElementTerm Destructor");
4988 #endif
4989 }// end of LinearMatrixElementTerm::~LinearMatrixElementTerm()
4990 
4992 {
4993 #ifndef NDEBUG
4994  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in LinearMatrixElementTerm");
4995 #endif
4996  if (this == NULL)
4997  {
4998  if (that == NULL)
4999  return true;
5000  else
5001  {
5002 #ifndef NDEBUG
5004  "First object is NULL, second is not");
5005 #endif
5006  return false;
5007  }
5008  }
5009  else
5010  {
5011  if (that == NULL)
5012  {
5013 #ifndef NDEBUG
5015  "Second object is NULL, first is not");
5016 #endif
5017  return false;
5018  }
5019  else
5020  {
5021  if (this->idx != that->idx) return false;
5022  if (this->coef != that->coef) return false;
5023 
5024  return true;
5025  }
5026  }
5027 }// end of LinearMatrixElementTerm::IsEqual()
5028 
5029 bool LinearMatrixElementTerm::setRandom(double density, bool conformant, int iMin, int iMax)
5030 {
5031  return true;
5032 }// end of LinearMatrixElementTerm::setRandom()
5033 
5035 {
5036  this->coef = that->coef;
5037  this->idx = that->idx;
5038  return true;
5039 }// end of LinearMatrixElementTerm::deepCopyFrom()
5040 
5041 
5044  value(NULL)
5045 {
5046 #ifndef NDEBUG
5047  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralMatrixElements Constructor");
5048 #endif
5049 }// end of GeneralMatrixElements::GeneralMatrixElements()
5050 
5052 {
5053 #ifndef NDEBUG
5055  ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralMatrixElements Destructor");
5056 
5057  ostringstream outStr;
5058  outStr.str("");
5059  outStr.clear();
5060  outStr << "deleting GeneralMatrixElements->value at " << &value << std::endl;
5062  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
5063 #endif
5064  if (value != NULL)
5065  delete value;
5066  value = NULL;
5067 }// end of GeneralMatrixElements::~GeneralMatrixElements()
5068 
5070 {
5072 }// end of GeneralMatrixElements::getNodeType()
5073 
5075 {
5076  return "generalElements";
5077 }// end of GeneralMatrixElements::getNodeName()
5078 
5080 {
5083  return matrixType;
5084 }// end of GeneralMatrixElements::getMatrixType()
5085 
5087 {
5088  ostringstream outStr;
5089  outStr << "<generalElements";
5090  if (rowMajor)
5091  outStr << " rowMajor=\"true\"";
5092  outStr << " numberOfValues=\"" << numberOfValues << "\"";
5093  outStr << ">" << std::endl;
5094 
5095  outStr << "<start>" << std::endl;
5096  outStr << writeIntVectorData(start, true, false);
5097  outStr << "</start>" << std::endl;
5098 
5099  if (numberOfValues > 0)
5100  {
5101  outStr << "<index>" << std::endl;
5102  outStr << writeIntVectorData(index, true, false);
5103  outStr << "</index>" << std::endl;
5104 
5105  outStr << "<value>" << std::endl;
5106 
5107  for (int i=0; i < numberOfValues; i++)
5108  {
5109  outStr << "<el>";
5110  outStr << value->el[i]->m_treeRoot->getNonlinearExpressionInXML();
5111  outStr << "</el>" << std::endl;
5112  }
5113  outStr << "</value>" << std::endl;
5114  }
5115  outStr << "</generalElements>" << std::endl;
5116  return outStr.str();
5117 }// end of GeneralMatrixElements::getMatrixNodeInXML()
5118 
5119 bool GeneralMatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
5120 {
5121  return false;
5122 }// end of GeneralMatrixElements::alignsOnBlockBoundary()
5123 
5125 {
5126  GeneralMatrixElements *nodePtr;
5127  nodePtr = new GeneralMatrixElements();
5128  return (GeneralMatrixElements*)nodePtr;
5129 }// end of GeneralMatrixElements::cloneMatrixNode
5130 
5132 {
5133 #ifndef NDEBUG
5134  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in GeneralMatrixElements");
5135 #endif
5136  if (this == NULL)
5137  {
5138  if (that == NULL)
5139  return true;
5140  else
5141  {
5142 #ifndef NDEBUG
5144  "First object is NULL, second is not");
5145 #endif
5146  return false;
5147  }
5148  }
5149  else
5150  {
5151  if (that == NULL)
5152  {
5153 #ifndef NDEBUG
5155  "Second object is NULL, first is not");
5156 #endif
5157  return false;
5158  }
5159  else
5160  {
5161  if (this->rowMajor != that->rowMajor) return false;
5162  if (this->numberOfValues != that->numberOfValues) return false;
5163 
5164  if (!this->start->IsEqual(that->start)) return false;
5165  if (!this->index->IsEqual(that->index)) return false;
5166  if (!this->value->IsEqual(that->value)) return false;
5167 
5168  return true;
5169  }
5170  }
5171 }// end of GeneralMatrixElements::IsEqual()
5172 
5173 bool GeneralMatrixElements::setRandom(double density, bool conformant, int iMin, int iMax)
5174 {
5175  return true;
5176 }// end of GeneralMatrixElements::setRandom()
5177 
5179 {
5180  return true;
5181 }// end of GeneralMatrixElements::deepCopyFrom()
5182 
5183 
5186  el(NULL)
5187 {
5188 #ifndef NDEBUG
5189  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralMatrixValues Constructor");
5190 #endif
5191 }// end of GeneralMatrixValues::GeneralMatrixValues()
5192 
5194 {
5195  std::ostringstream outStr;
5196 
5197 #ifndef NDEBUG
5199  ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralMatrixValues Destructor");
5200  outStr.str("");
5201  outStr.clear();
5202  outStr << "NUMBER OF VALUES = " << numberOfEl << endl;
5204 #endif
5205  if (numberOfEl > 0 && el != NULL)
5206  {
5207  for (int i=0; i < numberOfEl; i++)
5208  {
5209  if (el[i] != NULL)
5210  {
5211 #ifndef NDEBUG
5212  outStr.str("");
5213  outStr.clear();
5214  outStr << "deleting ConstantMatrixValues->el [" << i << "] at " << &el[i] << std::endl;
5216  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
5217 #endif
5218  delete el[i];
5219  el[i] = NULL;
5220  }
5221  }
5222  }
5223  if (el != NULL)
5224  delete [] el;
5225  el = NULL;
5226 }// end of GeneralMatrixValues::~GeneralMatrixValues()
5227 
5229 {
5230 #ifndef NDEBUG
5232  ENUM_OUTPUT_LEVEL_trace, "Start comparing in GeneralMatrixValues");
5233 #endif
5234  if (this == NULL)
5235  {
5236  if (that == NULL || that->numberOfEl == 0)
5237  return true;
5238  else
5239  {
5240 #ifndef NDEBUG
5242  "First object is NULL, second is not");
5243 #endif
5244  return false;
5245  }
5246  }
5247  else
5248  {
5249  if (that == NULL || that->numberOfEl == 0)
5250  {
5251 #ifndef NDEBUG
5253  "Second object is NULL, first is not");
5254 #endif
5255  return false;
5256  }
5257  else
5258  {
5259  if (this->numberOfEl != that->numberOfEl) return false;
5260 
5261  for (int i=0; i < numberOfEl; i++)
5262  if (!this->el[i]->IsEqual(that->el[i])) return false;
5263 
5264  return true;
5265  }
5266  }
5267 }// end of GeneralMatrixValues::IsEqual()
5268 
5270 {
5271 #ifndef NDEBUG
5272  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of GeneralMatrixValues");
5273 #endif
5274  this->numberOfEl = that->numberOfEl;
5275  this->el = new ScalarExpressionTree*[numberOfEl];
5276  for (int i=0; i<numberOfEl; i++)
5277  {
5278  this->el[i] = new ScalarExpressionTree();
5279 // this->el[i]->m_treeRoot = new OSnLNode();
5280  this->el[i]->m_treeRoot->copyNodeAndDescendants();
5281  }
5282  return true;
5283 }// end of GeneralMatrixValues::deepCopyFrom()
5284 
5287  value(NULL)
5288 {
5289 #ifndef NDEBUG
5290  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ObjReferenceMatrixElements Constructor");
5291 #endif
5292 }// end of ObjReferenceMatrixElements::ObjReferenceMatrixElements()
5293 
5295 {
5296 #ifndef NDEBUG
5298  ENUM_OUTPUT_LEVEL_trace, "Inside the ObjReferenceMatrixElements Destructor");
5299 
5300  ostringstream outStr;
5301  outStr.str("");
5302  outStr.clear();
5303  outStr << "deleting ObjReferenceMatrixElements->value at " << &value << std::endl;
5305  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
5306 #endif
5307  if (value != NULL)
5308  delete value;
5309  value = NULL;
5310 }// end of ObjReferenceMatrixElements::~ObjReferenceMatrixElements()
5311 
5313 {
5315 }// end of ObjReferenceMatrixElements::getNodeType()
5316 
5318 {
5319  return "objRefElements";
5320 }// end of ObjReferenceMatrixElements::getNodeName()
5321 
5323 {
5326  return matrixType;
5327 }// end of ObjReferenceMatrixElements::getMatrixType()
5328 
5330 {
5331  ostringstream outStr;
5332  outStr << "<objReferenceElements";
5333  if (rowMajor)
5334  outStr << " rowMajor=\"true\"";
5335  outStr << " numberOfValues=\"" << numberOfValues << "\"";
5336  outStr << ">" << std::endl;
5337 
5338  outStr << "<start>" << std::endl;
5339  outStr << writeIntVectorData(start, true, false);
5340  outStr << "</start>" << std::endl;
5341 
5342  int mult, incr;
5343  if (numberOfValues > 0)
5344  {
5345  outStr << "<index>" << std::endl;
5346  outStr << writeIntVectorData(index, true, false);
5347  outStr << "</index>" << std::endl;
5348 
5349  outStr << "<value>" << std::endl;
5350 
5351  for(int i = 0; i < numberOfValues;)
5352  {
5353  getMultIncr(&(value->el[i]), &mult, &incr, (value->numberOfEl) - i, 0);
5354  if (mult == 1)
5355  outStr << "<el>";
5356  else if (incr == 0)
5357  outStr << "<el mult=\"" << mult << "\">";
5358  else
5359  outStr << "<el mult=\"" << mult << "\" incr=\"" << incr << "\">";
5360  outStr << value->el[i];
5361  outStr << "</el>" << std::endl;
5362  i += mult;
5363  }
5364  outStr << "</value>" << std::endl;
5365  }
5366 
5367  outStr << "</objReferenceElements>" << std::endl;
5368  return outStr.str();
5369 }// end of ObjReferenceMatrixElements::getMatrixNodeInXML()
5370 
5371 bool ObjReferenceMatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
5372 {
5373  return false;
5374 }// end of ObjReferenceMatrixElements::alignsOnBlockBoundary()
5375 
5377 {
5378  ObjReferenceMatrixElements *nodePtr;
5379  nodePtr = new ObjReferenceMatrixElements();
5380  return (ObjReferenceMatrixElements*)nodePtr;
5381 }// end of ObjReferenceMatrixElements::cloneMatrixNode
5382 
5384 {
5385 #ifndef NDEBUG
5386  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in ObjReferenceMatrixElements");
5387 #endif
5388  if (this == NULL)
5389  {
5390  if (that == NULL)
5391  return true;
5392  else
5393  {
5394 #ifndef NDEBUG
5396  "First object is NULL, second is not");
5397 #endif
5398  return false;
5399  }
5400  }
5401  else
5402  {
5403  if (that == NULL)
5404  {
5405 #ifndef NDEBUG
5407  "Second object is NULL, first is not");
5408 #endif
5409  return false;
5410  }
5411  else
5412  {
5413  if (this->rowMajor != that->rowMajor) return false;
5414  if (this->numberOfValues != that->numberOfValues) return false;
5415 
5416  if (!this->start->IsEqual(that->start)) return false;
5417  if (!this->index->IsEqual(that->index)) return false;
5418  if (!this->value->IsEqual(that->value)) return false;
5419 
5420  return true;
5421  }
5422  }
5423 }// end of ObjReferenceMatrixElements::IsEqual()
5424 
5425 bool ObjReferenceMatrixElements::setRandom(double density, bool conformant, int iMin, int iMax)
5426 {
5427  return true;
5428 }// end of ObjReferenceMatrixElements::setRandom()
5429 
5431 {
5432  return true;
5433 }// end of ObjReferenceMatrixElements::deepCopyFrom()
5434 
5435 
5438  el(NULL)
5439 {
5440 #ifndef NDEBUG
5441  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ObjReferenceMatrixValues Constructor");
5442 #endif
5443 }// end of ObjReferenceMatrixValues::ObjReferenceMatrixValues()
5444 
5446 {
5447 #ifndef NDEBUG
5449  ENUM_OUTPUT_LEVEL_trace, "Inside the ObjReferenceMatrixValues Destructor");
5450 
5451  ostringstream outStr;
5452  outStr.str("");
5453  outStr.clear();
5454  outStr << "deleting ObjReferenceMatrixValues->el at " << &el << std::endl;
5456  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
5457 #endif
5458  if (el != NULL)
5459  delete [] el;
5460  el = NULL;
5461 }// end of ObjReferenceMatrixValues::~ObjReferenceMatrixValues()
5462 
5464 {
5465 #ifndef NDEBUG
5466  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in ObjReferenceMatrixValues");
5467 #endif
5468  if (this == NULL)
5469  {
5470  if (that == NULL)
5471  return true;
5472  else
5473  {
5474 #ifndef NDEBUG
5476  "First object is NULL, second is not");
5477 #endif
5478  return false;
5479  }
5480  }
5481  else
5482  {
5483  if (that == NULL)
5484  {
5485 #ifndef NDEBUG
5487  "Second object is NULL, first is not");
5488 #endif
5489  return false;
5490  }
5491  else
5492  {
5493  if (this->numberOfEl != that->numberOfEl) return false;
5494  for (int i=0; i < numberOfEl; i++)
5495  if (this->el[i] != that->el[i]) return false;
5496 
5497  return true;
5498  }
5499  }
5500 }// end of ObjReferenceMatrixValues::IsEqual()
5501 
5502 bool ObjReferenceMatrixValues::setRandom(double density, bool conformant, int iMin, int iMax)
5503 {
5504  return true;
5505 }// end of ObjReferenceMatrixValues::setRandom()
5506 
5508 {
5509 #ifndef NDEBUG
5510  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of ObjReferenceMatrixValues");
5511 #endif
5512  this->numberOfEl = that->numberOfEl;
5513  this->el = new int[numberOfEl];
5514  for (int i=0; i<numberOfEl; i++)
5515  this->el[i] = that->el[i];
5516  return true;
5517 }// end of ObjReferenceMatrixValues::deepCopyFrom()
5518 
5519 
5522  value(NULL)
5523 {
5524 #ifndef NDEBUG
5525  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConReferenceMatrixElements Constructor");
5526 #endif
5527 }// end of ConReferenceMatrixElements::ConReferenceMatrixElements()
5528 
5530 {
5531 #ifndef NDEBUG
5533  ENUM_OUTPUT_LEVEL_trace, "Inside the ConReferenceMatrixElements Destructor");
5534 
5535  ostringstream outStr;
5536  outStr.str("");
5537  outStr.clear();
5538  outStr << "deleting ConReferenceMatrixElements->value at " << &value << std::endl;
5540  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
5541 #endif
5542  if (value != NULL)
5543  delete value;
5544  value = NULL;
5545 }// end of ConReferenceMatrixElements::~ConReferenceMatrixElements()
5546 
5548 {
5550 }// end of ConReferenceMatrixElements::getNodeType()
5551 
5553 {
5554  return "conRefElements";
5555 }// end of ConReferenceMatrixElements::getNodeName()
5556 
5558 {
5561  return matrixType;
5562 }// end of ConReferenceMatrixElements::getMatrixType()
5563 
5565 {
5566  ostringstream outStr;
5567  outStr << "<conReferenceElements";
5568  if (rowMajor)
5569  outStr << " rowMajor=\"true\"";
5570  outStr << " numberOfValues=\"" << numberOfValues << "\"";
5571  outStr << ">" << std::endl;
5572 
5573  outStr << "<start>" << std::endl;
5574  outStr << writeIntVectorData(start, true, false);
5575  outStr << "</start>" << std::endl;
5576 
5577  if (numberOfValues > 0)
5578  {
5579  outStr << "<index>" << std::endl;
5580  outStr << writeIntVectorData(index, true, false);
5581  outStr << "</index>" << std::endl;
5582 
5583  outStr << "<value>" << std::endl;
5584 
5585  for(int i = 0; i < numberOfValues; i++)
5586  {
5587  outStr << "<el";
5589  {
5590  outStr << " valueType=\"";
5591  outStr << returnConReferenceValueTypeString(value->el[i]->valueType) << "\"";
5592  }
5593  outStr << ">";
5594  outStr << os_dtoa_format(value->el[i]->conReference);
5595  outStr << "</el>" << std::endl;
5596  }
5597  outStr << "</value>" << std::endl;
5598  }
5599 
5600  outStr << "</conReferenceElements>" << std::endl;
5601  return outStr.str();
5602 }// end of ConReferenceMatrixElements::getMatrixNodeInXML()
5603 
5604 bool ConReferenceMatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
5605 {
5606  return false;
5607 }// end of ConReferenceMatrixElements::alignsOnBlockBoundary()
5608 
5610 {
5611  ConReferenceMatrixElements *nodePtr;
5612  nodePtr = new ConReferenceMatrixElements();
5613  return (ConReferenceMatrixElements*)nodePtr;
5614 }// end of ConReferenceMatrixElements::cloneMatrixNode
5615 
5617 {
5618 #ifndef NDEBUG
5619  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in ConReferenceMatrixElements");
5620 #endif
5621  if (this == NULL)
5622  {
5623  if (that == NULL)
5624  return true;
5625  else
5626  {
5627 #ifndef NDEBUG
5629  "First object is NULL, second is not");
5630 #endif
5631  return false;
5632  }
5633  }
5634  else
5635  {
5636  if (that == NULL)
5637  {
5638 #ifndef NDEBUG
5640  "Second object is NULL, first is not");
5641 #endif
5642  return false;
5643  }
5644  else
5645  {
5646  if (this->rowMajor != that->rowMajor) return false;
5647  if (this->numberOfValues != that->numberOfValues) return false;
5648 
5649  if (!this->start->IsEqual(that->start)) return false;
5650  if (!this->index->IsEqual(that->index)) return false;
5651  if (!this->value->IsEqual(that->value)) return false;
5652 
5653  return true;
5654  }
5655  }
5656 }// end of ConReferenceMatrixElements::IsEqual()
5657 
5658 
5659 bool ConReferenceMatrixElements::setRandom(double density, bool conformant, int iMin, int iMax)
5660 {
5661  return true;
5662 }// end of ConReferenceMatrixElements::setRandom()
5663 
5665 {
5666  return true;
5667 }// end of ConReferenceMatrixElements::deepCopyFrom()
5668 
5669 
5672  el(NULL)
5673 {
5674 #ifndef NDEBUG
5675  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConReferenceMatrixValues Constructor");
5676 #endif
5677 }// end of ConReferenceMatrixValues::ConReferenceMatrixValues()
5678 
5680 {
5681 #ifndef NDEBUG
5682  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConReferenceMatrixValues Destructor");
5683 #endif
5684  if (numberOfEl > 0 && el != NULL)
5685  {
5686  for (int i=0; i < numberOfEl; i++)
5687  {
5688  if (el[i] != NULL)
5689  {
5690 #ifndef NDEBUG
5691  ostringstream outStr;
5692  outStr.str("");
5693  outStr.clear();
5694  outStr << "deleting ConstantMatrixValues->el [" << i << "] at " << &el[i] << std::endl;
5696  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
5697 #endif
5698  delete el[i];
5699  el[i] = NULL;
5700  }
5701  }
5702  }
5703  if (el != NULL)
5704  delete [] el;
5705  el = NULL;
5706 }// end of ConReferenceMatrixValues::~ConReferenceMatrixValues()
5707 
5709 {
5710 #ifndef NDEBUG
5711  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in ConReferenceMatrixValues");
5712 #endif
5713  if (this == NULL)
5714  {
5715  if (that == NULL)
5716  return true;
5717  else
5718  {
5719 #ifndef NDEBUG
5721  "First object is NULL, second is not");
5722 #endif
5723  return false;
5724  }
5725  }
5726  else
5727  {
5728  if (that == NULL)
5729  {
5730 #ifndef NDEBUG
5732  "Second object is NULL, first is not");
5733 #endif
5734  return false;
5735  }
5736  else
5737  {
5738  if (this->numberOfEl != that->numberOfEl) return false;
5739  for (int i=0; i < numberOfEl; i++)
5740  if (!this->el[i]->IsEqual(that->el[i])) return false;
5741 
5742  return true;
5743  }
5744  }
5745 }// end of ConReferenceMatrixValues::IsEqual()
5746 
5747 bool ConReferenceMatrixValues::setRandom(double density, bool conformant, int iMin, int iMax)
5748 {
5749  return true;
5750 }// end of ConReferenceMatrixValues::setRandom()
5751 
5753 {
5754 #ifndef NDEBUG
5755  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of ConReferenceMatrixValues");
5756 #endif
5757  this->numberOfEl = that->numberOfEl;
5758  this->el = new ConReferenceMatrixElement*[numberOfEl];
5759  for (int i=0; i<numberOfEl; i++)
5760  ((ConReferenceMatrixValues*)this)->el[i]->deepCopyFrom(that->el[i]);
5761  return true;
5762 }// end of ConReferenceMatrixValues::deepCopyFrom()
5763 
5764 
5767  conReference(-1),
5769 {
5770 #ifndef NDEBUG
5771  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConReferenceMatrixElement Constructor");
5772 #endif
5773 }// end of ConReferenceMatrixElement::ConReferenceMatrixElement()
5774 
5776 {
5777 #ifndef NDEBUG
5778  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConReferenceMatrixElement Destructor");
5779 #endif
5780 }// end of ConReferenceMatrixElement::~ConReferenceMatrixElement()
5781 
5783 {
5784 #ifndef NDEBUG
5785  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in ConReferenceMatrixElement");
5786 #endif
5787  if (this == NULL)
5788  {
5789  if (that == NULL)
5790  return true;
5791  else
5792  {
5793 #ifndef NDEBUG
5795  "First object is NULL, second is not");
5796 #endif
5797  return false;
5798  }
5799  }
5800  else
5801  {
5802  if (that == NULL)
5803  {
5804 #ifndef NDEBUG
5806  "Second object is NULL, first is not");
5807 #endif
5808  return false;
5809  }
5810  else
5811  {
5812  if (this->conReference != that->conReference) return false;
5813  if (this->valueType != that->valueType ) return false;
5814 
5815  return true;
5816  }
5817  }
5818 }// end of ConReferenceMatrixElement::IsEqual()
5819 
5820 bool ConReferenceMatrixElement::setRandom(double density, bool conformant, int iMin, int iMax)
5821 {
5822  return true;
5823 }// end of ConReferenceMatrixElement::setRandom()
5824 
5826 {
5827  this->conReference = that->conReference;
5828  this->valueType = that->valueType;
5829  this->value = that->value;
5830  return true;
5831 }// end of ConReferenceMatrixElement::deepCopyFrom()
5832 
5833 
5836  value(NULL)
5837 {
5838 #ifndef NDEBUG
5839  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MixedRowReferenceMatrixElements Constructor");
5840 #endif
5841 }// end of MixedRowReferenceMatrixElements::MixedRowReferenceMatrixElements()
5842 
5844 {
5845 #ifndef NDEBUG
5846  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MixedRowReferenceMatrixElements Destructor");
5847 #endif
5848  if (value != NULL)
5849  delete value;
5850  value = NULL;
5851 }// end of MixedRowReferenceMatrixElements::~MixedRowReferenceMatrixElements()
5852 
5854 {
5856 }// end of MixedRowReferenceMatrixElements::getNodeType()
5857 
5859 {
5860  return "mixedRowRefElements";
5861 }// end of MixedRowReferenceMatrixElements::getNodeName()
5862 
5864 {
5867  return matrixType;
5868 }// end of MixedRowReferenceMatrixElements::getMatrixType()
5869 
5871 {
5875  ostringstream outStr;
5876  int tmpNum = 0;
5877  int i, j;
5878  for (i=0; i < start->numberOfEl - 1; i++)
5879  {
5880  for (j=start->el[i]; j<start->el[i+1]; j++)
5881  {
5882  if (value->el[j]->conReference < 0) tmpNum++;
5883  }
5884  }
5885 
5886  if (tmpNum > 0)
5887  {
5888  outStr << "<objReferenceElements";
5889  if (rowMajor)
5890  outStr << " rowMajor=\"true\"";
5891  outStr << " numberOfValues=\"" << tmpNum << "\"";
5892  outStr << ">" << std::endl;
5893 
5894  if (tmpNum < numberOfValues)
5895  {
5896  outStr << "<start>" << std::endl;
5897  outStr << "<el>0</el>" << std::endl;
5898  tmpNum = 0;
5899  for (i=0; i < start->numberOfEl - 1; i++)
5900  {
5901  for (j=start->el[i]; j<start->el[i+1]; j++)
5902  {
5903  if (value->el[j]->conReference < 0) tmpNum++;
5904  }
5905  outStr << "<el>" << tmpNum << "</el>" << std::endl;
5906  }
5907  outStr << "</start>" << std::endl;
5908 
5909  outStr << "<index>" << std::endl;
5910  for (i=0; i < start->numberOfEl - 1; i++)
5911  {
5912  for (j=start->el[i]; j<start->el[i+1]; j++)
5913  {
5914  if (value->el[j]->conReference < 0)
5915  outStr << "<el>" << index->el[j] << "</el>";
5916  }
5917  }
5918  outStr << "</index>" << std::endl;
5919 
5920  outStr << "<value>" << std::endl;
5921  for (i=0; i < start->numberOfEl - 1; i++)
5922  {
5923  for (j=start->el[i]; j<start->el[i+1]; j++)
5924  {
5925  if (value->el[j]->conReference < 0)
5926  outStr << "<el>" << value->el[j]->conReference << "</el>";
5927  }
5928  }
5929  outStr << "</value>" << std::endl;
5930  outStr << "</objReferenceElements>" << std::endl;
5931 
5932  outStr << "<conReferenceElements";
5933  if (rowMajor)
5934  outStr << " rowMajor=\"true\"";
5935  outStr << " numberOfValues=\"" << numberOfValues - tmpNum << "\"";
5936  outStr << ">" << std::endl;
5937 
5938  outStr << "<start>" << std::endl;
5939  outStr << "<el>0</el>" << std::endl;
5940  tmpNum = 0;
5941  for (i=0; i < start->numberOfEl - 1; i++)
5942  {
5943  for (j=start->el[i]; j<start->el[i+1]; j++)
5944  {
5945  if (value->el[j]->conReference >= 0) tmpNum++;
5946  }
5947  outStr << "<el>" << tmpNum << "</el>" << std::endl;
5948  }
5949  outStr << "</start>" << std::endl;
5950 
5951  outStr << "<index>" << std::endl;
5952  for (i=0; i < start->numberOfEl - 1; i++)
5953  {
5954  for (j=start->el[i]; j<start->el[i+1]; j++)
5955  {
5956  if (value->el[j]->conReference >= 0)
5957  outStr << "<el>" << index->el[j] << "</el>";
5958  }
5959  }
5960  outStr << "</index>" << std::endl;
5961 
5962  outStr << "<value>" << std::endl;
5963  for (i=0; i < start->numberOfEl - 1; i++)
5964  {
5965  for (j=start->el[i]; j<start->el[i+1]; j++)
5966  {
5967  if (value->el[j]->conReference >= 0)
5968  {
5969  outStr << "<el";
5971  {
5972  outStr << " valueType=\"";
5973  outStr << returnConReferenceValueTypeString(value->el[i]->valueType) << "\"";
5974  }
5975  outStr << ">" << value->el[j]->conReference << "</el>";
5976  }
5977  }
5978  }
5979  outStr << "</value>" << std::endl;
5980  outStr << "</conReferenceElements>" << std::endl;
5981 
5982  }
5983  else // there are only objReferenceElements
5984  {
5985  outStr << "<start>" << std::endl;
5986  outStr << writeIntVectorData(start, true, false);
5987  outStr << "</start>" << std::endl;
5988 
5989  if (numberOfValues > 0)
5990  {
5991  outStr << "<index>" << std::endl;
5992  outStr << writeIntVectorData(index, true, false);
5993  outStr << "</index>" << std::endl;
5994 
5995  outStr << "<value>" << std::endl;
5996 
5997  for(int i = 0; i < numberOfValues; i++)
5998  {
5999  outStr << "<el";
6000  //gus: work out mult and incr
6001  outStr << ">";
6002  outStr << os_dtoa_format(value->el[i]->conReference);
6003  outStr << "</el>" << std::endl;
6004  }
6005  outStr << "</value>" << std::endl;
6006  }
6007  outStr << "</objReferenceElements>" << std::endl;
6008  }
6009  }
6010  else // there are only conReferenceElements
6011  {
6012  outStr << "<conReferenceElements";
6013  if (rowMajor)
6014  outStr << " rowMajor=\"true\"";
6015  outStr << " numberOfValues=\"" << numberOfValues << "\"";
6016  outStr << ">" << std::endl;
6017 
6018  outStr << "<start>" << std::endl;
6019  outStr << writeIntVectorData(start, true, false);
6020  outStr << "</start>" << std::endl;
6021 
6022  if (numberOfValues > 0)
6023  {
6024  outStr << "<index>" << std::endl;
6025  outStr << writeIntVectorData(index, true, false);
6026  outStr << "</index>" << std::endl;
6027 
6028  outStr << "<value>" << std::endl;
6029 
6030  for(int i = 0; i < numberOfValues; i++)
6031  {
6032  outStr << "<el";
6034  {
6035  outStr << " valueType=\"";
6036  outStr << returnConReferenceValueTypeString(value->el[i]->valueType) << "\"";
6037  }
6038  //gus: work out mult and incr
6039  outStr << ">";
6040  outStr << os_dtoa_format(value->el[i]->conReference);
6041  outStr << "</el>" << std::endl;
6042  }
6043  outStr << "</value>" << std::endl;
6044  }
6045  outStr << "</conReferenceElements>" << std::endl;
6046  }
6047 
6048  return outStr.str();
6049 }// end of MixedRowReferenceMatrixElements::getMatrixNodeInXML()
6050 
6051 bool MixedRowReferenceMatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
6052 {
6053  return false;
6054 }// end of MixedRowReferenceMatrixElements::alignsOnBlockBoundary()
6055 
6057 {
6059  nodePtr = new MixedRowReferenceMatrixElements();
6060  return (MixedRowReferenceMatrixElements*)nodePtr;
6061 }// end of MixedRowReferenceMatrixElements::cloneMatrixNode
6062 
6064 {
6065 #ifndef NDEBUG
6066  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in MixedRowReferenceMatrixElements");
6067 #endif
6068  if (this == NULL)
6069  {
6070  if (that == NULL)
6071  return true;
6072  else
6073  {
6074 #ifndef NDEBUG
6076  "First object is NULL, second is not");
6077 #endif
6078  return false;
6079  }
6080  }
6081  else
6082  {
6083  if (that == NULL)
6084  {
6085 #ifndef NDEBUG
6087  "Second object is NULL, first is not");
6088 #endif
6089  return false;
6090  }
6091  else
6092  {
6093  if (this->rowMajor != that->rowMajor) return false;
6094  if (this->numberOfValues != that->numberOfValues) return false;
6095 
6096  if (!this->start->IsEqual(that->start)) return false;
6097  if (!this->index->IsEqual(that->index)) return false;
6098  if (!this->value->IsEqual(that->value)) return false;
6099 
6100  return true;
6101  }
6102  }
6103 }// end of MixedRowReferenceMatrixElements::IsEqual()
6104 
6105 bool MixedRowReferenceMatrixElements::setRandom(double density, bool conformant, int iMin, int iMax)
6106 {
6107  return true;
6108 }// end of MixedRowReferenceMatrixElements::setRandom()
6109 
6111 {
6112  return true;
6113 }// end of MixedRowReferenceMatrixElements::deepCopyFrom()
6114 
6115 
6118  colOffset(NULL),
6119  rowOffset(NULL)
6120 {
6121 #ifndef NDEBUG
6122  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixBlocks Constructor");
6123 #endif
6125 }// end of MatrixBlocks::MatrixBlocks()
6126 
6128 {
6129  std::ostringstream outStr;
6130 
6131 #ifndef NDEBUG
6132  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixBlocks Destructor");
6133  outStr.str("");
6134  outStr.clear();
6135  outStr << "NUMBER OF BLOCKS = " << inumberOfChildren << endl;
6137 
6138  outStr.str("");
6139  outStr.clear();
6140  outStr << "deleting MatrixBlocks->colOffset at " << &colOffset << std::endl;
6142  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
6143 
6144  outStr.str("");
6145  outStr.clear();
6146  outStr << "deleting MatrixBlocks->rowOffset at " << &rowOffset << std::endl;
6148  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
6149 #endif
6150  if (colOffset != NULL)
6151  delete colOffset;
6152  colOffset = NULL;
6153 
6154  if (rowOffset != NULL)
6155  delete rowOffset;
6156  rowOffset = NULL;
6157 
6158 #if 0
6159  if(inumberOfChildren > 0 && block != NULL)
6160  {
6161  for (int i=0; i < numberOfBlocks; i++)
6162  {
6163  if (block[i] != NULL)
6164  {
6165 #ifndef NDEBUG
6166  outStr.str("");
6167  outStr.clear();
6168  outStr << "deleting MatrixBlocks->block [" << i << "] at " << &block[i] << std::endl;
6170  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
6171 #endif
6172  delete block[i];
6173  block[i] = NULL;
6174  }
6175  }
6176  }
6177  if (block != NULL)
6178  delete [] block;
6179  block = NULL;
6180 #endif
6181 }// end of MatrixBlocks::~MatrixBlocks()
6182 
6184 {
6186 }// end of MatrixBlocks::getNodeType()
6187 
6189 {
6190  return "blocks";
6191 }// end of MatrixBlocks::getNodeName()
6192 
6194 {
6196  {
6198  for (unsigned int i=0; i<inumberOfChildren; i++)
6200  }
6201  return matrixType;
6202 }// end of MatrixBlocks::getMatrixType()
6203 
6205 {
6206  ostringstream outStr;
6207  outStr << "<blocks numberOfBlocks=\"" << inumberOfChildren << "\">" << std::endl;
6208  outStr << "<colOffset numberOfEl=\"" << colOffset->numberOfEl << "\">" << std::endl;
6209  outStr << writeIntVectorData(colOffset, true, false);
6210  outStr << "</colOffset>" << std::endl;
6211  outStr << "<rowOffset numberOfEl=\"" << rowOffset->numberOfEl << "\">" << std::endl;
6212  outStr << writeIntVectorData(rowOffset, true, false);
6213  outStr << "</rowOffset>" << std::endl;
6214 
6215  for (unsigned int i=0; i < inumberOfChildren; i++)
6216  outStr << m_mChildren[i]->getMatrixNodeInXML();
6217 
6218  outStr << "</blocks>" << std::endl;
6219  return outStr.str();
6220 }// end of MatrixBlocks::getMatrixNodeInXML()
6221 
6222 bool MatrixBlocks::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
6223 {
6224  bool accumulator = false;
6225  int nrBlocks = rowOffset->numberOfEl - 1;
6226  int ncBlocks = colOffset->numberOfEl - 1;
6227  for (int i=0; i < nrBlocks; i++)
6228  if ( (rowOffset->el[i] == firstRow) && ((firstRow+nRows) == rowOffset->el[i+1]) )
6229  {
6230  accumulator = true;
6231  break;
6232  }
6233  if (!accumulator) return false;
6234  for (int i=0; i < ncBlocks; i++)
6235  if ( (colOffset->el[i] == firstColumn) && ((firstColumn+nCols) == colOffset->el[i+1]) )
6236  {
6237  accumulator = true;
6238  break;
6239  }
6240  return accumulator;
6241 }// end of MatrixTransformation::alignsOnBlockBoundary()
6242 
6244 {
6245  MatrixNode *nodePtr;
6246  nodePtr = new MatrixBlocks();
6247  return (MatrixBlocks*)nodePtr;
6248 }// end of MatrixBlocks::cloneMatrixNode
6249 
6251 {
6252 #ifndef NDEBUG
6253  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixBlocks");
6254 #endif
6255  if (this == NULL)
6256  {
6257  if (that == NULL)
6258  return true;
6259  else
6260  {
6261 #ifndef NDEBUG
6263  "First object is NULL, second is not");
6264 #endif
6265  return false;
6266  }
6267  }
6268  else
6269  {
6270  if (that == NULL)
6271  {
6272 #ifndef NDEBUG
6274  "Second object is NULL, first is not");
6275 #endif
6276  return false;
6277  }
6278  else
6279  {
6280  if (!this->colOffset->IsEqual(that->colOffset))
6281  return false;
6282  if (!this->rowOffset->IsEqual(that->rowOffset))
6283  return false;
6284  return true;
6285  }
6286  }
6287 }// end of MatrixBlocks::IsEqual()
6288 // end of methods for MatrixBlocks
6289 
6290 
6293  blockRowIdx(-1),
6294  blockColIdx(-1)
6295 {
6296 #ifndef NDEBUG
6297  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixBlock Constructor");
6298 #endif
6300 }// end of MatrixBlock
6301 
6303 {
6304 #ifndef NDEBUG
6305  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixBlock Destructor");
6306 #endif
6307 }// end of ~MatrixBlock
6308 
6310 {
6312 }// end of MatrixBlock::getNodeType()
6313 
6315 {
6316  return "block";
6317 }// end of MatrixBlock::getNodeName()
6318 
6320 {
6322  {
6324  for (unsigned int i=0; i<inumberOfChildren; i++)
6325  {
6327  }
6328  }
6329  return matrixType;
6330 }// end of MatrixBlock::getMatrixType()
6331 
6333 {
6334  ostringstream outStr;
6335  outStr << "<block";
6336  outStr << " blockRowIdx=\"" << blockRowIdx << "\"";
6337  outStr << " blockColIdx=\"" << blockColIdx << "\"";
6339  outStr << " symmetry=\"" << returnMatrixSymmetryString(symmetry) << "\"";
6341  outStr << " type=\"" << returnMatrixTypeString(matrixType) << "\"";
6342 
6343  if (inumberOfChildren > 0)
6344  {
6345  outStr << ">" << std::endl;
6346  for (unsigned int i=0; i < inumberOfChildren; i++)
6347  outStr << m_mChildren[i]->getMatrixNodeInXML();
6348  outStr << "</block>" << std::endl;
6349  }
6350  else
6351  outStr << "/>" << std::endl;
6352  return outStr.str();
6353 }// end of MatrixBlock::getMatrixNodeInXML()
6354 
6355 bool MatrixBlock::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
6356 {
6357  return (firstRow == 0 && firstColumn == 0 && nRows == numberOfRows && nCols == numberOfColumns);
6358 }// end of MatrixBlock::alignsOnBlockBoundary()
6359 
6360 bool MatrixBlock::expandElements(bool rowMajor)
6361 {
6362  return NULL;
6363 }// end of expandElements
6364 
6366 {
6367  MatrixType *nodePtr;
6368  nodePtr = new MatrixBlock();
6369  return (MatrixBlock*)nodePtr;
6370 }// end of MatrixBlock::cloneMatrixNode
6371 
6373 {
6374  return true;
6375 }// end of MatrixBlock::IsEqual()
6376 
6377 bool MatrixBlock::setRandom(double density, bool conformant, int iMin, int iMax)
6378 {
6379  return true;
6380 }// end of MatrixBlock::setRandom()
6381 
6383 {
6384  return true;
6385 }// end of MatrixBlock::deepCopyFrom()
6386 // end of methods for MatrixBlock ----------------------------------------------
6387 
6388 
6391  b_deleteStartArray(true),
6392  b_deleteIndexArray(true),
6393  b_deleteValueArray(true),
6394  isRowMajor(false),
6395  startSize(-1),
6396  valueSize(-1),
6397  vType(ENUM_MATRIX_TYPE_unknown),
6398  start(NULL),
6399  index(NULL),
6400  value(NULL)
6401 {
6402 #ifndef NDEBUG
6403  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralSparseMatrix Constructor");
6404 #endif
6405 }// end of GeneralSparseMatrix
6406 
6407 GeneralSparseMatrix::GeneralSparseMatrix(bool isColumnMajor_, int startSize_, int valueSize_,
6408  ENUM_MATRIX_TYPE type_):
6409  b_deleteStartArray(true),
6410  b_deleteIndexArray(true),
6411  b_deleteValueArray(true),
6412  value(NULL)
6413 {
6414 #ifndef NDEBUG
6415  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the alternate GeneralSparseMatrix Constructor");
6416 #endif
6417  isRowMajor = !(isColumnMajor_);
6418  startSize = startSize_;
6419  valueSize = valueSize_;
6420  vType = type_;
6421  start = new int[startSize];
6422  index = new int[valueSize];
6423 }// end of GeneralSparseMatrix
6424 
6426 {
6427 #ifndef NDEBUG
6428  ostringstream outStr;
6429 
6431  ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralSparseMatrix Destructor");
6432 #endif
6433  if (b_deleteStartArray)
6434  {
6435  if (start != NULL)
6436  {
6437 #ifndef NDEBUG
6438  outStr.str("");
6439  outStr.clear();
6440  outStr << "deleting GeneralSparseMatrix->start at " << &start << std::endl;
6442  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
6443 #endif
6444  delete [] start;
6445  start = NULL;
6446  }
6447  }
6448  if (b_deleteIndexArray)
6449  {
6450  if (index != NULL)
6451  {
6452 #ifndef NDEBUG
6453  outStr.str("");
6454  outStr.clear();
6455  outStr << "deleting GeneralSparseMatrix->index at " << &index << std::endl;
6457  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
6458 #endif
6459  delete [] index;
6460  index = NULL;
6461  }
6462  }
6463  if (b_deleteValueArray)
6464  {
6465  if (value != NULL)
6466  {
6467 #ifndef NDEBUG
6468  outStr.str("");
6469  outStr.clear();
6470  outStr << "deleting GeneralSparseMatrix->value at " << &value << std::endl;
6472  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
6473 #endif
6474  delete value;
6475  value = NULL;
6476  }
6477  }
6478 }// end of ~GeneralSparseMatrix
6479 
6481 {
6482 #ifndef NDEBUG
6484  "Inside GeneralSparseMatrix::isDiagonal()");
6485 #endif
6486  if (valueSize == 0)
6487  return true;
6488  if (valueSize >= startSize)
6489  return false;
6490 
6491  for (int i=1; i < startSize; i++)
6492  {
6493  if (start[i] - start[i-1] > 1)
6494  return false;
6495  for (int j=start[i-1]; j<start[i]; j++)
6496  if (index[j] != i-1)
6497  return false;
6498  }
6499 
6500  return true;
6501 }// end of GeneralSparseMatrix::isDiagonal
6502 
6503 bool GeneralSparseMatrix::display(int secondaryDim)
6504 {
6505  return true;
6506 }
6507 
6508 
6511  bDeleteArrays(true),
6512  isRowMajor(false),
6513  blockNumber(0),
6514  blockRows(NULL),
6515  blockColumns(NULL),
6516  blocks(NULL)
6517 {
6518 #ifndef NDEBUG
6519  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralSparseMatrix default constructor");
6520 #endif
6521 }// end of ExpandedMatrixBlocks
6522 
6523 ExpandedMatrixBlocks::ExpandedMatrixBlocks(bool isRowMajor_, int startSize, int valueSize):
6524  bDeleteArrays(true),
6525  blockNumber(0),
6526  blockRows(NULL),
6527  blockColumns(NULL),
6528  blocks(NULL)
6529 {
6530 #ifndef NDEBUG
6531  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralSparseMatrix default constructor");
6532 #endif
6533  isRowMajor = isRowMajor_;
6534 }// end of ExpandedMatrixBlocks
6535 
6537 {
6538  std::ostringstream outStr;
6539 #ifndef NDEBUG
6540  osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ExpandedMatrixBlocks Destructor");
6541 #endif
6542  if (bDeleteArrays)
6543  {
6544  if (blockRows != NULL)
6545  {
6546 #ifndef NDEBUG
6547  outStr.str("");
6548  outStr.clear();
6549  outStr << "deleting ExpandedMatrixBlocks->blockRows at " << &blockRows << std::endl;
6551  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
6552 #endif
6553  delete [] blockRows;
6554  blockRows = NULL;
6555  }
6556  if (blockColumns != NULL)
6557  {
6558 #ifndef NDEBUG
6559  outStr.str("");
6560  outStr.clear();
6561  outStr << "deleting ExpandedMatrixBlocks->blockColumns at " << &blockColumns << std::endl;
6563  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
6564 #endif
6565  delete [] blockColumns;
6566  blockColumns = NULL;
6567  }
6568  if (blockNumber > 0 && blocks != NULL)
6569  {
6570  for (int i=0; i < blockNumber; i++)
6571  {
6572  if (blocks[i] != NULL)
6573  {
6574 #ifndef NDEBUG
6575  outStr.str("");
6576  outStr.clear();
6577  outStr << "deleting ExpandedMatrixBlocks->blocks[" << i << "] at "
6578  << &blocks[i] << std::endl;
6580  ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
6581 #endif
6582  delete blocks[i];
6583  blocks[i] = NULL;
6584  }
6585  }
6586  }
6587  if (blocks != NULL) delete [] blocks;
6588  blocks = NULL;
6589  }
6590 }// end of ~ExpandedMatrixBlocks
6591 
6593 {
6594 #ifndef NDEBUG
6596  "Inside ExpandedMatrixBlocks::getBlock()");
6597 #endif
6598  for (int i=0; i < blockNumber; i++)
6599  if (blockRows[i] == rowIdx && blockColumns[i] == colIdx)
6600  return blocks[i];
6601 
6602  return NULL;
6603 }// end of ExpandedMatrixBlocks::getBlock
6604 
6606 {
6607 #ifndef NDEBUG
6609  "Inside ExpandedMatrixBlocks::isBlockDiagonal()");
6610 #endif
6612  return false;
6613 
6614  for (int i=0; i < blockNumber; i++)
6615  if (blockRows[i] != blockColumns[i])
6616  return false;
6617 
6618  return true;
6619 }// end of ExpandedMatrixBlocks::isBlockDiagonal
6620 
6621 
6622 bool ExpandedMatrixBlocks::display(int secondaryDim)
6623 {
6624  return true;
6625 }
6626 
6627 
6628 //-------------------------------------
6633 {
6634  try
6635  {
6637  tmp->constant = val;
6638  tmp->numberOfVarIdx = 0;
6639  tmp->varIdx = NULL;
6640  return tmp;
6641  }
6642  catch(const ErrorClass& eclass)
6643  {
6644  throw ErrorClass( eclass.errormsg);
6645  }
6646 }// end of convertToLinearMatrixElement
6647 
6649 {
6650  try
6651  {
6653  tmp->constant = 0.0;
6654  tmp->numberOfVarIdx = 1;
6655  tmp->varIdx = new LinearMatrixElementTerm*[1];
6656  tmp->varIdx[0] = new LinearMatrixElementTerm();
6657  tmp->varIdx[0]->coef = 1.0;
6658  tmp->varIdx[0]->idx = varref;
6659  return tmp;
6660  }
6661  catch(const ErrorClass& eclass)
6662  {
6663  throw ErrorClass( eclass.errormsg);
6664  }
6665 }
6666 
6668 {
6669  try
6670  {
6671  std::vector<ExprNode*> nlNodeVec;
6673 
6674  OSnLNodeNumber* tmpNum = new OSnLNodeNumber();
6675  tmpNum->value = val;
6676  nlNodeVec.push_back(tmpNum);
6677 
6678  tmp->m_treeRoot =
6679  ((OSnLNode*)nlNodeVec[ 0])->createExpressionTreeFromPostfix(nlNodeVec);
6680  nlNodeVec.clear();
6681  return tmp;
6682  }
6683  catch(const ErrorClass& eclass)
6684  {
6685  throw ErrorClass( eclass.errormsg);
6686  }
6687 }
6688 
6689 ScalarExpressionTree* convertToGeneralMatrixElement(int refIdx, bool varRef) // varref or objref
6690 {
6691  try
6692  {
6693  std::vector<ExprNode*> nlNodeVec;
6695 
6696  OSnLNode* tmpRef;
6697 
6698  if (varRef)
6699  {
6700  tmpRef = new OSnLNodeVariable();
6701  ((OSnLNodeVariable*)tmpRef)->idx = refIdx;
6702  }
6703  else
6704  throw ErrorClass("OSnLNodeObjective not yet implemented");
6705  nlNodeVec.push_back(tmpRef);
6706 
6707  tmp->m_treeRoot =
6708  ((OSnLNode*)nlNodeVec[ 0])->createExpressionTreeFromPostfix(nlNodeVec);
6709  nlNodeVec.clear();
6710  return tmp;
6711  }
6712  catch(const ErrorClass& eclass)
6713  {
6714  throw ErrorClass( eclass.errormsg);
6715  }
6716 }
6717 
6719 {
6720  try
6721  {
6722  std::vector<ExprNode*> nlNodeVec;
6724 
6725 //push this back as a sum node : [c_1*] x_1 + [c_2*] x_2 + ... (+ c_0)
6726  OSnLNodeSum* tmpSum = new OSnLNodeSum();
6727  OSnLNodeNumber* tmpNum;
6728  OSnLNodeVariable* tmpVar;
6729  OSnLNodeTimes* tmpTimes;
6730 
6731  for (int i=0; i < linearExpr->numberOfVarIdx; i++)
6732  {
6733  tmpVar = new OSnLNodeVariable();
6734  tmpVar->idx = linearExpr->varIdx[i]->idx;
6735  nlNodeVec.push_back(tmpVar);
6736  if (linearExpr->varIdx[i]->coef != 1.0)
6737  {
6738  tmpNum = new OSnLNodeNumber();
6739  tmpNum->value = linearExpr->varIdx[i]->coef;
6740  nlNodeVec.push_back(tmpNum);
6741 
6742  tmpTimes = new OSnLNodeTimes();
6743  nlNodeVec.push_back(tmpTimes);
6744  }
6745  }
6746 
6747  if (linearExpr->constant != 0.0)
6748  {
6749  tmpNum = new OSnLNodeNumber();
6750  tmpNum->value = linearExpr->constant;
6751  nlNodeVec.push_back(tmpNum);
6752  }
6753 
6754  nlNodeVec.push_back(tmpSum);
6755 
6756  tmp->m_treeRoot =
6757  ((OSnLNode*)nlNodeVec[ 0])->createExpressionTreeFromPostfix(nlNodeVec);
6758  nlNodeVec.clear();
6759  return tmp;
6760  }
6761  catch(const ErrorClass& eclass)
6762  {
6763  throw ErrorClass( eclass.errormsg);
6764  }
6765 }
6766 
6768 {
6769  try
6770  {
6771  throw ErrorClass("In convertToGeneralMatrixElement: OSnLNodeConstraint not yet implemented");
6772  return NULL;
6773  }
6774  catch(const ErrorClass& eclass)
6775  {
6776  throw ErrorClass( eclass.errormsg);
6777  }
6778 }
6779 
6781 {
6782  try
6783  {
6784  throw ErrorClass("In convertToConReferenceMatrixElement: OSnLNodeConstraint not yet implemented");
6785  return NULL;
6786  }
6787  catch(const ErrorClass& eclass)
6788  {
6789  throw ErrorClass( eclass.errormsg);
6790  }
6791 }
6792 
6793 #if 0
6794  // define the vectors
6795  OSnLNode *nlNodePoint;
6796  OSnLNodeVariable *nlNodeVariablePoint;
6797  std::vector<ExprNode*> nlNodeVec;
6798  //
6799  //
6800  int i;
6801  for(i = 0; i < numQPTerms; i++)
6802  {
6803  instanceData->nonlinearExpressions->nl[ i] = new Nl();
6804  instanceData->nonlinearExpressions->nl[ i]->idx = rowIndexes[ i];
6805  instanceData->nonlinearExpressions->nl[ i]->osExpressionTree = new ScalarExpressionTree();
6806  // create a variable nl node for x0
6807  nlNodeVariablePoint = new OSnLNodeVariable();
6808  nlNodeVariablePoint->idx = varOneIndexes[ i];
6809  // give this variable the coefficient
6810  nlNodeVariablePoint->coef = coefficients[ i];
6811  nlNodeVec.push_back( nlNodeVariablePoint);
6812  // create the nl node for x1
6813  nlNodeVariablePoint = new OSnLNodeVariable();
6814  nlNodeVariablePoint->idx = varTwoIndexes[ i];
6815  nlNodeVec.push_back( nlNodeVariablePoint);
6816  // create the nl node for *
6817  nlNodePoint = new OSnLNodeTimes();
6818  nlNodeVec.push_back( (OSnLNode*)nlNodePoint);
6819  // the vectors are in postfix format
6820  // now the expression tree
6821  instanceData->nonlinearExpressions->nl[ i]->osExpressionTree->m_treeRoot =
6822  ((OSnLNode*)nlNodeVec[ 0])->createExpressionTreeFromPostfix( nlNodeVec);
6823  nlNodeVec.clear();
6824  }
6825 #endif
const OSSmartPtr< OSOutput > osoutput
Definition: OSOutput.cpp:39
std::string os_dtoa_format(double x)
Definition: OSMathUtil.cpp:154
void getMultIncr(int *i, int *mult, int *incr, int size, int defaultIncr)
getMultIncr
Definition: OSMathUtil.h:168
int getMult(int *i, int size)
getMult
Definition: OSMathUtil.h:246
ScalarExpressionTree * convertToGeneralMatrixElement(double val)
Definition: OSMatrix.cpp:6667
LinearMatrixElement * convertToLinearMatrixElement(double val)
Some methods to convert one type of matrix element into another.
Definition: OSMatrix.cpp:6632
ConReferenceMatrixElement * convertToConReferenceMatrixElement(int objref)
Definition: OSMatrix.cpp:6780
if(!yyg->yy_init)
for(;;)
static Bigint * mult(Bigint *a, Bigint *b)
Definition: OSdtoa.cpp:857
std::string writeIntVectorData(IntVector *v, bool addWhiteSpace, bool writeBase64)
Take an IntVector object and write a string that validates against the OSgL schema.
Definition: OSgLWriter.cpp:104
a data structure to represent a point of departure for constructing a matrix by modifying parts of a ...
Definition: OSMatrix.h:1537
virtual BaseMatrix * cloneMatrixNode()
The implementation of the virtual functions.
Definition: OSMatrix.cpp:3976
virtual ENUM_MATRIX_CONSTRUCTOR_TYPE getNodeType()
Definition: OSMatrix.cpp:3931
int baseMatrixStartRow
to select the position of the upper left corner of the portion of the base matrix that is to be selec...
Definition: OSMatrix.h:1559
int baseMatrixEndCol
Definition: OSMatrix.h:1567
bool IsEqual(BaseMatrix *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:3983
int targetMatrixFirstRow
to pinpoint the position of the upper left corner of the base matrix within the target matrix
Definition: OSMatrix.h:1552
double scalarMultiplier
to allow the base matrix to be scaled before it is attached to the target matrix
Definition: OSMatrix.h:1577
virtual bool alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
Check whether a submatrix aligns with the block partition of a matrix or block or other constructor.
Definition: OSMatrix.cpp:3971
BaseMatrix()
Standard constructor and destructor methods.
Definition: OSMatrix.cpp:3906
virtual std::string getMatrixNodeInXML()
Definition: OSMatrix.cpp:3946
int baseMatrixIdx
the index of the base matrix
Definition: OSMatrix.h:1542
OSMatrix * baseMatrix
a pointer to the base matrix
Definition: OSMatrix.h:1547
virtual std::string getNodeName()
Definition: OSMatrix.cpp:3936
int baseMatrixStartCol
Definition: OSMatrix.h:1560
bool baseTranspose
to allow the base matrix to be transposed before it is attached to the target matrix
Definition: OSMatrix.h:1572
virtual ENUM_MATRIX_TYPE getMatrixType()
Definition: OSMatrix.cpp:3941
int baseMatrixEndRow
to select the position of the lower right corner of the portion of the base matrix that is to be sele...
Definition: OSMatrix.h:1566
int targetMatrixFirstCol
Definition: OSMatrix.h:1553
a data structure to represent an entry in a conReferenceMatrix element, which consists of a constrain...
Definition: OSMatrix.h:454
ENUM_CONREFERENCE_VALUETYPE valueType
Several different types of values can be derived from a problem constraint.
Definition: OSMatrix.h:466
double value
This element contains the value.
Definition: OSMatrix.h:469
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:5820
bool deepCopyFrom(ConReferenceMatrixElement *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:5825
ConReferenceMatrixElement()
-------— Methods for class ConReferenceMatrixElement -------—
Definition: OSMatrix.cpp:5766
bool IsEqual(ConReferenceMatrixElement *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:5782
int conReference
contains a reference to a row of the problem (objective if negative, constraint otherwise)
Definition: OSMatrix.h:460
a data structure to represent row reference elements in a MatrixType object Each nonzero element is o...
Definition: OSMatrix.h:1178
virtual ENUM_MATRIX_TYPE getMatrixType()
Definition: OSMatrix.cpp:5557
virtual bool alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
Check whether a submatrix aligns with the block partition of a matrix or block or other constructor.
Definition: OSMatrix.cpp:5604
virtual ENUM_MATRIX_CONSTRUCTOR_TYPE getNodeType()
Definition: OSMatrix.cpp:5547
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:5659
ConReferenceMatrixValues * value
The constraint references (indexes of core constraints and value types) of the elements.
Definition: OSMatrix.h:1181
virtual std::string getNodeName()
Definition: OSMatrix.cpp:5552
bool deepCopyFrom(ConReferenceMatrixElements *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:5664
virtual std::string getMatrixNodeInXML()
Definition: OSMatrix.cpp:5564
ConReferenceMatrixElements()
-------— Methods for class ConReferenceMatrixElements -------—
Definition: OSMatrix.cpp:5521
virtual ConReferenceMatrixElements * cloneMatrixNode()
Definition: OSMatrix.cpp:5609
bool IsEqual(ConReferenceMatrixElements *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:5616
a data structure to represent the nonzeros in a conReferenceMatrix element
Definition: OSMatrix.h:712
virtual bool deepCopyFrom(ConReferenceMatrixValues *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:5752
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:5747
bool IsEqual(ConReferenceMatrixValues *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:5708
ConReferenceMatrixValues()
-------— Methods for class ConReferenceMatrixValues -------—
Definition: OSMatrix.cpp:5671
ConReferenceMatrixElement ** el
el contains the indices of the matrix constraints along with the valueType.
Definition: OSMatrix.h:717
a data structure to represent the constant elements in a MatrixType object
Definition: OSMatrix.h:750
virtual bool alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
Check whether a submatrix aligns with the block partition of a matrix or block or other constructor.
Definition: OSMatrix.cpp:4217
virtual ENUM_MATRIX_TYPE getMatrixType()
Definition: OSMatrix.cpp:4171
ConstantMatrixElements()
-------— Methods for class ConstantMatrixElements -------—
Definition: OSMatrix.cpp:4135
bool IsEqual(ConstantMatrixElements *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:4229
virtual std::string getNodeName()
Definition: OSMatrix.cpp:4166
virtual std::string getMatrixNodeInXML()
Definition: OSMatrix.cpp:4178
virtual ENUM_MATRIX_CONSTRUCTOR_TYPE getNodeType()
Definition: OSMatrix.cpp:4161
ConstantMatrixValues * value
The value array of the (nonzero) constant elements.
Definition: OSMatrix.h:753
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:4271
virtual ConstantMatrixElements * cloneMatrixNode()
Definition: OSMatrix.cpp:4222
bool deepCopyFrom(ConstantMatrixElements *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:4276
to represent the nonzeros in a constantMatrix element
Definition: OSMatrix.h:502
bool IsEqual(ConstantMatrixValues *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:4307
ConstantMatrixValues()
-------— Methods for class ConstantMatrixValues -------—
Definition: OSMatrix.cpp:4283
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:4346
bool deepCopyFrom(ConstantMatrixValues *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:4351
used for throwing exceptions.
Definition: OSErrorClass.h:32
std::string errormsg
errormsg is the error that is causing the exception to be thrown
Definition: OSErrorClass.h:42
a sparse matrix data structure for matrices that can hold nonconstant values and have block structure...
Definition: OSMatrix.h:1769
int blockNumber
blockNumber gives the number of blocks (which is the size of the blockRows and blockColumns arrays).
Definition: OSMatrix.h:1793
GeneralSparseMatrix ** blocks
blocks holds the blocks that make up the matrix.
Definition: OSMatrix.h:1838
bool display(int secondaryDim)
This method displays data structure in the matrix format.
Definition: OSMatrix.cpp:6622
ENUM_MATRIX_TYPE vType
vType holds the type of all (nonzero) values in the collection of blocks contained in this set of blo...
Definition: OSMatrix.h:1781
int * blockRows
blockRows holds an integer array of the row to which a block belongs.
Definition: OSMatrix.h:1823
int rowOffsetSize
These two parameters give the size of the rowOffset and colOffset arrays, respectively.
Definition: OSMatrix.h:1814
int * colOffset
colOffset gives the column offsets of the block decomposition It does not have to correspond to the c...
Definition: OSMatrix.h:1809
bool isRowMajor
isRowMajor holds whether the (nonzero) values holding the data are stored by columnrow.
Definition: OSMatrix.h:1787
~ExpandedMatrixBlocks()
Default destructor.
Definition: OSMatrix.cpp:6536
bool isBlockDiagonal()
a method to determine whether the collection is blockDiagonal
Definition: OSMatrix.cpp:6605
int * rowOffset
rowOffset gives the row offsets of the block decomposition It does not have to correspond to the row ...
Definition: OSMatrix.h:1801
GeneralSparseMatrix * getBlock(int rowIdx, int colIdx)
a method to retrieve a particular block from a collection
Definition: OSMatrix.cpp:6592
int * blockColumns
blockColumns holds an integer array of the column to which a block belongs.
Definition: OSMatrix.h:1831
bool bDeleteArrays
bDeleteArrays is true if we delete the arrays in garbage collection set to true by default
Definition: OSMatrix.h:1775
ExpandedMatrixBlocks()
Default constructor.
Definition: OSMatrix.cpp:6510
OSnLNode ** m_mChildren
m_mChildren holds all the operands, that is, nodes that the current node operates on.
Definition: OSnLNode.h:84
virtual std::string getNonlinearExpressionInXML()
The following method writes an OSnLNode or OSnLMNode in OSiL format.
Definition: OSnLNode.cpp:221
a data structure to represent the nonzero values in a generalMatrix element
Definition: OSMatrix.h:1006
virtual ENUM_MATRIX_CONSTRUCTOR_TYPE getNodeType()
Definition: OSMatrix.cpp:5069
virtual std::string getMatrixNodeInXML()
Definition: OSMatrix.cpp:5086
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:5173
virtual ENUM_MATRIX_TYPE getMatrixType()
Definition: OSMatrix.cpp:5079
bool deepCopyFrom(GeneralMatrixElements *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:5178
virtual std::string getNodeName()
Definition: OSMatrix.cpp:5074
virtual bool alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
Check whether a submatrix aligns with the block partition of a matrix or block or other constructor.
Definition: OSMatrix.cpp:5119
bool IsEqual(GeneralMatrixElements *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:5131
GeneralMatrixElements()
-------— Methods for class GeneralMatrixElements -------—
Definition: OSMatrix.cpp:5043
virtual GeneralMatrixElements * cloneMatrixNode()
Definition: OSMatrix.cpp:5124
GeneralMatrixValues * value
The values are general nonlinear expressions.
Definition: OSMatrix.h:1011
a data structure to represent the nonzeros in a generalMatrix element
Definition: OSMatrix.h:640
virtual bool deepCopyFrom(GeneralMatrixValues *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:5269
GeneralMatrixValues()
-------— Methods for class GeneralMatrixValues -------—
Definition: OSMatrix.cpp:5185
ScalarExpressionTree ** el
Definition: OSMatrix.h:642
bool IsEqual(GeneralMatrixValues *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:5228
a sparse matrix data structure for matrices that can hold nonconstant values
Definition: OSMatrix.h:1655
bool isRowMajor
isRowMajor holds whether the matrix is stored by row.
Definition: OSMatrix.h:1680
GeneralSparseMatrix()
Default constructor.
Definition: OSMatrix.cpp:6390
bool b_deleteStartArray
b_deleteStartArray is true if we delete the start array in garbage collection — set to true by defaul...
Definition: OSMatrix.h:1662
bool isDiagonal()
a method to determine whether the matrix is diagonal
Definition: OSMatrix.cpp:6480
MatrixElementValues * value
value holds a general array of value elements in the matrix, which could be constants,...
Definition: OSMatrix.h:1723
int * index
index holds an integer array of rowIdx (or colIdx) elements in coefMatrix (AMatrix).
Definition: OSMatrix.h:1708
bool b_deleteIndexArray
b_deleteIndexArray is true if we delete the index array in garbage collection — set to true by defaul...
Definition: OSMatrix.h:1668
bool display(int secondaryDim)
This method displays the data contained in the matrix.
Definition: OSMatrix.cpp:6503
bool b_deleteValueArray
b_deleteValueArray is true if we delete the value array in garbage collection — set to true by defaul...
Definition: OSMatrix.h:1674
int * start
start holds an integer array of start elements in the matrix, which points to the start of a column (...
Definition: OSMatrix.h:1702
ENUM_MATRIX_SYMMETRY symmetry
To track the type of symmetry present in the matrix or block.
Definition: OSMatrix.h:1686
int valueSize
valueSize is the dimension of the index and value arrays
Definition: OSMatrix.h:1696
~GeneralSparseMatrix()
Default destructor.
Definition: OSMatrix.cpp:6425
ENUM_MATRIX_TYPE vType
vType holds the type of values found in the value array.
Definition: OSMatrix.h:1714
int startSize
startSize is the dimension of the starts array
Definition: OSMatrix.h:1691
bool IsEqual(IntVector *that)
A method to compare two invectors.
Definition: OSGeneral.cpp:495
int numberOfEl
Definition: OSGeneral.h:483
int * el
Definition: OSGeneral.h:484
a data structure to represent an expression in a linearMatrix element A LinearMatrixElement is a (fin...
Definition: OSMatrix.h:412
bool IsEqual(LinearMatrixElement *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:4907
LinearMatrixElementTerm ** varIdx
Definition: OSMatrix.h:417
LinearMatrixElement()
-------— Methods for class LinearMatrixElement -------—
Definition: OSMatrix.cpp:4866
bool deepCopyFrom(LinearMatrixElement *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:4953
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:4948
a data structure to represent a term in a linearMatrix element A term has the form c*x_{k},...
Definition: OSMatrix.h:374
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:5029
bool deepCopyFrom(LinearMatrixElementTerm *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:5034
bool IsEqual(LinearMatrixElementTerm *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:4991
LinearMatrixElementTerm()
-------— Methods for class LinearMatrixElementTerm -------—
Definition: OSMatrix.cpp:4975
a data structure to represent the nonzero values in a linearMatrix element
Definition: OSMatrix.h:918
virtual ENUM_MATRIX_TYPE getMatrixType()
Definition: OSMatrix.cpp:4637
virtual std::string getNodeName()
Definition: OSMatrix.cpp:4632
virtual ENUM_MATRIX_CONSTRUCTOR_TYPE getNodeType()
Definition: OSMatrix.cpp:4627
virtual LinearMatrixElements * cloneMatrixNode()
Definition: OSMatrix.cpp:4697
bool IsEqual(LinearMatrixElements *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:4704
virtual std::string getMatrixNodeInXML()
Definition: OSMatrix.cpp:4644
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:4746
LinearMatrixValues * value
The values are expressions of the form a_0 + a_1 x_{i_1} * a_2 x_{i_2} + ...
Definition: OSMatrix.h:925
LinearMatrixElements()
-------— Methods for class LinearMatrixElements -------—
Definition: OSMatrix.cpp:4601
virtual bool alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
Check whether a submatrix aligns with the block partition of a matrix or block or other constructor.
Definition: OSMatrix.cpp:4692
bool deepCopyFrom(LinearMatrixElements *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:4751
a data structure to represent the linear expressions in a LinearMatrixElement object
Definition: OSMatrix.h:603
virtual bool deepCopyFrom(LinearMatrixValues *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:4849
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:4844
bool IsEqual(LinearMatrixValues *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:4804
LinearMatrixValues()
-------— Methods for class LinearMatrixValues -------—
Definition: OSMatrix.cpp:4758
LinearMatrixElement ** el
Definition: OSMatrix.h:605
a data structure to represent a MatrixBlock object (derived from MatrixType)
Definition: OSMatrix.h:2501
virtual ENUM_MATRIX_CONSTRUCTOR_TYPE getNodeType()
Definition: OSMatrix.cpp:6309
bool deepCopyFrom(MatrixBlock *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:6382
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:6377
virtual std::string getMatrixNodeInXML()
Definition: OSMatrix.cpp:6332
int blockRowIdx
Definition: OSMatrix.h:2503
virtual std::string getNodeName()
Definition: OSMatrix.cpp:6314
int blockColIdx
Definition: OSMatrix.h:2504
virtual bool expandElements(bool rowMajor)
A method to expand a matrix or block The result is a GeneralSparseMatrix object of constant matrix el...
Definition: OSMatrix.cpp:6360
bool IsEqual(MatrixBlock *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:6372
virtual bool alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
Check whether a submatrix aligns with the block partition of a matrix or block or other constructor.
Definition: OSMatrix.cpp:6355
virtual ENUM_MATRIX_TYPE getMatrixType()
Definition: OSMatrix.cpp:6319
virtual MatrixBlock * cloneMatrixNode()
The implementation of the virtual functions.
Definition: OSMatrix.cpp:6365
MatrixBlock()
-------— Methods for class MatrixBlock -------—
Definition: OSMatrix.cpp:6292
a data structure to represent the nonzeroes of a matrix in a blockwise fashion. Each block can be giv...
Definition: OSMatrix.h:1450
virtual std::string getNodeName()
Definition: OSMatrix.cpp:6188
IntVector * colOffset
An array listing the leftmost column of each block within the larger matrix It is assumed that the bl...
Definition: OSMatrix.h:1456
virtual ENUM_MATRIX_TYPE getMatrixType()
Definition: OSMatrix.cpp:6193
virtual std::string getMatrixNodeInXML()
Definition: OSMatrix.cpp:6204
virtual bool alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
Check whether a submatrix aligns with the block partition of a matrix or block or other constructor.
Definition: OSMatrix.cpp:6222
virtual ENUM_MATRIX_CONSTRUCTOR_TYPE getNodeType()
Definition: OSMatrix.cpp:6183
MatrixBlocks()
-------— Methods for class MatrixBlocks -------—
Definition: OSMatrix.cpp:6117
virtual MatrixBlocks * cloneMatrixNode()
The implementation of the virtual functions.
Definition: OSMatrix.cpp:6243
bool IsEqual(MatrixBlocks *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:6250
IntVector * rowOffset
An array listing the top row of each block within the larger matrix.
Definition: OSMatrix.h:1461
virtual ~MatrixConstructor()
destructor
Definition: OSMatrix.cpp:152
MatrixConstructor()
constructor
Definition: OSMatrix.cpp:145
an abstract class to help represent the elements in a MatrixType object From this we derive concrete ...
Definition: OSMatrix.h:322
virtual ~MatrixElementValues()
Definition: OSMatrix.cpp:2951
virtual bool deepCopyFrom(MatrixElementValues *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:2958
MatrixElementValues()
-------— Methods for class MatrixElementValues -------—
Definition: OSMatrix.cpp:2943
int numberOfEl
each type of value is stored as an array named "el".
Definition: OSMatrix.h:327
an abstract class to help represent the elements in a MatrixType object From this we derive concrete ...
Definition: OSMatrix.h:249
MatrixElements()
-------— Methods for class MatrixElements -------—
Definition: OSMatrix.cpp:2837
IntVector * start
A vector listing the row or column starts.
Definition: OSMatrix.h:266
IntVector * index
The index array of the (nonzero) elements.
Definition: OSMatrix.h:269
virtual ~MatrixElements()
Definition: OSMatrix.cpp:2848
bool rowMajor
To indicate whether the matrix elements are stored in row major form or column major form.
Definition: OSMatrix.h:255
bool getRowMajor()
Returns whether the matrix is stored row-wise or column-wise.
Definition: OSMatrix.cpp:2879
int numberOfValues
numberOfValues records the number of entries in the arrays that make up the instance of nonzeros
Definition: OSMatrix.h:261
bool IsEqual(MatrixElements *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:2896
a generic class from which we derive matrix constructors (BaseMatrix, MatrixElements,...
Definition: OSMatrix.h:51
virtual bool IsEqual(MatrixNode *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:99
virtual ENUM_MATRIX_TYPE getMatrixType()=0
ENUM_MATRIX_TYPE matrixType
matrixType tracks the type of elements contained in this MatrixNode, which may be useful in solver se...
Definition: OSMatrix.h:58
unsigned int inumberOfChildren
inumberOfChildren is the number of MatrixNode child elements For the matrix types (OSMatrix and Matri...
Definition: OSMatrix.h:70
MatrixNode()
default constructor
Definition: OSMatrix.cpp:40
virtual std::string getMatrixNodeInXML()=0
Definition: OSMatrix.cpp:89
MatrixNode ** m_mChildren
m_mChildren holds all the children, that is, nodes used in the definition or construction of the curr...
Definition: OSMatrix.h:76
virtual ~MatrixNode()
destructor
Definition: OSMatrix.cpp:50
virtual bool alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)=0
Check whether a submatrix aligns with the block partition of a matrix or block or other constructor.
Definition: OSMatrix.cpp:94
virtual ENUM_MATRIX_CONSTRUCTOR_TYPE getNodeType()
Definition: OSMatrix.cpp:84
ENUM_MATRIX_CONSTRUCTOR_TYPE nType
nType is a unique integer assigned to each type of matrix node (see OSParameters.h)
Definition: OSMatrix.h:64
virtual std::string getNodeName()=0
a data structure to represent the nonzeroes of a matrix by transformation from other (previously defi...
Definition: OSMatrix.h:1359
virtual ENUM_MATRIX_CONSTRUCTOR_TYPE getNodeType()
Definition: OSMatrix.cpp:4051
virtual std::string getNodeName()
Definition: OSMatrix.cpp:4056
OSnLMNode * transformation
A transformation is essentially an expression tree that evaluates to a matrix.
Definition: OSMatrix.h:1364
virtual bool alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
Check whether a submatrix aligns with the block partition of a matrix or block or other constructor.
Definition: OSMatrix.cpp:4082
virtual ENUM_MATRIX_TYPE getMatrixType()
Definition: OSMatrix.cpp:4061
MatrixTransformation()
-------— Methods for class MatrixTransformation -------—
Definition: OSMatrix.cpp:4031
bool IsEqual(MatrixTransformation *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:4094
virtual MatrixTransformation * cloneMatrixNode()
The implementation of the virtual functions.
Definition: OSMatrix.cpp:4087
ENUM_NL_EXPR_SHAPE shape
shape can be used to specify linearity etc.
Definition: OSMatrix.h:1370
virtual std::string getMatrixNodeInXML()
Definition: OSMatrix.cpp:4068
a data structure to represent a MatrixType object (from which we derive OSMatrix and MatrixBlock)
Definition: OSMatrix.h:1890
bool deepCopyFrom(MatrixType *that)
A function to make a deep copy of an instance of this class.
int * m_miRowPartition
m_miRowPartition is the partition vector of the matrix rows into blocks
Definition: OSMatrix.h:1919
bool matrixHasElements()
Definition: OSMatrix.cpp:201
int numberOfRows
Definition: OSMatrix.h:1904
GeneralSparseMatrix * convertToOtherMajor(bool isColumnMajor)
A method to convert a matrix to the other major.
Definition: OSMatrix.cpp:1913
int getNumberOfElementConstructors()
Definition: OSMatrix.cpp:236
int m_iRowPartitionSize
m_iRowPartitionSize gives the size of the m_miRowPartition array, which is one more than the number o...
Definition: OSMatrix.h:1924
GeneralSparseMatrix * ExpandedMatrixInColumnMajorForm
Definition: OSMatrix.h:1912
MatrixType()
-------— Methods for class MatrixType -------—
Definition: OSMatrix.cpp:163
bool m_bHaveRowPartition
m_bHaveRowPartition tracks whether the row partition has been determined from the constructor list an...
Definition: OSMatrix.h:1939
int * getColumnPartition()
get the column partition of the matrix
Definition: OSMatrix.cpp:2130
int * getRowPartition()
get the row partition of the matrix
Definition: OSMatrix.cpp:2110
ENUM_MATRIX_SYMMETRY symmetry
To track the type of symmetry present in the matrix or block.
Definition: OSMatrix.h:1896
int m_iColumnPartitionSize
m_iColumnPartitionSize gives the size of the m_miColumnPartition array, which is one more than the nu...
Definition: OSMatrix.h:1934
bool matrixHasTransformations()
Definition: OSMatrix.cpp:216
GeneralSparseMatrix * getMatrixCoefficientsInColumnMajor()
Definition: OSMatrix.cpp:274
int getColumnPartitionSize()
get the size of the column partition of a matrix
Definition: OSMatrix.cpp:2120
GeneralSparseMatrix * extractBlock(int firstrow, int firstcol, int lastrow, int lastcol, bool rowMajor, ENUM_MATRIX_SYMMETRY symmetry)
A method to extract a block from a larger matrix The result is a sparse matrix object,...
Definition: OSMatrix.cpp:2806
virtual bool expandElements(bool rowMajor)
A method to expand a matrix or block The result is a GeneralSparseMatrix object of constant matrix el...
Definition: OSMatrix.cpp:1779
ExpandedMatrixBlocks * getBlocks(int *rowPartition, int rowPartitionSize, int *colPartition, int colPartitionSize, bool rowMajor, bool appendToBlockArray)
A method to extract a block from a larger matrix The result is a sparse matrix object,...
Definition: OSMatrix.cpp:2268
int getNumberOfTransformationConstructors()
Definition: OSMatrix.cpp:252
int numberOfColumns
Definition: OSMatrix.h:1905
int getRowPartitionSize()
get the size of the row partition of a matrix
Definition: OSMatrix.cpp:2100
virtual bool alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
A method to check whether a matrix or block is diagonal.
Definition: OSMatrix.cpp:190
virtual bool processBlocks(bool rowMajor, ENUM_MATRIX_SYMMETRY symmetry)
A method to process a matrixType into a block structure defined by the <blocks> element or elements.
Definition: OSMatrix.cpp:2303
bool matrixHasBase()
Several tools to parse the constructor list of a matrix.
Definition: OSMatrix.cpp:195
virtual ~MatrixType()
Definition: OSMatrix.cpp:183
std::vector< ExpandedMatrixBlocks * > ExpandedMatrixByBlocks
Definition: OSMatrix.h:1913
GeneralSparseMatrix * getMatrixBlockInColumnMajorForm(int columnIdx, int rowIdx)
Definition: OSMatrix.cpp:2260
bool matrixHasBlocks()
Definition: OSMatrix.cpp:226
ENUM_MATRIX_TYPE type
To track the type of values present in the matrix or block.
Definition: OSMatrix.h:1902
GeneralSparseMatrix * getMatrixCoefficientsInRowMajor()
Definition: OSMatrix.cpp:1027
bool m_bHaveColumnPartition
m_bHaveColumnPartition tracks whether the column partition has been determined from the constructor l...
Definition: OSMatrix.h:1944
bool processBlockPartition()
A method to determine the block structure of a matrixType as defined by the <blocks> element or eleme...
Definition: OSMatrix.cpp:2141
int getNumberOfBlocksConstructors()
Definition: OSMatrix.cpp:263
int * m_miColumnPartition
m_miColumnPartition is the partition vector of the matrix columns into blocks
Definition: OSMatrix.h:1929
GeneralSparseMatrix * ExpandedMatrixInRowMajorForm
The matrix can be held in expanded form by rows or by columns and in a number of ways stored by block...
Definition: OSMatrix.h:1911
bool printExpandedMatrix(bool rowMajor)
a utility routine to print the expanded matrix or block.
Definition: OSMatrix.cpp:1784
ExpandedMatrixBlocks * disassembleMatrix(int *rowPartition, int rowPartitionSize, int *colPartition, int colPartitionSize, bool rowMajor, ENUM_MATRIX_SYMMETRY symmetry)
A method to disassemble a MatrixType into individual blocks of specific structure.
Definition: OSMatrix.cpp:2594
a data structure to represent row reference elements in a MatrixType object Each nonzero element refe...
Definition: OSMatrix.h:1265
bool deepCopyFrom(MixedRowReferenceMatrixElements *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:6110
virtual ENUM_MATRIX_CONSTRUCTOR_TYPE getNodeType()
Definition: OSMatrix.cpp:5853
ConReferenceMatrixValues * value
The row references (indexes of core rows plus value type) of the elements.
Definition: OSMatrix.h:1275
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:6105
virtual ENUM_MATRIX_TYPE getMatrixType()
Definition: OSMatrix.cpp:5863
virtual std::string getMatrixNodeInXML()
Definition: OSMatrix.cpp:5870
virtual MixedRowReferenceMatrixElements * cloneMatrixNode()
Definition: OSMatrix.cpp:6056
virtual bool alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
Check whether a submatrix aligns with the block partition of a matrix or block or other constructor.
Definition: OSMatrix.cpp:6051
MixedRowReferenceMatrixElements()
-------— Methods for class MixedRowReferenceMatrixElements -------—
Definition: OSMatrix.cpp:5835
virtual std::string getNodeName()
Definition: OSMatrix.cpp:5858
bool IsEqual(MixedRowReferenceMatrixElements *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:6063
The in-memory representation of the <nl> element.
Definition: OSInstance.h:411
a data structure to represent a matrix object (derived from MatrixType)
Definition: OSMatrix.h:2186
int idx
Definition: OSMatrix.h:2188
virtual bool alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
Check whether a submatrix aligns with the block partition of a matrix or block or other constructor.
Definition: OSMatrix.cpp:3410
virtual bool expandElements(bool rowMajor)
A method to process a matrixType into a specific block structure.
Definition: OSMatrix.cpp:3030
bool setMatrix(std::string name, int numberOfRows, int numberOfColumns, ENUM_MATRIX_SYMMETRY symmetry, ENUM_MATRIX_TYPE matrixType, unsigned int inumberOfChildren, MatrixNode **m_mChildren)
add values to this matrix.
Definition: OSMatrix.cpp:3667
virtual std::string getNodeName()
Definition: OSMatrix.cpp:3014
std::string name
Definition: OSMatrix.h:2189
OSMatrix * createConstructorTreeFromPrefix(std::vector< MatrixNode * > mtxConstructorVec)
Definition: OSMatrix.cpp:2986
virtual OSMatrix * cloneMatrixNode()
The implementation of the virtual functions.
Definition: OSMatrix.cpp:3707
virtual ENUM_MATRIX_CONSTRUCTOR_TYPE getNodeType()
Definition: OSMatrix.cpp:3009
bool isBlockDiagonal()
A method to check whether a matrix is block-diagonal.
bool IsEqual(OSMatrix *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:3714
OSMatrix()
-------— Methods for class OSMatrix -------—
Definition: OSMatrix.cpp:2967
virtual std::string getMatrixNodeInXML()
Definition: OSMatrix.cpp:3682
virtual ENUM_MATRIX_TYPE getMatrixType()
Definition: OSMatrix.cpp:3019
this class extends OSMatrix for use, e.g., in the matrixCon section of OSoL and OSrL
Definition: OSMatrix.h:2446
OSMatrixWithMatrixConIdx()
-------— Methods for class OSMatrixWithMatrixConIdx -------—
Definition: OSMatrix.cpp:3856
virtual OSMatrixWithMatrixConIdx * cloneMatrixNode()
The implementation of the virtual functions.
Definition: OSMatrix.cpp:3898
virtual std::string getMatrixNodeInXML()
Definition: OSMatrix.cpp:3872
this class extends OSMatrix for use, e.g., in the matrixObj section of OSoL and OSrL
Definition: OSMatrix.h:2392
virtual OSMatrixWithMatrixObjIdx * cloneMatrixNode()
The implementation of the virtual functions.
Definition: OSMatrix.cpp:3848
OSMatrixWithMatrixObjIdx()
-------— Methods for class OSMatrixWithMatrixObjIdx -------—
Definition: OSMatrix.cpp:3805
virtual std::string getMatrixNodeInXML()
Definition: OSMatrix.cpp:3822
this class extends OSMatrix for use, e.g., in the matrixVar section of OSoL and OSrL
Definition: OSMatrix.h:2337
virtual std::string getMatrixNodeInXML()
Definition: OSMatrix.cpp:3771
virtual OSMatrixWithMatrixVarIdx * cloneMatrixNode()
The implementation of the virtual functions.
Definition: OSMatrix.cpp:3797
OSMatrixWithMatrixVarIdx()
-------— Methods for class OSMatrixWithMatrixVarIdx -------—
Definition: OSMatrix.cpp:3754
bool IsEqual(OSnLMNode *that)
A function to check for the equality of two objects.
Definition: OSnLNode.cpp:2760
The OSnLNode Class for nonlinear expressions.
Definition: OSnLNode.h:180
OSnLNode * createExpressionTreeFromPostfix(std::vector< ExprNode * > nlNodeVec)
Take a vector of ExprNodes (OSnLNodes and OSnLMNodes) in postfix format and create a scalar-valued OS...
Definition: OSnLNode.cpp:413
virtual OSnLNode * copyNodeAndDescendants()
make a copy of this node and all its descendants
Definition: OSnLNode.cpp:505
The OSnLNodeNumber Class.
Definition: OSnLNode.h:1263
double value
value is the value of the number
Definition: OSnLNode.h:1266
The OSnLNodeSum Class.
Definition: OSnLNode.h:366
The OSnLNodeTimes Class.
Definition: OSnLNode.h:618
The OSnLNodeVariable Class.
Definition: OSnLNode.h:1479
int idx
idx is the index of the variable
Definition: OSnLNode.h:1488
double coef
coef is an option coefficient on the variable, the default value is 1.0
Definition: OSnLNode.h:1485
a data structure to represent objective reference elements in a MatrixType object Each nonzero elemen...
Definition: OSMatrix.h:1092
virtual ENUM_MATRIX_TYPE getMatrixType()
Definition: OSMatrix.cpp:5322
virtual std::string getMatrixNodeInXML()
Definition: OSMatrix.cpp:5329
virtual std::string getNodeName()
Definition: OSMatrix.cpp:5317
bool deepCopyFrom(ObjReferenceMatrixElements *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:5430
virtual ObjReferenceMatrixElements * cloneMatrixNode()
Definition: OSMatrix.cpp:5376
virtual bool alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
Check whether a submatrix aligns with the block partition of a matrix or block or other constructor.
Definition: OSMatrix.cpp:5371
virtual ENUM_MATRIX_CONSTRUCTOR_TYPE getNodeType()
Definition: OSMatrix.cpp:5312
ObjReferenceMatrixValues * value
The objective references (indexes of core objectives) of the elements.
Definition: OSMatrix.h:1095
ObjReferenceMatrixElements()
-------— Methods for class ObjReferenceMatrixElements -------—
Definition: OSMatrix.cpp:5286
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:5425
bool IsEqual(ObjReferenceMatrixElements *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:5383
to represent the nonzeros in an objReferenceMatrix element
Definition: OSMatrix.h:676
ObjReferenceMatrixValues()
-------— Methods for class ObjReferenceMatrixValues -------—
Definition: OSMatrix.cpp:5437
virtual bool deepCopyFrom(ObjReferenceMatrixValues *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:5507
bool IsEqual(ObjReferenceMatrixValues *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:5463
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:5502
Used to hold part of the instance in memory.
OSnLNode * m_treeRoot
m_treeRoot holds the root node (of OSnLNode type) of the expression tree.
a data structure to represent variable reference elements in a MatrixType object Each nonzero element...
Definition: OSMatrix.h:836
bool IsEqual(VarReferenceMatrixElements *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:4463
VarReferenceMatrixElements()
-------— Methods for class VarReferenceMatrixElements -------—
Definition: OSMatrix.cpp:4366
bool deepCopyFrom(VarReferenceMatrixElements *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:4510
virtual ENUM_MATRIX_CONSTRUCTOR_TYPE getNodeType()
Definition: OSMatrix.cpp:4392
virtual std::string getNodeName()
Definition: OSMatrix.cpp:4397
virtual VarReferenceMatrixElements * cloneMatrixNode()
Definition: OSMatrix.cpp:4456
virtual bool alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
Check whether a submatrix aligns with the block partition of a matrix or block or other constructor.
Definition: OSMatrix.cpp:4451
virtual std::string getMatrixNodeInXML()
Definition: OSMatrix.cpp:4409
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:4505
VarReferenceMatrixValues * value
The variable references (indexes of core variables) of the elements.
Definition: OSMatrix.h:839
virtual ENUM_MATRIX_TYPE getMatrixType()
Definition: OSMatrix.cpp:4402
A concrete class that is used to store a specific type of matrix values, references to variable index...
Definition: OSMatrix.h:564
bool IsEqual(VarReferenceMatrixValues *that)
A function to check for the equality of two objects.
Definition: OSMatrix.cpp:4542
bool setRandom(double density, bool conformant, int iMin, int iMax)
A function to make a random instance of this class.
Definition: OSMatrix.cpp:4581
virtual bool deepCopyFrom(VarReferenceMatrixValues *that)
A function to make a deep copy of an instance of this class.
Definition: OSMatrix.cpp:4586
int * el
Each el is a reference to a constraint defined in the <constraints> section of the OSiL file.
Definition: OSMatrix.h:569
VarReferenceMatrixValues()
-------— Methods for class VarReferenceMatrixValues -------—
Definition: OSMatrix.cpp:4517
@ ENUM_NL_EXPR_SHAPE_general
Definition: OSParameters.h:832
std::string returnConReferenceValueTypeString(ENUM_CONREFERENCE_VALUETYPE valueType)
Definition: OSParameters.h:711
std::string returnExprShapeString(ENUM_NL_EXPR_SHAPE shape)
Definition: OSParameters.h:849
std::string returnMatrixSymmetryString(ENUM_MATRIX_SYMMETRY symmetry)
Definition: OSParameters.h:746
std::string returnMatrixTypeString(ENUM_MATRIX_TYPE type)
Definition: OSParameters.h:637
@ ENUM_OUTPUT_LEVEL_detailed_trace
Definition: OSParameters.h:116
@ ENUM_OUTPUT_LEVEL_debug
Definition: OSParameters.h:114
@ ENUM_OUTPUT_LEVEL_trace
Definition: OSParameters.h:115
@ ENUM_OUTPUT_LEVEL_warning
Definition: OSParameters.h:112
ENUM_MATRIX_TYPE
An enum to track the many different types of values that a matrix can contain Note that these types a...
Definition: OSParameters.h:600
@ ENUM_MATRIX_TYPE_linear
Definition: OSParameters.h:605
@ ENUM_MATRIX_TYPE_varReference
Definition: OSParameters.h:604
@ ENUM_MATRIX_TYPE_constant
Definition: OSParameters.h:603
@ ENUM_MATRIX_TYPE_conReference
Definition: OSParameters.h:610
@ ENUM_MATRIX_TYPE_general
Definition: OSParameters.h:607
@ ENUM_MATRIX_TYPE_unknown
Definition: OSParameters.h:615
@ ENUM_MATRIX_TYPE_mixedRowReference
Definition: OSParameters.h:611
@ ENUM_MATRIX_TYPE_empty
Definition: OSParameters.h:601
@ ENUM_MATRIX_TYPE_objReference
Definition: OSParameters.h:609
ENUM_MATRIX_SYMMETRY
Definition: OSParameters.h:736
@ ENUM_MATRIX_SYMMETRY_none
Definition: OSParameters.h:737
ENUM_MATRIX_TYPE mergeMatrixType(ENUM_MATRIX_TYPE type1, ENUM_MATRIX_TYPE type2)
A function to merge two matrix types so we can infer the type of a matrix recursively.
Definition: OSParameters.h:661
ENUM_MATRIX_CONSTRUCTOR_TYPE
Definition: OSParameters.h:777
@ ENUM_MATRIX_CONSTRUCTOR_TYPE_mixedRowRefElements
Definition: OSParameters.h:786
@ ENUM_MATRIX_CONSTRUCTOR_TYPE_generalElements
Definition: OSParameters.h:783
@ ENUM_MATRIX_CONSTRUCTOR_TYPE_varRefElements
Definition: OSParameters.h:781
@ ENUM_MATRIX_CONSTRUCTOR_TYPE_transformation
Definition: OSParameters.h:788
@ ENUM_MATRIX_CONSTRUCTOR_TYPE_objRefElements
Definition: OSParameters.h:784
@ ENUM_MATRIX_CONSTRUCTOR_TYPE_conRefElements
Definition: OSParameters.h:785
@ ENUM_MATRIX_CONSTRUCTOR_TYPE_unknown
Definition: OSParameters.h:778
@ ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks
Definition: OSParameters.h:789
@ ENUM_MATRIX_CONSTRUCTOR_TYPE_linearElements
Definition: OSParameters.h:782
@ ENUM_MATRIX_CONSTRUCTOR_TYPE_block
Definition: OSParameters.h:790
@ ENUM_MATRIX_CONSTRUCTOR_TYPE_matrix
Definition: OSParameters.h:791
@ ENUM_MATRIX_CONSTRUCTOR_TYPE_constantElements
Definition: OSParameters.h:780
@ ENUM_MATRIX_CONSTRUCTOR_TYPE_baseMatrix
Definition: OSParameters.h:779
@ ENUM_OUTPUT_AREA_OSMatrix
Definition: OSParameters.h:140
@ ENUM_OUTPUT_AREA_OSGeneral
Definition: OSParameters.h:136
@ ENUM_OUTPUT_AREA_OSInstance
Definition: OSParameters.h:137
@ ENUM_CONREFERENCE_VALUETYPE_value
Definition: OSParameters.h:705