Topic
  • 3 replies
  • Latest Post - ‏2013-03-27T11:41:31Z by SystemAdmin
SystemAdmin
SystemAdmin
1883 Posts

Pinned topic help with objective function (operator not available for string +int)

‏2013-03-26T01:20:15Z |
Hello,

I am not used with CPLEX thus in other softwares this problem never happened to me, let me see if you might know how i can do this:

I am using a objective function that uses a binary decision variable lets say Y[i][j]
My objective function (maximization) will calculate a price if there Y exists in [i][j], this is Y[i][j] * Price, but will discount a penalty if Y exists in i+1[j], this is Yi+1[j] * Penalty. In the end the function would be something like:

maximize sum (i in days, j in years) Y[i][j] * Price - Yi+1[j] * Penalty

But this brings an error: operator not available for string +int

if I use Y[i][j] * Price - Y[i][j] * Penalty (no i+1) the optimization runs smoothly.

days is defined as a string, {string} Days =...; and is associated with a excel table something like this C2:E2 (monday, tuesday, sunday). Might this be the problem, to have the index as a string and therefore not possible to calculate the i+1?
How can I implement this?

Also I was told about a next() function that might help me on this. Can I implement it inside the objective/decision function?

Thank you for the help.
Updated on 2013-03-27T11:41:31Z at 2013-03-27T11:41:31Z by SystemAdmin
  • AlexFleischer
    AlexFleischer
    1246 Posts

    Re: help with objective function (operator not available for string +int)

    ‏2013-03-26T08:01:36Z  
    Hi,

    indeed next could help you, it will give you the next one in a string set like the days in the week.
    But you may also use the function ord that will turn Monday into its rank in the set. To do the opposite, ie turn a rank in an element you may then use item.
    All those keywords are in the documentation.
    I hope this helps.

    Regards
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: help with objective function (operator not available for string +int)

    ‏2013-03-26T11:17:25Z  
    Hi,

    indeed next could help you, it will give you the next one in a string set like the days in the week.
    But you may also use the function ord that will turn Monday into its rank in the set. To do the opposite, ie turn a rank in an element you may then use item.
    All those keywords are in the documentation.
    I hope this helps.

    Regards
    I will check on these and Will get back to let you know if I could manage my problem with.

    Thank you.
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: help with objective function (operator not available for string +int)

    ‏2013-03-27T11:41:31Z  
    I will check on these and Will get back to let you know if I could manage my problem with.

    Thank you.
    Ok, I used the next and was able to solve the problem (i checked the solution on excel and the objective function values match thus they are beeing well calculated).

    I will open a new question thread with some futher questions with a better subject so other people might find it.
    I hope you can check this threat I will create since it regards your suggested functions.

    Best regards,
    Marco Amorim