ArrayList<Instance> inputPins = new ArrayList<Instance>();
ArrayList<String> inputNames = new ArrayList<String>();
ArrayList<Instance> outputPins = new ArrayList<Instance>();
ArrayList<String> outputNames = new ArrayList<String>();
for (Map.Entry<Instance, String> entry : pinLabels.entrySet()) {
Instance pin = entry.getKey();
if (Pin.FACTORY.isInputPin(pin)) {
inputPins.add(pin);
inputNames.add(entry.getValue());
} else {
outputPins.add(pin);
outputNames.add(entry.getValue());
}
}
int inputCount = inputPins.size();
int rowCount = 1 << inputCount;
Entry[][] columns = new Entry[outputPins.size()][rowCount];
for (int i = 0; i < rowCount; i++) {
CircuitState circuitState = new CircuitState(proj, circuit);
for (int j = 0; j < inputCount; j++) {
Instance pin = inputPins.get(j);
InstanceState pinState = circuitState.getInstanceState(pin);
boolean value = TruthTable.isInputSet(i, j, inputCount);
Pin.FACTORY.setValue(pinState, value ? Value.TRUE : Value.FALSE);
}
Propagator prop = circuitState.getPropagator();
prop.propagate();
/* TODO for the SimulatorPrototype class
do {
prop.step();
} while (prop.isPending()); */
// TODO: Search for circuit state
if (prop.isOscillating()) {
for (int j = 0; j < columns.length; j++) {
columns[j][i] = Entry.OSCILLATE_ERROR;
}
} else {
for (int j = 0; j < columns.length; j++) {
Instance pin = outputPins.get(j);
InstanceState pinState = circuitState.getInstanceState(pin);
Entry out;
Value outValue = Pin.FACTORY.getValue(pinState).get(0);
if (outValue == Value.TRUE) out = Entry.ONE;
else if (outValue == Value.FALSE) out = Entry.ZERO;