support.icc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 inline
00023 Options::Options(const char* n)
00024 : icl(ICL_DEF),
00025 c_d(Search::Config::c_d),
00026 a_d(Search::Config::a_d),
00027 mode(EM_SOLUTION),
00028 quiet(false),
00029 samples(1),
00030 iterations(1),
00031 solutions(1),
00032 naive(false),
00033 size(0),
00034 name(n) {}
00035
00036
00037 template <class Script, template<class> class Engine>
00038 void
00039 Example::run(const Options& o) {
00040 using namespace std;
00041 try {
00042 if (!o.quiet)
00043 cout << o.name << endl;
00044 switch (o.mode) {
00045 case EM_SOLUTION:
00046 {
00047 Timer t;
00048 int i = o.solutions;
00049 t.start();
00050 Script* s = new Script(o);
00051 unsigned int p = 0;
00052 unsigned int b = 0;
00053 if (s->status() != SS_FAILED) {
00054 p = s->propagators();
00055 b = s->branchings();
00056 }
00057 Engine<Script> e(s,o.c_d,o.a_d);
00058 delete s;
00059 do {
00060 Example* ex = e.next();
00061 if (ex == NULL)
00062 break;
00063 ex->print();
00064 delete ex;
00065 } while (--i != 0);
00066 Search::Statistics stat = e.statistics();
00067 cout << endl;
00068 cout << "Initial" << endl
00069 << "\tpropagators: " << p << endl
00070 << "\tbranchings: " << b << endl
00071 << endl
00072 << "Summary" << endl
00073 << "\truntime: " << t.stop() << endl
00074 << "\tsolutions: " << abs(static_cast<int>(o.solutions) - i) << endl
00075 << "\tpropagations: " << stat.propagate << endl
00076 << "\tfailures: " << stat.fail << endl
00077 << "\tclones: " << stat.clone << endl
00078 << "\tcommits: " << stat.commit << endl
00079 << "\tpeak memory: "
00080 << static_cast<int>((stat.memory+1023) / 1024) << " KB"
00081 << endl;
00082 }
00083 break;
00084 case EM_STAT:
00085 {
00086 int i = o.solutions;
00087 Script* s = new Script(o);
00088 unsigned int p = 0;
00089 unsigned int b = 0;
00090 if (s->status() != SS_FAILED) {
00091 p = s->propagators();
00092 b = s->branchings();
00093 }
00094 Engine<Script> e(s,o.c_d,o.a_d);
00095 delete s;
00096 do {
00097 Example* ex = e.next();
00098 if (ex == NULL)
00099 break;
00100 delete ex;
00101 } while (--i != 0);
00102 Search::Statistics stat = e.statistics();
00103 cout << endl
00104 << "\tpropagators: " << p << endl
00105 << "\tbranchings: " << b << endl
00106 << "\tsolutions: " << abs(static_cast<int>(o.solutions) - i) << endl
00107 << "\tpropagations: " << stat.propagate << endl
00108 << "\tfailures: " << stat.fail << endl
00109 << "\tclones: " << stat.clone << endl
00110 << "\tcommits: " << stat.commit << endl
00111 << "\tpeak memory: "
00112 << static_cast<int>((stat.memory+1023) / 1024) << " KB"
00113 << endl;
00114 }
00115 break;
00116 case EM_TIME:
00117 {
00118 Timer t;
00119 GECODE_AUTOARRAY(double,ts,o.samples);
00120 for (int s = o.samples; s--; ) {
00121 t.start();
00122 for (int k = o.iterations; k--; ) {
00123 unsigned int i = o.solutions;
00124 Script* s = new Script(o);
00125 Engine<Script> e(s,o.c_d,o.a_d);
00126 delete s;
00127 do {
00128 Example* ex = e.next();
00129 if (ex == NULL)
00130 break;
00131 delete ex;
00132 } while (--i != 0);
00133 }
00134 ts[s] = t.stop() / o.iterations;
00135 }
00136 double m = am(ts,o.samples);
00137 double d = dev(ts,o.samples) * 100.0;
00138 if (o.quiet) {
00139 cout << showpoint << setprecision(6) << m << " "
00140 << setprecision(2) << d
00141 << endl;
00142 } else {
00143 cout << "\tRuntime: "
00144 << setw(20) << right
00145 << showpoint << fixed
00146 << setprecision(6) << m << "ms"
00147 << setprecision(2) << " (" << d << "% deviation)"
00148 << endl;
00149 }
00150 }
00151 break;
00152 }
00153 } catch (Exception e) {
00154 cout << "Exception in \"Gecode::" << e.location()
00155 << "\": " << e.info() << "." << endl
00156 << "Stopping..." << endl;
00157 }
00158 }
00159
00160