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

    Default I set the bound correctly but "Exception...ArrayIndexOutOfBoundsException"

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


    Error for the last line
    "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 12
    at TestCase.main(TestCase.java:36)"

    but I dont think my i, t ,t1 range is not logical.

    Is it because for model.addVar(0, 1, h[t1]*D[i], GRB.BINARY), where h[t1]*D[i] is improper?

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

    Default Re: I set the bound correctly but "Exception...ArrayIndexOutOfBoundsException"

    "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 12
    Which array has less than 12 elements?
    Which index has the value of 12? Add a print statement to print out the index values so you can see which one is wrong.
    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: I set the bound correctly but "Exception...ArrayIndexOutOfBoundsException"

    K=0,1....10
    T=0,1....11,
    those lines are for one constraint, after blocking them, i can run java and print out and got the same thing as my input one.

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

    Default Re: I set the bound correctly but "Exception...ArrayIndexOutOfBoundsException"

    Have you solved your problem now?
    If not you need to answer the questions I asked in post#2

    Java Code:
      y[i][t] = model.addVar(0, 1, h[t1]*D[i], GRB.BINARY, "Stock:"+i+t1);
    What are the sizes of all the arrays in that statement?
    What are the values of all the indexes used in that statement?
    Last edited by Norm; 10-29-2016 at 09:48 PM.
    If you don't understand my response, don't ignore it, ask a question.

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

    Default Re: I set the bound correctly but "Exception...ArrayIndexOutOfBoundsException"

    Hi,
    Soory that I dont understand your question.
    But can I ask you another one?
    Those are for one part of the objective function (not the constraint)
    Do you know how to just get the obj value for this part, rather than get the total obj value?

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

    Default Re: I set the bound correctly but "Exception...ArrayIndexOutOfBoundsException"

    I'll show you what I am asking
    What are the sizes of all the arrays in that statement?
    int[] array1 = new int[4]; // this array's size is 4
    String array2 = new String[22]; // this array's size is 22
    What are the values of all the indexes used in that statement?
    int aVal = array1[3]; // the value of the index is 3
    int anIdx = 11;
    String var2 = array2[anIdx]; // the value of the index is 11

    can I ask you another one?
    how to just get the obj value
    What field in the object has the value you want to get? Can you write a getter method ti return the value?
    If you don't understand my response, don't ignore it, ask a question.

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

    Default Re: I set the bound correctly but "Exception...ArrayIndexOutOfBoundsException"

    Hey.
    OH i see:)
    Those array sizes are not big, and Im sure Id it correctly.
    Believe it or not, I adjusted this and that and that error is gone...
    And another thing is about my obj value problem as I asked you.
    I have 2 parts obj function, both of them have the same variable y[i][t] . part A just have k and t indexes, part 2 has k, t and t1 indexes. BOth od them should be positive
    When I bolck part 2, I even got a lower obj value than the one with 2 parts obj functions.
    So I wanted to get the value of those 2 parts' value rather than the total obj value.
    Do you think it's possible that I use y[i][t] = model.addVar(0, 1,4, GRB.BINARY...) in part 1, but y[i][t] = model.addVar(0, 1, 3, GRB.BINARY...) in part 2, and then it got updated always by the latest one?

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

    Default Re: I set the bound correctly but "Exception...ArrayIndexOutOfBoundsException"

    and the coef 4 and 3 are made up to make my question short.
    they are presented by [t, k] and [t1, k] seperately

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

    Default Re: I set the bound correctly but "Exception...ArrayIndexOutOfBoundsException"

    that error is gone.
    Glad you fixed the problem.

    The new questions make no sense without the complete code and the output that shows the problem.

    Note: It is very hard to work with code that uses single letter variable names. I wouldn't even try myself.
    Last edited by Norm; 10-29-2016 at 11:27 PM.
    If you don't understand my response, don't ignore it, ask a question.

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

    Default Re: I set the bound correctly but "Exception...ArrayIndexOutOfBoundsException"

    Thanks for your reply:)
    Im pretty new for Java and sorry that didnt answer your reply precisly.
    Will post my question above again and hope to get some help:)

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

    Default Re: I set the bound correctly but "Exception...ArrayIndexOutOfBoundsException"

    Will post my question above again
    Make sure to give the variables names that describe the data that they contain. Single letters for names makes the code very hard to read and understand.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: 06-25-2013, 02:04 PM
  2. Replies: 11
    Last Post: 10-31-2012, 09:51 AM
  3. Replies: 1
    Last Post: 11-20-2009, 07:58 PM
  4. Replies: 2
    Last Post: 08-07-2009, 10:21 PM
  5. Replies: 1
    Last Post: 07-25-2007, 10:55 PM

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
  •