Last active
December 3, 2018 13:30
-
-
Save Bert-Proesmans/82e7a1d5769ff779d6fdf05e98a31d52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* PASS - REDUCE DISTANCE BETWEEN ROWS; BUILD PATHS OF CONNECTIONS */ | |
// Depth first traversal strategy | |
$processedRows = array(); | |
$rowStack = array(); | |
$n = 0; | |
$lastRowCount = count($rowList); | |
/** @var RowModel $rowItem */ | |
while (($rowItem = array_shift($rowList)) !== null) { | |
// Make sure to keep the stack hydrated. | |
array_push($rowStack, $rowItem); | |
/** @var RowModel $rowCurrent */ | |
while (($rowCurrent = array_pop($rowStack)) !== null) { | |
// We can only be sure from the current row that it's valid to be pushed into the output model. | |
array_push($processedRows, $rowCurrent); | |
$listCountTest = count($rowList); | |
echo "\nTEST LIST COUNT: $listCountTest\n"; | |
/* | |
* Note: For $row->from_point = A, $row->to_point = B. | |
* We reduce the distance between connections (group them) when connections either: | |
* - start at the same point A; | |
* - end at the same point B. | |
* The result looks similar to the following table: | |
* | |
* _ | _____ | |
* 0 | A -> B -- Right grouped | |
* 1 | C -> B | |
* 2 | D -> B | |
* 3 | E -> B -- Left grouped | |
* 4 | E -> F | |
* 5 | G -> F | |
* 4 | Y -> Z | |
* ... | |
* | |
* WARN; Groups must be created from both FROM (LEFT) and TO (RIGHT) points! | |
*/ | |
// WARN; There might be mismatches between SOURCE and TARGET rowKeys, this is due to input errors. | |
// eg: the following rows encode the same connection: | |
// AX:4 -> BX:3 | |
// BX.A:3 -> AX:4 | |
// ^ notice the mismatch in exact comparison | |
// | |
$sourcePointKey = PointModel::generatePointKey($rowCurrent); | |
$reversedConnection = $connectionModel->getOppositeWire($rowCurrent); | |
$targetPointKey = PointModel::generatePointKey($reversedConnection); | |
// Group all connections relating to the starting point. | |
// WARN; This is necessary because we have no constraint on the sort-order of the source list. | |
$sourceConnections = array_filter($rowList, function ($item) use ($sourcePointKey) { | |
// NOTE; This will never be the current row itself, since it's already removed. | |
$test_point_key = PointModel::generatePointKey($item); | |
return $test_point_key === $sourcePointKey; | |
}); | |
// Group all connections relating to the end point. | |
$targetConnections = array_filter($rowList, function ($item) use ($targetPointKey, $connectionModel) { | |
// Transform all A' -> B' connections into B' -> A'. | |
$opposite_wire = $connectionModel->getOppositeWire($item); | |
// Check if B == B'. | |
$test_point_key = PointModel::generatePointKey($opposite_wire); | |
return $test_point_key === $targetPointKey; | |
}); | |
// NOTE; Order is important here, because we're using a stack (push/pop) | |
$relevantRows = array_reverse($sourceConnections, TRUE) + array_reverse($targetConnections, TRUE); | |
echo "FOR KEY: $sourcePointKey - $targetPointKey\n"; | |
$relevantRowCount = count($relevantRows); | |
echo "RELEVANT ROWS: $relevantRowCount\n"; | |
// var_export($relevantRows); | |
$indicesForRemoval = array_flip(array_keys($relevantRows)); | |
var_export($relevantRows); | |
// Remove the selected rows from the source list.. | |
$rowList = array_diff_key($rowList, array_flip($indicesForRemoval)); | |
echo "\nLAST ROWCOUNT: $lastRowCount\n"; | |
$newCount = count($rowList); | |
echo "CURRENT ROWCOUNT: $newCount\n"; | |
$lastRowCount = $newCount; | |
// and add them to the row stack for further processing. | |
$rowStack = array_merge($rowStack, $relevantRows); | |
if (++$n > 5) { | |
echo "BREAK INNER\n"; | |
break; | |
} | |
} | |
echo "BREAK OUTER\n"; | |
break; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PRE-PROCESS | |
TEST LIST COUNT: 107 | |
FOR KEY: A10:R - K1:30 | |
RELEVANT ROWS: 2 | |
array ( | |
15 => | |
RowModel::__set_state(array( | |
'conn_id' => '53', | |
'component_group' => 'VERMOGENSCHEMA', | |
'from_component_code' => 'C1', | |
'to_component_code' => 'K1', | |
'from_point' => 'G', | |
'to_point' => '30', | |
'from_component_name' => 'REGELAAR', | |
'to_component_name' => 'RELAIS', | |
'from_huls' => 'NIET-GEÏSOLEERD SCH.', | |
'to_huls' => 'VR KABELSCH.', | |
'wir_kind' => 'W', | |
'wir_diam_inch' => 1.0, | |
'wir_length_mm' => false, | |
'cable_kind' => '', | |
'cable_diam_inch' => false, | |
)), | |
6 => | |
RowModel::__set_state(array( | |
'conn_id' => '52', | |
'component_group' => 'KABELBOOM', | |
'from_component_code' => 'A6', | |
'to_component_code' => 'K1', | |
'from_point' => '1', | |
'to_point' => '30', | |
'from_component_name' => 'SOLENOID', | |
'to_component_name' => 'RELAIS', | |
'from_huls' => 'NIET-GEÏSOLEERD SCH.', | |
'to_huls' => 'VR KABELSCH.', | |
'wir_kind' => 'R', | |
'wir_diam_inch' => 1.0, | |
'wir_length_mm' => false, | |
'cable_kind' => '', | |
'cable_diam_inch' => false, | |
)), | |
) | |
LAST ROWCOUNT: 108 | |
CURRENT ROWCOUNT: 105 | |
TEST LIST COUNT: 105 | |
FOR KEY: A6:1 - K1:30 | |
RELEVANT ROWS: 2 | |
array ( | |
6 => | |
RowModel::__set_state(array( | |
'conn_id' => '52', | |
'component_group' => 'KABELBOOM', | |
'from_component_code' => 'A6', | |
'to_component_code' => 'K1', | |
'from_point' => '1', | |
'to_point' => '30', | |
'from_component_name' => 'SOLENOID', | |
'to_component_name' => 'RELAIS', | |
'from_huls' => 'NIET-GEÏSOLEERD SCH.', | |
'to_huls' => 'VR KABELSCH.', | |
'wir_kind' => 'R', | |
'wir_diam_inch' => 1.0, | |
'wir_length_mm' => false, | |
'cable_kind' => '', | |
'cable_diam_inch' => false, | |
)), | |
15 => | |
RowModel::__set_state(array( | |
'conn_id' => '53', | |
'component_group' => 'VERMOGENSCHEMA', | |
'from_component_code' => 'C1', | |
'to_component_code' => 'K1', | |
'from_point' => 'G', | |
'to_point' => '30', | |
'from_component_name' => 'REGELAAR', | |
'to_component_name' => 'RELAIS', | |
'from_huls' => 'NIET-GEÏSOLEERD SCH.', | |
'to_huls' => 'VR KABELSCH.', | |
'wir_kind' => 'W', | |
'wir_diam_inch' => 1.0, | |
'wir_length_mm' => false, | |
'cable_kind' => '', | |
'cable_diam_inch' => false, | |
)), | |
) | |
LAST ROWCOUNT: 105 | |
CURRENT ROWCOUNT: 105 | |
TEST LIST COUNT: 105 | |
FOR KEY: C1:G - K1:30 | |
RELEVANT ROWS: 2 | |
array ( | |
15 => | |
RowModel::__set_state(array( | |
'conn_id' => '53', | |
'component_group' => 'VERMOGENSCHEMA', | |
'from_component_code' => 'C1', | |
'to_component_code' => 'K1', | |
'from_point' => 'G', | |
'to_point' => '30', | |
'from_component_name' => 'REGELAAR', | |
'to_component_name' => 'RELAIS', | |
'from_huls' => 'NIET-GEÏSOLEERD SCH.', | |
'to_huls' => 'VR KABELSCH.', | |
'wir_kind' => 'W', | |
'wir_diam_inch' => 1.0, | |
'wir_length_mm' => false, | |
'cable_kind' => '', | |
'cable_diam_inch' => false, | |
)), | |
6 => | |
RowModel::__set_state(array( | |
'conn_id' => '52', | |
'component_group' => 'KABELBOOM', | |
'from_component_code' => 'A6', | |
'to_component_code' => 'K1', | |
'from_point' => '1', | |
'to_point' => '30', | |
'from_component_name' => 'SOLENOID', | |
'to_component_name' => 'RELAIS', | |
'from_huls' => 'NIET-GEÏSOLEERD SCH.', | |
'to_huls' => 'VR KABELSCH.', | |
'wir_kind' => 'R', | |
'wir_diam_inch' => 1.0, | |
'wir_length_mm' => false, | |
'cable_kind' => '', | |
'cable_diam_inch' => false, | |
)), | |
) | |
LAST ROWCOUNT: 105 | |
CURRENT ROWCOUNT: 105 | |
TEST LIST COUNT: 105 | |
FOR KEY: A6:1 - K1:30 | |
RELEVANT ROWS: 2 | |
array ( | |
6 => | |
RowModel::__set_state(array( | |
'conn_id' => '52', | |
'component_group' => 'KABELBOOM', | |
'from_component_code' => 'A6', | |
'to_component_code' => 'K1', | |
'from_point' => '1', | |
'to_point' => '30', | |
'from_component_name' => 'SOLENOID', | |
'to_component_name' => 'RELAIS', | |
'from_huls' => 'NIET-GEÏSOLEERD SCH.', | |
'to_huls' => 'VR KABELSCH.', | |
'wir_kind' => 'R', | |
'wir_diam_inch' => 1.0, | |
'wir_length_mm' => false, | |
'cable_kind' => '', | |
'cable_diam_inch' => false, | |
)), | |
15 => | |
RowModel::__set_state(array( | |
'conn_id' => '53', | |
'component_group' => 'VERMOGENSCHEMA', | |
'from_component_code' => 'C1', | |
'to_component_code' => 'K1', | |
'from_point' => 'G', | |
'to_point' => '30', | |
'from_component_name' => 'REGELAAR', | |
'to_component_name' => 'RELAIS', | |
'from_huls' => 'NIET-GEÏSOLEERD SCH.', | |
'to_huls' => 'VR KABELSCH.', | |
'wir_kind' => 'W', | |
'wir_diam_inch' => 1.0, | |
'wir_length_mm' => false, | |
'cable_kind' => '', | |
'cable_diam_inch' => false, | |
)), | |
) | |
LAST ROWCOUNT: 105 | |
CURRENT ROWCOUNT: 105 | |
TEST LIST COUNT: 105 | |
FOR KEY: C1:G - K1:30 | |
RELEVANT ROWS: 2 | |
array ( | |
15 => | |
RowModel::__set_state(array( | |
'conn_id' => '53', | |
'component_group' => 'VERMOGENSCHEMA', | |
'from_component_code' => 'C1', | |
'to_component_code' => 'K1', | |
'from_point' => 'G', | |
'to_point' => '30', | |
'from_component_name' => 'REGELAAR', | |
'to_component_name' => 'RELAIS', | |
'from_huls' => 'NIET-GEÏSOLEERD SCH.', | |
'to_huls' => 'VR KABELSCH.', | |
'wir_kind' => 'W', | |
'wir_diam_inch' => 1.0, | |
'wir_length_mm' => false, | |
'cable_kind' => '', | |
'cable_diam_inch' => false, | |
)), | |
6 => | |
RowModel::__set_state(array( | |
'conn_id' => '52', | |
'component_group' => 'KABELBOOM', | |
'from_component_code' => 'A6', | |
'to_component_code' => 'K1', | |
'from_point' => '1', | |
'to_point' => '30', | |
'from_component_name' => 'SOLENOID', | |
'to_component_name' => 'RELAIS', | |
'from_huls' => 'NIET-GEÏSOLEERD SCH.', | |
'to_huls' => 'VR KABELSCH.', | |
'wir_kind' => 'R', | |
'wir_diam_inch' => 1.0, | |
'wir_length_mm' => false, | |
'cable_kind' => '', | |
'cable_diam_inch' => false, | |
)), | |
) | |
LAST ROWCOUNT: 105 | |
CURRENT ROWCOUNT: 105 | |
TEST LIST COUNT: 105 | |
FOR KEY: A6:1 - K1:30 | |
RELEVANT ROWS: 2 | |
array ( | |
6 => | |
RowModel::__set_state(array( | |
'conn_id' => '52', | |
'component_group' => 'KABELBOOM', | |
'from_component_code' => 'A6', | |
'to_component_code' => 'K1', | |
'from_point' => '1', | |
'to_point' => '30', | |
'from_component_name' => 'SOLENOID', | |
'to_component_name' => 'RELAIS', | |
'from_huls' => 'NIET-GEÏSOLEERD SCH.', | |
'to_huls' => 'VR KABELSCH.', | |
'wir_kind' => 'R', | |
'wir_diam_inch' => 1.0, | |
'wir_length_mm' => false, | |
'cable_kind' => '', | |
'cable_diam_inch' => false, | |
)), | |
15 => | |
RowModel::__set_state(array( | |
'conn_id' => '53', | |
'component_group' => 'VERMOGENSCHEMA', | |
'from_component_code' => 'C1', | |
'to_component_code' => 'K1', | |
'from_point' => 'G', | |
'to_point' => '30', | |
'from_component_name' => 'REGELAAR', | |
'to_component_name' => 'RELAIS', | |
'from_huls' => 'NIET-GEÏSOLEERD SCH.', | |
'to_huls' => 'VR KABELSCH.', | |
'wir_kind' => 'W', | |
'wir_diam_inch' => 1.0, | |
'wir_length_mm' => false, | |
'cable_kind' => '', | |
'cable_diam_inch' => false, | |
)), | |
) | |
LAST ROWCOUNT: 105 | |
CURRENT ROWCOUNT: 105 | |
BREAK INNER | |
BREAK OUTER |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment