MCPcopy Create free account
hub / github.com/avaneev/biteopt / main

Function main

constr3.cpp:106–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104};
105
106int main()
107{
108 CBiteRnd rnd;
109 rnd.init( 1 ); // Needs to be seeded with different values on each run.
110
111 int i;
112
113 CTestOpt opt;
114 opt.updateDims( N, 6 );
115 opt.init( rnd );
116
117 for( i = 0; i < 500000; i++ )
118 {
119 if( opt.optimize( rnd ) > N * 128 )
120 {
121 break;
122 }
123 }
124
125 opt.optcost( opt.getBestParams() );
126
127 printf( "Finished at iteration %i\n", i + 1 );
128 printf( "Objective = %.8g\n", opt.real_value );
129 printf( "Constraints not met: %i\n", opt.con_notmet );
130
131 for( i = 0; i < N; i++ )
132 {
133 printf( "x[%i] = %0.15g\n", i, applyRound( opt.getBestParams()[ i ]));
134 }
135
136 // Optimum provided by function's source.
137
138 double x[ 10 ];
139 x[ 0 ] = 2.171996;
140 x[ 1 ] = 2.363683;
141 x[ 2 ] = 8.773926;
142 x[ 3 ] = 5.095984;
143 x[ 4 ] = 0.9906548;
144 x[ 5 ] = 1.430574;
145 x[ 6 ] = 1.321644;
146 x[ 7 ] = 9.828726;
147 x[ 8 ] = 8.280092;
148 x[ 9 ] = 8.375927;
149 opt.optcost( x );
150
151 printf( "Source objective = %.8g\n", opt.real_value );
152
153 return( 0 );
154}

Callers

nothing calls this directly

Calls 6

applyRoundFunction · 0.85
initMethod · 0.45
updateDimsMethod · 0.45
optimizeMethod · 0.45
optcostMethod · 0.45
getBestParamsMethod · 0.45

Tested by

no test coverage detected