Results 1 to 4 of 4
  1. #1
    tingtingzeng is offline Member
    Join Date
    Oct 2016
    Posts
    8
    Rep Power
    0

    Default obj function has 2 parts, both use the same variable but have different indexes

    Hi.
    I have 2 parts for the obj function, both of them have the same variable y[i][t] .
    part A just have k and t indexes, meaning SUMk SUMt D[i,t] * y[i][t],
    part 2 has k, t and t1 indexes, meaning SUMk SUMt SUMt1 D[i,t1] *y[i][t]. (t1 is in part range of t)
    Both od them should not be negative.
    When I bolck part 2, I even got a higher obj value than the one with 2 parts obj functions.

    Do you think it's possible that I use y[i][t] = model.addVar(0, 1, D[i,t], GRB.BINARY...) in part 1, but y[i][t] = model.addVar(0, 1, D[i,t1], GRB.BINARY...) in part 2, and then java ges confused y[i][t] ?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: obj function has 2 parts, both use the same variable but have different indexes

    Please post some code that shows the problem. Be sure to wrap the code in code tags.

    Note: java has methods not functions.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    tingtingzeng is offline Member
    Join Date
    Oct 2016
    Posts
    8
    Rep Power
    0

    Default Re: obj function has 2 parts, both use the same variable but have different indexes

    HI.
    Im talking objective function from my model.

    // Define variables for objective function
    //1
    GRBVar[][] y = new GRBVar[K][T];
    for (int k = 0; k < K; k++){
    for(int t = 0; t < T; t++){
    y[k][t] = model.addVar(0, 1, p[t]*D[k], GRB.BINARY, "Produce:"+k+t);
    }
    }

    //2
    for (int k = 0; k < K; k++){
    for(int t = 0; t < T; t++){
    for(int t1 = t; t1 < e[k]; t1++){
    y[k][t] = model.addVar(0, 1, h[t1]*D[k], GRB.BINARY, "Stock:"+k+t1);
    }
    }
    }

    codes above is what Im taling about, basically I want to get the optimised value by suming these 2 parts up.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: obj function has 2 parts, both use the same variable but have different indexes

    Please post a small, complete program that will compile and execute for testing.
    Be sure to wrap the code in code tags.

    Also change the variable names to something that has some meaning and describes what the variable contains.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 7
    Last Post: 10-19-2012, 09:53 AM
  2. Replies: 5
    Last Post: 09-17-2012, 06:47 AM
  3. change variable given as argument to function
    By Danieljabailey in forum New To Java
    Replies: 4
    Last Post: 07-27-2011, 11:48 PM
  4. Setting a variable in JSTL for use in a JSP function
    By MikeStringfellow in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-19-2009, 04:48 PM
  5. Function in a variable
    By beserie in forum New To Java
    Replies: 4
    Last Post: 01-07-2008, 03:12 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •