COPASI API  4.16.103
Public Member Functions | Protected Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
CQOptimizationResult Class Reference

#include <CQOptimizationResult.h>

Inheritance diagram for CQOptimizationResult:
Inheritance graph
[legend]
Collaboration diagram for CQOptimizationResult:
Collaboration graph
[legend]

Public Member Functions

 CQOptimizationResult (QWidget *parent=0, const char *name=0)
 
virtual bool leave ()
 
virtual bool update (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
 
 ~CQOptimizationResult ()
 
- Public Member Functions inherited from CopasiWidget
 CopasiWidget (QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
 
bool enter (const std::string &key)
 
CCopasiDataModelgetDataModel ()
 
bool getIgnoreUpdates ()
 
virtual void setFramework (int framework)
 
void setIgnoreUpdates (bool v)
 

Protected Member Functions

virtual bool enterProtected ()
 

Private Slots

void slotSave (void)
 
void slotUpdateModel ()
 

Private Member Functions

void init ()
 

Private Attributes

const COptProblemmpProblem
 
const COptTaskmpTask
 

Additional Inherited Members

- Protected Slots inherited from CopasiWidget
virtual bool protectedNotify (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
 
- Protected Attributes inherited from CopasiWidget
int mFramework
 
bool mIgnoreUpdates
 
std::string mKey
 
CCopasiDataModelmpDataModel
 
ListViewsmpListView
 
CCopasiObjectmpObject
 

Detailed Description

Definition at line 29 of file CQOptimizationResult.h.

Constructor & Destructor Documentation

CQOptimizationResult::CQOptimizationResult ( QWidget *  parent = 0,
const char *  name = 0 
)

Definition at line 30 of file CQOptimizationResult.cpp.

References init().

31  : CopasiWidget(parent, name)
32 {
33  setupUi(this);
34 
35  init();
36 }
CopasiWidget(QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
CQOptimizationResult::~CQOptimizationResult ( )

Definition at line 41 of file CQOptimizationResult.cpp.

42 {
43  // no need to delete child widgets, Qt does it all for us
44 }

Member Function Documentation

bool CQOptimizationResult::enterProtected ( )
protectedvirtual

Reimplemented from CopasiWidget.

Definition at line 63 of file CQOptimizationResult.cpp.

References C_FLOAT64, C_INT32, FROM_UTF8, CCopasiRootContainer::getDatamodelList(), CCopasiDataModel::getDataObject(), COptProblem::getExecutionTime(), COptProblem::getFunctionEvaluations(), CCopasiObject::getObjectDisplayName(), COptProblem::getOptItemList(), CCopasiTask::getProblem(), COptProblem::getSolutionValue(), COptProblem::getSolutionVariables(), COptProblem::getVariableGradients(), mpProblem, and mpTask.

64 {
65  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
67  assert(pDataModel != NULL);
68 
69  mpTask =
70  dynamic_cast<COptTask *>((*(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList())["Optimization"]);
71 
72  if (!mpTask) return false;
73 
74  mpProblem = dynamic_cast<const COptProblem *>(mpTask->getProblem());
75 
76  if (!mpProblem) return false;
77 
78  // Objective Value
79  mpEditObjectiveValue->setText(QString::number(mpProblem->getSolutionValue()));
80 
81  // Performance Statistics
82  const unsigned C_INT32 & FunctionEvaluations = mpProblem->getFunctionEvaluations();
83  mpEditEvaluations->setText(QString::number(FunctionEvaluations));
84  const C_FLOAT64 & ExecutionTime = mpProblem->getExecutionTime();
85  mpEditCPUTime->setText(QString::number(ExecutionTime));
86  mpEditSpeed->setText(QString::number(FunctionEvaluations / ExecutionTime));
87 
88  size_t i, imax;
89 
90  // Loop over the optimization items
91  const std::vector< COptItem * > & Items = mpProblem->getOptItemList();
94 
95  imax = Items.size();
96  QTableWidgetItem * pItem;
97 
99  imax = 0;
100 
101  mpParameters->setRowCount((int) imax);
102 
103  QColor BackgroundColor = mpParameters->palette().brush(QPalette::Active, QPalette::Base).color();
104 
105  int h, s, v;
106  BackgroundColor.getHsv(&h, &s, &v);
107 
108  if (s < 20)
109  {
110  s = 20;
111  }
112 
113  BackgroundColor.setHsv(0, s, v);
114 
115  for (i = 0; i != imax; i++)
116  {
117  //1st column: parameter name
118  const CCopasiObject *pObject =
119  pDataModel->getDataObject(Items[i]->getObjectCN());
120 
121  if (pObject)
122  pItem = new QTableWidgetItem(FROM_UTF8(pObject->getObjectDisplayName()));
123  else
124  pItem = new QTableWidgetItem("Not Found");
125 
126  mpParameters->setItem((int) i, 0, pItem);
127 
128  const C_FLOAT64 & Solution = Solutions[i];
129 
130  //2nd column: lower bound
131  pItem = new QTableWidgetItem(FROM_UTF8(Items[i]->getLowerBound()));
132  mpParameters->setItem((int) i, 1, pItem);
133 
134  if (1.01 * *Items[i]->getLowerBoundValue() > Solution)
135  {
136  pItem->setBackgroundColor(BackgroundColor);
137  }
138 
139  //3rd column: start value
140  pItem = new QTableWidgetItem(QString::number(Items[i]->getLastStartValue()));
141  pItem->setForeground(QColor(120, 120, 140));
142  mpParameters->setItem((int) i, 2, pItem);
143 
144  //4th column: solution value
145  pItem = new QTableWidgetItem(QString::number(Solution));
146  mpParameters->setItem((int) i, 3, pItem);
147 
148  //5th column: upper bound
149  pItem = new QTableWidgetItem(FROM_UTF8(Items[i]->getUpperBound()));
150  mpParameters->setItem((int) i, 4, pItem);
151 
152  if (0.99 * *Items[i]->getUpperBoundValue() < Solution)
153  {
154  pItem->setBackgroundColor(BackgroundColor);
155  }
156 
157  pItem = new QTableWidgetItem(QString::number(Gradients[i]));
158  mpParameters->setItem((int) i, 5, pItem);
159  }
160 
161  mpParameters->resizeColumnsToContents();
162  mpParameters->resizeRowsToContents();
163 
164  return true;
165 }
CCopasiObject * getDataObject(const CCopasiObjectName &CN) const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CCopasiProblem * getProblem()
const CVector< C_FLOAT64 > & getVariableGradients() const
const COptProblem * mpProblem
#define C_INT32
Definition: copasi.h:90
const C_FLOAT64 & getSolutionValue() const
const C_FLOAT64 & getExecutionTime() const
const std::vector< COptItem * > & getOptItemList() const
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
const CVector< C_FLOAT64 > & getSolutionVariables() const
#define C_FLOAT64
Definition: copasi.h:92
const unsigned C_INT32 & getFunctionEvaluations() const
void CQOptimizationResult::init ( )
private

Definition at line 46 of file CQOptimizationResult.cpp.

Referenced by CQOptimizationResult().

47 {}
bool CQOptimizationResult::leave ( )
virtual

Reimplemented from CopasiWidget.

Definition at line 57 of file CQOptimizationResult.cpp.

58 {
59  // :TODO:
60  return true;
61 }
void CQOptimizationResult::slotSave ( void  )
privateslot

Definition at line 167 of file CQOptimizationResult.cpp.

References C_FLOAT64, C_INT32, checkSelection(), CLocaleString::fromUtf8(), COptProblem::getExecutionTime(), COptProblem::getFunctionEvaluations(), CopasiFileDialog::getSaveFileName(), COptProblem::getSolutionValue(), mpProblem, and TO_UTF8.

168 {
169  C_INT32 Answer = QMessageBox::No;
170  QString fileName;
171 
172  while (Answer == QMessageBox::No)
173  {
174  fileName =
175  CopasiFileDialog::getSaveFileName(this, "Save File Dialog",
176  "untitled.txt", "TEXT Files (*.txt)", "Save to");
177 
178  if (fileName.isEmpty()) return;
179 
180  // Checks whether the file exists
181  Answer = checkSelection(fileName);
182 
183  if (Answer == QMessageBox::Cancel) return;
184  }
185 
186  std::ofstream file(CLocaleString::fromUtf8(TO_UTF8(fileName)).c_str());
187 
188  if (file.fail()) return;
189 
190  size_t i, imax;
191 
192  // The global result and statistics
193  file << "Objective Value" << std::endl;
194  file << mpProblem->getSolutionValue() << std::endl;
195 
196  file << "Function Evaluations\tCPU Time [s]\tEvaluations/second [1/s]" << std::endl;
197  const size_t & FunctionEvaluations = mpProblem->getFunctionEvaluations();
198  const C_FLOAT64 & ExecutionTime = mpProblem->getExecutionTime();
199  file << FunctionEvaluations << "\t";
200  file << ExecutionTime << "\t";
201  file << FunctionEvaluations / ExecutionTime << std::endl << std::endl;
202 
203  // Set up the parameters table
204  file << "Parameters:" << std::endl;
205  file << "Parameter\tLower Bound\tStart Value\tValue\tUpper Bound\tGradient" << std::endl;
206 
207  // Loop over the fitted values objects
208  imax = mpParameters->rowCount();
209 
210  for (i = 0; i != imax; i++)
211  {
212  file << TO_UTF8(mpParameters->item((int) i, 0)->text()) << "\t";
213  file << TO_UTF8(mpParameters->item((int) i, 1)->text()) << "\t";
214  file << TO_UTF8(mpParameters->item((int) i, 2)->text()) << "\t";
215  file << TO_UTF8(mpParameters->item((int) i, 3)->text()) << "\t";
216  file << TO_UTF8(mpParameters->item((int) i, 4)->text()) << "\t";
217  file << TO_UTF8(mpParameters->item((int) i, 5)->text()) << std::endl;
218  }
219 
220  file << std::endl;
221 }
const COptProblem * mpProblem
#define C_INT32
Definition: copasi.h:90
const C_FLOAT64 & getSolutionValue() const
const C_FLOAT64 & getExecutionTime() const
C_INT32 checkSelection(const QString &file)
#define C_FLOAT64
Definition: copasi.h:92
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
static CLocaleString fromUtf8(const std::string &utf8)
const unsigned C_INT32 & getFunctionEvaluations() const
static QString getSaveFileName(QWidget *parent=0, const char *name=0, const QString &startWith=QString::null, const QString &filter=QString::null, const QString &caption=QString::null, QString *pSelectedFilter=NULL, QFileDialog::Options options=0)
void CQOptimizationResult::slotUpdateModel ( )
privateslot

Definition at line 223 of file CQOptimizationResult.cpp.

References mpProblem.

224 {
225  const_cast< COptProblem * >(mpProblem)->restoreModel(true);
226 }
const COptProblem * mpProblem
bool CQOptimizationResult::update ( ListViews::ObjectType  objectType,
ListViews::Action  action,
const std::string &  key 
)
virtual

Reimplemented from CopasiWidget.

Definition at line 49 of file CQOptimizationResult.cpp.

52 {
53  // :TODO:
54  return true;
55 }

Member Data Documentation

const COptProblem* CQOptimizationResult::mpProblem
private

Definition at line 46 of file CQOptimizationResult.h.

Referenced by enterProtected(), slotSave(), and slotUpdateModel().

const COptTask* CQOptimizationResult::mpTask
private

Definition at line 47 of file CQOptimizationResult.h.

Referenced by enterProtected().


The documentation for this class was generated from the following files: