gtsam/gtsam_unstable/discrete/Constraint.h

103 lines
2.8 KiB
C
Raw Normal View History

/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
/**
* @file Constraint.h
* @date May 15, 2012
* @author Frank Dellaert
*/
#pragma once
2021-11-18 23:17:49 +08:00
#include <gtsam/discrete/DiscreteFactor.h>
2021-12-14 02:46:53 +08:00
#include <gtsam/discrete/DiscreteValues.h>
2021-11-19 04:08:01 +08:00
#include <gtsam_unstable/dllexport.h>
2021-12-25 02:27:02 +08:00
#include <boost/format.hpp>
2021-11-21 04:52:12 +08:00
#include <map>
namespace gtsam {
2021-11-19 04:08:01 +08:00
class Domain;
2021-11-21 04:52:12 +08:00
using Domains = std::map<Key, Domain>;
2021-11-19 04:08:01 +08:00
/**
* Base class for constraint factors
* Derived classes include SingleValue, BinaryAllDiff, and AllDiff.
*/
class GTSAM_UNSTABLE_EXPORT Constraint : public DiscreteFactor {
2021-11-19 04:08:01 +08:00
public:
typedef boost::shared_ptr<Constraint> shared_ptr;
2021-11-19 04:08:01 +08:00
protected:
/// Construct unary constraint factor.
Constraint(Key j) : DiscreteFactor(KeyVector{j}) {}
2021-11-19 04:08:01 +08:00
/// Construct binary constraint factor.
Constraint(Key j1, Key j2) : DiscreteFactor(KeyVector{j1, j2}) {}
2021-11-19 04:08:01 +08:00
/// Construct n-way constraint factor.
Constraint(const KeyVector& js) : DiscreteFactor(js) {}
2021-11-19 04:08:01 +08:00
/// construct from container
template <class KeyIterator>
Constraint(KeyIterator beginKey, KeyIterator endKey)
: DiscreteFactor(beginKey, endKey) {}
2021-11-18 23:17:49 +08:00
2021-11-19 04:08:01 +08:00
public:
/// @name Standard Constructors
/// @{
2021-11-18 23:17:49 +08:00
2021-11-19 04:08:01 +08:00
/// Default constructor for I/O
Constraint();
2021-11-18 23:17:49 +08:00
2021-11-19 04:08:01 +08:00
/// Virtual destructor
~Constraint() override {}
2021-11-18 23:17:49 +08:00
2021-11-19 04:08:01 +08:00
/// @}
/// @name Standard Interface
/// @{
2021-11-18 23:17:49 +08:00
2021-11-19 04:08:01 +08:00
/*
2021-11-21 04:52:12 +08:00
* Ensure Arc-consistency by checking every possible value of domain j.
2021-11-19 04:08:01 +08:00
* @param j domain to be checked
2021-11-21 04:52:12 +08:00
* @param (in/out) domains all domains, but only domains->at(j) will be checked.
* @return true if domains->at(j) was changed, false otherwise.
2021-11-19 04:08:01 +08:00
*/
2021-11-21 04:52:12 +08:00
virtual bool ensureArcConsistency(Key j, Domains* domains) const = 0;
2021-11-19 04:08:01 +08:00
/// Partially apply known values
2021-12-14 02:46:53 +08:00
virtual shared_ptr partiallyApply(const DiscreteValues&) const = 0;
2021-11-19 04:08:01 +08:00
/// Partially apply known values, domain version
2021-11-21 04:52:12 +08:00
virtual shared_ptr partiallyApply(const Domains&) const = 0;
2021-11-19 04:08:01 +08:00
/// @}
2021-12-25 02:27:02 +08:00
/// @name Wrapper support
/// @{
/// Render as markdown table.
std::string markdown(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const Names& names = {}) const override {
2021-12-25 02:27:02 +08:00
return (boost::format("`Constraint` on %1% variables\n") % (size())).str();
}
2022-01-09 21:19:44 +08:00
/// Render as html table.
std::string html(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const Names& names = {}) const override {
return (boost::format("<p>Constraint on %1% variables</p>") % (size())).str();
}
2021-12-25 02:27:02 +08:00
/// @}
2021-11-19 04:08:01 +08:00
};
// DiscreteFactor
2021-11-19 04:08:01 +08:00
} // namespace gtsam