How to use the gekko.gk_parameter.GKParameter function in gekko

To help you get started, we’ve selected a few gekko examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BYU-PRISM / GEKKO / gekko / View on Github external
def Param(self, value=None, name=None):
        """GK parameters can become MVs and FVs. Since GEKKO defines
        MVs and FVs directly, there's not much use for parameters. Parameters
        are effectively constants unless the resulting .spm model is used later
        and the parameters can be set as MVs or FVs. """
        if name is not None:
            name = re.sub(r'\W+', '_', name).lower()
            name = 'p' + str(len(self._parameters) + 1)

        parameter = GKParameter(name, value)
        return parameter
github BYU-PRISM / GEKKO / gekko / View on Github external
becomes an alias for the first.
        var1 = Variable 1 name
        var2 = Variable 2 name (default=None)
        pos1 = Step position in the collocation horizon for var1 (default=None)
        pos2 = Step position in the collocation horizon for var2 (default=None)
        node1 = Node within the pos1 step (default='end')
        node2 = Node within the pos2 step (default='end')        
        # TODO: add checks for types
            #e.g. if connecting a variable position (pos1 not None) to another variable,
            #     it must be an FV
        # make string versions of var1 and var2
        if pos1 is not None:
            #make sure var1 is a GEKKO param or var
            if isinstance(var1,(GKVariable,GKParameter)):
                var1_str = 'p(' + str(pos1) + ').n(' + str(node1) + ').' +
                raise TypeError('Variable 1 must be GEKKO Param or Var to use position')
            if var1 is not None:
                var1_str = str(var1)
                raise Exception('Error: var1 must not be None')

        if pos2 is not None:
            # make sure var1 is a GEKKO param or var
            if isinstance(var2,(GKVariable,GKParameter)):
                var2_str = 'p(' + str(pos2) + ').n(' + str(node2) + ').' +
            elif (var2=='fixed'):
                var2 = 'fixed'
            elif (var2=='calculated'):
github BYU-PRISM / GEKKO / gekko / View on Github external
raise TypeError
                except TypeError:
                    raise AttributeError(str(name)+" is an output property")

            #no other properties allowed
                raise AttributeError(str(name)+" is not a property of this variable")

        #for initializing model
            self.__dict__[name] = value
class GK_FV(GKParameter):
    """Fixed Variable. Inherits GKParameter."""

    def __init__(self, name='', value=0, lb=None, ub=None, gk_model=None, model_path=None, integer=False):

        # prevents the __setattr__ function from sending options to the server
        # until the __init__ function has completed since they should only be
        # sent if changed from their defaults
        self.__dict__['_initialized'] = False

        if not hasattr(self,'type'): #don't overwrite MV
            self.type = 'FV'
        self.model_name = gk_model
        #self.path = os.path.join(os.path.dirname(os.path.realpath(__file__)), self.model_name) OLD from when model file were in the same directory; now using temp files
        self.path = model_path #use the same path as the model 
        # FV options
github BYU-PRISM / GEKKO / gekko / View on Github external
                if main_dict[var].name + '.tr' in self.results:
                    d = var_dict.copy()
                    d['name'] = var + '(Tr)'
                if main_dict[var].name + '.bcv' in self.results:
                    d1 = var_dict.copy()
                    d1['name'] = var + '_hist(bias)'
                    d2 = var_dict.copy()
                    d2['name'] = var + '_hist(nobias)'
                    d3 = var_dict.copy()
                    d3['name'] = var + '(nobias)'
            elif isinstance(main_dict[var], GKParameter):
                if isinstance(main_dict[var], (GK_MV, GK_FV)):
                    d = var_dict.copy()
                    d['name'] = var + '_hist'
            elif isinstance(main_dict[var], GK_Intermediate):

        # Update the variable if the data has been loaded before
        data = False
        if isinstance(main_dict[var], GKVariable):
        elif isinstance(main_dict[var], GKParameter):
github BYU-PRISM / GEKKO / gekko / View on Github external
self.LOWER = None
        self.LSTVAL = None
        self.MEAS = None
        self.NEWVAL = None
        self.PSTATUS = None
        self.STATUS = None
        if ub is not None:
            self.UPPER = ub
            self.UPPER = None
        self.VDVL = None
        self.VLACTION = None
        self.VLHI = None
        self.VLLO = None
        GKParameter.__init__(self, name=name, value=value, integer=integer)