Example #1
0
def ler_resultado():

    from gams import GamsWorkspace

    ws = GamsWorkspace(working_directory="./files")

    # add a new GamsDatabase and initialize it from the GDX file just created
    db2 = ws.add_database_from_gdx("out.gdx")

    x = dict((tuple(rec.keys), rec.level) for rec in db2["x"])

    alocacao = []
    for r in x:
        if x[r] == 1:
            alocacao.append(r)

    lotacao = Lotacao.objects.filter(turma__in=turmas)
    resultado = []
    for a in alocacao:
        for l in lotacao:
            # if int(a[0]) == l.disciplina.pk:
            # a[0] -> disciplina
            # a[1] -> semana
            # a[2] -> turno
            # a[3] -> horario
            # a[4] -> dia da semana
            if a[0] == l.disciplina.nome:
                resultado.append([l, a[1], a[4], a[2], a[3]])

    return resultado;
Example #2
0
import os
import sys
from timeit import default_timer as timer
from gams import GamsWorkspace
from gams.database import GamsDatabase
from gams import GamsVariable

# Read execution parameters
args = sys.argv
assert len(args) > 2, "GAMS path and input path must be specified."
ws = GamsWorkspace(system_directory=args[1])
input_path: str = os.path.abspath(args[2])
assert input_path[-4:] == ".gdx", f"{input_path} is not a .gdx file."
dir_path: str = os.path.split(input_path)[0]

db: GamsDatabase = ws.add_database_from_gdx(input_path)
output: GamsDatabase = ws.add_database()

# Find the dummy variables by searching for symbols starting with 'exo_' or 'endo_'
exo_dummies = [symbol for symbol in db if symbol.name[:4] == "exo_"]
endo_dummies = [symbol for symbol in db if symbol.name[:5] == "endo_"]

endo_exo_strings = []

for dummy in exo_dummies:
    var_name = dummy.name[4:]
    if len(db.get_symbol(var_name)) > 1:
        endo_exo_strings += [
            f"{var_name}.fx{rec.keys} = {var_name}.l{rec.keys};"
            for rec in dummy
        ]