How to use the gekko.gk_variable.GK_CV 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 / gk_gui.py View on Github external
def get_variable_fron_main(self, variable):
        """Special handling for GK_Variables"""
        main_dict = vars(main)
            
        ## Store historical data
        timestep = self.results['time'][1] - self.results['time'][0]
        
        if isinstance(main_dict[variable], (GK_CV, GK_SV)):
            if main_dict[variable].name + '.bcv' in self.results:
                #biased history
                var_hist_bias = list(filter(
                    lambda d: d['name'] == variable + '_hist(bias)', self.gekko_data['vars']['variables']))[0]
                var_hist_bias['data'] = var_hist_bias['data'] + [self.results[main_dict[variable].name + '.bcv'][0]] #store data value
                var_hist_bias['x'] = [var_hist_bias['x'][0] - timestep] + var_hist_bias['x']    #update time array
                #unbiased history
                var_hist_nobias = list(filter(
                    lambda d: d['name'] == variable + '_hist(nobias)', self.gekko_data['vars']['variables']))[0]
                var_hist_nobias['data'] = var_hist_nobias['data'] + [self.results[main_dict[variable].name][0]] #store data value
                var_hist_nobias['x'] = [var_hist_nobias['x'][0] - timestep] + var_hist_nobias['x']    #update time array
            
        
        ## Plot prediction from current solve
        var = list(filter(lambda d: d['name'] == variable, self.gekko_data['vars']['variables']))[0]
        try:
github BYU-PRISM / GEKKO / gekko / gekko.py View on Github external
def CV(self, value=None, lb=None, ub=None, integer=False, fixed_initial=True, name=None):
        """A variable with a setpoint. Reaching the setpoint is added to the
        objective."""
        if name is not None:
            name = re.sub(r'\W+', '_', name).lower()
        else:
            name = 'v' + str(len(self._variables) + 1)
        if integer == True:
            name = 'int_'+name

        variable = GK_CV(name=name, value=value, lb=lb, ub=ub, gk_model=self._model_name, model_path=self._path, integer=integer)
        self._variables.append(variable)
        if fixed_initial is False:
            self.Connection(variable,'calculated',pos1=1,node1=1)
        return variable