Configurable max switch combination count for circuit analysis (using org.diylc.maxSwitchCombinations argument)

This commit is contained in:
Bane Stojkovic
2023-03-28 16:11:57 +02:00
parent 4710d1b484
commit 24c8afd620
2 changed files with 19 additions and 2 deletions
@@ -29,6 +29,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import org.apache.log4j.Logger;
import org.diylc.common.ComponentType;
import org.diylc.core.ICommonNode;
import org.diylc.core.IContinuity;
@@ -50,10 +51,12 @@ public class NetlistBuilder {
public static final float eps = 4; // consider any nodes closer than this as connected
private static final int MAX_SWITCH_COMBINATIONS = 64;
public static int MAX_SWITCH_COMBINATIONS = 64;
private static final String MAX_SWITCH_COMBINATIONS_ERROR = LangUtil
.translate("Maximum number of switching combinations exceeded. Allowed: %s, actual: %s");
private static final Logger LOG = Logger.getLogger(NetlistBuilder.class);
@SuppressWarnings("unchecked")
public static List<Netlist> extractNetlists(boolean includeSwitches, Project project,
@@ -130,8 +133,18 @@ public class NetlistBuilder {
int totalSwitchCombinations =
switches.stream().map(sw -> sw.getPositionCount()).reduce(1, (a, b) -> a * b);
int maxSwitch = MAX_SWITCH_COMBINATIONS;
String maxSwitchStr = System.getProperty("org.diylc.maxSwitchCombinations");
if (maxSwitchStr != null) {
try {
maxSwitch = Integer.parseInt(maxSwitchStr);
} catch (Exception e) {
LOG.error("Could not apply property org.diylc.maxSwitchCombinations", e);
}
}
if (totalSwitchCombinations > MAX_SWITCH_COMBINATIONS) {
if (totalSwitchCombinations > maxSwitch) {
throw new NetlistException(String.format(MAX_SWITCH_COMBINATIONS_ERROR,
MAX_SWITCH_COMBINATIONS, totalSwitchCombinations));
}
@@ -4322,6 +4322,10 @@
<changeType>NEW_FEATURE</changeType>
<description>Title Block added as one of factory building blocks (was missing in 4.35 by mistake)</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>General application slowness when Inductor component is added to the drawing</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>Lever switch orientation not loaded correctly from files created prior to version 4.35</description>