@@ -39,47 +39,10 @@ do(State) ->
39
39
NrNodes = proplists :get_value (nodes , KVs , 8 ),
40
40
Locs = proplists :get_value (locations , KVs , 4 ),
41
41
Verbose = proplists :get_value (verbose , KVs , false ),
42
- calc_nvals (RingSize , NrNodes , Locs , Verbose ),
42
+ ring_calculator : nvals (RingSize , NrNodes , Locs , Verbose ),
43
43
{ok , State }.
44
44
45
45
-spec format_error (any ()) -> iolist ().
46
46
format_error (Reason ) ->
47
47
io_lib :format (" ~p " , [Reason ]).
48
48
49
- calc_nvals (RingSize , NrMachines , NrLocations , Verbose ) when NrMachines > 0 , NrLocations > 0 ->
50
- LVals = lists :seq (1 , min (NrMachines , NrLocations )),
51
- TargetNVals = lists :seq (1 , NrMachines ),
52
- Sols = lists :flatten ([ solutions (RingSize , LVal , TargetNVals , NrMachines , Locs , Verbose )
53
- || LVal <- LVals , % % NVal <- TargetNVals,
54
- Locs <- lists :seq (1 , NrLocations ) ]),
55
- case Sols of
56
- [] ->
57
- io :format (" No solution~n " );
58
- _ ->
59
- {BestLVal , BestNVal , Config , Ring } =
60
- lists :last (lists :sort ([ Sol || {_ , _ , _ , _ } = Sol <- Sols ])),
61
- io :format (" ~n Best solution:~n Target Nval ~p~n Location val ~p~n Config ~p~n Ring: ~s~n " ,
62
- [BestNVal , BestLVal , Config , ring_calculator_ring :show (Ring , {BestNVal , BestLVal })])
63
- end .
64
-
65
- solutions (RingSize , LVal , [NVal | NVals ], NrMachines , NrLocations , Verbose ) when 0 < LVal , LVal =< NrLocations ->
66
- % % spread machines evenly
67
- Config = spread_over_locations (lists :duplicate (NrLocations , 0 ), NrMachines ),
68
- [ io :format (" Config ~p " , [Config ]) || Verbose ],
69
- Solution = ring_calculator_ring :solve (RingSize , Config , {NVal , LVal }),
70
- ZeroViolations = ring_calculator_ring :zero_violations (Solution , {NVal , LVal }),
71
- [ io :format (" Target Nval: ~p , Locaction val: ~p Success: ~p~n " , [NVal , LVal , ZeroViolations ]) || Verbose ],
72
- if ZeroViolations ->
73
- [ io :format (" ." ) || not Verbose ],
74
- [{LVal , NVal , Config , Solution } | solutions (RingSize , LVal , NVals , NrMachines , NrLocations , Verbose ) ];
75
- true ->
76
- [ io :format (" x" ) || not Verbose ],
77
- []
78
- end ;
79
- solutions (_RingSize , _LVal , _ , _NrMachines , _NrLocations , _Verbose ) ->
80
- [].
81
-
82
- spread_over_locations (Config , 0 ) ->
83
- Config ;
84
- spread_over_locations ([Hd | Tl ], NrMachines ) ->
85
- spread_over_locations (Tl ++ [Hd + 1 ], NrMachines - 1 ).
0 commit comments