mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-15 07:48:29 -04:00
fixed a bug in max path len calculation
This commit is contained in:
parent
d8e4703468
commit
12e85e62f9
@ -9,8 +9,6 @@ import de.neemann.digital.core.*;
|
||||
import de.neemann.digital.core.Observer;
|
||||
import de.neemann.digital.draw.elements.PinException;
|
||||
import de.neemann.digital.lang.Lang;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -20,9 +18,7 @@ import java.util.*;
|
||||
* really depends on.
|
||||
*/
|
||||
public class DependencyAnalyser {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DependencyAnalyser.class);
|
||||
private final HashMap<Signal, Set<ObservableValue>> dependencyMap;
|
||||
private int maxDepth;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
@ -35,10 +31,9 @@ public class DependencyAnalyser {
|
||||
dependencyMap = new HashMap<>();
|
||||
for (Signal s : modelAnalyser.getInputs()) {
|
||||
Set<ObservableValue> effected = new HashSet<>();
|
||||
backtracking(s.getValue(), effected, 0);
|
||||
backtracking(s.getValue(), effected);
|
||||
dependencyMap.put(s, effected);
|
||||
}
|
||||
LOGGER.info("circuit max depth: " + getMaxPathLen());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,31 +66,18 @@ public class DependencyAnalyser {
|
||||
return num;
|
||||
}
|
||||
|
||||
private void backtracking(ObservableValue value, Set<ObservableValue> effected, int depth) throws PinException, BacktrackException {
|
||||
if (depth > maxDepth)
|
||||
maxDepth = depth;
|
||||
private void backtracking(ObservableValue value, Set<ObservableValue> effected) throws PinException, BacktrackException {
|
||||
if (!effected.contains(value)) {
|
||||
effected.add(value);
|
||||
|
||||
for (Observer o : value.getObservers()) {
|
||||
if ((o instanceof NodeInterface)) {
|
||||
ObservableValues outputs = ((NodeInterface) o).getOutputs();
|
||||
int d = depth;
|
||||
if (!(o instanceof NodeWithoutDelay)) d++;
|
||||
for (ObservableValue co : outputs)
|
||||
backtracking(co, effected, d);
|
||||
backtracking(co, effected);
|
||||
} else
|
||||
throw new BacktrackException(Lang.get("err_backtrackOf_N_isImpossible", o.getClass().getSimpleName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the max depth of the circuit.
|
||||
*
|
||||
* @return the max depth of the circuit
|
||||
*/
|
||||
public int getMaxPathLen() {
|
||||
return maxDepth;
|
||||
}
|
||||
}
|
||||
|
@ -324,7 +324,7 @@ public class ModelAnalyser {
|
||||
if (!Main.isExperimentalMode() && !modelContainsSwitches())
|
||||
CycleDetector.checkForCycles(inputs);
|
||||
|
||||
DependencyAnalyser da = new DependencyAnalyser(this);
|
||||
PathLenAnalyser da = new PathLenAnalyser(this);
|
||||
return da.getMaxPathLen();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2017 Helmut Neemann
|
||||
* Use of this source code is governed by the GPL v3 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
package de.neemann.digital.analyse;
|
||||
|
||||
import de.neemann.digital.core.Observer;
|
||||
import de.neemann.digital.core.*;
|
||||
import de.neemann.digital.draw.elements.PinException;
|
||||
import de.neemann.digital.lang.Lang;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Used to determine the max path len in the circuit.
|
||||
* This means the max number of gates between on of the inputs and one of the outputs.
|
||||
*/
|
||||
public class PathLenAnalyser {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PathLenAnalyser.class);
|
||||
private int maxDepth;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param modelAnalyser the model analyser
|
||||
* @throws BacktrackException BacktrackException
|
||||
* @throws PinException PinException
|
||||
*/
|
||||
public PathLenAnalyser(ModelAnalyser modelAnalyser) throws BacktrackException, PinException {
|
||||
for (Signal s : modelAnalyser.getInputs()) {
|
||||
LOGGER.debug(s.getName());
|
||||
HashMap<ObservableValue, Integer> found = new HashMap<>();
|
||||
backtracking(s.getValue(), found, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void backtracking(ObservableValue value, HashMap<ObservableValue, Integer> found, int depth) throws PinException, BacktrackException {
|
||||
Integer d = found.get(value);
|
||||
if (d == null || d < depth) {
|
||||
found.put(value, depth);
|
||||
|
||||
if (depth > maxDepth)
|
||||
maxDepth = depth;
|
||||
for (Observer o : value.getObservers()) {
|
||||
if ((o instanceof NodeInterface)) {
|
||||
LOGGER.debug(o.toString());
|
||||
ObservableValues outputs = ((NodeInterface) o).getOutputs();
|
||||
int de = depth;
|
||||
if (!(o instanceof NodeWithoutDelay)) de++;
|
||||
for (ObservableValue co : outputs)
|
||||
backtracking(co, found, de);
|
||||
} else
|
||||
throw new BacktrackException(Lang.get("err_backtrackOf_N_isImpossible", o.getClass().getSimpleName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the max path len in the circuit
|
||||
*/
|
||||
public int getMaxPathLen() {
|
||||
return maxDepth;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user