8#ifndef IMPKERNEL_OPTIMIZER_H
9#define IMPKERNEL_OPTIMIZER_H
11#include <IMP/kernel_config.h>
23#include <cereal/access.hpp>
24#include <cereal/types/base_class.hpp>
26IMPKERNEL_BEGIN_NAMESPACE
48class IMPKERNELEXPORT Optimizer :
public ModelObject {
49 bool stop_on_good_score_;
52 friend class cereal::access;
54 template<
class Archive>
void serialize(Archive &ar) {
55 ar(cereal::base_class<ModelObject>(
this), stop_on_good_score_,
56 scoring_function_, mutable_access_optimizer_states());
57 if (std::is_base_of<cereal::detail::InputArchiveBase, Archive>::value) {
58 for (
auto &obj : mutable_access_optimizer_states()) {
59 set_optimizer_state_optimizer(obj,
this);
64 static void set_optimizer_state_optimizer(
OptimizerState *os, Optimizer *o);
68 void set_is_optimizing_states(
bool tf)
const;
72 return get_optimizer_state_inputs();
99 bool get_stop_on_good_score()
const {
return stop_on_good_score_; }
107 if (scoring_function_) {
108 return scoring_function_;
110 IMP_THROW(
"No scoring function was set. "
111 "Use Optimizer::set_scoring_function() to set one.",
125 set_optimizer_state_optimizer(obj,
this);
127 { Optimizer::set_optimizer_state_optimizer(obj,
nullptr); });
147IMPKERNEL_END_NAMESPACE
Base class for objects in a Model that depend on other objects.
Storage of a model, its restraints, constraints and particles.
A shared base class to help in debugging and things.
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
A nullptr-initialized pointer to an IMP Object.
A class for storing lists of IMP items.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
Class for storing model, its restraints, constraints, and particles.
Shared optimizer state that is invoked upon commitment of new coordinates.
Base class for all optimizers.
virtual void set_scoring_function(ScoringFunctionAdaptor sf)
Set the scoring function to use.
virtual ModelObjectsTemp do_get_outputs() const override
don't return anything here to avoid pointless dependencies
void update_states() const
Update optimizer states, should be called at each successful step.
virtual double do_optimize(unsigned int ns)=0
override this function to do actual optimization
ScoringFunction * get_scoring_function() const
Return the scoring function that is being used.
double get_last_score() const
Return the score found in the last evaluate.
virtual ModelObjectsTemp do_get_inputs() const override
double optimize(unsigned int max_steps)
Optimize the model for up to max_steps iterations.
void set_stop_on_good_score(bool tf)
Represents a scoring function on the model.
An exception for an invalid value being passed to IMP.
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
IMP::Vector< IMP::Pointer< Optimizer > > Optimizers
IMP::Vector< IMP::Pointer< OptimizerState > > OptimizerStates
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
#define IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(Name)
A smart pointer to a reference counted object.
Various general useful functions for IMP.