From b5fb5c3fbd78684f1b686b21a3bad6aac80f2dc0 Mon Sep 17 00:00:00 2001 From: Jan Huwald Date: Thu, 27 Nov 2014 23:44:19 +0100 Subject: find optimal solution, fix timing information from spec, make bit width a param, print solution asm diff --git a/gen_demultiplexer.cpp b/gen_demultiplexer.cpp index edf4acd..d554c7f 100644 --- a/gen_demultiplexer.cpp +++ b/gen_demultiplexer.cpp @@ -1,7 +1,10 @@ #include #include +#include #include +#include +#include #include #include @@ -10,6 +13,8 @@ using namespace std; using namespace Gecode; +using boost::dynamic_bitset; +using boost::lexical_cast; string S() { return ""; @@ -28,14 +33,18 @@ struct Op { int delay; }; -struct Demultiplexer : public Space { - +struct Demultiplexer : public MinimizeScript { IntVarArray op_times; + IntVarArray timeDistortions; + IntVar maxTimeDistortion; array ops; uint opCount; - Demultiplexer(vector bits) - : op_times(*this, 17, 0, 16) + Demultiplexer(dynamic_bitset<> bits) + : op_times(*this, 17, 0, 16), + timeDistortions(*this, bits.size(), 0, 170), + maxTimeDistortion(*this, 0, 170), + opCount(0) { /// post the problem (the instructions and their temporal /// dependencies) @@ -51,12 +60,18 @@ struct Demultiplexer : public Space { for (uint i=0; i gp("print solution"); - // Gist::Options go; - // go.inspect.click(&gp); - // Gist::dfs(d, go); - - DFS e(d); - delete d; - d = e.next(); - if (d) { - cout << d->print(); - delete d; - }else{ - cerr << "no instruction sequence found"; + if (argc != 2) { + cout << "Usage:\n" << argv[0] << " number-of-channels" << endl; + return 1; } + + auto bits = lexical_cast(argv[1]); + set> noSolutions; + double maxDev{0}; + + // find the optimal solution (legal instruction sequence with + // minimal deviation from WS2812 specs central delay value) + for (uint i=0; i < uint(1)< pattern(bits, i); + Demultiplexer init(pattern), + *best = nullptr, *cur; + + BAB search(&init); + while (cur = search.next()) { + if (best) delete best; + best = cur; + } + if (best) { + auto dev = double(best->cost().min()); + maxDev = max(maxDev, dev); + + cout << ".ws2812_mux" << bits << "_pat" << pattern << ":\n; max. time deviation: "; + printDev(dev); + cout << "; ind. deviations: " << best->timeDistortions << " (decicycles)\n"; + best->print(cout, false); + cout << endl; + + delete best; + }else{ + noSolutions.insert(pattern); + } + } + + // terminate if not all solutions have been found + if (!noSolutions.empty()) { + cerr << "No solutions found for:\n"; + for (auto p : noSolutions) + cerr << " " << p << endl; + cerr << "Total: no solution for " << noSolutions.size() + << " of " << (1<(bits, i) << endl; + + // print statistics + cout << ";\n; Maximal deviation of all patterns: "; + printDev(maxDev); + + + return 0; } -- cgit v0.10.1