Beispiel #1
0
def get_values(instance, var_, list_, units):
    '''
    get variable value from model instance
    '''
    owner = []
    x_var = getattr(instance, str(var_))
    for xx in x_var:
        value_ = x_var[xx].value
        owner = []
        try:
            if type(xx) is str:
                owner.append(xx)
            else:
                for mem in xx:
                    owner.append(mem)
            varmodel = None
            for varmodel_ in list_:
                if varmodel_.name == str(var_) and varmodel_.owner == owner:
                    varmodel = varmodel_
                    break
            if (varmodel == None):
                desc = "Imported using Pyomo apps"
                if str(var_) in units.keys():
                    unit = units[str(var_)]
                else:
                    unit = None
                varmodel = ModelVarable(str(var_), owner, desc, unit)
                list_.append(varmodel)
            varmodel.add_data(value_)
        except:
            pass
    return list_
Beispiel #2
0
def get_values(instance, var_, list_, units):
    '''
    get variable value from model instance
    '''
    owner=[]
    x_var = getattr(instance, str(var_))
    for xx in x_var:
        value_=x_var[xx].value
        owner=[]
        try:
            if type(xx) is str:
                owner.append(xx)
            else:
                for mem in xx:
                    owner.append(mem)
            varmodel=None
            for varmodel_ in list_:
                if varmodel_.name==str(var_) and varmodel_.owner==owner:
                    varmodel=varmodel_
                    break
            if(varmodel==None):
                desc="Imported using Pyomo apps"
                if str(var_) in units.keys():
                    unit=units[str(var_)]
                else:
                    unit=None
                varmodel=ModelVarable(str(var_), owner, desc, unit)
                list_.append(varmodel)
            varmodel.add_data(value_)
        except:
            pass
    return list_
Beispiel #3
0
def get_obj_value(result, obj, list_, units):
    '''
    get objectives values from the result
    '''
    #if 'Termination message' in result.Solver[0].keys():
    #if result.Solver[0]['Termination message'] is not None:
    value_ = obj.expr()

    #value_=result.solution[0].objective[1].Value
    #zvalue_=result.objective[1].Value
    varmodel = None
    for varmodel_ in list_:
        if varmodel_.name == str(obj) and varmodel_.owner == 'Network':
            varmodel = varmodel_
            break
    if (varmodel == None):
        desc = "Imported using Pyomo apps"
        if str(obj) in units.keys():
            unit = units[str(obj)]
        else:
            unit = None
        varmodel = ModelVarable(str(obj), 'Network', desc, unit)
        list_.append(varmodel)
    if (value_ is None):
        pass
    else:
        varmodel.add_data(value_)
    return list_
Beispiel #4
0
def get_obj_value(result, obj, list_, units):
    '''
    get objectives values from the result
    '''
    #if 'Termination message' in result.Solver[0].keys():
    #if result.Solver[0]['Termination message'] is not None:
    value_=obj.expr()

     #value_=result.solution[0].objective[1].Value
    #zvalue_=result.objective[1].Value
    varmodel=None
    for varmodel_ in list_:
        if varmodel_.name==str(obj) and varmodel_.owner=='Network':
            varmodel=varmodel_
            break
    if(varmodel==None):
        desc="Imported using Pyomo apps"
        if str(obj) in units.keys():
            unit=units[str(obj)]
        else:
            unit=None
        varmodel=ModelVarable(str(obj), 'Network', desc, unit)
        list_.append(varmodel)
    if(value_ is None):
        pass
    else:
        varmodel.add_data(value_)
    return list_