fixes a bug in the switch net formation, closes #480

This commit is contained in:
hneemann 2020-06-24 11:14:16 +02:00
parent 118ffc4956
commit ee5fd615dd
6 changed files with 493 additions and 18 deletions

View File

@ -102,7 +102,7 @@ public final class PlainSwitch implements NodeInterface {
if (constant != null)
return new UniDirectionalSwitch(constant, output1);
else
return new RealSwitch(in1, in2);
return new RealSwitch(in1, output1, in2, output2);
}
} else
return new UniDirectionalSwitch(input1, output2);
@ -250,12 +250,16 @@ public final class PlainSwitch implements NodeInterface {
*/
public static final class RealSwitch implements SwitchModel {
private final CommonBusValue input1;
private final ObservableValue output1;
private final CommonBusValue input2;
private final ObservableValue output2;
private BusModelStateObserver obs;
private RealSwitch(CommonBusValue input1, CommonBusValue input2) {
private RealSwitch(CommonBusValue input1, ObservableValue output1, CommonBusValue input2, ObservableValue output2) {
this.input1 = input1;
this.output1 = output1;
this.input2 = input2;
this.output2 = output2;
}
@Override
@ -285,5 +289,19 @@ public final class PlainSwitch implements NodeInterface {
public CommonBusValue getInput2() {
return input2;
}
/**
* @return the output used by the left hand side pin
*/
public ObservableValue getOutput1() {
return output1;
}
/**
* @return the output used by the right hand side pin
*/
public ObservableValue getOutput2() {
return output2;
}
}
}

View File

@ -97,20 +97,24 @@ public final class BusModelStateObserver implements ModelStateObserverTyped {
createdHandlers.add(h);
h.addNet(s.getInput1());
h.addNet(s.getInput2());
h.addExclude(s.getOutput1(), s.getOutput2());
netMap.put(s.getInput1(), h);
netMap.put(s.getInput2(), h);
} else {
h2.addNet(s.getInput1());
h2.addExclude(s.getOutput1(), s.getOutput2());
netMap.put(s.getInput1(), h2);
}
} else {
if (h2 == null) {
h1.addNet(s.getInput2());
h1.addExclude(s.getOutput1(), s.getOutput2());
netMap.put(s.getInput2(), h1);
} else {
if (h1 != h2) {
// merge the nets
h1.addNet(h2);
h1.addExcludesFrom(h2);
for (CommonBusValue v : h2.getValues())
netMap.put(v, h1);
createdHandlers.remove(h2);
@ -118,6 +122,8 @@ public final class BusModelStateObserver implements ModelStateObserverTyped {
}
}
}
for (ConnectedBusHandler h : createdHandlers)
h.removeExcludes();
for (ConnectedBusHandler h : createdHandlers)
h.recalculate();
}

View File

@ -19,8 +19,9 @@ import java.util.List;
*/
public final class ConnectedBusHandler extends AbstractBusHandler {
private PinDescription.PullResistor resistor = PinDescription.PullResistor.none;
private ArrayList<CommonBusValue> values;
private ArrayList<ObservableValue> inputs;
private final ArrayList<CommonBusValue> values;
private final ArrayList<ObservableValue> inputs;
private final ArrayList<ObservableValue> excludes;
/**
* Creates a new instance
@ -31,6 +32,7 @@ public final class ConnectedBusHandler extends AbstractBusHandler {
super(obs);
values = new ArrayList<>();
inputs = new ArrayList<>();
excludes = new ArrayList<>();
}
/**
@ -100,4 +102,31 @@ public final class ConnectedBusHandler extends AbstractBusHandler {
return "ConnectedBusHandler{"
+ "values=" + values + '}';
}
/**
* Adds output to the net which are to ignore.
*
* @param output1 output1
* @param output2 output2
*/
public void addExclude(ObservableValue output1, ObservableValue output2) {
excludes.add(output1);
excludes.add(output2);
}
/**
* Adds output which are to ignore by net other.
*
* @param other adds the outputs to ignore from this net
*/
public void addExcludesFrom(ConnectedBusHandler other) {
excludes.addAll(other.excludes);
}
/**
* Removes all the outputs which are to ignore
*/
public void removeExcludes() {
inputs.removeAll(excludes);
}
}

View File

@ -43,8 +43,8 @@ public class TestExamples extends TestCase {
*/
public void testTestExamples() throws Exception {
File examples = new File(Resources.getRoot(), "/dig/test");
assertEquals(191, new FileScanner(this::check).scan(examples));
assertEquals(179, testCasesInFiles);
assertEquals(192, new FileScanner(this::check).scan(examples));
assertEquals(181, testCasesInFiles);
}
/**

View File

@ -0,0 +1,430 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<attributes/>
<visualElements>
<visualElement>
<elementName>RelayDT</elementName>
<elementAttributes>
<entry>
<string>mirror</string>
<boolean>true</boolean>
</entry>
<entry>
<string>rotation</string>
<rotation rotation="1"/>
</entry>
<entry>
<string>Label</string>
<string>S4</string>
</entry>
</elementAttributes>
<pos x="80" y="1480"/>
</visualElement>
<visualElement>
<elementName>RelayDT</elementName>
<elementAttributes>
<entry>
<string>mirror</string>
<boolean>true</boolean>
</entry>
<entry>
<string>rotation</string>
<rotation rotation="1"/>
</entry>
<entry>
<string>Label</string>
<string>S1</string>
</entry>
</elementAttributes>
<pos x="440" y="1480"/>
</visualElement>
<visualElement>
<elementName>Ground</elementName>
<elementAttributes/>
<pos x="480" y="1420"/>
</visualElement>
<visualElement>
<elementName>RelayDT</elementName>
<elementAttributes>
<entry>
<string>mirror</string>
<boolean>true</boolean>
</entry>
<entry>
<string>rotation</string>
<rotation rotation="1"/>
</entry>
<entry>
<string>Label</string>
<string>S2</string>
</entry>
</elementAttributes>
<pos x="320" y="1480"/>
</visualElement>
<visualElement>
<elementName>Ground</elementName>
<elementAttributes/>
<pos x="360" y="1420"/>
</visualElement>
<visualElement>
<elementName>RelayDT</elementName>
<elementAttributes>
<entry>
<string>mirror</string>
<boolean>true</boolean>
</entry>
<entry>
<string>rotation</string>
<rotation rotation="1"/>
</entry>
<entry>
<string>Label</string>
<string>S3</string>
</entry>
</elementAttributes>
<pos x="200" y="1480"/>
</visualElement>
<visualElement>
<elementName>Ground</elementName>
<elementAttributes/>
<pos x="240" y="1420"/>
</visualElement>
<visualElement>
<elementName>Ground</elementName>
<elementAttributes/>
<pos x="120" y="1420"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>rotation</string>
<rotation rotation="1"/>
</entry>
<entry>
<string>Label</string>
<string>A</string>
</entry>
</elementAttributes>
<pos x="480" y="1560"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>rotation</string>
<rotation rotation="1"/>
</entry>
<entry>
<string>Label</string>
<string>B</string>
</entry>
</elementAttributes>
<pos x="360" y="1560"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>rotation</string>
<rotation reference="../../../../visualElement[9]/elementAttributes/entry/rotation"/>
</entry>
<entry>
<string>Label</string>
<string>C</string>
</entry>
</elementAttributes>
<pos x="240" y="1560"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>rotation</string>
<rotation reference="../../../../visualElement[9]/elementAttributes/entry/rotation"/>
</entry>
<entry>
<string>Label</string>
<string>D</string>
</entry>
</elementAttributes>
<pos x="120" y="1560"/>
</visualElement>
<visualElement>
<elementName>Const</elementName>
<elementAttributes>
<entry>
<string>Value</string>
<long>0</long>
</entry>
</elementAttributes>
<pos x="-20" y="1440"/>
</visualElement>
<visualElement>
<elementName>Const</elementName>
<elementAttributes/>
<pos x="-20" y="1400"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>rotation</string>
<rotation rotation="1"/>
</entry>
<entry>
<string>Label</string>
<string>Y</string>
</entry>
</elementAttributes>
<pos x="160" y="1340"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>rotation</string>
<rotation rotation="1"/>
</entry>
<entry>
<string>Label</string>
<string>X</string>
</entry>
</elementAttributes>
<pos x="280" y="1340"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>rotation</string>
<rotation rotation="1"/>
</entry>
<entry>
<string>Label</string>
<string>Z</string>
</entry>
</elementAttributes>
<pos x="400" y="1340"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>rotation</string>
<rotation rotation="1"/>
</entry>
<entry>
<string>Label</string>
<string>U</string>
</entry>
</elementAttributes>
<pos x="520" y="1340"/>
</visualElement>
<visualElement>
<elementName>Testcase</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>comb</string>
</entry>
<entry>
<string>Testdata</string>
<testData>
<dataString> D C B A Y X Z U
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1
0 0 1 0 0 0 1 1
0 0 1 1 0 0 1 1
0 1 0 0 0 1 1 1
0 1 0 1 0 1 1 1
0 1 1 0 0 1 1 1
0 1 1 1 0 1 1 1
1 0 0 0 1 1 1 1
1 0 0 1 1 1 1 1
1 0 1 0 1 1 1 1
1 0 1 1 1 1 1 1
1 1 0 0 1 1 1 1
1 1 0 1 1 1 1 1
1 1 1 0 1 1 1 1
1 1 1 1 1 1 1 1
</dataString>
</testData>
</entry>
</elementAttributes>
<pos x="0" y="1200"/>
</visualElement>
<visualElement>
<elementName>Testcase</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>#480</string>
</entry>
<entry>
<string>Testdata</string>
<testData>
<dataString> D C B A Y X Z U
0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 1
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1
0 0 0 0 0 0 0 0
0 1 0 0 0 1 1 1
0 0 0 0 0 0 0 0
1 0 0 0 1 1 1 1
0 0 0 0 0 0 0 0
</dataString>
</testData>
</entry>
</elementAttributes>
<pos x="0" y="1280"/>
</visualElement>
</visualElements>
<wires>
<wire>
<p1 x="-20" y="1440"/>
<p2 x="60" y="1440"/>
</wire>
<wire>
<p1 x="160" y="1440"/>
<p2 x="180" y="1440"/>
</wire>
<wire>
<p1 x="400" y="1440"/>
<p2 x="420" y="1440"/>
</wire>
<wire>
<p1 x="280" y="1440"/>
<p2 x="300" y="1440"/>
</wire>
<wire>
<p1 x="-20" y="1400"/>
<p2 x="80" y="1400"/>
</wire>
<wire>
<p1 x="80" y="1400"/>
<p2 x="200" y="1400"/>
</wire>
<wire>
<p1 x="200" y="1400"/>
<p2 x="320" y="1400"/>
</wire>
<wire>
<p1 x="320" y="1400"/>
<p2 x="440" y="1400"/>
</wire>
<wire>
<p1 x="200" y="1500"/>
<p2 x="280" y="1500"/>
</wire>
<wire>
<p1 x="80" y="1500"/>
<p2 x="160" y="1500"/>
</wire>
<wire>
<p1 x="440" y="1500"/>
<p2 x="520" y="1500"/>
</wire>
<wire>
<p1 x="320" y="1500"/>
<p2 x="400" y="1500"/>
</wire>
<wire>
<p1 x="160" y="1340"/>
<p2 x="160" y="1440"/>
</wire>
<wire>
<p1 x="160" y="1440"/>
<p2 x="160" y="1500"/>
</wire>
<wire>
<p1 x="320" y="1480"/>
<p2 x="320" y="1500"/>
</wire>
<wire>
<p1 x="320" y="1400"/>
<p2 x="320" y="1440"/>
</wire>
<wire>
<p1 x="480" y="1480"/>
<p2 x="480" y="1560"/>
</wire>
<wire>
<p1 x="480" y="1420"/>
<p2 x="480" y="1440"/>
</wire>
<wire>
<p1 x="240" y="1480"/>
<p2 x="240" y="1560"/>
</wire>
<wire>
<p1 x="240" y="1420"/>
<p2 x="240" y="1440"/>
</wire>
<wire>
<p1 x="80" y="1480"/>
<p2 x="80" y="1500"/>
</wire>
<wire>
<p1 x="80" y="1400"/>
<p2 x="80" y="1440"/>
</wire>
<wire>
<p1 x="400" y="1340"/>
<p2 x="400" y="1440"/>
</wire>
<wire>
<p1 x="400" y="1440"/>
<p2 x="400" y="1500"/>
</wire>
<wire>
<p1 x="520" y="1340"/>
<p2 x="520" y="1500"/>
</wire>
<wire>
<p1 x="360" y="1480"/>
<p2 x="360" y="1560"/>
</wire>
<wire>
<p1 x="360" y="1420"/>
<p2 x="360" y="1440"/>
</wire>
<wire>
<p1 x="200" y="1480"/>
<p2 x="200" y="1500"/>
</wire>
<wire>
<p1 x="200" y="1400"/>
<p2 x="200" y="1440"/>
</wire>
<wire>
<p1 x="440" y="1400"/>
<p2 x="440" y="1440"/>
</wire>
<wire>
<p1 x="440" y="1480"/>
<p2 x="440" y="1500"/>
</wire>
<wire>
<p1 x="280" y="1340"/>
<p2 x="280" y="1440"/>
</wire>
<wire>
<p1 x="280" y="1440"/>
<p2 x="280" y="1500"/>
</wire>
<wire>
<p1 x="120" y="1480"/>
<p2 x="120" y="1560"/>
</wire>
<wire>
<p1 x="120" y="1420"/>
<p2 x="120" y="1440"/>
</wire>
</wires>
<measurementOrdering/>
</circuit>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<attributes/>
<visualElements>
<visualElement>
<elementName>Ground</elementName>
@ -1205,22 +1206,12 @@
</visualElement>
<visualElement>
<elementName>FGNFET</elementName>
<elementAttributes>
<entry>
<string>Blown</string>
<boolean>true</boolean>
</entry>
</elementAttributes>
<elementAttributes/>
<pos x="440" y="1120"/>
</visualElement>
<visualElement>
<elementName>FGNFET</elementName>
<elementAttributes>
<entry>
<string>Blown</string>
<boolean>true</boolean>
</entry>
</elementAttributes>
<elementAttributes/>
<pos x="500" y="1120"/>
</visualElement>
<visualElement>
@ -5881,4 +5872,5 @@ repeat(8) 1 0 C bits(3,7-n)
<p2 x="1140" y="1440"/>
</wire>
</wires>
<measurementOrdering/>
</circuit>