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

1. Member
Join Date
Oct 2016
Posts
8
Rep Power
0

## 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. ## 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.

3. Member
Join Date
Oct 2016
Posts
8
Rep Power
0

## 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. ## 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.

#### Posting Permissions

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