This library provides functions operating on vectors that have a Boolean vector as input argument.
Extends from Modelica.Icons.Package (Icon for standard packages).
Name | Description |
---|---|
allTrue | Returns true, if all elements of the Boolean input vector are true ('and') |
anyTrue | Returns true, if at least on element of the Boolean input vector is true ('or') |
oneTrue | Returns true, if exactly one element of the Boolean input vector is true ('xor') |
firstTrueIndex | Returns the index of the first element of the Boolean vector that is true and returns 0, if no element is true |
allTrue(b);
Returns true if all elements of the Boolean input vector b are true. Otherwise the function returns false. If b is an empty vector, i.e., size(b,1)=0, the function returns false.
Boolean b1[3] = {true, true, true}; Boolean b2[3] = {false, true, false}; Boolean r1, r2; algorithm r1 = allTrue(b1); // r1 = true r2 = allTrue(b2); // r2 = false
anyTrue, oneTrue, firstTrueIndex.
Extends from Modelica.Icons.Function (Icon for functions).
Type | Name | Default | Description |
---|---|---|---|
Boolean | b[:] | Boolean vector |
Type | Name | Description |
---|---|---|
Boolean | result | = true, if all elements of b are true |
function allTrue "Returns true, if all elements of the Boolean input vector are true ('and')" extends Modelica.Icons.Function; input Boolean b[:] "Boolean vector"; output Boolean result "= true, if all elements of b are true"; algorithm result := size(b,1) > 0; for i in 1:size(b,1) loop result := result and b[i]; end for;end allTrue;
anyTrue(b);
Returns true if at least one elements of the input Boolean vector b is true. Otherwise the function returns false. If b is an empty vector, i.e., size(b,1)=0, the function returns false.
Boolean b1[3] = {false, false, false}; Boolean b2[3] = {false, true, false}; Boolean r1, r2; algorithm r1 = anyTrue(b1); // r1 = false r2 = anyTrue(b2); // r2 = true
allTrue, oneTrue, firstTrueIndex.
Extends from Modelica.Icons.Function (Icon for functions).
Type | Name | Default | Description |
---|---|---|---|
Boolean | b[:] |
Type | Name | Description |
---|---|---|
Boolean | result |
function anyTrue "Returns true, if at least on element of the Boolean input vector is true ('or')" extends Modelica.Icons.Function; input Boolean b[:]; output Boolean result; algorithm result := false; for i in 1:size(b,1) loop result := result or b[i]; end for;end anyTrue;
oneTrue(b);
Returns true if exactly one element of the input Boolean vector b is true. Otherwise the function returns false. If b is an empty vector, i.e., size(b,1)=0, the function returns false.
Boolean b1[3] = {false, false, false}; Boolean b2[3] = {false, true, false}; Boolean b3[3] = {false, true, true}; Boolean r1, r2, r3; algorithm r1 = oneTrue(b1); // r1 = false r2 = oneTrue(b2); // r2 = true r3 = oneTrue(b3); // r3 = false
allTrue, anyTrue, firstTrueIndex.
Extends from Modelica.Icons.Function (Icon for functions).
Type | Name | Default | Description |
---|---|---|---|
Boolean | b[:] |
Type | Name | Description |
---|---|---|
Boolean | result |
function oneTrue "Returns true, if exactly one element of the Boolean input vector is true ('xor')" extends Modelica.Icons.Function; input Boolean b[:]; output Boolean result; protected Integer count = 0; algorithm for i in 1:size(b,1) loop count := if b[i] then count+1 else count; end for; result :=count == 1;end oneTrue;
firstTrueIndex(b);
Returns the index of the first element of the Boolean vector b that is true and returns 0, if no element is true" If b is an empty vector, i.e., size(b,1)=0, the function returns 0.
Boolean b1[3] = {false, false, false}; Boolean b2[3] = {false, true, false}; Boolean b3[4] = {false, true, false, true}; Integer r1, r2, r3; algorithm r1 = firstTrueIndex(b1); // r1 = 0 r2 = firstTrueIndex(b2); // r2 = 2 r3 = firstTrueIndex(b3); // r3 = 2
Type | Name | Default | Description |
---|---|---|---|
Boolean | b[:] |
Type | Name | Description |
---|---|---|
Integer | index |
function firstTrueIndex "Returns the index of the first element of the Boolean vector that is true and returns 0, if no element is true" input Boolean b[:]; output Integer index; algorithm index :=0; for i in 1:size(b,1) loop if b[i] then index :=i; return; end if; end for;end firstTrueIndex;