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

Revision history [back]

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! I'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.javaand 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.


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.

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! I'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 operatoroperator ==.

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, 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.javaand 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...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 $x0.. x5$ variables in your template file for each water heater.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.

people: we're doing this for "the children".

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! I'll 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".