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

#include <CQOptimizationWidget.h>

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

Public Slots

void slotConstraintNumberChanged (int number)
 
virtual void slotEditExpression ()
 
void slotParameterNumberChanged (int number)
 
- Public Slots inherited from TaskWidget
void adjustTable ()
 
void slotFinishThread ()
 

Public Member Functions

 CQOptimizationWidget (QWidget *parent=0, const char *name=0)
 
bool isSteadyState ()
 
virtual bool runTask ()
 
 ~CQOptimizationWidget ()
 
- Public Member Functions inherited from TaskWidget
CCopasiTaskgetTask ()
 
virtual bool leave ()
 
 TaskWidget (QWidget *parent=0, const char *name=0, Qt::WFlags fl=0)
 
virtual bool update (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
 
 ~TaskWidget ()
 
- 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 Slots

void slotExpressionValid (bool valid)
 
void slotPageChange (QWidget *currentPage)
 
void slotSubtaskChanged (const QString &subtask)
 
- Protected Slots inherited from TaskWidget
void assistantBtnClicked ()
 
void reportBtnClicked ()
 
void revertBtnClicked ()
 
void runBtnClicked ()
 
- Protected Slots inherited from CopasiWidget
virtual bool protectedNotify (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
 

Protected Member Functions

virtual CCopasiMethodcreateMethod (const CCopasiMethod::SubType &type)
 
virtual bool loadTask ()
 
virtual bool saveTask ()
 
- Protected Member Functions inherited from TaskWidget
bool commonAfterRunTask ()
 
bool commonBeforeRunTask ()
 
bool commonRunTask ()
 
virtual bool enterProtected ()
 
void finishTask ()
 
bool loadCommon ()
 
bool loadMethod ()
 
bool saveCommon ()
 
bool saveMethod ()
 
virtual bool taskFinishedEvent ()
 

Protected Attributes

QColor mChangedColor
 
CQFittingItemWidgetmpCurrentList
 
QColor mSavedColor
 
std::map< std::string, C_INT32mSubtaskMap
 
bool mTypeChanged
 
- Protected Attributes inherited from TaskWidget
bool mChanged
 
CQTaskBtnWidgetmpBtnWidget
 
CQTaskHeaderWidgetmpHeaderWidget
 
CCopasiMethodmpMethod
 
QGridLayout * mpMethodLayout
 
CQTaskMethodWidgetmpMethodWidget
 
CProgressBarmProgressBar
 
QSpacerItem * mpSpacer1
 
QSpacerItem * mpSpacer2
 
CCopasiTaskmpTask
 
CQTaskThreadmpTaskThread
 
- Protected Attributes inherited from CopasiWidget
int mFramework
 
bool mIgnoreUpdates
 
std::string mKey
 
CCopasiDataModelmpDataModel
 
ListViewsmpListView
 
CCopasiObjectmpObject
 

Private Member Functions

void destroy ()
 
void init ()
 

Detailed Description

Definition at line 28 of file CQOptimizationWidget.h.

Constructor & Destructor Documentation

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

Definition at line 41 of file CQOptimizationWidget.cpp.

References init().

42  : TaskWidget(parent, name)
43 {
44  setupUi(this);
45 
46  init();
47 }
TaskWidget(QWidget *parent=0, const char *name=0, Qt::WFlags fl=0)
Definition: TaskWidget.cpp:52
CQOptimizationWidget::~CQOptimizationWidget ( )

Definition at line 52 of file CQOptimizationWidget.cpp.

References destroy().

53 {
54  destroy();
55  // no need to delete child widgets, Qt does it all for us
56 }

Member Function Documentation

CCopasiMethod * CQOptimizationWidget::createMethod ( const CCopasiMethod::SubType type)
protectedvirtual

Implements TaskWidget.

Definition at line 185 of file CQOptimizationWidget.cpp.

References COptMethod::createMethod().

186 {return COptMethod::createMethod(type);}
static COptMethod * createMethod(CCopasiMethod::SubType subType=CCopasiMethod::RandomSearch)
Definition: COptMethod.cpp:50
void CQOptimizationWidget::destroy ( )
private

Definition at line 237 of file CQOptimizationWidget.cpp.

Referenced by ~CQOptimizationWidget().

238 {}
void CQOptimizationWidget::init ( )
private

Definition at line 200 of file CQOptimizationWidget.cpp.

References FROM_UTF8, TaskWidget::mpBtnWidget, mpCurrentList, TaskWidget::mpHeaderWidget, TaskWidget::mpMethodWidget, mSubtaskMap, CQExpressionWidget::ObjectiveFunctions, CQFittingItemWidget::OPT_CONSTRAINT, CQFittingItemWidget::OPT_ITEM, CQTaskHeaderWidget::setTaskName(), CQTaskMethodWidget::setValidMethods(), CQTaskMethodWidget::showMethodParameters(), slotConstraintNumberChanged(), slotParameterNumberChanged(), CCopasiTask::TypeName, CCopasiTask::unset, COptTask::ValidMethods, and COptProblem::ValidSubtasks.

Referenced by CQOptimizationWidget().

201 {
202  std::string taskName = "Optimization";
203 
204  mpHeaderWidget->setTaskName(taskName);
205 
206  verticalLayout->insertWidget(0, mpHeaderWidget);
207  // verticalLayout->insertSpacing(1, 14); // space between header and body
208 
211  verticalLayout->addWidget(mpMethodWidget);
212 
213  verticalLayout->addWidget(mpBtnWidget);
214 
215  mpExpressionEMW->mpExpressionWidget->setExpressionType(CQExpressionWidget::ObjectiveFunctions);
216 
217  //mpBtnMaximize->setMinimumWidth(mpLblExpression->width());
218  const unsigned int * pSubtask = COptProblem::ValidSubtasks;
219 
220  for (; *pSubtask != CCopasiTask::unset; ++pSubtask)
221  {
222  mpBoxSubtask->insertItem(mpBoxSubtask->count(), FROM_UTF8(CCopasiTask::TypeName[*pSubtask]));
223  mSubtaskMap[CCopasiTask::TypeName[*pSubtask]] = *pSubtask;
224  }
225 
226  mpParameters->setItemType(CQFittingItemWidget::OPT_ITEM);
227 
228  connect(mpParameters, SIGNAL(numberChanged(int)), this, SLOT(slotParameterNumberChanged(int)));
229 
230  mpConstraints->setItemType(CQFittingItemWidget::OPT_CONSTRAINT);
231 
232  connect(mpConstraints, SIGNAL(numberChanged(int)), this, SLOT(slotConstraintNumberChanged(int)));
233 
234  mpCurrentList = mpParameters;
235 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static const std::string TypeName[]
Definition: CCopasiTask.h:67
void slotConstraintNumberChanged(int number)
bool setTaskName(const std::string &name)
static const unsigned int ValidMethods[]
Definition: COptTask.h:50
std::map< std::string, C_INT32 > mSubtaskMap
void showMethodParameters(const bool &show)
CQTaskMethodWidget * mpMethodWidget
Definition: TaskWidget.h:123
static const unsigned int ValidSubtasks[]
Definition: COptProblem.h:57
CQFittingItemWidget * mpCurrentList
CQTaskBtnWidget * mpBtnWidget
Definition: TaskWidget.h:124
CQTaskHeaderWidget * mpHeaderWidget
Definition: TaskWidget.h:122
void slotParameterNumberChanged(int number)
void setValidMethods(const unsigned int *validMethods)
bool CQOptimizationWidget::isSteadyState ( )
bool CQOptimizationWidget::loadTask ( )
protectedvirtual

Implements TaskWidget.

Definition at line 123 of file CQOptimizationWidget.cpp.

References FROM_UTF8, COptProblem::getCalculateStatistics(), CCopasiParameterGroup::getGroup(), COptProblem::getObjectiveFunction(), CCopasiTask::getProblem(), COptProblem::getRandomizeStartValues(), COptProblem::getSubtaskType(), TaskWidget::loadCommon(), TaskWidget::loadMethod(), COptProblem::maximize(), TaskWidget::mChanged, CopasiWidget::mpDataModel, TaskWidget::mpTask, pTask, and CCopasiTask::TypeName.

124 {
125  COptTask * pTask =
126  dynamic_cast< COptTask * >(mpTask);
127 
128  if (!pTask) return false;
129 
130  loadCommon();
131  loadMethod();
132 
133  COptProblem * pProblem =
134  dynamic_cast<COptProblem *>(mpTask->getProblem());
135 
136  if (!pProblem) return false;
137 
138  // expression
139  mpExpressionEMW->mpExpressionWidget->setExpression(pProblem->getObjectiveFunction());
140  mpExpressionEMW->updateWidget();
141 
142  mpBtnMaximize->setChecked(pProblem->maximize());
143  mpBtnMinimize->setChecked(!pProblem->maximize());
144 
145  mpCheckRandomize->setChecked(pProblem->getRandomizeStartValues());
146  mpCheckStatistics->setChecked(pProblem->getCalculateStatistics());
147 
148  mpBoxSubtask->setCurrentIndex(mpBoxSubtask->findText(FROM_UTF8(CCopasiTask::TypeName[pProblem->getSubtaskType()])));
149 
150  mpParameters->load(mpDataModel, pProblem->getGroup("OptimizationItemList"), NULL, NULL);
151 
152  mpConstraints->load(mpDataModel, pProblem->getGroup("OptimizationConstraintList"), NULL, NULL);
153 
154  mChanged = false;
155 
156  return true;
157 }
CCopasiTask::Type getSubtaskType() const
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static const std::string TypeName[]
Definition: CCopasiTask.h:67
CCopasiProblem * getProblem()
bool loadCommon()
Definition: TaskWidget.cpp:247
bool loadMethod()
Definition: TaskWidget.cpp:284
const bool & getRandomizeStartValues() const
const bool & maximize() const
bool mChanged
Definition: TaskWidget.h:133
CTSSATask * pTask
CCopasiTask * mpTask
Definition: TaskWidget.h:130
CCopasiDataModel * mpDataModel
Definition: copasiWidget.h:65
const std::string getObjectiveFunction()
const bool & getCalculateStatistics() const
CCopasiParameterGroup * getGroup(const std::string &name)
bool CQOptimizationWidget::runTask ( )
virtual

Implements TaskWidget.

Definition at line 159 of file CQOptimizationWidget.cpp.

References TaskWidget::commonBeforeRunTask(), TaskWidget::commonRunTask(), CKeyFactory::get(), CCopasiRootContainer::getKeyFactory(), CopasiWidget::mKey, and pTask.

Referenced by SliderDialog::runOptimizationTask().

160 {
161  // --- expression
162 
163  mpExpressionEMW->updateWidget();
164 
165  // ----
166 
167  COptTask * pTask =
168  dynamic_cast< COptTask * >(CCopasiRootContainer::getKeyFactory()->get(mKey));
169 
170  if (!pTask) return false;
171 
172  if (!commonBeforeRunTask()) return false;
173 
174  return commonRunTask();
175 }
CCopasiObject * get(const std::string &key)
CTSSATask * pTask
static CKeyFactory * getKeyFactory()
bool commonRunTask()
Definition: TaskWidget.cpp:395
bool commonBeforeRunTask()
Definition: TaskWidget.cpp:317
std::string mKey
Definition: copasiWidget.h:63
bool CQOptimizationWidget::saveTask ( )
protectedvirtual

Implements TaskWidget.

Definition at line 58 of file CQOptimizationWidget.cpp.

References CCopasiMessage::ERROR, FROM_UTF8, COptProblem::getCalculateStatistics(), CCopasiRootContainer::getDatamodelList(), COptProblem::getObjectiveFunction(), CCopasiTask::getProblem(), COptProblem::getRandomizeStartValues(), COptProblem::getSubtaskType(), COptProblem::maximize(), TaskWidget::mChanged, MCOptimization, TaskWidget::mpTask, mSubtaskMap, pTask, TaskWidget::saveCommon(), TaskWidget::saveMethod(), COptProblem::setCalculateStatistics(), COptProblem::setMaximize(), COptProblem::setObjectiveFunction(), COptProblem::setRandomizeStartValues(), COptProblem::setSubtaskType(), TO_UTF8, and CCopasiTask::TypeName.

59 {
60  COptTask * pTask =
61  dynamic_cast< COptTask * >(mpTask);
62 
63  if (!pTask) return false;
64 
65  saveCommon();
66  saveMethod();
67 
68  COptProblem * pProblem =
69  dynamic_cast<COptProblem *>(mpTask->getProblem());
70 
71  if (!pProblem) return false;
72 
73  // expression
74  if (pProblem->getObjectiveFunction() != mpExpressionEMW->mpExpressionWidget->getExpression())
75  {
76  if (!pProblem->setObjectiveFunction(mpExpressionEMW->mpExpressionWidget->getExpression()))
77  {
79  return false;
80  }
81 
82  mChanged = true;
83  }
84 
85  if (mpBoxSubtask->currentText() != FROM_UTF8(CCopasiTask::TypeName[pProblem->getSubtaskType()]))
86  {
87  mChanged = true;
88  pProblem->setSubtaskType((CCopasiTask::Type) mSubtaskMap[TO_UTF8(mpBoxSubtask->currentText())]);
89  }
90 
91  if (mpBtnMaximize->isChecked() != pProblem->maximize())
92  {
93  mChanged = true;
94  pProblem->setMaximize(mpBtnMaximize->isChecked());
95  }
96 
97  if (mpCheckRandomize->isChecked() != pProblem->getRandomizeStartValues())
98  {
99  mChanged = true;
100  pProblem->setRandomizeStartValues(mpCheckRandomize->isChecked());
101  }
102 
103  if (mpCheckStatistics->isChecked() != pProblem->getCalculateStatistics())
104  {
105  mChanged = true;
106  pProblem->setCalculateStatistics(mpCheckStatistics->isChecked());
107  }
108 
109  mChanged |= mpParameters->save(NULL, NULL);
110  mChanged |= mpConstraints->save(NULL, NULL);
111 
112  if (mChanged)
113  {
114  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
115  (*CCopasiRootContainer::getDatamodelList())[0]->changed();
116  }
117 
118  mChanged = false;
119 
120  return true;
121 }
CCopasiTask::Type getSubtaskType() const
bool saveMethod()
Definition: TaskWidget.cpp:308
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static const std::string TypeName[]
Definition: CCopasiTask.h:67
CCopasiProblem * getProblem()
#define MCOptimization
bool saveCommon()
Definition: TaskWidget.cpp:258
const bool & getRandomizeStartValues() const
const bool & maximize() const
bool mChanged
Definition: TaskWidget.h:133
CTSSATask * pTask
std::map< std::string, C_INT32 > mSubtaskMap
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
CCopasiTask * mpTask
Definition: TaskWidget.h:130
void setRandomizeStartValues(const bool &randomize)
const std::string getObjectiveFunction()
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
const bool & getCalculateStatistics() const
bool setSubtaskType(const CCopasiTask::Type &subtaskType)
void setMaximize(const bool &maximize)
void setCalculateStatistics(const bool &calculate)
bool setObjectiveFunction(const std::string &infix)
void CQOptimizationWidget::slotConstraintNumberChanged ( int  number)
slot

Definition at line 194 of file CQOptimizationWidget.cpp.

Referenced by init().

195 {
196  QString TabLabel = "Constraints (" + QString::number(number) + ")";
197  mpTabWidget->setTabText(mpTabWidget->indexOf(mpConstraints), TabLabel);
198 }
void CQOptimizationWidget::slotEditExpression ( )
virtualslot

The slot to activate the editor page of type CQExpressionWidget for being able to type a new mathematical expression or edit the existing one

Definition at line 249 of file CQOptimizationWidget.cpp.

250 {}
void CQOptimizationWidget::slotExpressionValid ( bool  valid)
protectedslot

Definition at line 240 of file CQOptimizationWidget.cpp.

References TaskWidget::mpBtnWidget.

241 {
242  mpBtnWidget->mpBtnRun->setEnabled(valid);
243 }
CQTaskBtnWidget * mpBtnWidget
Definition: TaskWidget.h:124
void CQOptimizationWidget::slotPageChange ( QWidget *  currentPage)
protectedslot

Definition at line 177 of file CQOptimizationWidget.cpp.

References mpCurrentList.

178 {
179  if (mpTabWidget->tabText(mpTabWidget->indexOf(currentPage)).contains("Parameters", Qt::CaseSensitive))
180  mpCurrentList = mpParameters;
181  else
182  mpCurrentList = mpConstraints;
183 }
CQFittingItemWidget * mpCurrentList
void CQOptimizationWidget::slotParameterNumberChanged ( int  number)
slot

Definition at line 188 of file CQOptimizationWidget.cpp.

Referenced by init().

189 {
190  QString TabLabel = "Parameters (" + QString::number(number) + ")";
191  mpTabWidget->setTabText(mpTabWidget->indexOf(mpParameters), TabLabel);
192 }
void CQOptimizationWidget::slotSubtaskChanged ( const QString &  subtask)
protectedslot

Definition at line 252 of file CQOptimizationWidget.cpp.

253 {}

Member Data Documentation

QColor CQOptimizationWidget::mChangedColor
protected

Definition at line 46 of file CQOptimizationWidget.h.

CQFittingItemWidget* CQOptimizationWidget::mpCurrentList
protected

Definition at line 45 of file CQOptimizationWidget.h.

Referenced by init(), and slotPageChange().

QColor CQOptimizationWidget::mSavedColor
protected

Definition at line 47 of file CQOptimizationWidget.h.

std::map< std::string, C_INT32 > CQOptimizationWidget::mSubtaskMap
protected

Definition at line 50 of file CQOptimizationWidget.h.

Referenced by init(), and saveTask().

bool CQOptimizationWidget::mTypeChanged
protected

Definition at line 48 of file CQOptimizationWidget.h.


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