MCPcopy Create free account
hub / github.com/NeuralNetworkVerification/Marabou / generateQuery

Method generateQuery

src/input_parsers/BerkeleyParser.cpp:27–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27void BerkeleyParser::generateQuery( InputQuery &inputQuery )
28{
29 _berkeleyNeuralNetwork.parseFile();
30
31 // The total number of variables required for the encoding is computed as follows:
32 // 1. One for every variable that's part of the query
33
34 unsigned numberOfVariables = _berkeleyNeuralNetwork.getNumVariables();
35
36 printf( "Total number of Marabou variables: %u\n", numberOfVariables );
37
38 inputQuery.setNumberOfVariables( numberOfVariables );
39
40 // Set bounds for inputs. Currently just [0,1]
41 Set<unsigned> inputVariables = _berkeleyNeuralNetwork.getInputVariables();
42 for ( const auto &it : inputVariables )
43 {
44 double min = 0.0;
45 double max = 1.0;
46
47 inputQuery.setLowerBound( it, min );
48 inputQuery.setUpperBound( it, max );
49 }
50
51 // Declare relu pairs and set bounds
52 Map<unsigned, unsigned> fToB = _berkeleyNeuralNetwork.getFToB();
53 for ( const auto &it : fToB )
54 {
55 unsigned f = it.first;
56 unsigned b = it.second;
57
58 PiecewiseLinearConstraint *relu = new ReluConstraint( b, f );
59 inputQuery.addPiecewiseLinearConstraint( relu );
60
61 inputQuery.setLowerBound( f, 0.0 );
62 inputQuery.setUpperBound( f, FloatUtils::infinity() );
63
64 inputQuery.setLowerBound( b, FloatUtils::negativeInfinity() );
65 inputQuery.setUpperBound( b, FloatUtils::infinity() );
66 }
67
68 // Create the equations
69 List<BerkeleyNeuralNetwork::Equation> equations = _berkeleyNeuralNetwork.getEquations();
70 for ( const auto &berkeleyEquation : equations )
71 {
72 Equation marabouEquation;
73
74 // The Berkeley equation is of the form y = x1 + x2 + x3 + c.
75 // The Marabou equation is of the form y - x1 - x2 - x3 = c.
76 unsigned lhs = berkeleyEquation._lhs;
77 marabouEquation.addAddend( 1.0, lhs );
78
79 for ( const auto &rhs : berkeleyEquation._rhs )
80 {
81 unsigned var = rhs._var;
82 double coefficient = rhs._coefficient;
83 marabouEquation.addAddend( -coefficient, var );
84 }

Callers

nothing calls this directly

Calls 12

parseFileMethod · 0.80
getNumVariablesMethod · 0.80
setNumberOfVariablesMethod · 0.80
getFToBMethod · 0.80
getEquationsMethod · 0.80
getInputVariablesMethod · 0.45
setLowerBoundMethod · 0.45
setUpperBoundMethod · 0.45
addAddendMethod · 0.45
setScalarMethod · 0.45
addEquationMethod · 0.45

Tested by

no test coverage detected