Exemplo n.º 1
0
 def applyChanges(self):
     """
     Update the node with the settings in the forms
     """
     if self.nodeName not in self.dat.flowsheet.nodes:
         return  # don't apply if node was deleted already
     gr = self.dat.flowsheet  # shorter name for graph
     gr.nodes[self.nodeName] = self.node
     self.node.x = float(self.xBox.text())
     self.node.y = float(self.yBox.text())
     self.node.z = float(self.zBox.text())
     self.node.pythonCode = self.pyCode.toPlainText()
     if self.postRadio.isChecked():
         self.node.scriptMode = "post"
     elif self.preRadio.isChecked():
         self.node.scriptMode = "pre"
     else:
         self.node.scriptMode = "total"
     table = self.inputVarTable
     for row in range(table.rowCount()):
         name = gh.getCellText(table, row, self.ivCols["Name"])
         var = self.node.inVars[name]
         var.desc = gh.getCellText(table, row, self.ivCols["Description"])
         var.unit = gh.getCellText(table, row, self.ivCols["Unit"])
         var.setType(gh.getCellText(table, row, self.ivCols["Type"]))
         var.min = gh.getCellJSON(table, row, self.ivCols["Min"])
         var.max = gh.getCellJSON(table, row, self.ivCols["Max"])
         var.value = gh.getCellJSON(table, row, self.ivCols["Value"])
         var.tags = gh.getCellJSON(table, row, self.ivCols["Tags"])
         var.default = gh.getCellJSON(table, row, self.ivCols["Default"])
         distName = gh.getCellText(table, row, self.ivCols["Distribution"])
         var.dist.setDistributionType(distName)
         val = gh.getCellJSON(table, row, self.ivCols["Param 1"])
         var.dist.firstParamValue = val
         var.dist.secondParamValue = gh.getCellJSON(table, row,
                                                    self.ivCols["Param 2"])
     table = self.outputVarTable
     for row in range(self.outputVarTable.rowCount()):
         name = gh.getCellText(table, row, self.ovCols["Name"])
         var = self.node.outVars[name]
         var.value = gh.getCellJSON(table, row, self.ovCols["Value"])
         var.desc = gh.getCellText(table, row, self.ovCols["Description"])
         var.unit = gh.getCellText(table, row, self.ovCols["Unit"])
         var.setType(gh.getCellText(table, row, self.ovCols["Type"]))
         var.tags = gh.getCellJSON(table, row, self.ovCols["Tags"])
     table = self.simSettingsTable
     for row in range(table.rowCount()):
         name = gh.getCellText(table, row, 0)
         if self.node.options[name].dtype == bool:
             val = gh.isChecked(table, row, 1)
         elif len(self.node.options[name].validValues) > 0:
             val = gh.cellPulldownJSON(table, row, 1)
         else:
             val = gh.getCellJSON(table, row, 1)
         self.node.options[name].value = val
     self.redrawFlowsheet.emit()
Exemplo n.º 2
0
 def applyChanges(self, tool=None):
     '''
         Save surrogate model setup in foqus session
     '''
     if self.blockapply:
         return
     if tool is None:
         tool = self.toolSelectBox.currentText()
     pg = self.dat.surrogateMethods.plugins[tool].\
         surrogateMethod(self.dat)
     inputs = []
     outputs = []
     dataFilter = self.dataBrowser.filterSelectBox.currentText()
     if dataFilter == '':
         dataFilter = None
     # inputs and input var options
     for i in range(self.inputTable.rowCount()):
         c = gh.isCellChecked(self.inputTable, i, 0)
         var = self.dat.flowsheet.input.get(c[1])
         var.setMin(
             gh.getCellJSON(self.inputTable, i, self.inputCols['Min']))
         var.setMax(
             gh.getCellJSON(self.inputTable, i, self.inputCols['Max']))
         if c[0]:
             inputs.append(c[1])
             for item in pg.inputCols:
                 col = self.inputCols[item[0]]
                 val = gh.getCellJSON(self.inputTable, i, col)
                 pg.setInputVarOption(item[0], c[1], val)
     # outputs and output var options
     for i in range(self.outputTable.rowCount()):
         c = gh.isCellChecked(self.outputTable, i, 0)
         if c[0]:
             outputs.append(c[1])
             for item in pg.outputCols:
                 col = self.outputCols[item[0]]
                 val = gh.getCellJSON(self.outputTable, i, col)
                 pg.setOutputVarOption(item[0], c[1], val)
     pg.input = inputs
     pg.output = outputs
     pg.dataFilter = dataFilter
     for i in range(self.optTable[tool].rowCount()):
         optName = gh.getCellText(self.optTable[tool], i, 0)
         if pg.options[optName].dtype == bool:
             optValue = gh.isChecked(self.optTable[tool], i, 1)
         elif len(pg.options[optName].validValues) > 0:
             optValue = gh.cellPulldownJSON(self.optTable[tool], i, 1)
         else:
             optValue = gh.getCellJSON(self.optTable[tool], i, 1)
         pg.options[optName].value = optValue
     pg.saveInSession()
     self.dat.surrogateCurrent = pg.name
Exemplo n.º 3
0
 def applyChanges(self):
     '''
         Use information stored in this form to update the
         optimization options
     '''
     #
     # Delete optimization settings and rebuild them from the form
     if self.running: return
     prob = self.dat.optProblem
     gr = self.dat.flowsheet
     prob.solver = self.solverBox.currentText()
     # Get solver options
     s = self.lastSolver
     prob.solverOptions[s] = {}
     opts = self.methods[s].opt().options
     for row in range(self.solverOptionTable.rowCount()):
         settingName = self.solverOptionTable.item(row, 0).text()
         if opts[settingName].dtype == bool:
             setting = gh.isChecked(self.solverOptionTable, row, 1)
         elif len(opts[settingName].validValues)>0:
             setting = \
                 gh.cellPulldownJSON(self.solverOptionTable,row,1)
         else:
             setting = gh.getCellJSON(self.solverOptionTable, row, 1)
         prob.solverOptions[s][settingName] = setting
     # Get objective functions
     prob.obj = []
     table = self.fTable
     for row in range(self.fTable.rowCount()):
         pc = gh.getCellText(table, row, self.ofCols["Expression"])
         ps = gh.getCellJSON(table, row, self.ofCols["Penalty Scale"])
         fv = gh.getCellJSON(
             table,
             row,
             self.ofCols["Value for Failure"])
         prob.obj.append( optimObj(pc, ps, fv) )
     # Get constraints
     prob.g = []
     table = self.gTable
     for row in range(self.gTable.rowCount()):
         pc = gh.getCellText(table, row, self.icCols["Expression"])
         ps = gh.getCellJSON(
             table,
             row,
             self.icCols["Penalty Factor"])
         pf = gh.getCellText(table, row, self.icCols["Form"] )
         prob.g.append( optimInEq(pc, ps, pf) )
     # Get decision variables
     prob.v = []
     prob.vs = []
     table = self.varForm
     for row in range(self.varForm.rowCount()):
         name = gh.getCellText(table, row, self.vtCols["Variable"])
         gr.x[name].scaling = gh.getCellText(
             table,
             row,
             self.vtCols["Scale"])
         gr.x[name].min = gh.getCellJSON(
             table,
             row,
             self.vtCols["Min"])
         gr.x[name].max = gh.getCellJSON(
             table,
             row,
             self.vtCols["Max"])
         gr.x[name].value = gh.getCellJSON(
             table,
             row,
             self.vtCols["Value"])
         vt = gh.cellPulldownValue(table, row, self.vtCols["Type"])
         if  vt == "Decision":
             prob.v.append(name)
             gr.x[name].optVar=True
         elif vt == "Sample":
             prob.vs.append(name)
         else:
             gr.x[name].optVar=False
     # Get sample information
     table = self.sampleTable
     ci = gh.colIndexes(table)
     n = prob.numSamples()
     for row in range(table.rowCount()):
         if row < n: #re-set sample data
             for name in ci:
                 if name in prob.samp:
                     prob.samp[name][row] = \
                         gh.getCellJSON(table, row, ci[name])
                 else:
                     prob.addSampleVar(name)
                     prob.samp[name][row] = \
                         gh.getCellJSON(table, row, ci[name])
         else:
             s = ci.copy()
             for name in s:
                 s[name] = gh.getCellJSON(table, row, ci[name])
             prob.addSample(s)
     # Get objective type
     if self.objTypeCombo.currentIndex() == 0:
         prob.objtype = prob.OBJ_TYPE_EVAL
     elif self.objTypeCombo.currentIndex() == 1:
         prob.objtype = prob.OBJ_TYPE_CUST
     # Get custom code
     prob.custpy = self.customCodeEdit.toPlainText()
     self.updateSampleVarsTable()