本文整理汇总了Java中net.ssehub.easy.varModel.model.values.RealValue类的典型用法代码示例。如果您正苦于以下问题:Java RealValue类的具体用法?Java RealValue怎么用?Java RealValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RealValue类属于net.ssehub.easy.varModel.model.values包,在下文中一共展示了RealValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDouble
import net.ssehub.easy.varModel.model.values.RealValue; //导入依赖的package包/类
/**
* Returns the value of a double compound slot.
*
* @param var the variable to look into (may be <b>null</b>)
* @param name the name of the slot
* @return the double value of the slot, <b>null</b> if there is no variable, no slot or no integer value in
* the slot
*/
public static final Double getDouble(IDecisionVariable var, String name) {
Double result = null;
if (null != var) {
IDecisionVariable nested = var.getNestedElement(name);
if (null != nested) {
Value value = nested.getValue();
if (value instanceof RealValue) {
result = ((RealValue) value).getValue();
} else if (value instanceof IntValue) {
Integer tmp = ((IntValue) value).getValue();
if (null != tmp) {
result = tmp.doubleValue();
}
}
}
}
return result;
}
示例2: assertEquals
import net.ssehub.easy.varModel.model.values.RealValue; //导入依赖的package包/类
/**
* Asserts equality between an expected double value and an actual evaluation accessor value.
* Releases <code>actual</code>.
*
* @param expected the expected value
* @param actual the actual evaluation result
*/
static final void assertEquals(Double expected, EvaluationAccessor actual) {
Value val;
if (null != actual) {
val = actual.getValue();
actual.release();
} else {
val = null;
}
if (null != expected && val instanceof RealValue) {
Assert.assertEquals(expected, ((RealValue) val).getValue());
} else if (null == expected && null == val) {
Assert.assertTrue(true); // useless, I know
} else {
Assert.fail("expected " + expected + " is not equal to " + val);
}
}
示例3: equalsRealInt
import net.ssehub.easy.varModel.model.values.RealValue; //导入依赖的package包/类
/**
* Implements the mixed int-real equality operation.
*
* @param operand the operand
* @param arguments the arguments
* @param negate whether the result shall be negated
* @return the comparison result, <b>null</b> if the operation cannot be applied
*/
static EvaluationAccessor equalsRealInt(EvaluationAccessor operand, EvaluationAccessor[] arguments,
boolean negate) {
EvaluationAccessor result = null;
if (arguments.length == 1) {
Value oValue = operand.getValue();
Value aValue = arguments[0].getValue();
if (aValue instanceof IntValue) {
if (oValue instanceof RealValue) {
double op = ((RealValue) oValue).getValue();
int arg = ((IntValue) aValue).getValue();
boolean equals = ((int) op == arg);
if (negate) {
equals = !equals;
}
result = ConstantAccessor.POOL.getInstance().bind(
BooleanValue.toBooleanValue(equals), operand.getContext());
} else if (oValue == NullValue.INSTANCE) {
result = ConstantAccessor.POOL.getInstance().bind(
BooleanValue.toBooleanValue(negate), operand.getContext());
}
}
}
return result;
}
示例4: equalsIntReal
import net.ssehub.easy.varModel.model.values.RealValue; //导入依赖的package包/类
/**
* Implements the mixed int-real equality operation.
*
* @param operand the operand
* @param arguments the arguments
* @param negate whether the result shall be negated
* @return the comparison result, <b>null</b> if the operation cannot be applied
*/
static EvaluationAccessor equalsIntReal(EvaluationAccessor operand, EvaluationAccessor[] arguments,
boolean negate) {
EvaluationAccessor result = null;
if (arguments.length == 1) {
Value oValue = operand.getValue();
Value aValue = arguments[0].getValue();
if (aValue instanceof RealValue) {
if (oValue instanceof IntValue) {
int op = ((IntValue) oValue).getValue();
double arg = ((RealValue) aValue).getValue();
boolean equals = (op == (int) arg);
if (negate) {
equals = !equals;
}
result = ConstantAccessor.POOL.getInstance().bind(
BooleanValue.toBooleanValue(equals), operand.getContext());
}
}
}
return result;
}
示例5: visitRealValue
import net.ssehub.easy.varModel.model.values.RealValue; //导入依赖的package包/类
@Override
public void visitRealValue(RealValue value) {
if (this.visitingNonNested) {
if (visitingConatinerValue) {
this.value += value.getValue();
} else {
this.declaration += " = " + value.getValue();
}
} else if (visitingNested) {
if (visitingConatinerValue) {
this.value += value.getValue();
} else {
this.compDeclaration += " = " + value.getValue();
}
} else if (visitingConfiguration) {
this.value += value.getValue();
}
}
示例6: getRealValue
import net.ssehub.easy.varModel.model.values.RealValue; //导入依赖的package包/类
/**
* Returns the Integer value of a decision variable.
*
* @param var the variable to return the Integer for
* @return the value, only if <code>var</code> is not <b>null</b> and of type Integer
*/
public static Double getRealValue(IDecisionVariable var) {
Double result = null;
if (null != var) {
Value value = var.getValue();
if (value instanceof RealValue) {
result = ((RealValue) value).getValue();
}
}
return result;
}
示例7: visitRealValue
import net.ssehub.easy.varModel.model.values.RealValue; //导入依赖的package包/类
@Override
public void visitRealValue(RealValue value) {
Assert.assertTrue(decl.getValue() instanceof Double);
Assert.assertNotNull(decl.getRealValue());
Assert.assertTrue(decl.getRealValue().equals(decl.getValue()));
Assert.assertEquals(value.getValue(), decl.getRealValue());
}
示例8: visitRealType
import net.ssehub.easy.varModel.model.values.RealValue; //导入依赖的package包/类
@Override
public void visitRealType(RealType type) {
variableName.append(variable.getDeclaration().getName());
RealValue realValue = (RealValue) variable.getValue();
if (null != realValue) {
values.add(new VelocityContextItem(variableName.toString(), realValue.getValue()));
}
}
示例9: toDouble
import net.ssehub.easy.varModel.model.values.RealValue; //导入依赖的package包/类
/**
* Turns an evaluation <code>accessor</code> into its double value if possible.
*
* @param accessor the accessor (may be <b>null</b> resulting in <b>null</b>)
* @return the double value or <b>null</b> if the conversion is not possible
*/
private Double toDouble(EvaluationAccessor accessor) {
Double result = null;
if (null != accessor) {
Value value = accessor.getValue();
if (value instanceof IntValue) {
result = ((IntValue) value).getValue().doubleValue();
} else if (value instanceof RealValue) {
result = ((RealValue) value).getValue();
}
}
return result;
}
示例10: setUp
import net.ssehub.easy.varModel.model.values.RealValue; //导入依赖的package包/类
/**
* setUp for all testCases.
* @throws ValueDoesNotMatchTypeException should not occur
*/
@Before
public void setUp() throws ValueDoesNotMatchTypeException {
project = new Project("Projekt");
realDec = new DecisionVariableDeclaration("real", RealType.TYPE, project);
value = 5.5;
realV = (RealValue) ValueFactory.createValue(realDec.getType(), value);
}
示例11: cloneReal
import net.ssehub.easy.varModel.model.values.RealValue; //导入依赖的package包/类
/**
* Test case to clone a realValue.
* @throws ValueDoesNotMatchTypeException should not occur
*/
@Test
public void cloneReal() throws ValueDoesNotMatchTypeException {
Double newValue = 1.8;
realV.setValue(newValue);
Assert.assertEquals(newValue, realV.getValue());
RealValue clonedValue = (RealValue) realV.clone();
Assert.assertEquals(realV.getValue(), clonedValue.getValue());
Assert.assertNotSame(realV, clonedValue);
}
示例12: basisDatatypeTest
import net.ssehub.easy.varModel.model.values.RealValue; //导入依赖的package包/类
/**
* tests the BasisDataTypes.
* @throws ValueDoesNotMatchTypeException .
*/
@Test
public void basisDatatypeTest() throws ValueDoesNotMatchTypeException {
//StringValue
DecisionVariableDeclaration string = new DecisionVariableDeclaration("string", StringType.TYPE, project);
StringValue strV = (StringValue) ValueFactory.createValue(string.getType(), "Hallo");
Assert.assertTrue(strV.isConfigured());
//IntValue
DecisionVariableDeclaration integer = new DecisionVariableDeclaration("integer", IntegerType.TYPE, project);
int intValue = 5;
IntValue intV = (IntValue) ValueFactory.createValue(integer.getType(), intValue);
Assert.assertTrue(intV.isConfigured());
Assert.assertEquals(intValue, (int) intV.getValue());
//BoolVBalue
DecisionVariableDeclaration booleanD = new DecisionVariableDeclaration("bool", BooleanType.TYPE, project);
BooleanValue boolV = (BooleanValue) ValueFactory.createValue(booleanD.getType(), "true");
Assert.assertTrue(boolV.isConfigured());
//RealValue
DecisionVariableDeclaration real = new DecisionVariableDeclaration("real", RealType.TYPE, project);
RealValue realV = (RealValue) ValueFactory.createValue(real.getType(), "5.5");
Assert.assertTrue(realV.isConfigured());
//RealValue initialized with a double instead of a string
DecisionVariableDeclaration realOfDouble = new DecisionVariableDeclaration("real", RealType.TYPE, project);
Double value = 5.5;
RealValue realOfDoubleV = (RealValue) ValueFactory.createValue(realOfDouble.getType(), value);
Assert.assertTrue(realOfDoubleV.isConfigured());
Assert.assertEquals(value, realOfDoubleV.getValue());
}
示例13: evaluate
import net.ssehub.easy.varModel.model.values.RealValue; //导入依赖的package包/类
public EvaluationAccessor evaluate(EvaluationAccessor operand, EvaluationAccessor[] arguments) {
EvaluationAccessor result = null;
Value value = operand.getValue();
if (value instanceof RealValue) {
double rValue = ((RealValue) value).getValue();
try {
Value iValue = ValueFactory.createValue(IntegerType.TYPE, (int) rValue);
ConstantAccessor.POOL.getInstance().bind(iValue, operand.getContext());
} catch (ValueDoesNotMatchTypeException e) {
operand.getContext().addErrorMessage("toInt: " + e.getMessage());
}
}
return result;
}
示例14: round
import net.ssehub.easy.varModel.model.values.RealValue; //导入依赖的package包/类
/**
* Implements arithmetic operations of two integer variables/values.
* @param operand the operand
* @param arguments the arguments
* @param roundUp If <tt>true</tt> this operation will round commercial (*.5 and higher will be round up), else
* numbers will be round down in any case.
* @return The result of the arithmetic operation, <b>null</b> if the operation cannot be applied
*/
private static EvaluationAccessor round(EvaluationAccessor operand,
EvaluationAccessor[] arguments, boolean roundUp) {
EvaluationAccessor result = null;
if (null == arguments || arguments.length == 0) {
Value value = operand.getValue();
if (value instanceof RealValue) {
double op = ((Double) value.getValue()).doubleValue();
// Handle greater range of doubles in relation to range of integer
int resultOfOperation = Integer.MAX_VALUE;
if (op >= Integer.MIN_VALUE && op <= Integer.MAX_VALUE) {
resultOfOperation = (int) (roundUp ? Math.round(op) : Math.floor(op));
} else if (op < Integer.MIN_VALUE) {
resultOfOperation = Integer.MIN_VALUE;
}
// Create (result) value
try {
Value rValue = ValueFactory.createValue(IntegerType.TYPE, resultOfOperation);
result = ConstantAccessor.POOL.getInstance().bind(rValue, operand.getContext());
} catch (ValueDoesNotMatchTypeException e) {
EASyLoggerFactory.INSTANCE.getLogger(GenericNumberOperations.class, Bundle.ID).exception(e);
}
}
}
return result;
}
示例15: visitRealValue
import net.ssehub.easy.varModel.model.values.RealValue; //导入依赖的package包/类
@Override
public void visitRealValue(RealValue value) {
Double val = value.getValue();
if (null != val) {
appendOutput(val.toString());
}
}