Hi everybody, I don't know why the result of the f[n] variable is only 0 or 1 and not a float such us I request in the variables declaration. Are there any mistakes in the code below? Thank you

range n=0..9; float A[n]=[33.16479327, -67.47344778, -5.940004493, 29.5089636, 68.69174626, 4.840210522, 21.07559612, -7.089604808, -4.939224516, -13.38608625]; float B[n]=[-593.63, 3895.672009, 1949.281166, -27.8694549, -18.9597056, 4479.880643, 904.7304375, -4993.571365, -349.6486495, 8535.998486]; float C[n]=[2.424937409, 15.57329839, 7.160911971, 1.267162245, 6.071135478, 0.644973685, 4.615640621, 13.68181686, 11.81301007, 8.201283407]; int htotmax=35; int hmax[n]=[6, 8, 5, 6, 8, 7, 9, 10, 6, 5]; int j;

//var decisionali

dvar int+ hours[n]; dvar float+ f[n];

// ob.f

minimize sum (j in n) A[j]hours[j]+ B[j]f[j] +C[j]hours[j]f[j];

subject to {

forall (j in n) hours[j]<=hmax[j]; sum (j in n) hours[j]<=htotmax; 0<=f[0]<=1; 0<=f[1]<=1; 0<=f[2]<=1; 0<=f[3]<=1; 0<=f[4]<=1; 0<=f[5]<=1; 0<=f[6]<=1; 0<=f[7]<=1; 0<=f[8]<=1; 0<=f[9]<=1; }

asked 13 Aug '15, 03:12

maffo's gravatar image

maffo
111
accept rate: 0%


I'm not crazy about multiplying variables hours[j]f[j] (whatever you are are trying to do can likely be a linear rather than a nonlinear program) but it is not surprising the f[] values are 0 or 1. If B[j]+C[j]hours[j] < 0 then the best f[j] is 1; if B[j]+C[j]hours[j] > 0 the the best f[j] is 0. No optimal solution will want a fractional f[j].

link

answered 13 Aug '15, 06:28

Mike%20Trick's gravatar image

Mike Trick ♦♦
1.0k16
accept rate: 21%

Thank you for the reply but probably my question wasn't so clear.​ I don't know why it give me everytime in every iteration f[0]=1 and the others f[n]=0. ​ In that problem the right solution might have some 0 and some 1 and not like the situation I have described. ​Thank you to all that can help me,​Manuel​.

(24 Aug '15, 11:03) maffo
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×191
×7
×5

Asked: 13 Aug '15, 03:12

Seen: 560 times

Last updated: 24 Aug '15, 12:13

OR-Exchange! Your site for questions, answers, and announcements about operations research.