示例#1
0
Assignment get_merged_assignment(const Subset &s, const Assignment &ss0,
                                 const Ints &i0, const Assignment &ss1,
                                 const Ints &i1) {
  Ints ret(s.size(), -1);
  IMP_USAGE_CHECK(ss0.size() == i0.size(),
                  "The size of the subset and "
                      << "the index don't match: " << ss0.size() << " vs "
                      << i0.size());
  IMP_USAGE_CHECK(ss1.size() == i1.size(),
                  "The size of the subset and "
                      << "the index don't match: " << ss1.size() << " vs "
                      << i1.size());
  for (unsigned int i = 0; i < i0.size(); ++i) {
    ret[i0[i]] = ss0[i];
  }
  for (unsigned int i = 0; i < i1.size(); ++i) {
    ret[i1[i]] = ss1[i];
  }
  IMP_IF_CHECK(USAGE) {
    for (unsigned int i = 0; i < ret.size(); ++i) {
      IMP_USAGE_CHECK(ret[i] >= 0, "Not all set");
    }
  }
  return Assignment(ret);
}
示例#2
0
 /// Check whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   for (int i=0; i<x.size(); i++)
     for (int j=i+1; j<x.size(); j++)
       if (x[i]+i==x[j]+j)
         return false;
   return true;
 }
示例#3
0
文件: rel.cpp 项目: Wushaowei001/vcp
 /// %Test whether \a x is solution
 virtual MaybeType solution(const Assignment& x) const {
   if (x.size() == 1) {
     return cmp(x[0],frt,c);
   } else {
     return cmp(x[0],frt,c) & cmp(x[1],frt,c);
   }
 }
示例#4
0
 /// %Test whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   int m = 0;
   for (int i=x.size(); i--; )
     if (x[i] == 0)
       m += 2;
   return cmp(m,irt,4);
 }
示例#5
0
 /// %Test whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   int m = 0;
   for (int i=x.size(); i--; )
     if ((x[i] >= -1) && (x[i] <= 1))
       m++;
   return cmp(m,irt,2);
 }
示例#6
0
文件: dom.cpp 项目: Wushaowei001/vcp
 /// %Test whether \a x is solution
 virtual MaybeType solution(const Assignment& x) const {
   if (max < min)
     return MT_FALSE;
   for (int i=x.size(); i--; )
     if ((x[i].max() > max) || (x[i].min() < min))
       return MT_FALSE;
   return MT_TRUE;
 }
示例#7
0
bool CNFClause::check_bitstring(const Assignment & bitstring) const {
  bool ok = false;
  // we check whether an assignment is compatible with the clause literal by literal
  for(const auto & lit : clause){
    ok = ok || (lit.variable >= bitstring.size()) || (lit.value == bitstring[lit.variable]);
  }
  return ok;
}
示例#8
0
 /// %Test whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   for (int i=x.size(); i--; )
     if (!(((x[i] >= -4) && (x[i] <= -3)) ||
           ((x[i] >= -1) && (x[i] <= -1)) ||
           ((x[i] >=  1) && (x[i] <=  1)) ||
           ((x[i] >=  3) && (x[i] <=  5))))
       return false;
   return true;
 }
示例#9
0
文件: gcc.cpp 项目: Gecode/gecode
 /// %Test whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   int n[4];
   for (int i=4; i--; )
     n[i]=0;
   for (int i=x.size(); i--; )
     n[x[i]-1]++;
   if ((n[0] < 2) || (n[1] < 2) || (n[2] > 0) || (n[3] > 0))
     return false;
   return true;
 }
示例#10
0
 /// %Test whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   int n = x.size();
   for (int i = 0 ; i < n ; i++) {
     if (x[i] == t)
       return false;
     if (x[i] == s)
       return true;
   }
   return true;
 }
示例#11
0
 /// %Test whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   for (int j=0; j<c.size()-1; j++)
     for (int i=0; i<x.size(); i++) {
       if (x[i] == c[j+1])
         return false;
       if (x[i] == c[j])
         break;
     }
   return true;
 }
示例#12
0
文件: gcc.cpp 项目: Gecode/gecode
 /// %Test whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   int n[2];
   for (int i=2; i--; )
     n[i] = 0;
   for (int i=x.size(); i--; )
     n[x[i] - 1]++;
   if (n[0] != 2 || n[1] != 2)
     return false;
   return true;
 }
示例#13
0
文件: rel.cpp 项目: Wushaowei001/vcp
 /// %Test whether \a x is solution
 virtual MaybeType solution(const Assignment& x) const {
   if (x.size() == 2) {
     return cmp(x[0],frt,x[1]);
   } else {
     MaybeType r1 = cmp(x[0],frt,x[2]);
     MaybeType r2 = cmp(x[1],frt,x[2]);
     if ((r1 == MT_TRUE) && (r2 == MT_TRUE)) return MT_TRUE;
     else if ((r1 == MT_FALSE) || (r2 == MT_FALSE)) return MT_FALSE;
     else return MT_MAYBE;
   }
 }
示例#14
0
bool Assignment::is_compatible(const Assignment & partial) const{
  int maxsize = std::max(partial.size(), size());
  for(int i = 0; i<maxsize; i++){
    if(partial[i] == -1){
      continue;
    }
    if(partial[i] != assignment[i]){
      return false;
    }
  }
  return true;
}
示例#15
0
文件: linear.cpp 项目: Gecode/gecode
 /// %Test whether \a x is solution
 virtual MaybeType solution(const Assignment& x) const {
   Gecode::FloatVal e = 0.0;
   for (int i=x.size(); i--; )
     e += a[i]*x[i];
   switch (cmp(e, frt, Gecode::FloatVal(c))) {
   case MT_FALSE: {
     Gecode::FloatVal eError = e;
     for (int i=x.size(); i--; )
       eError -= a[i]*x[i];
     if (cmp(e+eError, frt, Gecode::FloatVal(c)) == MT_FALSE)
       return MT_FALSE;
     else
       return MT_MAYBE;
   }
   case MT_TRUE:
     return MT_TRUE;
   case MT_MAYBE:
     return MT_MAYBE;
   }
   GECODE_NEVER;
   return MT_FALSE;
 }
示例#16
0
文件: gcc.cpp 项目: Gecode/gecode
 /// %Test whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   int n[4];
   for (int i=4; i--; )
     n[i]=0;
   for (int i=x.size(); i--; )
     n[x[i]]++;
   if (n[2] > 0)
     return false;
   for (int i=4; i--;)
     if (n[i]>2)
       return false;
   return true;
 }
示例#17
0
 /// %Test whether \a xy is solution
 virtual bool solution(const Assignment& xy) const {
   int n = xy.size() / 2;
   for (int i=0; i<n; i++) {
     int xi=xy[2*i+0], yi=xy[2*i+1];
     for (int j=i+1; j<n; j++) {
       int xj=xy[2*j+0], yj=xy[2*j+1];
       if (!((xi + w[i] <= xj) || (xj + w[j] <= xi) ||
             (yi + h[i] <= yj) || (yj + h[j] <= yi)))
         return false;
     }
   }
   return true;
 }
示例#18
0
 /// %Test whether \a x is solutionin
 virtual bool solution(const Assignment& x) const {
   for (int i=0; i< (x.size() - q + 1); i++ ) {
     int total = 0;
     for (int j=i; j < i + q; j++ ) {
       if (s.in(x[j]))
         total++;
       if (total > u)
         return false;
     }
     if ( total < l )
       return false;
   }
   return true;
 }
示例#19
0
 /// %Test whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   int n = x.size();
   bool* v = new bool[n+1];
   for (int i=n+1; i--; )
     v[i] = false;
   int k = 0;
   for (int i=n; i--; )
     if (!v[x[i]]) {
       k++;
       v[x[i]] = true;
     }
   delete [] v;
   return cmp(k,irt,m);
 }
示例#20
0
 /// %Test whether \a xwyh is solution
 virtual bool solution(const Assignment& xwyh) const {
   int n = xwyh.size() / 4;
   for (int i=0; i<n; i++) {
     int xi=xwyh[4*i+0], yi=xwyh[4*i+2];
     int wi=xwyh[4*i+1], hi=xwyh[4*i+3];
     for (int j=i+1; j<n; j++) {
       int xj=xwyh[4*j+0], yj=xwyh[4*j+2];
       int wj=xwyh[4*j+1], hj=xwyh[4*j+3];
       if (!((xi + wi <= xj) || (xj + wj <= xi) ||
             (yi + hi <= yj) || (yj + hj <= yi)))
         return false;
     }
   }
   return true;
 }
示例#21
0
 /// %Test whether \a xyo is solution
 virtual bool solution(const Assignment& xyo) const {
   int n = xyo.size() / 3;
   for (int i=0; i<n; i++) {
     int xi=xyo[3*i+0], yi=xyo[3*i+1];
     int oi=xyo[3*i+2];
     for (int j=i+1; j<n; j++) {
       int xj=xyo[3*j+0], yj=xyo[3*j+1];
       int oj=xyo[3*j+2];
       if ((oi > 0) && (oj > 0) &&
           !((xi + w[i] <= xj) || (xj + w[j] <= xi) ||
             (yi + h[i] <= yj) || (yj + h[j] <= yi)))
         return false;
     }
   }
   return true;
 }
示例#22
0
 /// Check whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   int n = x.size()-1;
   for (int i=n; i--; )
     if ((x[i] != 0) && (x[i] != 1))
       return false;
   int k=x[n]-o;
   if ((k<0) || (k>=n))
     return false;
   for (int i=0; i<k; i++)
     if (x[i] != 0)
       return false;
   for (int i=k+1; i<n; i++)
     if (x[i] != 0)
       return false;
   return x[k] == 1;
 }
示例#23
0
 /// %Test whether \a xwyho is solution
 virtual bool solution(const Assignment& xwyho) const {
   int n = (xwyho.size() - 2) / 2;
   for (int i=0; i<n; i++) {
     int xi=xwyho[2*i+0], yi=xwyho[2*i+0];
     int wi=xwyho[2*i+1], hi=xwyho[2*i+1];
     int oi=xwyho[2*n + (i % 2)];
     for (int j=i+1; j<n; j++) {
       int xj=xwyho[2*j+0], yj=xwyho[2*j+0];
       int wj=xwyho[2*j+1], hj=xwyho[2*j+1];
       int oj=xwyho[2*n + (j % 2)];
       if ((oi > 0) && (oj > 0) &&
           !((xi + wi <= xj) || (xj + wj <= xi) ||
             (yi + hi <= yj) || (yj + hj <= yi)))
         return false;
     }
   }
   return true;
 }
bool Configuration::apply_assignment(Assignment &assignment){

    /* This method apply each individual assignment in order.
     * If one of them fails, the complete process fails.
     */
    for(int i=0;i<assignment.size();i++){
        switch(assignment[i].second){
            case SELECTED:
                if(!this->apply_selection(assignment[i].first))
                    return false;
                break;
            case DESELECTED:
                if(!this->apply_deselection(assignment[i].first))
                    return false;
                break;
        }
    }
    return true;
}
示例#25
0
文件: gcc.cpp 项目: Gecode/gecode
 /// %Test whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   // Number of cardinality variables
   int m = x.size()-n;
   int* card = new int[m];
   for (int i=0; i<m; i++) {
     card[i] = 0;
     if ((x[n+i] < 0) || (x[n+i] > n)) {
       delete [] card;
       return false;
     }
   }
   for (int i=0; i<n; i++)
     card[x[i]-dom.min()]++;
   for (int i=0; i<m; i++)
     if (card[i] != x[n+i]) {
       delete [] card;
       return false;
     }
   delete [] card;
   return true;
 }
NNGraph MSConnectivityScore::build_subgraph_from_assignment(
    NNGraph &G, Assignment const &assignment) const {
  unsigned int num_particles = restraint_.particle_matrix_.size();
  Ints vertices;
  for (unsigned int i = 0; i < assignment.size(); ++i)
    if (!assignment[i].empty()) {
      Ints const &conf = assignment[i].get_tuple();
      for (unsigned int j = 0; j < conf.size(); ++j)
        vertices.push_back(conf[j]);
    }
  boost::property_map<NNGraph, boost::vertex_name_t>::type vertex_id =
      boost::get(boost::vertex_name, G);
  boost::property_map<NNGraph, boost::edge_weight_t>::type dist =
      boost::get(boost::edge_weight, G);
  NNGraph ng(vertices.size());
  boost::property_map<NNGraph, boost::vertex_name_t>::type new_vertex_id =
      boost::get(boost::vertex_name, ng);
  boost::property_map<NNGraph, boost::edge_weight_t>::type new_dist =
      boost::get(boost::edge_weight, ng);
  for (unsigned int i = 0; i < vertices.size(); ++i)
    boost::put(new_vertex_id, i, vertices[i]);
  Ints vertex_id_to_idx(num_particles, -1);
  for (unsigned int i = 0; i < vertices.size(); ++i)
    vertex_id_to_idx[vertices[i]] = i;
  NNGraph::edge_iterator e, end;
  for (boost::tie(e, end) = edges(G); e != end; ++e) {
    unsigned int source_id = boost::get(vertex_id, source(*e, G));
    unsigned int dest_id = boost::get(vertex_id, target(*e, G));
    unsigned int p_src = vertex_id_to_idx[source_id];
    unsigned int p_dst = vertex_id_to_idx[dest_id];
    if (p_src == static_cast<unsigned int>(-1) ||
        p_dst == static_cast<unsigned int>(-1))
      continue;
    NNGraph::edge_descriptor ed = boost::add_edge(p_src, p_dst, ng).first;
    double d = boost::get(dist, *e);
    boost::put(new_dist, ed, d);
  }
  return ng;
}
示例#27
0
 /// %Test whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   for (int i=x.size(); i--; )
     if ((x[i] < -2) || (x[i] > 2))
       return false;
   return true;
 }
示例#28
0
 /// Check whether \a x is solution
 virtual bool solution(const Assignment& x) const {
   int t=0;
   for (int i=0; i<x.size(); i++)
     t += x[i];
   return t==2;
 }