@@ -286,3 +286,53 @@ fn test_minimum_negative_weight_overflows() {
286286 crate :: rules:: ReductionError :: IntegerOverflow { .. }
287287 ) ) ;
288288}
289+
290+ #[ test]
291+ fn test_unrepresentable_matrix_objective_is_rejected ( ) {
292+ for ( n, edges, weights) in [
293+ ( 2 , vec ! [ ( 0 , 1 ) ] , vec ! [ -3_000_000_000_000_000_000 ] ) ,
294+ ( 2 , vec ! [ ( 0 , 1 ) ] , vec ! [ -( ( i64 :: MAX - 2 ) / 4 + 1 ) ] ) ,
295+ ( 2 , vec ! [ ( 0 , 1 ) ] , vec ! [ i64 :: MAX / 2 + 1 ] ) ,
296+ ( 3 , vec ! [ ( 0 , 1 ) , ( 1 , 2 ) ] , vec ! [ -2_000_000_000_000_000_000 ; 2 ] ) ,
297+ (
298+ 3 ,
299+ vec ! [ ( 0 , 1 ) , ( 1 , 2 ) ] ,
300+ vec ! [ -1_000_000_000_000_000_000 , 3_000_000_000_000_000_000 ] ,
301+ ) ,
302+ ] {
303+ let source = MaxCut :: < SimpleGraph , i64 > :: new ( SimpleGraph :: new ( n, edges) , weights) ;
304+ // Every source configuration is evaluable, including its optimum.
305+ let optimum = BruteForce :: new ( ) . solve ( & source) . unwrap ( ) . unwrap ( ) ;
306+ assert ! ( source. evaluate( & optimum) . unwrap( ) . 0 . is_some( ) ) ;
307+ assert ! ( matches!(
308+ ReduceTo :: <MinimumMatrixCover >:: reduce_to( & source) ,
309+ Err ( crate :: rules:: ReductionError :: IntegerOverflow { .. } )
310+ ) ) ;
311+ }
312+ }
313+
314+ #[ test]
315+ fn test_representable_matrix_objective_boundaries ( ) {
316+ for ( weight, expected) in [ ( -( ( i64:: MAX - 2 ) / 4 ) , 0 ) , ( i64:: MAX / 2 , i64:: MAX / 2 ) ] {
317+ let source =
318+ MaxCut :: < SimpleGraph , i64 > :: new ( SimpleGraph :: new ( 2 , vec ! [ ( 0 , 1 ) ] ) , vec ! [ weight] ) ;
319+ let reduction = ReduceTo :: < MinimumMatrixCover > :: reduce_to ( & source) . unwrap ( ) ;
320+ assert_optimization_round_trip_from_optimization_target (
321+ & source,
322+ & reduction,
323+ "MaxCut at the matrix objective boundary" ,
324+ ) ;
325+ let target = reduction. target_problem ( ) ;
326+ assert_eq ! (
327+ target. evaluate( & vec![ false ; target. num_rows( ) ] ) . unwrap( ) ,
328+ Min ( Some ( i64 :: MAX - 1 ) )
329+ ) ;
330+ let target_optimum = BruteForce :: new ( ) . solve ( target) . unwrap ( ) . unwrap ( ) ;
331+ assert_eq ! (
332+ target. evaluate( & target_optimum) . unwrap( ) ,
333+ Min ( Some ( -( i64 :: MAX - 1 ) ) )
334+ ) ;
335+ let extracted = reduction. extract_solution ( & target_optimum) . unwrap ( ) ;
336+ assert_eq ! ( source. evaluate( & extracted) . unwrap( ) , Max ( Some ( expected) ) ) ;
337+ }
338+ }
0 commit comments