From 646317f8097f8fe6f7de3c55e1c7f660f5e68c7f Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Mon, 19 Feb 2024 14:37:58 +0900 Subject: [PATCH 1/6] Use only `solve_in_polynomial_time_without_correctness` --- src/bean_prv.erl | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/bean_prv.erl b/src/bean_prv.erl index 4131fe7..850884f 100644 --- a/src/bean_prv.erl +++ b/src/bean_prv.erl @@ -27,25 +27,11 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> - {Args, _} = rebar_state:command_parsed_args(State), - FunOpt = - case proplists:get_value(algorithm, Args, polynomial_time_without_correctness) of - polynomial_time_without_correctness -> - {some, - fun all_local_minimum_vertex_splitters_solver:solve_in_polynomial_time_without_correctness/1}; - exp_time_with_correctness -> - {some, - fun all_local_minimum_vertex_splitters_solver:solve_in_exp_time_with_correctness/1}; - _ -> none - end, - case FunOpt of - {some, TakeAllLocalMinimumVertexSplitters} -> - lists:foreach(fun(App) -> generate_supervisor(App, TakeAllLocalMinimumVertexSplitters) - end, - rebar_state:project_apps(State)), - {ok, State}; - none -> {error, "Invalid algorithm"} - end. + lists:foreach(fun(App) -> + generate_supervisor(App, + fun all_local_minimum_vertex_splitters_solver:solve_in_polynomial_time_without_correctness/1) + end, + rebar_state:project_apps(State)). -spec format_error(any()) -> iolist(). format_error(Reason) -> io_lib:format("~p", [Reason]). From 8a2feb5f626c7b84ccc9da1182550f27cf4a0506 Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Mon, 19 Feb 2024 14:38:16 +0900 Subject: [PATCH 2/6] Remove the plugin options --- src/bean_prv.erl | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/bean_prv.erl b/src/bean_prv.erl index 850884f..31fb90b 100644 --- a/src/bean_prv.erl +++ b/src/bean_prv.erl @@ -19,8 +19,7 @@ init(State) -> true}, % The task can be run by the user, always true {deps, ?DEPS}, % The list of dependencies {example, "rebar3 bean"}, % How to use the plugin - {opts, - bean_opts()}, % list of options understood by the plugin + {opts, []}, % list of options understood by the plugin {short_desc, "A rebar plugin"}, {desc, "A rebar plugin"}]), {ok, rebar_state:add_provider(State, Provider)}. @@ -84,12 +83,3 @@ generate_supervisor(_App, TakeAllLocalMinimumVertexSplitters) -> find_source_files(Dir) -> filelib:fold_files(Dir, ".*\.erl", true, fun(X, Acc) -> [X | Acc] end, []). - -bean_opts() -> - [{algorithm, - $a, - "algorithm", - atom, - "Algorithm used to generate a supervision tree. " - "Choice of `polynomial_time_without_correctness` and `exp_time_with_correctness`. " - "[default: polynomial_time_without_correctness]"}]. From 8745cb8561f81382b9f54c9f3278751e52cb8ab2 Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Mon, 19 Feb 2024 14:39:32 +0900 Subject: [PATCH 3/6] Demonstrate only `solve_in_polynomial_time_without_correctness` --- .github/workflows/demo.yml | 38 ++------------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index e46ba31..455605d 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -14,7 +14,7 @@ env: rebar3: 3.22.1 jobs: - demo_with_polynomial_time_without_correctness: + demo: runs-on: ubuntu-22.04 defaults: @@ -28,7 +28,7 @@ jobs: otp-version: ${{ env.otp }} rebar3-version: ${{ env.rebar3 }} - - name: Demonstrate with polynomial_time_without_correctness + - name: Demonstrate run: | mkdir _checkouts ln -s ${PWD}/../ _checkouts/bean @@ -47,37 +47,3 @@ jobs: rebar3 compile erlc run.erl [ $(erl -pa _build/default/lib/demo/ebin -run run main -noshell | grep 'Result: 55' | wc -l) -eq 2 ] - - demo_with_exp_time_with_correctness: - runs-on: ubuntu-22.04 - - defaults: - run: - working-directory: ./demo - - steps: - - uses: actions/checkout@v4 - - uses: erlef/setup-beam@v1 - with: - otp-version: ${{ env.otp }} - rebar3-version: ${{ env.rebar3 }} - - - name: Demonstrate with exp_time_with_correctness - run: | - mkdir _checkouts - ln -s ${PWD}/../ _checkouts/bean - rebar3 bean --algorithm exp_time_with_correctness - # NOTE: - # The processing of the following three commands can be achieved - # in some environments with the command - # `[ $(rebar3 shell --script run.escript | grep 'Result: 55' | wc -l) -eq 2 ]` alone. - # However, when the command are executed in GitHub Actions, - # the evaluation of `supervisor:start_link(bean, [])` causes a "Terminating erlang" error. - # The cause of this problem seems to depend on - # whether or not the Erlang runtime system is started with a shell - # (i.e., with or without `-noshell` at startup). - # Unfortunately, this option is currently not supported by Rebar3, - # so I used `erl` directly to solve this problem. - rebar3 compile - erlc run.erl - [ $(erl -pa _build/default/lib/demo/ebin -run run main -noshell | grep 'Result: 55' | wc -l) -eq 2 ] From 4f89a095ce9710fda31eec64de2ffe9e8cbbd1c3 Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Mon, 19 Feb 2024 14:40:10 +0900 Subject: [PATCH 4/6] Ignore `all_local_minimum_vertex_splitters_solver:solve_in_exp_time_with_correctness/1` in xref --- rebar.config | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rebar.config b/rebar.config index caaaf27..080e681 100644 --- a/rebar.config +++ b/rebar.config @@ -58,4 +58,5 @@ {dependency_digraph, satisfy_vertex_splitter_constraint1, 2}, {dependency_digraph, satisfy_vertex_splitter_constraint2, 2}, {my_lists, sublist_randomly, 1}, - {my_digraph_utils, clone, 1}]}. + {my_digraph_utils, clone, 1}, + {all_local_minimum_vertex_splitters_solver, solve_in_exp_time_with_correctness, 1}]}. From 33fbe19ee3af65f8a9d66b27bd0b58af2ccdd7df Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Mon, 19 Feb 2024 14:42:02 +0900 Subject: [PATCH 5/6] Test that the cost of a supervision tree in either case "exp time & correct" and "polynomial time & incorrect" is equal --- test/prop_optimum_supervision_tree_solver.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/prop_optimum_supervision_tree_solver.erl b/test/prop_optimum_supervision_tree_solver.erl index 85fe74a..6d1fb7f 100644 --- a/test/prop_optimum_supervision_tree_solver.erl +++ b/test/prop_optimum_supervision_tree_solver.erl @@ -49,7 +49,7 @@ take_restart_processes({_, Children}) -> lists:map(fun take_restart_processes/1, Children)); take_restart_processes(Child) -> Child. -prop_solve2(doc) -> "About cost, exp time & correct ≤ polynomial time & incorrect". +prop_solve2(doc) -> "About cost, exp time & correct = polynomial time & incorrect". prop_solve2() -> ?FORALL(Graph, @@ -57,6 +57,6 @@ prop_solve2() -> supervision_tree:calc_cost( optimum_supervision_tree_solver:solve(Graph, fun all_local_minimum_vertex_splitters_solver:solve_in_exp_time_with_correctness/1)) - =< supervision_tree:calc_cost( - optimum_supervision_tree_solver:solve(Graph, - fun all_local_minimum_vertex_splitters_solver:solve_in_polynomial_time_without_correctness/1))). + =:= supervision_tree:calc_cost( + optimum_supervision_tree_solver:solve(Graph, + fun all_local_minimum_vertex_splitters_solver:solve_in_polynomial_time_without_correctness/1))). From f4d4f0a78be326b9216159ab36dae8daf2671935 Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Mon, 19 Feb 2024 14:47:25 +0900 Subject: [PATCH 6/6] Fix the return value --- src/bean_prv.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bean_prv.erl b/src/bean_prv.erl index 31fb90b..2049cc3 100644 --- a/src/bean_prv.erl +++ b/src/bean_prv.erl @@ -30,7 +30,8 @@ do(State) -> generate_supervisor(App, fun all_local_minimum_vertex_splitters_solver:solve_in_polynomial_time_without_correctness/1) end, - rebar_state:project_apps(State)). + rebar_state:project_apps(State)), + {ok, State}. -spec format_error(any()) -> iolist(). format_error(Reason) -> io_lib:format("~p", [Reason]).