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