From cfb472bd2b220d0a5c45ca860a98ec6717642bd6 Mon Sep 17 00:00:00 2001 From: Luc-Sol Date: Wed, 4 Feb 2026 18:09:39 +0100 Subject: [PATCH] New DoubleCompare class - Added a double compare class with static methods - Removed the J_GlobalParameters --- Zero_engine.alpx | 10 ++--- .../Agents/GridConnection/Code/Functions.java | 2 +- _alp/Classes/Class.DoubleCompare.java | 41 +++++++++++++++++++ _alp/Classes/Class.J_EABuilding.java | 4 +- _alp/Classes/Class.J_EAConversion.java | 5 +-- _alp/Classes/Class.J_GlobalParameters.java | 7 ---- 6 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 _alp/Classes/Class.DoubleCompare.java delete mode 100644 _alp/Classes/Class.J_GlobalParameters.java diff --git a/Zero_engine.alpx b/Zero_engine.alpx index 0fee2ff..c7857b0 100644 --- a/Zero_engine.alpx +++ b/Zero_engine.alpx @@ -1860,11 +1860,6 @@ EXCLUDE_PV => Use PV profile to preprocess gridnode profile to create a more acc 1762850578079 - - 1763570262548 - - 1764938574089 - 1764337491572 @@ -1940,6 +1935,11 @@ EXCLUDE_PV => Use PV profile to preprocess gridnode profile to create a more acc 1752677832758 + + 1770210283060 + + 1764938574089 + com.anylogic.libraries.modules.markup_descriptors diff --git a/_alp/Agents/GridConnection/Code/Functions.java b/_alp/Agents/GridConnection/Code/Functions.java index ce0840e..1972565 100644 --- a/_alp/Agents/GridConnection/Code/Functions.java +++ b/_alp/Agents/GridConnection/Code/Functions.java @@ -35,7 +35,7 @@ double f_connectionMetering(J_TimeVariables timeVariables,boolean isRapidRun) {/*ALCODESTART::1660212665961*/ -if ( abs(fm_currentConsumptionFlows_kW.get(OL_EnergyCarriers.HEAT) - fm_currentProductionFlows_kW.get(OL_EnergyCarriers.HEAT)) > 0.1 && p_parentNodeHeat == null ) { +if ( DoubleCompare.greaterThanZero(abs(fm_currentBalanceFlows_kW.get(OL_EnergyCarriers.HEAT))) && p_parentNodeHeat == null ) { //if (p_BuildingThermalAsset == null || !p_BuildingThermalAsset.hasHeatBuffer()) { traceln("heat consumption: %s kW", fm_currentConsumptionFlows_kW.get(OL_EnergyCarriers.HEAT)); traceln("heat production: %s kW", fm_currentProductionFlows_kW.get(OL_EnergyCarriers.HEAT)); diff --git a/_alp/Classes/Class.DoubleCompare.java b/_alp/Classes/Class.DoubleCompare.java new file mode 100644 index 0000000..5bd74f7 --- /dev/null +++ b/_alp/Classes/Class.DoubleCompare.java @@ -0,0 +1,41 @@ +import java.lang.Math; +/** + * DoubleCompare + */ +public class DoubleCompare { + private final static int FLOATINGPOINTPRECISION = 10; + private final static double EPSILON = 1e-10; + + public static boolean equalsZero(double d) { + //d = round(d); + //return d == 0.0; + + return Math.abs(d) < EPSILON; + } + + public static boolean lessThanZero(double d) { + //d = round(d); + //return d < 0.0; + return d < -EPSILON; + } + + public static boolean greaterThanZero(double d) { + //d = round(d); + //return d > 0.0; + return d > EPSILON; + } + + public static boolean equals(double a, double b) { + + //a = round(a); + //b = round(b); + //return a == b; + return Math.abs(a - b) < EPSILON; + + } + + //private static double round(double d) { + //return Math.floor(d * Math.pow(10, FLOATINGPOINTPRECISION) + 0.5) / Math.pow(10, FLOATINGPOINTPRECISION); + //} + +} \ No newline at end of file diff --git a/_alp/Classes/Class.J_EABuilding.java b/_alp/Classes/Class.J_EABuilding.java index 61b7fdc..61a3df5 100644 --- a/_alp/Classes/Class.J_EABuilding.java +++ b/_alp/Classes/Class.J_EABuilding.java @@ -73,10 +73,10 @@ public J_FlowPacket f_updateAllFlows(double powerFraction_fr, J_TimeVariables ti @Override public void operate(double powerFraction_fr, J_TimeVariables timeVariables) { - if (powerFraction_fr < 0) { + + if (DoubleCompare.lessThanZero(powerFraction_fr)) { throw new RuntimeException("Cooling of the J_EABuilding is not yet supported."); } - double lossPower_kW = calculateLoss(); // Heat exchange with environment through convection double solarHeating_kW = solarHeating(); // Heat influx from sunlight this.energyUse_kW = lossPower_kW - solarHeating_kW; diff --git a/_alp/Classes/Class.J_EAConversion.java b/_alp/Classes/Class.J_EAConversion.java index 09308cf..d0ac9f1 100644 --- a/_alp/Classes/Class.J_EAConversion.java +++ b/_alp/Classes/Class.J_EAConversion.java @@ -33,11 +33,10 @@ public J_EAConversion(I_AssetOwner owner, OL_EnergyAssetType energyAssetType, do @Override public J_FlowPacket f_updateAllFlows(double powerFraction_fr, J_TimeVariables timeVariables) { - powerFraction_fr = roundToDecimal(powerFraction_fr, J_GlobalParameters.floatingPointPrecision); - if(powerFraction_fr < 0) { + if(DoubleCompare.lessThanZero(powerFraction_fr)) { throw new RuntimeException("Impossible to operate conversion asset with negative powerfraction."); } - else if ( powerFraction_fr == 0 ) { + else if ( DoubleCompare.equalsZero(powerFraction_fr) ) { this.lastFlowsMap.clear(); this.lastEnergyUse_kW = 0; J_FlowsMap flowsMapCopy = new J_FlowsMap(); diff --git a/_alp/Classes/Class.J_GlobalParameters.java b/_alp/Classes/Class.J_GlobalParameters.java deleted file mode 100644 index b81fb54..0000000 --- a/_alp/Classes/Class.J_GlobalParameters.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * J_GlobalParameters - */ -public abstract class J_GlobalParameters { - //public final static double floatingPointErrorMargin = 1e-15; - public final static int floatingPointPrecision = 10; -} \ No newline at end of file