how to declare a non linear objective function in pyomo? and efficient way of declaring constraints?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am trying to declare a non linear objective constraint in Pyomo and everytime I try to solve it using Bonmin Solver, I get the following error:



ERROR: Solver (asl) returned non-zero return code (3221225477)
ERROR: Solver log: Bonmin 1.8.6 using Cbc 2.9.9 and Ipopt 3.12.8 bonmin:
Traceback (most recent call last):



File "", line 2, in
results = opt.solve(model)



File "C:Anacondalibsite-packagespyomooptbasesolvers.py", line 626, in solve
"Solver (%s) did not exit normally" % self.name)



ApplicationError: Solver (asl) did not exit normally



#

My Objective function definition is:



`def obj_func(model):
global summer
summer = 0
global volumer
volumer = 0
for i in range(0,len(data)):
summer += model.x[i]*data.loc[i,'Predicted.Profit']
for j in range(0,len(data)):
volumer += model.x[j]*data.loc[j,'Predicted.Liters.Sold']
return summer/volumer`


I am invoking the solver through SolverFactory,
Lastly I would also like to know the most efficient way of creating constraints as i have constraints of the range 100+ and some of them are non linear. When i try to solve the problem using this model, my memory usage spikes to 100% and my computer hangs.










share|improve this question























  • Look for the logs. They are written to some place. But it sounds just like a memory error and then it's hard to recommend someting different than solving a smaller model or buy ram. It looks like a ML task where general nlp solvers often do not scale.

    – sascha
    Nov 23 '18 at 19:01













  • What do you mean by "It looks like a ML task where general nlp solvers often do not scale"?

    – linearprogrammer
    Nov 23 '18 at 19:06











  • Are you doing machine learning with big data? Then dont expect to be able to use general nonlinear opt

    – sascha
    Nov 23 '18 at 19:12











  • No, I have dataset with size (178848,40). I am able to run CBC very easily but it is failing with BONMIN or COUENNE

    – linearprogrammer
    Nov 23 '18 at 19:19











  • That's pretty big and you should not compare linear opt with nonlinear opt.

    – sascha
    Nov 23 '18 at 19:34


















0















I am trying to declare a non linear objective constraint in Pyomo and everytime I try to solve it using Bonmin Solver, I get the following error:



ERROR: Solver (asl) returned non-zero return code (3221225477)
ERROR: Solver log: Bonmin 1.8.6 using Cbc 2.9.9 and Ipopt 3.12.8 bonmin:
Traceback (most recent call last):



File "", line 2, in
results = opt.solve(model)



File "C:Anacondalibsite-packagespyomooptbasesolvers.py", line 626, in solve
"Solver (%s) did not exit normally" % self.name)



ApplicationError: Solver (asl) did not exit normally



#

My Objective function definition is:



`def obj_func(model):
global summer
summer = 0
global volumer
volumer = 0
for i in range(0,len(data)):
summer += model.x[i]*data.loc[i,'Predicted.Profit']
for j in range(0,len(data)):
volumer += model.x[j]*data.loc[j,'Predicted.Liters.Sold']
return summer/volumer`


I am invoking the solver through SolverFactory,
Lastly I would also like to know the most efficient way of creating constraints as i have constraints of the range 100+ and some of them are non linear. When i try to solve the problem using this model, my memory usage spikes to 100% and my computer hangs.










share|improve this question























  • Look for the logs. They are written to some place. But it sounds just like a memory error and then it's hard to recommend someting different than solving a smaller model or buy ram. It looks like a ML task where general nlp solvers often do not scale.

    – sascha
    Nov 23 '18 at 19:01













  • What do you mean by "It looks like a ML task where general nlp solvers often do not scale"?

    – linearprogrammer
    Nov 23 '18 at 19:06











  • Are you doing machine learning with big data? Then dont expect to be able to use general nonlinear opt

    – sascha
    Nov 23 '18 at 19:12











  • No, I have dataset with size (178848,40). I am able to run CBC very easily but it is failing with BONMIN or COUENNE

    – linearprogrammer
    Nov 23 '18 at 19:19











  • That's pretty big and you should not compare linear opt with nonlinear opt.

    – sascha
    Nov 23 '18 at 19:34














0












0








0








I am trying to declare a non linear objective constraint in Pyomo and everytime I try to solve it using Bonmin Solver, I get the following error:



ERROR: Solver (asl) returned non-zero return code (3221225477)
ERROR: Solver log: Bonmin 1.8.6 using Cbc 2.9.9 and Ipopt 3.12.8 bonmin:
Traceback (most recent call last):



File "", line 2, in
results = opt.solve(model)



File "C:Anacondalibsite-packagespyomooptbasesolvers.py", line 626, in solve
"Solver (%s) did not exit normally" % self.name)



ApplicationError: Solver (asl) did not exit normally



#

My Objective function definition is:



`def obj_func(model):
global summer
summer = 0
global volumer
volumer = 0
for i in range(0,len(data)):
summer += model.x[i]*data.loc[i,'Predicted.Profit']
for j in range(0,len(data)):
volumer += model.x[j]*data.loc[j,'Predicted.Liters.Sold']
return summer/volumer`


I am invoking the solver through SolverFactory,
Lastly I would also like to know the most efficient way of creating constraints as i have constraints of the range 100+ and some of them are non linear. When i try to solve the problem using this model, my memory usage spikes to 100% and my computer hangs.










share|improve this question














I am trying to declare a non linear objective constraint in Pyomo and everytime I try to solve it using Bonmin Solver, I get the following error:



ERROR: Solver (asl) returned non-zero return code (3221225477)
ERROR: Solver log: Bonmin 1.8.6 using Cbc 2.9.9 and Ipopt 3.12.8 bonmin:
Traceback (most recent call last):



File "", line 2, in
results = opt.solve(model)



File "C:Anacondalibsite-packagespyomooptbasesolvers.py", line 626, in solve
"Solver (%s) did not exit normally" % self.name)



ApplicationError: Solver (asl) did not exit normally



#

My Objective function definition is:



`def obj_func(model):
global summer
summer = 0
global volumer
volumer = 0
for i in range(0,len(data)):
summer += model.x[i]*data.loc[i,'Predicted.Profit']
for j in range(0,len(data)):
volumer += model.x[j]*data.loc[j,'Predicted.Liters.Sold']
return summer/volumer`


I am invoking the solver through SolverFactory,
Lastly I would also like to know the most efficient way of creating constraints as i have constraints of the range 100+ and some of them are non linear. When i try to solve the problem using this model, my memory usage spikes to 100% and my computer hangs.







python constraints nonlinear-optimization pyomo






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 15:33









linearprogrammerlinearprogrammer

156




156













  • Look for the logs. They are written to some place. But it sounds just like a memory error and then it's hard to recommend someting different than solving a smaller model or buy ram. It looks like a ML task where general nlp solvers often do not scale.

    – sascha
    Nov 23 '18 at 19:01













  • What do you mean by "It looks like a ML task where general nlp solvers often do not scale"?

    – linearprogrammer
    Nov 23 '18 at 19:06











  • Are you doing machine learning with big data? Then dont expect to be able to use general nonlinear opt

    – sascha
    Nov 23 '18 at 19:12











  • No, I have dataset with size (178848,40). I am able to run CBC very easily but it is failing with BONMIN or COUENNE

    – linearprogrammer
    Nov 23 '18 at 19:19











  • That's pretty big and you should not compare linear opt with nonlinear opt.

    – sascha
    Nov 23 '18 at 19:34



















  • Look for the logs. They are written to some place. But it sounds just like a memory error and then it's hard to recommend someting different than solving a smaller model or buy ram. It looks like a ML task where general nlp solvers often do not scale.

    – sascha
    Nov 23 '18 at 19:01













  • What do you mean by "It looks like a ML task where general nlp solvers often do not scale"?

    – linearprogrammer
    Nov 23 '18 at 19:06











  • Are you doing machine learning with big data? Then dont expect to be able to use general nonlinear opt

    – sascha
    Nov 23 '18 at 19:12











  • No, I have dataset with size (178848,40). I am able to run CBC very easily but it is failing with BONMIN or COUENNE

    – linearprogrammer
    Nov 23 '18 at 19:19











  • That's pretty big and you should not compare linear opt with nonlinear opt.

    – sascha
    Nov 23 '18 at 19:34

















Look for the logs. They are written to some place. But it sounds just like a memory error and then it's hard to recommend someting different than solving a smaller model or buy ram. It looks like a ML task where general nlp solvers often do not scale.

– sascha
Nov 23 '18 at 19:01







Look for the logs. They are written to some place. But it sounds just like a memory error and then it's hard to recommend someting different than solving a smaller model or buy ram. It looks like a ML task where general nlp solvers often do not scale.

– sascha
Nov 23 '18 at 19:01















What do you mean by "It looks like a ML task where general nlp solvers often do not scale"?

– linearprogrammer
Nov 23 '18 at 19:06





What do you mean by "It looks like a ML task where general nlp solvers often do not scale"?

– linearprogrammer
Nov 23 '18 at 19:06













Are you doing machine learning with big data? Then dont expect to be able to use general nonlinear opt

– sascha
Nov 23 '18 at 19:12





Are you doing machine learning with big data? Then dont expect to be able to use general nonlinear opt

– sascha
Nov 23 '18 at 19:12













No, I have dataset with size (178848,40). I am able to run CBC very easily but it is failing with BONMIN or COUENNE

– linearprogrammer
Nov 23 '18 at 19:19





No, I have dataset with size (178848,40). I am able to run CBC very easily but it is failing with BONMIN or COUENNE

– linearprogrammer
Nov 23 '18 at 19:19













That's pretty big and you should not compare linear opt with nonlinear opt.

– sascha
Nov 23 '18 at 19:34





That's pretty big and you should not compare linear opt with nonlinear opt.

– sascha
Nov 23 '18 at 19:34












1 Answer
1






active

oldest

votes


















0














You should check the solver output to see why it's failing. You can print this output to the screen by adding the tee=True option when calling the solver:



SolverFactory('bonmin').solve(model, tee=True)


Also, when declaring Pyomo Constraints and Objectives, you should avoid using +=. It can often lead to significant performance degradation when building Pyomo expressions. Here is the recommended way to write your objective function:



def obj_func(model):
return sum(model.x[i]*data.loc[i,'Predicted.Profit'] for i in model.I)/sum(model.x[j]*data.loc[j,'Predicted.Liters.Sold'] for j in model.J)
model.Objective(rule=_obj_func)


where model.I and model.J are either Pyomo Set components or Python lists.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449399%2fhow-to-declare-a-non-linear-objective-function-in-pyomo-and-efficient-way-of-de%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You should check the solver output to see why it's failing. You can print this output to the screen by adding the tee=True option when calling the solver:



    SolverFactory('bonmin').solve(model, tee=True)


    Also, when declaring Pyomo Constraints and Objectives, you should avoid using +=. It can often lead to significant performance degradation when building Pyomo expressions. Here is the recommended way to write your objective function:



    def obj_func(model):
    return sum(model.x[i]*data.loc[i,'Predicted.Profit'] for i in model.I)/sum(model.x[j]*data.loc[j,'Predicted.Liters.Sold'] for j in model.J)
    model.Objective(rule=_obj_func)


    where model.I and model.J are either Pyomo Set components or Python lists.






    share|improve this answer




























      0














      You should check the solver output to see why it's failing. You can print this output to the screen by adding the tee=True option when calling the solver:



      SolverFactory('bonmin').solve(model, tee=True)


      Also, when declaring Pyomo Constraints and Objectives, you should avoid using +=. It can often lead to significant performance degradation when building Pyomo expressions. Here is the recommended way to write your objective function:



      def obj_func(model):
      return sum(model.x[i]*data.loc[i,'Predicted.Profit'] for i in model.I)/sum(model.x[j]*data.loc[j,'Predicted.Liters.Sold'] for j in model.J)
      model.Objective(rule=_obj_func)


      where model.I and model.J are either Pyomo Set components or Python lists.






      share|improve this answer


























        0












        0








        0







        You should check the solver output to see why it's failing. You can print this output to the screen by adding the tee=True option when calling the solver:



        SolverFactory('bonmin').solve(model, tee=True)


        Also, when declaring Pyomo Constraints and Objectives, you should avoid using +=. It can often lead to significant performance degradation when building Pyomo expressions. Here is the recommended way to write your objective function:



        def obj_func(model):
        return sum(model.x[i]*data.loc[i,'Predicted.Profit'] for i in model.I)/sum(model.x[j]*data.loc[j,'Predicted.Liters.Sold'] for j in model.J)
        model.Objective(rule=_obj_func)


        where model.I and model.J are either Pyomo Set components or Python lists.






        share|improve this answer













        You should check the solver output to see why it's failing. You can print this output to the screen by adding the tee=True option when calling the solver:



        SolverFactory('bonmin').solve(model, tee=True)


        Also, when declaring Pyomo Constraints and Objectives, you should avoid using +=. It can often lead to significant performance degradation when building Pyomo expressions. Here is the recommended way to write your objective function:



        def obj_func(model):
        return sum(model.x[i]*data.loc[i,'Predicted.Profit'] for i in model.I)/sum(model.x[j]*data.loc[j,'Predicted.Liters.Sold'] for j in model.J)
        model.Objective(rule=_obj_func)


        where model.I and model.J are either Pyomo Set components or Python lists.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 22:23









        Bethany NicholsonBethany Nicholson

        1,1061412




        1,1061412
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449399%2fhow-to-declare-a-non-linear-objective-function-in-pyomo-and-efficient-way-of-de%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini