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