| 1206 | } |
| 1207 | |
| 1208 | bool InputQuery::constructRoundLayer( NLR::NetworkLevelReasoner *nlr, |
| 1209 | Map<unsigned, unsigned> &handledVariableToLayer, |
| 1210 | unsigned newLayerIndex, |
| 1211 | Set<NonlinearConstraint *> &handledNLConstraints ) |
| 1212 | { |
| 1213 | INPUT_QUERY_LOG( "Attempting to construct RoundLayer..." ); |
| 1214 | struct NeuronInformation |
| 1215 | { |
| 1216 | public: |
| 1217 | NeuronInformation( unsigned variable, unsigned neuron, unsigned sourceVariable ) |
| 1218 | : _variable( variable ) |
| 1219 | , _neuron( neuron ) |
| 1220 | , _sourceVariable( sourceVariable ) |
| 1221 | { |
| 1222 | } |
| 1223 | |
| 1224 | unsigned _variable; |
| 1225 | unsigned _neuron; |
| 1226 | unsigned _sourceVariable; |
| 1227 | }; |
| 1228 | |
| 1229 | List<NeuronInformation> newNeurons; |
| 1230 | |
| 1231 | // Look for ReLUs where all b variables have already been handled |
| 1232 | const List<NonlinearConstraint *> &nlConstraints = getNonlinearConstraints(); |
| 1233 | |
| 1234 | unsigned currentSourceLayer = 0; |
| 1235 | for ( const auto &nlc : nlConstraints ) |
| 1236 | { |
| 1237 | if ( handledNLConstraints.exists( nlc ) ) |
| 1238 | continue; |
| 1239 | |
| 1240 | // Only consider Rounds |
| 1241 | if ( nlc->getType() != ROUND ) |
| 1242 | continue; |
| 1243 | |
| 1244 | const RoundConstraint *round = (const RoundConstraint *)nlc; |
| 1245 | |
| 1246 | // Has the b variable been handled? |
| 1247 | unsigned b = round->getB(); |
| 1248 | if ( !handledVariableToLayer.exists( b ) || |
| 1249 | ( _ensureSameSourceLayerInNLR && !newNeurons.empty() && |
| 1250 | handledVariableToLayer[b] != currentSourceLayer ) ) |
| 1251 | continue; |
| 1252 | |
| 1253 | // If the f variable has also been handled, ignore this constraint |
| 1254 | unsigned f = round->getF(); |
| 1255 | if ( handledVariableToLayer.exists( f ) ) |
| 1256 | continue; |
| 1257 | |
| 1258 | // B has been handled, f hasn't. Add f |
| 1259 | if ( _ensureSameSourceLayerInNLR && newNeurons.empty() ) |
| 1260 | currentSourceLayer = handledVariableToLayer[b]; |
| 1261 | newNeurons.append( NeuronInformation( f, newNeurons.size(), b ) ); |
| 1262 | handledNLConstraints.insert( nlc ); |
| 1263 | } |
| 1264 | |
| 1265 | // No neurons found for the new layer |
nothing calls this directly
no test coverage detected