| 1598 | } |
| 1599 | |
| 1600 | bool InputQuery::constructMaxLayer( NLR::NetworkLevelReasoner *nlr, |
| 1601 | Map<unsigned, unsigned> &handledVariableToLayer, |
| 1602 | unsigned newLayerIndex, |
| 1603 | Set<PiecewiseLinearConstraint *> &handledPLConstraints ) |
| 1604 | { |
| 1605 | INPUT_QUERY_LOG( "Attempting to construct MaxLayer..." ); |
| 1606 | struct NeuronInformation |
| 1607 | { |
| 1608 | public: |
| 1609 | NeuronInformation( unsigned variable, |
| 1610 | unsigned neuron, |
| 1611 | const List<unsigned> &sourceVariables ) |
| 1612 | : _variable( variable ) |
| 1613 | , _neuron( neuron ) |
| 1614 | , _sourceVariables( sourceVariables ) |
| 1615 | { |
| 1616 | } |
| 1617 | |
| 1618 | unsigned _variable; |
| 1619 | unsigned _neuron; |
| 1620 | List<unsigned> _sourceVariables; |
| 1621 | }; |
| 1622 | |
| 1623 | List<NeuronInformation> newNeurons; |
| 1624 | |
| 1625 | // Look for Maxes where all the element variables have already been handled |
| 1626 | const List<PiecewiseLinearConstraint *> &plConstraints = getPiecewiseLinearConstraints(); |
| 1627 | |
| 1628 | unsigned currentSourceLayer = 0; |
| 1629 | for ( const auto &plc : plConstraints ) |
| 1630 | { |
| 1631 | if ( handledPLConstraints.exists( plc ) ) |
| 1632 | continue; |
| 1633 | |
| 1634 | // Only consider Max |
| 1635 | if ( plc->getType() != MAX ) |
| 1636 | continue; |
| 1637 | |
| 1638 | const MaxConstraint *max = (const MaxConstraint *)plc; |
| 1639 | |
| 1640 | // Have all elements been handled? |
| 1641 | // Have all input variables been handled? |
| 1642 | bool missingInput = false; |
| 1643 | bool sourceLayerDiffers = false; |
| 1644 | for ( const auto &input : max->getElements() ) |
| 1645 | { |
| 1646 | if ( !handledVariableToLayer.exists( input ) ) |
| 1647 | { |
| 1648 | missingInput = true; |
| 1649 | break; |
| 1650 | } |
| 1651 | else if ( _ensureSameSourceLayerInNLR && newNeurons.size() && |
| 1652 | handledVariableToLayer[input] != currentSourceLayer ) |
| 1653 | { |
| 1654 | sourceLayerDiffers = true; |
| 1655 | break; |
| 1656 | } |
| 1657 | } |
nothing calls this directly
no test coverage detected