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

PuLP not working #603

Closed
Dana-ggq opened this issue Apr 19, 2022 · 4 comments
Closed

PuLP not working #603

Dana-ggq opened this issue Apr 19, 2022 · 4 comments
Labels

Comments

@Dana-ggq
Copy link

Hi!
I'm new to Android and I'd like to build a small app that uses an optimization python algorithm written with PuLP. I've been trying to make it work for weeks with no result. It seems that there is a problem with the PuLP solver not working in chaquopy. My question is whether PuLP can be used in chaquopy ?

This is one of the errors I'm getting. But there are many more sice I tried a lot of different things to make it work.

'/data/data/com.example.myapplication/files/chaquopy/AssetFinder/requirements/pulp/apis/../solverdir/cbc/linux/64/cbc'

Thank you for your answer.

@mhsmith
Copy link
Member

mhsmith commented Apr 19, 2022

Please post the full stack trace, and the relevant sections of your code.

@Dana-ggq
Copy link
Author

Dana-ggq commented Apr 19, 2022

This is the stack trace

    Process: com.example.myapplication, PID: 11095
    com.chaquo.python.PyException: PermissionError: [Errno 13] Permission denied: '/data/data/com.example.myapplication/files/chaquopy/AssetFinder/requirements/pulp/apis/../solverdir/cbc/linux/64/cbc'
        at <python>.subprocess._execute_child(subprocess.py:1704)
        at <python>.subprocess.__init__(subprocess.py:858)
        at <python>.pulp.apis.coin_api.solve_CBC(coin_api.py:194)
        at <python>.pulp.apis.coin_api.actualSolve(coin_api.py:137)
        at <python>.pulp.pulp.solve(pulp.py:1913)
        at <python>.myscript.main(myscript.py:52)
        at <python>.chaquopy_java.call(chaquopy_java.pyx:380)
        at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrowsNative(chaquopy_java.pyx:352)
        at com.chaquo.python.PyObject.callAttrThrowsNative(Native Method)
        at com.chaquo.python.PyObject.callAttrThrows(PyObject.java:232)
        at com.chaquo.python.PyObject.callAttr(PyObject.java:221)
        at com.example.myapplication.MainActivity$1.onClick(MainActivity.java:62)
        at android.view.View.performClick(View.java:7441)
        at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1131)
        at android.view.View.performClickInternal(View.java:7418)
        at android.view.View.access$3700(View.java:835)
        at android.view.View$PerformClick.run(View.java:28676)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7842)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

Here is my code

    prob = pulp.LpProblem('MostEfficientConfiguration', LpMinimize)
    data['appliances_category'] = data['id'].astype(str) + data['category']
    appliances_category = list(data['appliances_category'])

    prices = dict(zip(appliances_category, data['price']))
    consumption = dict(zip(appliances_category, data['consumption']))

    appliances_var = LpVariable.dicts("appliance", appliances_category,0,1,cat='Integer')

    prob += lpSum([appliances_var[a] * consumption[a] for a in appliances_category])
    prob += lpSum([appliances_var[a] * prices[a] for a in appliances_category]) <= buget

    for c in unique_categories:
        lista = [item for item in appliances_category if item[-len(c):] == c]
        total = ""
        for index in lista:
            formula = 1*appliances_var[index]
            total += formula
        prob += (total == 1)

    solver_list = listSolvers(onlyAvailable=True)

    prob.solve()


    result = LpStatus[prob.status]
    if LpStatus[prob.status] == "Optimal":
        for v in prob.variables():
            if v.varValue>0:
                id = re.sub('[^0-9]', '', v.name)
                result += " " + id
    return result`

The line where it crashes is this one :
prob.solve()

I also tried a bunch of things from here https://coin-or.github.io/pulp/guides/how_to_configure_solvers.html , like giving the path to the solver and Configuring where the CMD solvers write their temporary files, but nothing seems to work.

@mhsmith
Copy link
Member

mhsmith commented Apr 20, 2022

Unfortunately it looks like this feature requires an external executable (#605), so we won't be able to support it at the moment. Sorry about that.

If anyone else wants this package too, please click the thumbs-up button above.

@mhsmith
Copy link
Member

mhsmith commented Jun 24, 2023

It's been over a year and only one person has requested this package, so we won't be building it in the foreseeable future.

However, the package build tool is now open-source, so if you'd like to try building this package yourself, follow the instructions here. And if you're successful, please make a pull request so we can add it to the public repository.

If anyone else wants this package, please click the thumbs-up button above and post a comment, and I'll reopen the issue.

@mhsmith mhsmith closed this as not planned Won't fix, can't repro, duplicate, stale Jun 24, 2023
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