ColoredGraph solve(const Graph& gr) { GC_Naive_2 naive; auto result = naive.solve(gr); for (;;) { auto c_gr = result; auto colorCount = result.colorCount()-1; for (auto i = 0; i < c_gr.nodeCount(); ++i) { if (c_gr.color(i) == colorCount) c_gr.unsetColor(i); } for (;;) { auto uncolored = c_gr.uncoloredNodes(); for (auto i : uncolored) { bool success = c_gr.setColor(i); if (success) continue; SetColorUsingKempeChain(c_gr, i); } if (uncolored.size() == c_gr.uncoloredNodeCount()) break; } if (c_gr.uncoloredNodeCount() > 0) break; else { cout << "new sol: " << c_gr.colorCount() << endl; assert(isFeasibleColoring(c_gr)); result = c_gr; } } return result; }
void Palette::setGlobalOSystemPalette() const { byte buf[256 * 4]; // Allocate space for the largest possible palette // The color format used by OSystem's setPalette-function: save(buf, sizeof(buf), Graphics::PixelFormat(4, 8, 8, 8, 0, 0, 8, 16, 0), CINE_LITTLE_ENDIAN); if (g_cine->getPlatform() == Common::kPlatformAmiga && colorCount() == 16) { // The Amiga version of Future Wars does use the upper 16 colors for a darkened // game palette to allow transparent dialog boxes. To support that in our code // we do calculate that palette over here and append it to the screen palette. for (uint i = 0; i < 16 * 4; ++i) buf[16 * 4 + i] = buf[i] >> 1; g_system->getPaletteManager()->setPalette(buf, 0, colorCount() * 2); } else {
Color ColorPalette::getColorOn1Scale(double val) { if(isUsingMaxIterMethod()){ std::cerr << "Error getColorOn1Scale called when method is iterMax!\n"; return Color(0,0,0); } if(val > 1 || val < 0){ std::cerr << "Error in getColorOn1Scale: value: " << val << " not on [0,1]!\n"; Color c; c.b = c.g = c.r = 0; return c; } if(type == "discrete"){ unsigned int index = (float)(val * (colorCount()-1)+0.5f); // on [0, colorCount()-1] if(index < 0 || index >= C.size()){ std::cerr << "Error in getColorOn1Scale: value: " << val << " gave color out of range!\n"; std::cerr << " There are " << colorCount() << " colors in palette.\n"; Color c; c.b = c.g = c.r = 0; return c; } return C[index]; }else{ // find 2 closest colors, then interpolate // get segement # (there are colorCount()-1 segements) unsigned int segNum = (float)(val * (colorCount()-2)+0.5f); // on [0, colorCount()-2] unsigned int indexLow = segNum; unsigned int indexHigh = segNum + 1; double posAtHigh = indexHigh / (colorCount() - 1); // now interpolate Color c; c.r = linearInterpolate(C[indexHigh].r, C[indexLow].r, posAtHigh - val); c.g = linearInterpolate(C[indexHigh].g, C[indexLow].g, posAtHigh - val); c.b = linearInterpolate(C[indexHigh].b, C[indexLow].b, posAtHigh - val); return c; } }
int QPixmap::numCols() const { return colorCount(); }
void Palette::setGlobalOSystemPalette() const { byte buf[256 * 4]; // Allocate space for the largest possible palette // The color format used by OSystem's setPalette-function: save(buf, sizeof(buf), Graphics::PixelFormat(4, 8, 8, 8, 0, 0, 8, 16, 0), CINE_LITTLE_ENDIAN); if (g_cine->getPlatform() == Common::kPlatformAmiga && colorCount() == 16) { // The Amiga version of Future Wars does use the upper 16 colors for a darkened // game palette to allow transparent dialog boxes. To support that in our code // we do calculate that palette over here and append it to the screen palette. for (uint i = 0; i < 16 * 4; ++i) buf[16 * 4 + i] = buf[i] >> 1; g_system->getPaletteManager()->setPalette(buf, 0, colorCount() * 2); } else { g_system->getPaletteManager()->setPalette(buf, 0, colorCount()); } } Cine::Palette::Color Palette::getColor(byte index) const { return _colors[index]; } uint8 Palette::getR(byte index) const { return _colors[index].r; } uint8 Palette::getG(byte index) const { return _colors[index].g; }
void Palette::setGlobalOSystemPalette() const { byte buf[256 * 4]; // Allocate space for the largest possible palette // The color format used by OSystem's setPalette-function: save(buf, sizeof(buf), Graphics::PixelFormat(4, 8, 8, 8, 0, 0, 8, 16, 0), CINE_LITTLE_ENDIAN); if (g_cine->getPlatform() == Common::kPlatformAmiga && colorCount() == 16) { // The Amiga version of Future Wars does use the upper 16 colors for a darkened // game palette to allow transparent dialog boxes. To support that in our code // we do calculate that palette over here and append it to the screen palette. for (uint i = 0; i < 16 * 4; ++i) buf[16 * 4 + i] = buf[i] >> 1; g_system->setPalette(buf, 0, colorCount() * 2); } else { g_system->setPalette(buf, 0, colorCount()); } } Cine::Palette::Color Palette::getColor(byte index) const { return _colors[index]; } uint8 Palette::getR(byte index) const { return _colors[index].r; } uint8 Palette::getG(byte index) const { return _colors[index].g; }
int main(int argc, const char * argv[]) { for (auto s : {"100_3", "100_5", "100_7"}) { // for (auto s : {"500_3", "500_5", "500_7"}) { #ifdef NAIVE GC_Naive solver; #endif #ifdef BACKTRACK GC_Backtracking solver(std::chrono::seconds{10}); #endif #ifdef HILL_CLIMBING GC_HillClimbing solver; #endif #ifdef GA GC_GA<GC_GA_Flags::None> solver; // GC_GA::Params params; // solver.set_max_iteration_count(10000); #endif #ifdef REC_LARGE_FIRST GC_RecursiveLargestFirst solver; #endif #ifdef TS GC_TabuSearch solver; solver.setMaxIteration(1000000); #endif #ifdef TABUCOL GC_Tabucol solver; #endif #ifdef KEMPE_CHAIN GC_KempeChain solver; #endif #ifdef LP GC_LP solver(GC_LP_Rules::PerEdge); #endif #ifdef SA GC_SA solver(1000*1000*1000); #endif ifstream in(Format("data/gc_%s", s)); auto gr = ReadProblem(in); auto c_gr = solver.solve(gr); if (!isFeasibleColoring(c_gr)) throw runtime_error("result is not feasible coloring"); cout << s << " : " << c_gr.colorCount() << endl; } }