Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Error in ABC example #65

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

Open
kai-pischke opened this issue Jan 4, 2022 · 0 comments
Open

Error in ABC example #65

kai-pischke opened this issue Jan 4, 2022 · 0 comments

Comments

@kai-pischke
Copy link

The code in examples/abc.py has a bug. The minvalue variable is actually never updated in the loop so it returns the wrong solution. The optimal solution to the problem is actually a=1, b=9, c=9 which achieves a value of 199/19=10.47 (better than 999/27=37) .

def solve():
    problem = Problem()
    problem.addVariables("abc", range(1, 10))
    problem.getSolutions()
    minvalue = 999 / (9 * 3)
    minsolution = {}
    for solution in problem.getSolutions():
        a = solution["a"]
        b = solution["b"]
        c = solution["c"]
        value = (a * 100 + b * 10 + c) / (a + b + c)
        if value < minvalue:
            minsolution = solution
    return minvalue, minsolution

Easy fix. Just need to remember to update minvalue.

if value < minvalue:
    minvalue = value
    minsolution = solution

The test case has the wrong solution too so will need to update that as well.

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

Successfully merging a pull request may close this issue.

1 participant