Chain-Load: implement generation mechanism

...introduce statistical control functions (based on hash)
...add processing stage for current set of nodes
...process forking, reduction and injection of new nodes
This commit is contained in:
Fischlurch 2023-11-12 23:31:08 +01:00
parent 60dc34a799
commit aa3c25e092
2 changed files with 110 additions and 22 deletions

View file

@ -59,7 +59,7 @@
//#include "lib/util.hpp"
#include <boost/functional/hash.hpp>
//#include <functional>
#include <functional>
#include <utility>
//#include <string>
//#include <deque>
@ -80,6 +80,7 @@ namespace test {
// using lib::time::Offset;
// using lib::meta::RebindVariadic;
// using util::isnil;
using util::max;
using util::unConst;
// using std::forward;
using std::swap;
@ -148,6 +149,15 @@ namespace test {
: hash{seed}
{ }
void
clear()
{
hash = 0;
level = repeat = 0;
pred.clear();
succ.clear();
}
Node&
addPred (Node* other)
{
@ -181,9 +191,14 @@ namespace test {
private:
using NodeTab = typename Node::Tab;
using NodeStorage = std::array<Node, numNodes>;
using CtrlRule = std::function<size_t(size_t, double)>;
std::unique_ptr<NodeStorage> nodes_;
CtrlRule seedingRule_ {[](size_t, double){ return 0; }};
CtrlRule expansionRule_{[](size_t, double){ return 0; }};
CtrlRule reductionRule_{[](size_t, double){ return 0; }};
public:
TestChainLoad()
: nodes_{new NodeStorage}
@ -204,26 +219,75 @@ namespace test {
TestChainLoad
buildToplolgy()
{
NodeTab a,b,
*curr{&a}, *next{&b};
NodeTab a,b, // working data for generation
*curr{&a}, // the current set of nodes to carry on
*next{&b}; // the next set of nodes connected to current
Node* node = &nodes_->front();
size_t level{0};
size_t expectedLevel = max (1u, numNodes/maxFan);
curr->add (node++);
++level;
// prepare building blocks for the topology generation...
auto height = [&](double level)
{
return level/expectedLevel;
};
auto spaceLeft = [&]{ return next->size() < maxFan; };
auto addNode = [&]{
Node* n = *next->add (node++);
n->clear();
n->level = level;
return n;
};
auto apply = [&](CtrlRule& rule, Node* n)
{
return rule (n->hash, height(level));
};
addNode(); // prime next with root node
// visit all further nodes and establish links
while (node < &nodes_->back())
{
Node* n = (*curr)[0];
next->add (node++);
(*next)[0]->level = level;
(*next)[0]->addPred(n);
swap (next, curr);
next->clear();
++level;
curr->clear();
swap (next, curr);
size_t toReduce{0};
Node* r;
REQUIRE (spaceLeft());
for (Node* o : *curr)
{ // follow-up on all Nodes in current level...
o->calculate();
size_t toSeed = apply (seedingRule_, o);
size_t toExpand = apply (expansionRule_,o);
while (0 < toSeed and spaceLeft())
{ // start a new chain from seed
Node* n = addNode();
n->hash = this->getSeed();
--toSeed;
}
while (0 < toExpand and spaceLeft())
{ // fork out secondary chain from o
Node* n = addNode();
o->addSucc(n);
--toExpand;
}
if (not toReduce and spaceLeft())
{ // carry-on the chain from o
r = addNode();
toReduce = apply (reductionRule_, o);
}
else
--toReduce;
ENSURE (r);
r->addPred(o);
}
}
ENSURE (node == &nodes_->back());
node->level = level;
node->addPred ((*curr)[0]);
// connect ends of all remaining chains to top-Node
node->clear();
node->level = ++level;
for (Node* o : *next)
node->addPred(o);
//
return move(*this);
}

View file

@ -95859,11 +95859,17 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<icon BUILTIN="button_ok"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1699804864545" ID="ID_73838770" MODIFIED="1699804873145" TEXT="verify_Topology">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1699804864545" ID="ID_73838770" MODIFIED="1699827764136" TEXT="verify_Topology">
<icon BUILTIN="pencil"/>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1699805908357" ID="ID_955671536" MODIFIED="1699813655109" TEXT="einfachster Verlinkungs-Durchlauf">
<icon BUILTIN="pencil"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1699827742164" ID="ID_1812083819" MODIFIED="1699827750460" TEXT="pr&#xfc;fen: hat lineare Kette erzeugt">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1699827751499" ID="ID_1702632260" MODIFIED="1699827760690" TEXT="pr&#xfc;fen: Hash ist reproduzierbar">
<icon BUILTIN="flag-yellow"/>
</node>
</node>
</node>
</node>
@ -95970,13 +95976,28 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<node CREATED="1699758626410" ID="ID_254710650" MODIFIED="1699803643433" TEXT="aber nat&#xfc;rlich quadratisch">
<icon BUILTIN="smiley-oh"/>
</node>
<node BACKGROUND_COLOR="#c8c0b6" COLOR="#435e98" CREATED="1699802151220" FOLDED="true" ID="ID_1133520353" MODIFIED="1699803652460" TEXT="eine spezialisierte Klasse w&#xe4;re besser">
<node BACKGROUND_COLOR="#c8c0b6" COLOR="#435e98" CREATED="1699802151220" FOLDED="true" ID="ID_1133520353" MODIFIED="1699827942359" TEXT="eine spezialisierte Klasse w&#xe4;re besser">
<arrowlink COLOR="#486792" DESTINATION="ID_1197014419" ENDARROW="Default" ENDINCLINATION="25;-24;" ID="Arrow_ID_1439179407" STARTARROW="None" STARTINCLINATION="-55;4;"/>
<icon BUILTIN="yes"/>
<node CREATED="1699802174727" ID="ID_1489941015" MODIFIED="1699802178642" TEXT="baut auf std::array auf"/>
<node CREATED="1699802179159" ID="ID_1822324287" MODIFIED="1699802196552" TEXT="speichert zus&#xe4;tzlich den Endpunkt-Iterator"/>
<node CREATED="1699802484022" ID="ID_1587433523" MODIFIED="1699802495258" TEXT="ansonsten so offen wie std::array selber"/>
</node>
</node>
<node COLOR="#435e98" CREATED="1699827809544" ID="ID_1197014419" MODIFIED="1699827949532">
<richcontent TYPE="NODE"><html>
<head>
</head>
<body>
<p>
<font face="Monospaced" color="#1f13ae"><b>NodeTab</b></font>&#160;: f&#252;r Verlinkungen und f&#252;r die Topologie-Erstellung
</p>
</body>
</html>
</richcontent>
<linktarget COLOR="#486792" DESTINATION="ID_1197014419" ENDARROW="Default" ENDINCLINATION="25;-24;" ID="Arrow_ID_1439179407" SOURCE="ID_1133520353" STARTARROW="None" STARTINCLINATION="-55;4;"/>
</node>
<node COLOR="#338800" CREATED="1699758650056" ID="ID_232473697" MODIFIED="1699758655959" TEXT="Backlinks einf&#xfc;gen">
<icon BUILTIN="button_ok"/>
</node>
@ -95988,14 +96009,17 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<node CREATED="1699805829000" ID="ID_270316664" MODIFIED="1699805831707" TEXT="Topologie">
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1699805833671" ID="ID_580627690" MODIFIED="1699805843455" TEXT="Verlinkungs-Algorithmus">
<icon BUILTIN="pencil"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1699805853717" ID="ID_1156505101" MODIFIED="1699805858453" TEXT="Schleifenrahmen">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1699805853717" ID="ID_1156505101" MODIFIED="1699821192765" TEXT="Schleifenrahmen">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1699805863906" ID="ID_857574027" MODIFIED="1699805883001" TEXT="Steuergr&#xf6;&#xdf;en einf&#xfc;hren">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1699805863906" ID="ID_857574027" MODIFIED="1699827724930" TEXT="Steuergr&#xf6;&#xdf;en einf&#xfc;hren">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1699805890752" ID="ID_604823204" MODIFIED="1699805896284" TEXT="Limitierungen einhalten">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1699821225351" ID="ID_1826969287" MODIFIED="1699827726975" TEXT="Verzweigen und Reduzieren">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1699805890752" ID="ID_604823204" MODIFIED="1699827731274" TEXT="Limitierungen einhalten">
<icon BUILTIN="pencil"/>
</node>
</node>
</node>