| 1401 | } |
| 1402 | |
| 1403 | bool InputQuery::constructAbsoluteValueLayer( |
| 1404 | NLR::NetworkLevelReasoner *nlr, |
| 1405 | Map<unsigned, unsigned> &handledVariableToLayer, |
| 1406 | unsigned newLayerIndex, |
| 1407 | Set<PiecewiseLinearConstraint *> &handledPLConstraints ) |
| 1408 | { |
| 1409 | INPUT_QUERY_LOG( "Attempting to construct AbsoluteValueLayer..." ); |
| 1410 | struct NeuronInformation |
| 1411 | { |
| 1412 | public: |
| 1413 | NeuronInformation( unsigned variable, unsigned neuron, unsigned sourceVariable ) |
| 1414 | : _variable( variable ) |
| 1415 | , _neuron( neuron ) |
| 1416 | , _sourceVariable( sourceVariable ) |
| 1417 | { |
| 1418 | } |
| 1419 | |
| 1420 | unsigned _variable; |
| 1421 | unsigned _neuron; |
| 1422 | unsigned _sourceVariable; |
| 1423 | }; |
| 1424 | |
| 1425 | List<NeuronInformation> newNeurons; |
| 1426 | |
| 1427 | // Look for ABSOLUTE_VALUEs where all b variables have already been handled |
| 1428 | const List<PiecewiseLinearConstraint *> &plConstraints = getPiecewiseLinearConstraints(); |
| 1429 | |
| 1430 | unsigned currentSourceLayer = 0; |
| 1431 | for ( const auto &plc : plConstraints ) |
| 1432 | { |
| 1433 | if ( handledPLConstraints.exists( plc ) ) |
| 1434 | continue; |
| 1435 | |
| 1436 | // Only consider ABSOLUTE_VALUE |
| 1437 | if ( plc->getType() != ABSOLUTE_VALUE ) |
| 1438 | continue; |
| 1439 | |
| 1440 | const AbsoluteValueConstraint *abs = (const AbsoluteValueConstraint *)plc; |
| 1441 | |
| 1442 | // Has the b variable been handled? |
| 1443 | unsigned b = abs->getB(); |
| 1444 | if ( !handledVariableToLayer.exists( b ) || |
| 1445 | ( _ensureSameSourceLayerInNLR && !newNeurons.empty() && |
| 1446 | handledVariableToLayer[b] != currentSourceLayer ) ) |
| 1447 | continue; |
| 1448 | |
| 1449 | // If the f variable has also been handled, ignore this constraint |
| 1450 | unsigned f = abs->getF(); |
| 1451 | if ( handledVariableToLayer.exists( f ) ) |
| 1452 | continue; |
| 1453 | |
| 1454 | // B has been handled, f hasn't. Add f |
| 1455 | if ( _ensureSameSourceLayerInNLR && newNeurons.empty() ) |
| 1456 | currentSourceLayer = handledVariableToLayer[b]; |
| 1457 | newNeurons.append( NeuronInformation( f, newNeurons.size(), b ) ); |
| 1458 | nlr->addConstraintInTopologicalOrder( plc ); |
| 1459 | handledPLConstraints.insert( plc ); |
| 1460 | } |
nothing calls this directly
no test coverage detected