Пример #1
0
void load_particle_states(const Subset &s,
                          const Assignment &ss,
                          const ParticleStatesTable *pst) {
  load_particle_states(s.begin(), s.end(), ss, pst);
  if (s.size()!=0) {
    s[0]->get_model()->update();
  }
}
Пример #2
0
/**
 * Compute the Kramer-Mesner matrix.
 *
 * Precondition: t < k
 */
KramerMesnerMatrix computeKMMatrix(const Group& G, unsigned int t, unsigned int k) {
	std::vector<KMBuilderOutput> builderOutputs;			// stores the relevant data for k = 2 onwards
	Matrix A;
	
	for (int i = 2; i <= k; i++) {
		boost::scoped_ptr<KMBuilder> builder;
		
		// Get orbit representatives of (i - 1)-subsets
		std::vector<Subset> orbitReps;
		if (i == 2) {
			// As it is the first time, we have to compute the orbit representatives of singleton subsets...
			Subset pointsRemaining = generateX(G.getNumPoints());
			while (!pointsRemaining.empty()) {
				typedef OrbitSet<Permutation, unsigned long>::const_iterator OrbitSetIterator;
				
				unsigned long point = *(pointsRemaining.begin());	// A new representative...
				Subset singletonSet = makeSingletonSet(point);		// ...as a set
				orbitReps.push_back(singletonSet);
				
				// Compute the orbit of the point, and remove it from the remaining points
				OrbitSet<Permutation, unsigned long> orbit = G.orbit(point, Transversal::TrivialAction());
				for (OrbitSetIterator it = orbit.begin(); it != orbit.end(); it++) {
					pointsRemaining.erase(pointsRemaining.find(*it));
				}
			}
			
			builder.reset(new KMBuilder(G, i, orbitReps));
		} else {
			// We get them from what we computed earlier
			KMBuilderOutput& input = builderOutputs[i - 3];
			orbitReps = input.getNewReps();
			
			builder.reset(new KMBuilder(G, i, orbitReps, input.getPrunerData()));
		}
		
		KMBuilderOutput builderOutput = builder->build();
		builderOutputs.push_back(builderOutput);
		
		// From the identity that A[t][k] = A[t][s] * A[s][k] / combinat(k - t, k - s) for any s
		// between t and k, we get the following:
		if (i == t + 1) {
			assignMatrix(A, builderOutput.getNewMatrix());
		} else if (i > t + 1) {
			assignMatrix(A, matrixMultiply(A, builderOutput.getNewMatrix()));
			scalarDivide(i - t, A);
		}
	}
	
	return KramerMesnerMatrix(G, builderOutputs[t - 2].getNewReps(), builderOutputs[k - 2].getNewReps(), A);
}
Пример #3
0
Ints get_partial_index(const ParticlesTemp &particles,
               const Subset &subset, const Subsets &excluded) {
  for (unsigned int i=0; i< excluded.size(); ++i) {
    bool all=true;
    for (unsigned int j=0; j< particles.size(); ++j) {
      if (!std::binary_search(excluded[i].begin(), excluded[i].end(),
                              particles[j])) {
        all=false;
        break;
      }
    }
    if (all) {
      return Ints();
    }
  }
  Ints ret(particles.size(), -1);
  for (unsigned int i=0; i< particles.size(); ++i) {
    Subset::const_iterator it= std::lower_bound(subset.begin(),
                                                subset.end(), particles[i]);
    if (it!= subset.end() && *it == particles[i]) {
      ret[i]= it-subset.begin();
    }
  }
  IMP_IF_LOG(VERBOSE) {
    IMP_LOG(VERBOSE, "Returning ");
    for (unsigned int i=0; i< ret.size(); ++i) {
      IMP_LOG(VERBOSE, ret[i] << " ");
    }
    IMP_LOG(VERBOSE, "for ");
     for (unsigned int i=0; i< particles.size(); ++i) {
       IMP_LOG(VERBOSE, particles[i]->get_name() << " ");
     }
     IMP_LOG(VERBOSE, " subset " << subset << std::endl);
  }
  return ret;
}
Пример #4
0
Subset MinRepPruner::minRep(const Subset& candidate) {
	typedef boost::dynamic_bitset<unsigned long> dset;
	
	dset candidateBitset(G->getNumPoints());
	for (Subset::const_iterator it = candidate.begin(); it != candidate.end(); ++it) {
		candidateBitset[*it] = true;
	}
	
	dset resultBitset = search.lexMin(candidateBitset);
	
	Subset result;
	for (dset::size_type i = resultBitset.find_first(); i != dset::npos; i = resultBitset.find_next(i)) {
		result.insert(i);
	}
	return result;
}
Пример #5
0
RestraintsTemp get_restraints(const Subset &s,
                              const ParticleStatesTable *pst,
                              const DependencyGraph &dg,
                              RestraintSet *rs) {
  RestraintsTemp rw= get_restraints(RestraintsTemp(1, rs));
  Subset other=pst->get_subset();
  ParticlesTemp oms;
  std::set_difference(other.begin(), other.end(),
                      s.begin(), s.end(),
                      std::back_inserter(oms));
  IMP::compatibility::map<Restraint*, int> index
    = IMP::base::internal::get_graph_index<Restraint>(dg);
  Ints to_remove;
  for (unsigned int i=0; i< rw.size(); ++i) {
    if (IMP::internal::get_has_ancestor(dg, index[rw[i]], oms)) {
      to_remove.push_back(i);
    }
  }
  for (int i=to_remove.size()-1; i >=0; --i) {
    rw.erase(rw.begin()+to_remove[i]);
  }
  return rw;
}
Пример #6
0
int S(const Subset &v) {
	return accumulate(v.begin(), v.end(), 0);
}
Пример #7
0
SubsetGraph get_restraint_graph(ScoringFunctionAdaptor in,
                                const ParticleStatesTable *pst) {
  RestraintsTemp rs =
      IMP::create_decomposition(in->create_restraints());
  // ScoreStatesTemp ss= get_required_score_states(rs);
  SubsetGraph ret(rs.size());  // + ss.size());
  IMP_LOG_TERSE("Creating restraint graph on " << rs.size() << " restraints."
                                               << std::endl);
  boost::unordered_map<Particle *, int> map;
  SubsetGraphVertexName pm = boost::get(boost::vertex_name, ret);
  DependencyGraph dg = get_dependency_graph(rs[0]->get_model());
  DependencyGraphVertexIndex index = IMP::get_vertex_index(dg);
  /*IMP_IF_LOG(VERBOSE) {
    IMP_LOG_VERBOSE( "dependency graph is \n");
    IMP::internal::show_as_graphviz(dg, std::cout);
    }*/
  Subset ps = pst->get_subset();
  for (unsigned int i = 0; i < ps.size(); ++i) {
    ParticlesTemp t = get_dependent_particles(
        ps[i], ParticlesTemp(ps.begin(), ps.end()), dg, index);
    for (unsigned int j = 0; j < t.size(); ++j) {
      IMP_USAGE_CHECK(map.find(t[j]) == map.end(),
                      "Currently particles which depend on more "
                          << "than one particle "
                          << "from the input set are not supported."
                          << "  Particle \"" << t[j]->get_name()
                          << "\" depends on \"" << ps[i]->get_name()
                          << "\" and \""
                          << ps[map.find(t[j])->second]->get_name() << "\"");
      map[t[j]] = i;
    }
    IMP_IF_LOG(VERBOSE) {
      IMP_LOG_VERBOSE("Particle \"" << ps[i]->get_name() << "\" controls ");
      for (unsigned int i = 0; i < t.size(); ++i) {
        IMP_LOG_VERBOSE("\"" << t[i]->get_name() << "\" ");
      }
      IMP_LOG_VERBOSE(std::endl);
    }
  }
  for (unsigned int i = 0; i < rs.size(); ++i) {
    ParticlesTemp pl = IMP::get_input_particles(rs[i]->get_inputs());
    std::sort(pl.begin(), pl.end());
    pl.erase(std::unique(pl.begin(), pl.end()), pl.end());
    Subset os(pl);
    for (unsigned int j = 0; j < pl.size(); ++j) {
      pl[j] = ps[map[pl[j]]];
    }
    std::sort(pl.begin(), pl.end());
    pl.erase(std::unique(pl.begin(), pl.end()), pl.end());
    Subset s(pl);
    IMP_LOG_VERBOSE("Subset for restraint " << rs[i]->get_name() << " is " << s
                                            << " from " << os << std::endl);
    pm[i] = s;
  }
  /*ScoreStatesTemp ss= get_required_score_states(rs);
    for (ScoreStatesTemp::const_iterator it= ss.begin();
    it != ss.end(); ++it) {
    ParticlesTemp pl= (*it)->get_input_particles();
    add_edges(ps, pl, map, *it, ret);
    ParticlesTemp opl= (*it)->get_output_particles();
    add_edges(ps, opl, map, *it, ret);
    }
    IMP_INTERNAL_CHECK(boost::num_vertices(ret) == ps.size(),
    "Wrong number of vertices "
    << boost::num_vertices(ret)
    << " vs " << ps.size());*/
  for (unsigned int i = 0; i < boost::num_vertices(ret); ++i) {
    for (unsigned int j = 0; j < i; ++j) {
      if (get_intersection(pm[i], pm[j]).size() > 0) {
        boost::add_edge(i, j, ret);
        IMP_LOG_VERBOSE("Connecting " << rs[i]->get_name() << " with "
                                      << rs[j]->get_name() << std::endl);
      }
    }
  }
  return ret;
}