73 #include <LEP/mcb/config.h> 77 #include <LEDA/graph/graph.h> 78 #include <LEDA/graph/edge_array.h> 79 #include <LEDA/core/array.h> 80 #include <LEDA/core/random_source.h> 81 #include <LEDA/numbers/integer.h> 83 #include <LEDA/graph.h> 84 #include <LEDA/array.h> 85 #include <LEDA/edge_array.h> 86 #include <LEDA/integer.h> 87 #include <LEDA/random_source.h> 91 #include <LEP/mcb/fp.h> 94 #include <LEP/mcb/transform.h> 95 #include <LEP/mcb/dsigned.h> 99 #if defined(LEDA_NAMESPACE) 102 using leda::edge_array;
104 using leda::node_array;
107 using leda::random_source;
151 W DMCB(
const graph& g,
152 const edge_array<W>& len,
153 array< mcb::spvecfp >&
mcb,
154 array< mcb::spvecfp >& proof,
159 #if ! defined(LEDA_CHECKING_OFF) 160 if ( Is_Simple( g ) ==
false )
161 error_handler(999,
"DMCB: illegal graph (non-simple?)");
162 if ( Is_Loopfree( g ) ==
false )
163 error_handler(999,
"DMCB: illegal graph (has loops?)");
166 forall_edges( e1 , g ) {
168 error_handler(999,
"MIN_CYCLE_BASIS: illegal edge (non-positive weight)");
171 if ( ! primes<ptype>::is_prime( p ) )
172 error_handler(999,
"DMCB: p is not a prime number!");
176 if ( d <= 0 )
return W(0);
179 array< spvecfp >& B = mcb;
181 array< spvecfp >& X = proof;
184 dirsp<W,ptype> SP( g, len, p, enumb );
186 #if defined(LEP_DEBUG_OUTPUT) 187 std::cout <<
"executing with prime p = " << p << std::endl;
194 for( i = 0; i < d; i++ ) {
201 spvecfp tmp = spvecfp( p );
204 for( i = 0; i < d; i++ ) {
208 B[i] = SP.get_shortest_cycle( X[i], mini );
218 while( tmpi < 0 ) tmpi += p;
219 while( tmpi >= p ) tmpi -= p;
220 tmp = X[i] * fp<ptype>::get_mult_inverse( tmpi, p );
223 for( j = i+1; j < d; j++ )
224 X[j] -= tmp * (B[i] * X[j]) ;
266 W DMCB(
const graph& g,
267 const edge_array<W>& len,
268 array< mcb::spvecfp >& mcb,
269 array< mcb::spvecfp >& proof,
274 #if ! defined(LEDA_CHECKING_OFF) 275 if ( Is_Simple( g ) ==
false )
276 error_handler(999,
"MIN_CYCLE_BASIS: illegal graph (non-simple?)");
277 if ( Is_Loopfree( g ) ==
false )
278 error_handler(999,
"MIN_CYCLE_BASIS: illegal graph (has loops?)");
279 if ( error <= 0 || error >= 1 )
280 error_handler(999,
"MIN_CYCLE_BASIS: error probability is out of range");
283 forall_edges( e1 , g ) {
285 error_handler(999,
"MIN_CYCLE_BASIS: illegal edge (non-positive weight)");
289 if ( d <= 0 )
return W(0);
295 int times = (int) ceil( log(error)/log(0.375) );
297 #if defined(LEP_DEBUG_OUTPUT) 298 std::cout <<
"Executing " << times;
299 std::cout <<
" number of times to achieve error probability ";
300 std::cout << error << std::endl;
304 array< spvecfp > X ( d );
305 array< spvecfp > B ( d );
307 bool min_so_far_inf =
true;
310 while( times-- > 0 ) {
315 int logd = log( integer( d + 1 ) );
316 int loglogd = log( integer( logd + 1 ) );
317 int randbits = 7 + 2 * logd + loglogd;
318 int failsafe = 50 * randbits;
323 if ( count++ > failsafe ) {
330 p = ptype::random( randbits );
335 if ( p > 1 && primes<ptype>::is_prime( p ) )
break;
339 #if defined(LEP_DEBUG_OUTPUT) 340 std::cout <<
"executing with prime p = " << p << std::endl;
343 W min = DMCB( g, len, B, X, enumb, p );
346 if ( ( min_so_far_inf ==
true ) ||
347 ( min_so_far_inf ==
false && min < min_so_far ) ) {
348 #if defined(LEP_DEBUG_OUTPUT) 349 if ( min_so_far_inf ==
false )
350 std::cout <<
"found better solution with weight " << min << std::endl;
354 min_so_far_inf =
false;
392 W DMCB(
const graph& g,
393 const edge_array<W>& len,
394 array< mcb::spvecfp >& mcb,
399 array< spvecfp > proof_tmp;
400 return DMCB(g, len, mcb, proof_tmp, enumb, error );
433 W DMCB(
const graph& g,
434 const edge_array<W>& len,
435 array< array<etype> >& mcb,
440 array< spvecfp > mcb_tmp;
441 array< spvecfp > proof_tmp;
446 W min = DMCB<W>( g, len, mcb_tmp, \
447 proof_tmp, enumb, error );
450 ptype p = proof_tmp[0].pvalue();
454 for (
int i = 0; i < d; i++ )
455 spvecfp_to_array_ints( g, enumb, p, mcb_tmp[i], mcb[i] );
Definition of edge numbering.
An edge numbering class.
Definition: edge_num.h:75
The main package namespace.
int indextype
Definition: arithm.h:54
Basic arithmetic definitions.
leda::integer ptype
Definition: arithm.h:58
int dim_cycle_space() const
Definition: edge_num.h:140