-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
synthesis: add greedy best first search (
GBFS
)
topology: append vars stage: move `plan_lts_state` back action instantiations: add FetchPermutation() action instantiations: remove `MarkUsed()`
- Loading branch information
Showing
39 changed files
with
645 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <benchmark/benchmark.h> | ||
#include "Hinge/hinge.h" | ||
#include "Hinge/Extended/recipe.h" | ||
|
||
using namespace scs; | ||
using namespace scs::examples; | ||
|
||
class HingeControllerExtended : public benchmark::Fixture { | ||
protected: | ||
std::unique_ptr<ITopology> topology; | ||
std::vector<CharacteristicGraph> graphs; | ||
scs::BasicActionTheory global; | ||
CharacteristicGraph graph_recipe; | ||
protected: | ||
void SetUp(const ::benchmark::State& state) { | ||
|
||
auto resource1 = HingeResource1(); | ||
graphs.emplace_back(resource1.program, ProgramType::Resource); | ||
|
||
auto resource2 = HingeResource2(); | ||
graphs.emplace_back(resource2.program, ProgramType::Resource); | ||
|
||
auto resource3 = HingeResource3(); | ||
graphs.emplace_back(resource3.program, ProgramType::Resource); | ||
|
||
auto resource4 = HingeResource4(); | ||
graphs.emplace_back(resource4.program, ProgramType::Resource); | ||
|
||
auto common = HingeCommon(); | ||
auto common_bat = HingeCommonBAT(); | ||
topology = std::make_unique<CompleteTopology>(&graphs, true); | ||
|
||
CoopMatrix cm(10); | ||
cm.Add(1, 2); | ||
cm.Add(1, 3); | ||
cm.Add(2, 3); | ||
RoutesMatrix rm(10); | ||
rm.Add(1, 2); | ||
|
||
std::vector<scs::BasicActionTheory> bats{common_bat, resource1.bat, resource2.bat, resource3.bat, resource4.bat}; | ||
global = CombineBATs(bats, cm, rm); | ||
|
||
auto recipe_prog = HingeExtendedRecipe(); | ||
graph_recipe = CharacteristicGraph(recipe_prog, ProgramType::Recipe); | ||
} | ||
|
||
void TearDown(const ::benchmark::State& state) { | ||
|
||
} | ||
|
||
}; | ||
|
||
BENCHMARK_DEFINE_F(HingeControllerExtended, AStar)(benchmark::State& state) { | ||
Limits lim{ .global_transition_limit = 50, .global_cost_limit = 200, | ||
.stage_transition_limit = 4, .stage_cost_limit = 50, .fairness_limit = 20 }; | ||
Best best(graphs, graph_recipe, global, *topology, lim); | ||
|
||
for (auto _ : state) { | ||
auto controller = best.Synthethise(); | ||
benchmark::DoNotOptimize(controller); | ||
benchmark::ClobberMemory(); | ||
} | ||
} | ||
BENCHMARK_REGISTER_F(HingeControllerExtended, AStar)->Unit(benchmark::kMillisecond); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include <format> | ||
|
||
#include "scs/SituationCalculus/situation_calculus.h" | ||
#include "scs/Common/strings.h" | ||
#include "scs/FirstOrderLogic/fol.h" | ||
#include "scs/ConGolog/Program/programs.h" | ||
#include "scs/ConGolog/resource.h" | ||
|
||
/* | ||
#Program | ||
Load(brass) || Load(tube); | ||
Paint(brass, metallic blue) | Paint(brass, metallic red); | ||
Clamp(brass) ||| RadialDrill(brass, 5); | ||
ApplyAdhesive(tube, brass); | ||
*/ | ||
|
||
namespace scs::examples { | ||
|
||
inline std::shared_ptr<IProgram> HingeExtendedRecipe() { | ||
scs::ActionProgram LoadBrass{scs::Action{"Load", {Object{"brass"}} }}; | ||
scs::ActionProgram LoadTube{scs::Action{"Load", {Object{"tube"}} }}; | ||
|
||
scs::ActionProgram PaintBlue{scs::Action{"Paint", { Object{"brass"}, Object{"metallic_red"} }}}; | ||
scs::ActionProgram PaintRed{scs::Action{"Paint", { Object{"brass"}, Object{"metallic_blue"} }}}; | ||
|
||
scs::ActionProgram Clamp{scs::Action{"Clamp", { Object{"brass"} }}}; | ||
scs::ActionProgram RadialDrill{scs::Action{"RadialDrill", { Object{"brass"}, Object{"5mm"}}}}; | ||
|
||
scs::ActionProgram ApplyAdhesive{scs::Action{"ApplyAdhesive", { Object{"tube"}, Object{"brass"} }}}; | ||
|
||
// ------ // | ||
|
||
Interleaved interleaved(LoadBrass, LoadTube); | ||
Branch nd1(PaintBlue, PaintRed); | ||
Simultaneous sim1(Clamp, RadialDrill); | ||
|
||
Sequence stage1(interleaved, nd1); | ||
Sequence stage2(stage1, sim1); | ||
Sequence stage3(stage2, ApplyAdhesive); | ||
|
||
return std::make_shared<Sequence>(stage3); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#pragma once | ||
|
||
#include "recipe.h" | ||
#include "Hinge/resource_1.h" | ||
#include "Hinge/resource_2.h" | ||
#include "Hinge/resource_3.h" | ||
#include "Hinge/resource_4.h" | ||
#include "Hinge/common.h" | ||
|
||
#include "scs/Common/timer.h" | ||
#include "scs/ConGolog/CharacteristicGraph/characteristic_graph.h" | ||
#include "scs/Synthesis/synthesis.h" | ||
#include "scs/Common/windows.h" | ||
#include "execution_type.h" | ||
|
||
namespace scs::examples { | ||
|
||
void RunHingeExtended(const ExecutionType& exec) { | ||
std::string dir; | ||
if (exec == ExecutionType::AStar) { | ||
dir = "Hinge/Extended/AStar/"; | ||
} else if (exec == ExecutionType::GBFS) { | ||
dir = "Hinge/Extended/GBFS/"; | ||
} else if (exec == ExecutionType::SPA) { | ||
dir = "Hinge/Extended/SPA/"; | ||
} | ||
|
||
// ------- Load BATs, Cg -------- | ||
std::vector<CharacteristicGraph> graphs; | ||
auto common = HingeCommon(); | ||
auto common_bat = HingeCommonBAT(); | ||
|
||
auto resource1 = HingeResource1(); | ||
graphs.emplace_back(resource1.program, ProgramType::Resource); | ||
ExportGraph(graphs.back(), dir + "Resource1"); | ||
|
||
auto resource2 = HingeResource2(); | ||
graphs.emplace_back(resource2.program, ProgramType::Resource); | ||
ExportGraph(graphs.back(), dir + "Resource2"); | ||
|
||
auto resource3 = HingeResource3(); | ||
graphs.emplace_back(resource3.program, ProgramType::Resource); | ||
ExportGraph(graphs.back(), dir + "Resource3"); | ||
|
||
auto resource4 = HingeResource4(); | ||
graphs.emplace_back(resource4.program, ProgramType::Resource); | ||
ExportGraph(graphs.back(), dir + "Resource4"); | ||
|
||
auto recipe_prog = HingeExtendedRecipe(); | ||
CharacteristicGraph graph_recipe(recipe_prog, ProgramType::Recipe); | ||
ExportGraph(graph_recipe, dir + "Recipe"); | ||
|
||
// ------------------------------ | ||
|
||
// ----- Coop & Routes ----- | ||
CoopMatrix cm(10); | ||
cm.Add(1, 2); | ||
cm.Add(1, 3); | ||
cm.Add(2, 3); | ||
RoutesMatrix rm(10); | ||
rm.Add(1, 2); | ||
rm.Add(2, 4); | ||
rm.Add(1, 4); | ||
|
||
// ------------------------- | ||
|
||
// ------ Global BAT ------- | ||
std::vector<scs::BasicActionTheory> bats{common_bat, resource1.bat, resource2.bat, resource3.bat, resource4.bat}; | ||
auto global = CombineBATs(bats, cm, rm); | ||
// ------------------------- | ||
|
||
// std::cout << common.within_reach; | ||
// std::cout << global.successors["part"].Form() << std::endl; | ||
// std::cout << global.pre["In"].Form() << std::endl; | ||
|
||
// std::cout << global; | ||
// std::cout << global.Initial(); | ||
// std::cout << *graphs[3].lts.states().at(2).key_; | ||
// ------------------------------- | ||
|
||
Limits lim { .global_transition_limit = 50, .global_cost_limit = 200, | ||
.stage_transition_limit = 4, .stage_cost_limit = 50, .fairness_limit = 20}; | ||
|
||
Timer topology_timer("Topology time"); | ||
CompleteTopology topology(&graphs, false); | ||
topology_timer.StopWithWrite(); | ||
|
||
if (1) { | ||
if (exec == ExecutionType::AStar) { | ||
Best best(graphs, graph_recipe, global, topology, lim); | ||
auto controller = best.Synthethise(); | ||
ExportController(controller.value().plan, dir + "Controller"); | ||
} else if (exec == ExecutionType::GBFS) { | ||
GBFS gbfs(graphs, graph_recipe, global, topology, lim); | ||
auto controller = gbfs.Synthethise(); | ||
ExportController(controller.value().plan, dir + "Controller"); | ||
} else if (exec == ExecutionType::SPA) { | ||
SPA spa(graphs, graph_recipe, global, topology, lim); | ||
auto controller = spa.Synthethise(); | ||
ExportController(controller.value().plan, dir + "Controller"); | ||
} | ||
} | ||
|
||
ExportTopology(topology, dir + "Topology"); | ||
if (exec == ExecutionType::AStar) { | ||
GenerateImagesFromDot("../../exports/Hinge/Extended/AStar/"); | ||
} else if (exec == ExecutionType::SPA) { | ||
GenerateImagesFromDot("../../exports/Hinge/Extended/SPA/"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include "execution_type.h" | ||
|
||
namespace scs::examples { | ||
|
||
void RunHingeExtended(const ExecutionType& exec = ExecutionType::AStar); | ||
|
||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.