view-values.cpp
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
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <gecode/int/branch.hh>
00035
00036 namespace Gecode { namespace Int { namespace Branch {
00037
00038 PosValuesChoice::PosValuesChoice(const Brancher& b, const Pos& p, IntView x)
00039 : PosChoice(b,x.size(),p), n(0) {
00040 for (ViewRanges<IntView> r(x); r(); ++r)
00041 n++;
00042 pm = heap.alloc<PosMin>(n+1);
00043 unsigned int w=0;
00044 int i=0;
00045 for (ViewRanges<IntView> r(x); r(); ++r) {
00046 pm[i].min = r.min();
00047 pm[i].pos = w;
00048 w += r.width(); i++;
00049 }
00050 pm[i].pos = w;
00051 }
00052
00053 PosValuesChoice::PosValuesChoice(const Brancher& b, unsigned int a, Pos p,
00054 Archive& e)
00055 : PosChoice(b,a,p) {
00056 e >> n;
00057 pm = heap.alloc<PosMin>(n+1);
00058 for (unsigned int i=0; i<n+1; i++) {
00059 e >> pm[i].pos;
00060 e >> pm[i].min;
00061 }
00062 }
00063
00064 PosValuesChoice::~PosValuesChoice(void) {
00065 heap.free<PosMin>(pm,n+1);
00066 }
00067
00068 forceinline void
00069 PosValuesChoice::archive(Archive& e) const {
00070 PosChoice::archive(e);
00071 e << this->alternatives() << n;
00072 for (unsigned int i=0; i<n+1; i++) {
00073 e << pm[i].pos;
00074 e << pm[i].min;
00075 }
00076 }
00077
00078 }}}
00079
00080