How to use the gekko.properties.variable_options 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_post_solve.py View on Github external
if o in data[vp.name]: #single value
                        vp.__dict__[o] = data[vp.name][o]
                    else:
                        try: #fill in an array up to 10 values
                            dpred = []
                            for i in range(1,11):
                                pred.append(data[vp.name][o+'['+str(i)+']'])
                        except:
                            pass
                        finally:
                            vp.__dict__[o] = dpred
                else: #everything besides value, dpred and pred
                    vp.__dict__[o] = data[vp.name][o]
    for vp in self._variables:
        if vp.type != None: #(FV/MV/SV/CV) not Param or Var
            for o in variable_options[vp.type]['outputs']+variable_options[vp.type]['inout']:

                if o == 'VALUE':
                    continue
                elif o == 'PRED': #Pred can be an array of up to 10
                    if o in data[vp.name]: #single value
                        vp.__dict__[o] = data[vp.name][o]
                    else:
                        try: #fill in an array up to 10 values
                            pred = []
                            for i in range(11):
                                pred.append(data[vp.name][o+'['+str(i)+']'])
                        except:
                            pass
                        finally:
                            vp.__dict__[o] = pred
                else: #everything besides value and pred
github BYU-PRISM / GEKKO / gekko / gk_debug.py View on Github external
for o in self.options._input_option_list: #for each global input option
        if o == 'CSV_READ' and self.csv_status == 'none':
            continue
        if self.options.__dict__[o] != data['APM'][o]: #compare APM to GK
            print(str(o)+" was not written correctly") #give message if they don't match
    ## Local Options
    for vp in self._parameters:
        if vp.type != None: #(FV/MV/SV/CV) not Param or Var
            for o in parameter_options[vp.type]['inputs']:
                if o not in ['LB','UB']: #TODO: for o in data[vp.name] to avoid this check
                    if vp.__dict__[o] is not None and not self.like(vp.__dict__[o], data[vp.name][o]):
                        print(str(vp)+'.'+str(o)+" was not written correctly") #give message if they don't match

    for vp in self._variables:
        if vp.type != None: #(FV/MV/SV/CV) not Param or Var
            for o in variable_options[vp.type]['inputs']:
                if o not in ['LB','UB']:
                    if vp.__dict__[o] is not None and not self.like(vp.__dict__[o], data[vp.name][o]):
                        print(str(vp)+'.'+str(o)+" was not written correctly") #give message if they don't match
github BYU-PRISM / GEKKO / gekko / gk_write_files.py View on Github external
#print all global options
    file_content = self.options.getOverridesString()
    #cycle through all Params and Vars to find set options
    with open(os.path.join(self._path,filename), 'w+') as f:
        f.write(file_content)
        #check for set options of each Var and Param
        for vp in self._parameters:
            for o in parameter_options[vp.type]['inputs']+parameter_options[vp.type]['inout']:
                if o == 'VALUE':
                    continue
                else: #everything else is an option
                    if vp.__dict__[o] is not None:
                        f.write(vp.name+'.'+o+' = '+str(vp.__dict__[o])+'\n')

        for vp in self._variables:
            for o in variable_options[vp.type]['inputs']+variable_options[vp.type]['inout']:
                if o == 'VALUE':
                    continue
                else: #everything else is an option
                    if vp.__dict__[o] is not None:
                        f.write(vp.name+'.'+o+' = '+str(vp.__dict__[o])+'\n')
github BYU-PRISM / GEKKO / gekko / gk_variable.py View on Github external
def __setattr__(self, name, value):
        if self._initialized:
            #ignore cases on global options
            name = name.upper()

            #only allow user to set input or input/output options:
            if name in options[self.type]['inputs']+options[self.type]['inout']:
                if name == 'VALUE':
                    # Extract input array from pandas series if needed
                    if type(value).__name__ == 'Series':
                        value = value.values
                    self.__dict__[name].value = value
                else:
                    self.__dict__[name] = value
                    
                        
            #don't allow writing to output properties by default
            elif name in options[self.type]['outputs']:
                #define outputs by passing list/tuple with 1st element being True
                #to override the output writing prevention 
                try:
                    if value[0] == True:
                        self.__dict__[name] = value[1]