Class SubmodularFunctionWrapper

Inheritance Relationships

Base Type

Class Documentation

class SubmodularFunctionWrapper : public SubmodularFunction

A simple Wrapper class which takse a std::function and uses it to implement the SubmodularFunction interface. This is used as a convience class for the SubmodularOptimizer interface. This wrapper is meant for stateless functions so that the std::function should not have / change / maintain an internal state which depends on the order of function calls. The main reason for this is, that the given std::function is likely to be moved into the member object (and not copied) which makes for very efficient code. However, some optimizers require multiple copies of the same function such as SieveStreaming(++) for multiple sub-optimizers. In this case, all (sub-) optimizers reference the same object, which works fine if the function is stateless but probably breaks for stateful functions. If your submodular function requires some internal states which e.g. depend on the order of items added please consider to implement a proper SubmodularFunction.

Note

returns None

Public Functions

inline SubmodularFunctionWrapper(std::function<data_t(std::vector<std::vector<data_t>> const&)> f)

Creates a new SubmodularFunction from a given std::function object.

Note

Parameters

f – The (stateless) function which implements the actual submodular function

Returns

inline virtual data_t operator()(std::vector<std::vector<data_t>> const &cur_solution) const

Implements the () operator by simply delegating the call to the underlying std::function.

Note

Parameters

&cur_solution –

Returns

inline virtual data_t peek(std::vector<std::vector<data_t>> const &cur_solution, std::vector<data_t> const &x, unsigned int pos)

Implements the peek method. This copies the current solution vector to a new one, adds x at the appropriate positon and calls the ()-operator. In most cases the copy is probably not necessary (e.g. if we only append x to the current solution) which makes this code slightly inefficient.

Note

Parameters
  • &cur_solution –

  • &x –

  • pos –

Returns

inline virtual void update(std::vector<std::vector<data_t>> const &cur_solution, std::vector<data_t> const &x, unsigned int pos)

Implements the update method. This class only wraps an std::function so it is state-less and the std::function would have to deal with any stateful behaviour. Thus, we don’t do anything here.

Note

Parameters
  • &cur_solution –

  • &x –

  • pos –

Returns None

inline virtual std::shared_ptr<SubmodularFunction> clone() const

Implements the clone method. Note, that it is very likely that the std::function f has been moved into this object and similarly, we will move it into the clone as-well. This is okay, as long as f is a stateless function. However, if f has some internal state, then the other optimizers will use the same function with the shared state which will probably lead to weird side-effects. In this case consider implementing a proper SubmodularFunction.

Note

Returns The

cloned object.

inline ~SubmodularFunctionWrapper()

Destroy the wrapper object.

Note

Protected Attributes

std::function<data_t(std::vector<std::vector<data_t>> const&)> f