| 877 | } |
| 878 | |
| 879 | bool InputQuery::constructWeighedSumLayer( NLR::NetworkLevelReasoner *nlr, |
| 880 | Map<unsigned, unsigned> &handledVariableToLayer, |
| 881 | unsigned newLayerIndex, |
| 882 | Set<unsigned> &handledEquations ) |
| 883 | { |
| 884 | INPUT_QUERY_LOG( "Attempting to construct weightedSumLayer..." ); |
| 885 | struct NeuronInformation |
| 886 | { |
| 887 | public: |
| 888 | NeuronInformation( unsigned variable, unsigned neuron, const Equation *eq ) |
| 889 | : _variable( variable ) |
| 890 | , _neuron( neuron ) |
| 891 | , _eq( eq ) |
| 892 | { |
| 893 | } |
| 894 | |
| 895 | NeuronInformation() |
| 896 | : _eq( NULL ) |
| 897 | { |
| 898 | } |
| 899 | |
| 900 | unsigned _variable; |
| 901 | unsigned _neuron; |
| 902 | const Equation *_eq; |
| 903 | }; |
| 904 | |
| 905 | List<NeuronInformation> newNeurons; |
| 906 | |
| 907 | // Look for equations where all variables except one have already been handled |
| 908 | const List<Equation> &equations = getEquations(); |
| 909 | unsigned index = 0; |
| 910 | for ( const auto &eq : equations ) |
| 911 | { |
| 912 | if ( handledEquations.exists( index++ ) ) |
| 913 | continue; |
| 914 | |
| 915 | // Only consider equalities |
| 916 | if ( eq._type != Equation::EQ ) |
| 917 | continue; |
| 918 | |
| 919 | List<unsigned> eqVariables = eq.getListParticipatingVariables(); |
| 920 | auto it = eqVariables.begin(); |
| 921 | while ( it != eqVariables.end() ) |
| 922 | { |
| 923 | if ( handledVariableToLayer.exists( *it ) ) |
| 924 | it = eqVariables.erase( it ); |
| 925 | else |
| 926 | ++it; |
| 927 | } |
| 928 | |
| 929 | if ( eqVariables.size() == 1 ) |
| 930 | { |
| 931 | // Add the surviving variable to the new layer |
| 932 | newNeurons.append( NeuronInformation( *eqVariables.begin(), newNeurons.size(), &eq ) ); |
| 933 | handledEquations.insert( index - 1 ); |
| 934 | } |
| 935 | } |
| 936 |
nothing calls this directly
no test coverage detected