Skip to content

Commit

Permalink
Merge pull request #40 from ajfAfg/use-only-solve_in_polynomial_time_…
Browse files Browse the repository at this point in the history
…without_correctness

use only solve in polynomial time without correctness
  • Loading branch information
ajfAfg authored Feb 19, 2024
2 parents e3cdfcb + f4d4f0a commit a8c9e1e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 71 deletions.
38 changes: 2 additions & 36 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
rebar3: 3.22.1

jobs:
demo_with_polynomial_time_without_correctness:
demo:
runs-on: ubuntu-22.04

defaults:
Expand All @@ -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
Expand All @@ -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 ]
3 changes: 2 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -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}]}.
37 changes: 7 additions & 30 deletions src/bean_prv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,19 @@ 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)}.

-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)),
{ok, State}.

-spec format_error(any()) -> iolist().
format_error(Reason) -> io_lib:format("~p", [Reason]).
Expand Down Expand Up @@ -98,12 +84,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]"}].
8 changes: 4 additions & 4 deletions test/prop_optimum_supervision_tree_solver.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ 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,
dependency_graph_generator:dependency_graph(18),
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))).

0 comments on commit a8c9e1e

Please sign in to comment.