+ Reply to Thread
Results 1 to 5 of 5

IF statement in decision variables OpenSolver

  1. #1
    Registered User
    Join Date
    04-20-2023
    Location
    Utrecht, Netherlands
    MS-Off Ver
    Office for Mac
    Posts
    3

    Red face IF statement in decision variables OpenSolver

    Hi everyone,

    I'm just new to this forum so forgive me if I not up to speed of any customs or rules of conduct or anything..

    I have a problem which I can't seem to fix on my own.

    I'm trying to optimize a problem right now, using the OpenSolver. In short: the optimization problem is minimizing costs of electricity use of electric vehicles (EVs) which have a certain driving pattern. The goal is to simulate an optimal charging strategy during the hours that the EV is connected to the grid, where electricity prices vary per hour. Since the EVs have batteries, they also allow electricity to be sold back to the grid. The decision variables contain the electricity extracted/sold back to the grid per specific hour.

    So for example: the car is connected to the grid at 10PM at 10 kWh and needs to be charged with 50 kWh the next morning at 09AM. The OpenSolver needs to find in which hours it is the cheapest to charge the vehicle. If prices between hours vary enough, it may also be possible that it discharges (earns money with the electricity) to reduce charging costs further.

    Here comes the catch: the price for electricity when discharging the vehicle differ from the price when charging. I want to include an IF-statement here to account for this (i.e. IFS(charge in hour I <0; charge* charge price; charge in hour I >0; charge*discharge price). The solver however does not recognize this since (I think) the IF statement is based on the decision variables. I've tried many things, but can't seem to work around an IF statement that is (in)directly based on the decision variables..

    Anyone that might know how to help?

  2. #2
    Valued Forum Contributor Hydraulics's Avatar
    Join Date
    07-15-2018
    Location
    Udine - Italy
    MS-Off Ver
    Office 365
    Posts
    373

    Re: IF statement in decision variables OpenSolver

    This question is more related to Operation Research than to Excel, anyhow...

    There are a number of ways to model your problem. When IF statements are introduced, usually we rely on additional binary variables (you may want to search for "MILP indicator variable", or something like that).

    In your problem, we can split the cost function to be optimized into two terms, the first for energy bought in each time interval, the second for energy sold. We introduce two real variables, and two binary variables (linked to the real ones) that will tell us IF we are buying or selling. A simple constraint will force OpenSolver to either buy or sell.

    Have a look at the attached file for a basic setup. As I wrote, this is not the only approach we can follow.

    HTH,

    Francesco
    Attached Files Attached Files
    Last edited by Hydraulics; 04-22-2023 at 07:09 PM.
    Aim high or don't even try.
    ---------------------------------
    If your question has been answered, don't forget to mark the thread as SOLVED.
    If you find an answer helpful, click on the star icon at the bottom of the post.

  3. #3
    Registered User
    Join Date
    04-20-2023
    Location
    Utrecht, Netherlands
    MS-Off Ver
    Office for Mac
    Posts
    3

    Re: IF statement in decision variables OpenSolver

    Thanks for the help. I set up my model similar to yours, and it should be working I guess. However, all decision variables have 0s in them, but the battery keeps charging anyway. Any idea what might be the problem?

    I use the OpenSolver since I have more than 200 variables.

  4. #4
    Valued Forum Contributor Hydraulics's Avatar
    Join Date
    07-15-2018
    Location
    Udine - Italy
    MS-Off Ver
    Office 365
    Posts
    373

    Re: IF statement in decision variables OpenSolver

    Quote Originally Posted by ExcellerenUU View Post
    Any idea what might be the problem?
    I may have, if you attach your actual workbook. Instructions are in the yellow banner at the top of the page.

    HTH,

    Francesco

  5. #5
    Registered User
    Join Date
    04-20-2023
    Location
    Utrecht, Netherlands
    MS-Off Ver
    Office for Mac
    Posts
    3

    Re: IF statement in decision variables OpenSolver

    Made a small error but I found it, it works now! thanks for the help and the offer though!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Understanding OpenSolver
    By mike_302 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-07-2020, 07:02 AM
  2. Implement decision tree for "make vs. buy" decision
    By heggej in forum Excel General
    Replies: 2
    Last Post: 10-23-2019, 01:02 PM
  3. Replies: 5
    Last Post: 09-03-2018, 03:20 AM
  4. Decision Variables
    By NatalieEC in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-16-2018, 01:52 PM
  5. [SOLVED] If..Then statement that uses RGB value of cell to make decision
    By TheRobsterUK in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-19-2014, 10:53 AM
  6. Solver loop with 2 sets of decision variables
    By Willie68 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-24-2014, 07:19 PM
  7. [SOLVED] Need IF statement or Macro to make decision based on multiple criteria
    By weddica in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-25-2013, 03:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1