Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duals from CBC #214

Open
glebbelov opened this issue Jun 20, 2023 · 0 comments
Open

Duals from CBC #214

glebbelov opened this issue Jun 20, 2023 · 0 comments
Assignees
Labels

Comments

@glebbelov
Copy link
Contributor

Cbc installable via coin does not return duals. Check this model:

%%ampl_eval

set CHIPS;

param profits{CHIPS};
param copper{CHIPS};

var x{CHIPS} >= 0;

maximize Profit: sum {c in CHIPS} profits[c] * x[c];

s.t. Silicon: x['logic'] <= 1000;
s.t. Germanium: x['memory'] <= 1500;
s.t. Plastic: sum {c in CHIPS} x[c] <= 1750;
s.t. Copper: sum {c in CHIPS} copper[c] * x[c] <= 4800;
chips = ["logic", "memory"]
profits = {"logic": 12, "memory": 9}
copper = {"logic": 4, "memory": 2}

ampl.set['CHIPS'] = chips
ampl.param['profits'] = profits
ampl.param['copper'] = copper

ampl.option["solver"] = "cbc"
ampl.solve()

x = ampl.get_variable('x').get_values().to_list()

print(f'x = ({x})')
print(f'optimal value = {ampl.obj["Profit"].value():.2f}')
def ShowDuals(ampl):
    import fractions
    
    # display all duals
    print("The dual variable corresponding to:\n")
    for c in ampl.get_constraints():
        print("- the constraint on", c[0],
              "is equal to ",
              str(c[1].dual()))
              #str(fractions.Fraction(c[1].get_value())), end="")

ShowDuals(ampl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants