Generated on Tue Apr 18 10:21:56 2017 for Gecode by doxygen 1.6.3

sym-imp.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christopher Mears <chris.mears@monash.edu>
00005  *
00006  *  Copyright:
00007  *     Christopher Mears, 2012
00008  *
00009  *  Last modified:
00010  *     $Date: 2013-05-13 07:50:41 +0200 (Mon, 13 May 2013) $ by $Author: mears $
00011  *     $Revision: 13633 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #include <gecode/int/ldsb.hh>
00039 #include <gecode/int/branch.hh>
00040 
00041 namespace Gecode { namespace Int { namespace LDSB {
00043   template <>
00044   ArgArray<Literal>
00045   VariableSymmetryImp<IntView>
00046   ::symmetric(Literal l, const ViewArray<IntView>& x) const {
00047     (void) x;
00048     if (indices.valid(l._variable) && indices.get(l._variable)) {
00049       int n = 0;
00050       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i)
00051         n++;
00052       ArgArray<Literal> lits(n);
00053       int j = 0;
00054       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i)
00055         lits[j++] = Literal(i.val(), l._value);
00056       return lits;
00057     } else {
00058       return ArgArray<Literal>(0);
00059     }
00060   }
00062   template <>
00063   ArgArray<Literal>
00064   VariableSymmetryImp<BoolView>
00065   ::symmetric(Literal l, const ViewArray<BoolView>& x) const {
00066     (void) x;
00067     if (indices.valid(l._variable) && indices.get(l._variable)) {
00068       int n = 0;
00069       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i)
00070         n++;
00071       ArgArray<Literal> lits(n);
00072       int j = 0;
00073       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(indices) ; i() ; ++i)
00074         lits[j++] = Literal(i.val(), l._value);
00075       return lits;
00076     } else {
00077       return ArgArray<Literal>(0);
00078     }
00079   }
00080 
00082   template <>
00083   ArgArray<Literal>
00084   ValueSymmetryImp<IntView>
00085   ::symmetric(Literal l, const ViewArray<IntView>& x) const {
00086     (void) x;
00087     if (values.valid(l._value) && values.get(l._value)) {
00088       int n = 0;
00089       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i)
00090         n++;
00091       ArgArray<Literal> lits(n);
00092       int j = 0;
00093       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i)
00094         lits[j++] = Literal(l._variable, i.val());
00095       return lits;
00096     } else {
00097       return ArgArray<Literal>(0);
00098     }
00099   }
00101   template <>
00102   ArgArray<Literal>
00103   ValueSymmetryImp<BoolView>
00104   ::symmetric(Literal l, const ViewArray<BoolView>& x) const {
00105     (void) x;
00106     if (values.valid(l._value) && values.get(l._value)) {
00107       int n = 0;
00108       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i)
00109         n++;
00110       ArgArray<Literal> lits(n);
00111       int j = 0;
00112       for (Iter::Values::BitSetOffset<Support::BitSetOffset<Space> > i(values) ; i() ; ++i)
00113         lits[j++] = Literal(l._variable, i.val());
00114       return lits;
00115     } else {
00116       return ArgArray<Literal>(0);
00117     }
00118   }
00119 
00121   template <>
00122   ArgArray<Literal>
00123   ValueSequenceSymmetryImp<Int::IntView>
00124   ::symmetric(Literal l, const ViewArray<IntView>& x) const {
00125     (void) x;
00126     Support::DynamicStack<Literal, Heap> s(heap);
00127     std::pair<int,int> location = findVar(values, n_values, seq_size, l._value);
00128     if (location.first == -1) return dynamicStackToArgArray(s);
00129     unsigned int seqNum = location.first;
00130     unsigned int seqPos = location.second;
00131     if (! dead_sequences.get(seqNum)) {
00132       for (unsigned int seq = 0 ; seq < n_seqs ; seq++) {
00133         if (seq == seqNum) continue;
00134         if (dead_sequences.get(seq)) continue;
00135         s.push(Literal(l._variable, getVal(seq,seqPos)));
00136       }
00137     }
00138     return dynamicStackToArgArray(s);
00139   }
00141   template <>
00142   ArgArray<Literal>
00143   ValueSequenceSymmetryImp<BoolView>
00144   ::symmetric(Literal l, const ViewArray<BoolView>& x) const {
00145     (void) x;
00146     Support::DynamicStack<Literal, Heap> s(heap);
00147     std::pair<int,int> location = findVar(values, n_values, seq_size, l._value);
00148     if (location.first == -1) return dynamicStackToArgArray(s);
00149     unsigned int seqNum = location.first;
00150     unsigned int seqPos = location.second;
00151     if (! dead_sequences.get(seqNum)) {
00152       for (unsigned int seq = 0 ; seq < n_seqs ; seq++) {
00153         if (seq == seqNum) continue;
00154         if (dead_sequences.get(seq)) continue;
00155         s.push(Literal(l._variable, getVal(seq,seqPos)));
00156       }
00157     }
00158     return dynamicStackToArgArray(s);
00159   }
00160 
00161 }}}
00162 
00163 // STATISTICS: int-branch