Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
2

Genopt: independent variables and function

asked 2016-05-03 18:03:05 -0600

Melissa's avatar

I want to ask if there is any way to enforce the sum of independent variables take a value one. the independent variables take the value of zero or 1 (they regulate the water entering the water heater in EnergyPlus)

for example when field 0 is 1 the remaining values must be zero, Therefore I want the result of the sum be 1. Can someone help me?

  Name2             = "termo1";
  Function2         = "add(%Field0%,%Field1%,%Field2%,%Field3%,%Field4%,%Field5%)";
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-05-04 02:40:26 -0600

updated 2016-05-04 02:46:11 -0600

A constraint on the outputs - a post-processing constraint - is typically done using a penalty function such as a barrier function: basically when evaluating the cost function if it doesn't respect your constraint you give the cost function - that you are trying to minimize - a very large value.

In your case, you want to constraint the input parameters, so there's no reason at all to have the simulation be executed and then to check that! It'll just be a waste of time and electricity, and we all want to be energy efficient don't we?

You can just reduce your problem by using only a single variable $x$ that can take DISCRETE integer values of 0, 1, 2, 3, 4, 5, and then define deriving variables by using the equality operator ==.

This is equivalent to the following system of equation:

$$ x \in [0..5] $$ $$x0 = (x == 0) $$ $$x1 = (x == 1) $$ $$x2 = (x == 2) $$ $$x3 = (x == 3) $$ $$x4 = (x == 4) $$ $$x5 = (x == 5) $$

Now, as far as implementation in GenOpt, it shouldn't be too hard. As stated in the user manual (section 11.3), GenOpt implements some built-in functions and all functions in java.lang.StrictMath, and you can also define your own functions that will return a double, so worse case scenario you can implement one in Fun.java and recompile it.

But you can try the following, see if it works out of the box, I think it will since the ternary operator ? is built-in Java...

Parameter{   // initial variable in [0..5]
    Name    = x;
    Min     =  0;
    Ini     =  0;
    Max     =  5;
    Step    =  1;
    Type = DISCRETE;
  }
Function{
    Name = x0;
    Function = "(%x% == 0)? 1.0 : 0.0;";
}
Function{
    Name = x1;
    Function = "(%x% == 1)? 1.0 : 0.0;";
}
Function{
    Name = x2;
    Function = "(%x% == 2)? 1.0 : 0.0;";
}
Function{
    Name = x3;
    Function = "(%x% == 3)? 1.0 : 0.0;";
}
Function{
    Name = x4;
    Function = "(%x% == 4)? 1.0 : 0.0;";
}
Function{
    Name = x5;
    Function = "(%x% == 5)? 1.0 : 0.0;";
}

Then obviously you would assign each of the $x0.. x5$ variables in your template file for each water heater using %x0%, %x1% etc.


PS: Note that I didn't try any of the above code, and I know nothing about Java so typos are expected. Let me know if it works and what you had to change so we can leave a clean code here that can be reused by more people: we're doing this for "the children".

edit flag offensive delete link more

Comments

@Neal Kruis: for some reason I didn't manage to put a left brace around the system of equations in MathJax, though it should work. See here

Julien Marrec's avatar Julien Marrec  ( 2016-05-04 02:42:29 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 2016-05-03 18:03:05 -0600

Seen: 216 times

Last updated: May 04 '16