def _parse_equations(self, Xi=None, match_Xi=None, **kwargs):
     auxiliary_variables = self.auxiliary_variables
     if Xi is not None:
         Xi = [i for i in Xi]
     elif match_Xi is not None:
         Xi = match_Xi.independent_variables
     if Xi is None:
         swigwrapper = DSSWIGDesignSpaceParseWrapper(
             self.equations.system, len(self.equations), auxiliary_variables, len(auxiliary_variables)
         )
     else:
         swigwrapper = DSSWIGDesignSpaceParseWrapperWithXi(
             self.equations.system, len(self.equations), auxiliary_variables, len(auxiliary_variables), Xi, len(Xi)
         )
     self.set_swigwrapper(swigwrapper)
     gma = DSDesignSpaceGMASystem(self._swigwrapper)
     eqs = DSGMASystemEquations(gma)
     equation_list = list()
     for i in xrange(0, DSGMASystemNumberOfEquations(gma)):
         expr = DSExpressionAtIndexOfExpressionArray(eqs, i)
         equation_list.append(DSExpressionAsString(expr))
         DSExpressionFree(expr)
     DSSecureFree(eqs)
     Xda = VariablePool()
     Xda.set_swigwrapper(DSVariablePoolCopy(DSGMASystemXd_a(gma)))
     equations = Equations(equation_list, auxiliary_variables=Xda.keys(), latex_symbols=self._latex)
     self._equations = equations
 def vertices_ND_slice(self, p_bounds=None, log_out=False):
     keys = []
     free_variables = []
     lower = VariablePool(names=self.independent_variables)
     upper = VariablePool(names=self.independent_variables)
     if p_bounds is None:
         p_bounds = {}
     for key in lower:           
         if key in p_bounds:
             try:
                 lower[key] = min(p_bounds[key])
             except:
                 lower[key] = p_bounds[key]
             try:
                 upper[key] = max(p_bounds[key])
             except:
                 upper[key] = p_bounds[key]
         else:
             lower[key]=1e-20
             upper[key]=1e20
         if lower[key] != upper[key]:
             keys.append(key)
             free_variables.append(lower.keys().index(key))
     vertices_data=DSCaseVerticesForNDSlice(self._swigwrapper, 
                                            lower._swigwrapper,
                                            upper._swigwrapper)
     vertices_raw = DSMatrixArrayMatrix(vertices_data, 0)
     vertices=[]
     for v in vertices_raw:
         vertices.append([v[i] for i in xrange(len(v)) if i in free_variables])
     connectivity = DSMatrixArrayMatrix(vertices_data, 1)
     return keys, vertices, connectivity
 def bounding_box(self, p_bounds=None, log_out=False):
     lower = VariablePool(names=self.independent_variables)
     upper = VariablePool(names=self.independent_variables)
     boundkeys = lower.keys()
     for key in lower:
         lower[key] = 1e-20
         upper[key] = 1e20
     if p_bounds is not None:
         for key,value in p_bounds.iteritems():
             if key not in lower:
                 continue;
             try:
                 min_value,max_value = value
             except TypeError:
                 min_value = value
                 max_value = value
                 boundkeys.remove(key)
             if min_value > max_value:
                 raise ValueError, 'Min cannot be larger than max'
             lower[key] = min_value
             upper[key] = max_value
     box = {}
     for key in boundkeys:
         box[key] = DSCaseBoundingRangeForVariableWithConstraints(self._swigwrapper,
                                                                  key,
                                                                  lower._swigwrapper,
                                                                  upper._swigwrapper)
         if log_out is False:
             box[key] = [10**i[0] for i in box[key]]
         else:
             box[key] = [i[0] for i in box[key]]
     return box
 def steady_state_flux(self, parameter_values, log_out=False):
     Xd = VariablePool()
     Xd.set_swigwrapper(DSSSystemXd(self._swigwrapper))
     flux = DSSSystemSteadyStateFlux(self._swigwrapper, parameter_values._swigwrapper)
     var_names = Xd.keys()
     if log_out is False:
         steady_states = {("V_" + var_names[i]): 10 ** flux[i][0] for i in xrange(len(var_names))}
     else:
         steady_states = {("V_" + var_names[i]): flux[i][0] for i in xrange(len(var_names))}
     Xd.set_swigwrapper(None)
     return steady_states
 def steady_state(self, parameter_values, log_out=False):
     if DSSSystemHasSolution(self._swigwrapper) is False:
         return None
     Xd = VariablePool()
     Xd.set_swigwrapper(DSSSystemXd(self._swigwrapper))
     steady_states = DSSSystemSteadyStateValues(self._swigwrapper, parameter_values._swigwrapper)
     var_names = Xd.keys()
     if log_out is False:
         steady_states = {var_names[i]: 10 ** steady_states[i][0] for i in xrange(len(var_names))}
     else:
         steady_states = {var_names[i]: steady_states[i][0] for i in xrange(len(var_names))}
     Xd.set_swigwrapper(None)
     return steady_states
Пример #6
0
 def update_latex_symbols(self, symbols):
     self._latex.update(symbols)
     equation_list = list()
     for i in xrange(0, DSGMASystemNumberOfEquations(self._swigwrapper)):
         expr = DSExpressionAtIndexOfExpressionArray(eqs, i)
         equation_list.append(DSExpressionAsString(expr))
         DSExpressionFree(expr)
     DSSecureFree(eqs)
     Xda = VariablePool()
     Xda.set_swigwrapper(DSVariablePoolCopy(DSGMASystemXd_a(gma)))
     equations = Equations(equation_list, 
                           auxiliary_variables=Xda.keys(),
                           latex_symbols=self._latex)
     self._equations = equations
 def steady_state_flux(self, parameter_values, log_out=False):
     steady_states = self.steady_state(parameter_values)
     Xd = VariablePool(names=self.dependent_variables)
     fluxes = dict()
     case_swigwrapper = DSCyclicalCaseOriginalCase(self._swigwrapper)
     for i in steady_states:
         Xd.update(steady_states[i])
         flux = DSSSystemSteadyStateFluxForDependentVariables(DSCaseSSystem(case_swigwrapper),
                                                                            Xd._swigwrapper,
                                                                            parameter_values._swigwrapper)
         var_names = Xd.keys()
         if log_out is False:
             flux = {('V_' + var_names[j]):10**flux[j][0] for j in xrange(len(var_names))}
         else:
             flux = {('V_' + var_names[j]):flux[j][0] for j in xrange(len(var_names))}
         fluxes[i] = flux
     return fluxes
 def steady_state(self, parameter_values, log_out=False):
     Xd = VariablePool(names=self.dependent_variables)
     p_vals = VariablePool(names=self.independent_variables)
     for i in p_vals:
         p_vals[i] = parameter_values[i]
     cases = self.valid_subcases(p_bounds=p_vals)
     steady_states = dict()
     for i in cases:
         case = self(i)
         ssys = case.ssystem
         ss = DSSSystemSteadyStateValues(ssys._swigwrapper, parameter_values._swigwrapper)
         var_names = Xd.keys()
         if log_out is False:
             steady_states[str(i)] = {var_names[j]:10**ss[j][0] for j in xrange(len(var_names))}
         else:
             steady_states[str(i)] = {var_names[j]:ss[j][0] for j in xrange(len(var_names))}
     return steady_states
Пример #9
0
 def _parse_equations(self, **kwargs):
     auxiliary_variables = self.auxiliary_variables
     swigwrapper = DSSWIGGMASystemParseWrapper(self.equations.system,
                                               len(self.equations),
                                               auxiliary_variables,
                                               len(auxiliary_variables)
                                               )
     self.set_swigwrapper(swigwrapper)
     eqs = DSGMASystemEquations(self._swigwrapper)
     equation_list = list()
     for i in xrange(0, DSGMASystemNumberOfEquations(self._swigwrapper)):
         expr = DSExpressionAtIndexOfExpressionArray(eqs, i)
         equation_list.append(DSExpressionAsString(expr))
         DSExpressionFree(expr)
     DSSecureFree(eqs)
     Xda = VariablePool()
     Xda.set_swigwrapper(DSVariablePoolCopy(DSGMASystemXd_a(gma)))
     equations = Equations(equation_list, 
                           auxiliary_variables=Xda.keys(), 
                           latex_symbols=self._latex)
     self._equations = equations
 def variables(self):
     vp = DSExpressionVariablesInExpression(self._swigwrapper)
     pv = VariablePool()
     pv.set_swigwrapper(vp)
     return pv.keys()