Gruß zum Sonntag,
hier mal eine UDF zum lösen einer PLA-Matrix. Wer Lust und Laune hat, der kann gerne einen Simulator schreiben, mit dem man PLAs bauen kann und entsprechend die Ergebnisse durchkalkuliert und ausgibt.
Da Dokumentation nicht ganz meine Stärke ist, versuche ich mich hier mal so klar wie möglich auszudrücken.
Der erste Parameter ist ein PLA-Array, 3-Dimensional.
Die erste Dimension des Arrays bestimmt die Anzahl der Reihen des PLA-Feldes.
Die zweite Dimension des Arrays bestimmt die Anzahl der Spalten des PLA-Feldes.
Die dritte Dimension besitzt 3 Elemente, welche die Eigenschaften & Zustände des PLA-Feldes angeben:
[0] ist das Gatter, welches dieses Feld vertritt.
[1] ist das X, welches dieses Feld annimmt
[2] ist das Y, welches dieses Feld annimmt.
Zur Initialisierung des Arrays wird das Feld mit [Zeilen] x [Spalten] aufgespannt und danach die Gatter belegt, also [0] einer Zeile x Spalte.
Der zweite Parameter ist ein eindimensionales Array, in welchem ihr die Zustände eurer Eingabevariablen gespeichert sind. Hier entspricht die erste Zeile auch der ersten Zeile eures Gatters (in der Pdf: [0] = x, [1] = y, [2] = z).
Die solvePLAMatrix Funktion errechnet selbst, wo sich die UND und ODER Ebene voneinander trennt. Daher muss lediglich die Matrix sowie die Eingabevariablen übergeben werden.
Als Ergebnis erhaltet ihr einen 1-Dimensionalen Array zurück, der folgenden Aufbau hat:
[0...Anzahl der Eingabevariablen] = die Rückgabewerte der UND-Zeilen, also im Prinzip x1, x2, x3, x...
[/\ + 1] = "---" - Einfach nur ein Trennstrich, falls man die Ergebnisse durchlaufen will ohne die Matrix zu kennen
[/\ + 1..Größe der ODER-Zeilen] = das Ergebnis der Funktion f1, f2, f3, ...
[/\ + 1] = "---" wieder ein Trennstrich, falls man die Ergebnisse der Funktionen durchlaufen will ohne die Matrix zu kennen
[/\ + 1..Anzahl der Spalten] = Die Ausgabe der einzelnen Konjunktionen
Viel Gerede, vermutlich nicht ganz einleuchtend, also habe ich mal was kleines aufgemalt um es verständlich(er) zu machen:
[Blockierte Grafik: http://i.epvpimg.com/xCFxd.png]
UDF:
plaMatrixSolver.au3
Func solvePLAMatrix($inputMatrixPLA, $aInputs)
Local $matrixPLA = $inputMatrixPLA
Local $outputArray[UBound($matrixPLA) + UBound($matrixPLA, 2) + 2]
Local $actualPLAArray
For $actualRow = 0 To UBound($aInputs) - 1 Step 1
$actualPLAArray = getPLAValues($matrixPLA[$actualRow][0][0], ($actualRow = 0 ? 1 : $matrixPLA[$actualRow - 1][0][1]), $aInputs[$actualRow])
$matrixPLA[$actualRow][0][1] = $actualPLAArray[0]
$matrixPLA[$actualRow][0][2] = $actualPLAArray[1]
If ($actualRow = 0) Then
For $actualColumn = 1 To UBound($matrixPLA, 2) - 1 Step 1
$actualPLAArray = getPLAValues($matrixPLA[$actualRow][$actualColumn][0], 1, $matrixPLA[$actualRow][$actualColumn - 1][2])
$matrixPLA[$actualRow][$actualColumn][1] = $actualPLAArray[0]
$matrixPLA[$actualRow][$actualColumn][2] = $actualPLAArray[1]
Next
Else
For $actualColumn = 1 To UBound($matrixPLA, 2) - 1 Step 1
$actualPLAArray = getPLAValues($matrixPLA[$actualRow][$actualColumn][0], $matrixPLA[$actualRow - 1][$actualColumn][1], $matrixPLA[$actualRow][$actualColumn - 1][2])
$matrixPLA[$actualRow][$actualColumn][1] = $actualPLAArray[0]
$matrixPLA[$actualRow][$actualColumn][2] = $actualPLAArray[1]
Next
EndIf
$outputArray[$actualRow] = $matrixPLA[$actualRow][UBound($matrixPLA, 2) - 1][2]
Next
$outPutArray[UBound($aInputs)] = "---"
For $actualRow = UBound($aInputs) To UBound($matrixPLA) - 1 Step 1
$actualPLAArray = getPLAValues($matrixPLA[$actualRow][0][0], $matrixPLA[$actualRow - 1][0][1], 0)
$matrixPLA[$actualRow][0][1] = $actualPLAArray[0]
$matrixPLA[$actualRow][0][2] = $actualPLAArray[1]
For $actualColumn = 1 To UBound($matrixPLA, 2) - 1 Step 1
$actualPLAArray = getPLAValues($matrixPLA[$actualRow][$actualColumn][0], $matrixPLA[$actualRow - 1][$actualColumn][1], $matrixPLA[$actualRow][$actualColumn - 1][2])
$matrixPLA[$actualRow][$actualColumn][1] = $actualPLAArray[0]
$matrixPLA[$actualRow][$actualColumn][2] = $actualPLAArray[1]
Next
$outputArray[$actualRow + 1] = $matrixPLA[$actualRow][UBound($matrixPLA, 2) - 1][2]
Next
$outputArray[UBound($matrixPLA) + 1] = "---"
For $actualColumn = 0 To UBound($matrixPLA, 2) - 1 Step 1
$outputArray[UBound($matrixPLA) + 2 + $actualColumn] = $matrixPLA[UBound($matrixPLA) - 1][$actualColumn][1]
Next
Return $outputArray
EndFunc ;==>solvePLAMatrix
;uvArray[0] = v
;uvArray[1] = u
Func getPLAValues($typePLA, $x, $y)
Local $uvArray[3]
$uvArray[2] = $typePLA & "|" & $x & "|" & $y
Local Const $IDENTER = 0
Local Const $ADDER = 1
Local Const $MULTIPLER = 2
Local Const $NEGAT_MULTIPLER = 3
Switch $typePLA
Case $IDENTER
$uvArray[0] = $x
$uvArray[1] = $y
Case $ADDER
$uvArray[0] = $x
$uvArray[1] = ($x Or $y) * 1
Case $MULTIPLER
$uvArray[0] = $x * $y
$uvArray[1] = $y
Case $NEGAT_MULTIPLER
$uvArray[0] = ($x And (Not $y)) * 1
$uvArray[1] = $y
EndSwitch
Return $uvArray
EndFunc ;==>getPLAValues
Alles anzeigen
Damit es vielleicht einleuchtend wird, wie alles aufgebaut ist, hier auch nochmal ein Script welches es für das Beispiel auf dem Papier zeigt:
Beispiel.au3
#include <Array.au3>
#include "plaMatrixSolver.au3"
;-1 ist dem Aufbau der For geschuldet, ist natürlich
;kein korrekter Zustand für ein Binäres Array
Local $Binarys[4] = [0, 0, 0, -1]
Local $plaMatrix[5][2][3]
$plaMatrix[0][0][0] = 0
$plaMatrix[0][1][0] = 3
$plaMatrix[1][0][0] = 3
$plaMatrix[1][1][0] = 2
$plaMatrix[2][0][0] = 3
$plaMatrix[2][1][0] = 0
$plaMatrix[3][0][0] = 0
$plaMatrix[3][1][0] = 3
$plaMatrix[4][0][0] = 1
$plaMatrix[4][1][0] = 1
For $i = 0 To 15 Step 1
$Binarys = addOneBinary($Binarys)
_ArrayDisplay(solvePLAMatrix($plaMatrix, $Binarys))
Next
Func addOneBinary($arrayBinary)
Local $newBinary = $arrayBinary
$newBinary[UBound($newBinary) - 1] += 1
For $i = UBound($newBinary) - 1 To 0 Step -1 ;Von rechts gelesen
If ($newBinary[$i] == 2) Then
$newBinary[$i] = 0
If ($i - 1 >= 0) Then
$newBinary[$i - 1] += 1
EndIf
EndIf
Next
Return $newBinary
EndFunc ;==>addOneBinary
Alles anzeigen
Wer Lust und Laune hat kann ja einen Simulator schreiben, mit dem man die PLAs sowie Eingabewerte direkt in der GUI erstellen kann und sich die Ergebnisse ausgeben lassen kann.
Grüße - Xorianator