Giter VIP home page Giter VIP logo

Comments (4)

vagmcs avatar vagmcs commented on May 31, 2024

Hello,

I think there are some things missing from the code above. For example what is the symbol Mz? Do you mean M? In the expression var w = Array.tabulate(numI)(_0.1) there is an operator missing between the placemarker _ and 0.1. There are other similar cases. Please check the code again and send me a revised version.

Thank you

from optimus.

shivang94 avatar shivang94 commented on May 31, 2024

Oh I'm sorry it got lost in Markdown styling.

Here is the correct version:

implicit val problem = LQProblem(SolverLib.ojalgo)

// Data (filled randomly)
val numI = 5
val I = 0 until numI
val numJ = 5
val J = 0 until numJ
var q = Array.tabulate(numI)(x=>(x+1) * 0.2)
var w = Array.tabulate(numI)(x=>(x+1) * 0.1)
var to = Array.tabulate(numI,numJ)((x,y)=>x+y)
var r = Array.tabulate(numI,numJ)((x,y)=>0.1 * x+0.2 * y )
var c = Array.tabulate(numI,numJ)((x,y)=>x+1+2*y)
var B = 50
var T = Array.tabulate(numJ)(x => (x+2)*3)
var M = 1000

//Variables
val x = Array.tabulate(numI,numJ)((i,j) => MPIntVar( 0 to 1))
val y = Array.tabulate(numI)(i=>MPFloatVar(s"y$i"))
val z = Array.tabulate(numI)(i=>MPIntVar(s"z$i", 0 to 1))

// Optimal Function
maximize(sum(I,J){ (i,j) => w(i)*y(i) })

// Constraints
for ( j <- J ) {
add(sum(I)(i => to(i)(j)*x(i)(j))<:=T(j))
}
for ( i <- I ) {
add(y(i) <:= q(i) + M * z(i))
add(y(i) <:= sum(J)(j => c(i)(j)*x(i)(j)) + M * (1-z(i)))
add(sum(J)(j => x(i)(j)) <:= z(i))
}
add(sum(I,J){(i,j) => c(i)(j)*x(i)(j)} <:= B)

from optimus.

vagmcs avatar vagmcs commented on May 31, 2024

Hello,

The problem is that you define an LQProblem instead of an MIProblem. LQProblem objects are intended for linear programming and use continuous variables, while MIProblem objects represent mixed-integer programming problems and can handle both continuous and integer variables. Nevertheless, maybe these two objects should be merged in order to make the API simpler, or some warning should notify the user for defining float variables in an LQProblem enviroment. I will try to fix this, but for now please just change the first line of your code into:

implicit val problem = MIProblem(SolverLib.ojalgo)

this should work. :)

from optimus.

shivang94 avatar shivang94 commented on May 31, 2024

Thanks a lot. :)

from optimus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.