Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::LinearSumAssignment< GraphType > Class Template Reference

This class does not take ownership of its underlying graph. More...

#include <linear_assignment.h>

Classes

class  BipartiteLeftNodeIterator
 

Public Types

typedef GraphType::NodeIndex NodeIndex
 
typedef GraphType::ArcIndex ArcIndex
 

Public Member Functions

 LinearSumAssignment (const GraphType &graph, NodeIndex num_left_nodes)
 
 LinearSumAssignment (NodeIndex num_left_nodes, ArcIndex num_arcs)
 
 LinearSumAssignment (const LinearSumAssignment &)=delete
 This type is neither copyable nor movable.
 
LinearSumAssignmentoperator= (const LinearSumAssignment &)=delete
 
 ~LinearSumAssignment ()
 
void SetGraph (const GraphType *graph)
 
void SetCostScalingDivisor (CostValue factor)
 
operations_research::PermutationCycleHandler< typename GraphType::ArcIndex > * ArcAnnotationCycleHandler ()
 Passes ownership of the cycle handler to the caller.
 
void OptimizeGraphLayout (GraphType *graph)
 
const GraphType & Graph () const
 Allows tests, iterators, etc., to inspect our underlying graph.
 
NodeIndex Head (ArcIndex arc) const
 
CostValue ArcCost (ArcIndex arc) const
 
void SetArcCost (ArcIndex arc, CostValue cost)
 Sets the cost of an arc already present in the given graph.
 
bool FinalizeSetup ()
 
bool ComputeAssignment ()
 
CostValue GetCost () const
 
NodeIndex NumNodes () const
 Returns the total number of nodes in the given problem.
 
NodeIndex NumLeftNodes () const
 
ArcIndex GetAssignmentArc (NodeIndex left_node) const
 Returns the arc through which the given node is matched.
 
CostValue GetAssignmentCost (NodeIndex node) const
 
NodeIndex GetMate (NodeIndex left_node) const
 Returns the node to which the given node is matched.
 
std::string StatsString () const
 

Detailed Description

template<typename GraphType>
class operations_research::LinearSumAssignment< GraphType >

This class does not take ownership of its underlying graph.

Definition at line 225 of file linear_assignment.h.

Member Typedef Documentation

◆ ArcIndex

template<typename GraphType >
GraphType::ArcIndex operations_research::LinearSumAssignment< GraphType >::ArcIndex

Definition at line 228 of file linear_assignment.h.

◆ NodeIndex

template<typename GraphType >
GraphType::NodeIndex operations_research::LinearSumAssignment< GraphType >::NodeIndex

Definition at line 227 of file linear_assignment.h.

Constructor & Destructor Documentation

◆ LinearSumAssignment() [1/3]

template<typename GraphType >
operations_research::LinearSumAssignment< GraphType >::LinearSumAssignment ( const GraphType & graph,
NodeIndex num_left_nodes )

Constructor for the case in which we will build the graph incrementally as we discover arc costs, as might be done with any of the dynamic graph representations such as StarGraph or ForwardStarGraph.

Definition at line 964 of file linear_assignment.h.

◆ LinearSumAssignment() [2/3]

template<typename GraphType >
operations_research::LinearSumAssignment< GraphType >::LinearSumAssignment ( NodeIndex num_left_nodes,
ArcIndex num_arcs )

Constructor for the case in which the underlying graph cannot be built until after all the arc costs are known, as is the case with ForwardStarStaticGraph. In this case, the graph is passed to us later via the SetGraph() method, below.

Definition at line 987 of file linear_assignment.h.

◆ LinearSumAssignment() [3/3]

template<typename GraphType >
operations_research::LinearSumAssignment< GraphType >::LinearSumAssignment ( const LinearSumAssignment< GraphType > & )
delete

This type is neither copyable nor movable.

◆ ~LinearSumAssignment()

template<typename GraphType >
operations_research::LinearSumAssignment< GraphType >::~LinearSumAssignment ( )
inline

Definition at line 245 of file linear_assignment.h.

Member Function Documentation

◆ ArcAnnotationCycleHandler()

template<typename GraphType >
PermutationCycleHandler< typename GraphType::ArcIndex > * operations_research::LinearSumAssignment< GraphType >::ArcAnnotationCycleHandler ( )

Passes ownership of the cycle handler to the caller.

Returns a permutation cycle handler that can be passed to the TransformToForwardStaticGraph method so that arc costs get permuted along with arcs themselves.

Passes ownership of the cycle handler to the caller.

Definition at line 1085 of file linear_assignment.h.

◆ ArcCost()

template<typename GraphType >
CostValue operations_research::LinearSumAssignment< GraphType >::ArcCost ( ArcIndex arc) const
inline

Returns the original arc cost for use by a client that's iterating over the optimum assignment.

Definition at line 294 of file linear_assignment.h.

◆ ComputeAssignment()

template<typename GraphType >
bool operations_research::LinearSumAssignment< GraphType >::ComputeAssignment ( )

Computes the optimum assignment. Returns true on success. Return value of false implies the given problem is infeasible.

Note
FinalizeSetup() might have been called already by white-box test code or by a client that wants to react to the possibility of overflow before solving the given problem, but FinalizeSetup() is idempotent and reasonably fast, so we call it unconditionally here.

Definition at line 1451 of file linear_assignment.h.

◆ FinalizeSetup()

template<typename GraphType >
bool operations_research::LinearSumAssignment< GraphType >::FinalizeSetup ( )

Completes initialization after the problem is fully specified. Returns true if we successfully prove that arithmetic calculations are guaranteed not to overflow. ComputeAssignment() calls this method itself, so only clients that care about obtaining a warning about the possibility of arithmetic precision problems need to call this method explicitly.

Separate from ComputeAssignment() for white-box testing and for clients that need to react to the possibility that arithmetic overflow is not ruled out.

FinalizeSetup() is idempotent.

epsilon_ must be greater than kMinEpsilon so that in the case where the largest arc cost is zero, we still do a Refine() iteration.

Initialize left-side node-indexed arrays and check incidence precondition.

Initialize right-side node-indexed arrays. Example: prices are stored only for right-side nodes.

Definition at line 1391 of file linear_assignment.h.

◆ GetAssignmentArc()

template<typename GraphType >
ArcIndex operations_research::LinearSumAssignment< GraphType >::GetAssignmentArc ( NodeIndex left_node) const
inline

Returns the arc through which the given node is matched.

Definition at line 341 of file linear_assignment.h.

◆ GetAssignmentCost()

template<typename GraphType >
CostValue operations_research::LinearSumAssignment< GraphType >::GetAssignmentCost ( NodeIndex node) const
inline

Returns the cost of the assignment arc incident to the given node.

Definition at line 348 of file linear_assignment.h.

◆ GetCost()

template<typename GraphType >
CostValue operations_research::LinearSumAssignment< GraphType >::GetCost ( ) const

Returns the cost of the minimum-cost perfect matching. Precondition: success_ == true, signifying that we computed the optimum assignment for a feasible problem.

It is illegal to call this method unless we successfully computed an optimum assignment.

Definition at line 1476 of file linear_assignment.h.

◆ GetMate()

template<typename GraphType >
NodeIndex operations_research::LinearSumAssignment< GraphType >::GetMate ( NodeIndex left_node) const
inline

Returns the node to which the given node is matched.

Definition at line 353 of file linear_assignment.h.

◆ Graph()

template<typename GraphType >
const GraphType & operations_research::LinearSumAssignment< GraphType >::Graph ( ) const
inline

Allows tests, iterators, etc., to inspect our underlying graph.

Definition at line 284 of file linear_assignment.h.

◆ Head()

template<typename GraphType >
NodeIndex operations_research::LinearSumAssignment< GraphType >::Head ( ArcIndex arc) const
inline

These handy member functions make the code more compact, and we expose them to clients so that client code that doesn't have direct access to the graph can learn about the optimum assignment once it is computed.

Definition at line 290 of file linear_assignment.h.

◆ NumLeftNodes()

template<typename GraphType >
NodeIndex operations_research::LinearSumAssignment< GraphType >::NumLeftNodes ( ) const
inline

Returns the number of nodes on the left side of the given problem.

Definition at line 338 of file linear_assignment.h.

◆ NumNodes()

template<typename GraphType >
NodeIndex operations_research::LinearSumAssignment< GraphType >::NumNodes ( ) const
inline

Returns the total number of nodes in the given problem.

Return a guess that must be true if ultimately we are given a feasible problem to solve.

Definition at line 326 of file linear_assignment.h.

◆ operator=()

template<typename GraphType >
LinearSumAssignment & operations_research::LinearSumAssignment< GraphType >::operator= ( const LinearSumAssignment< GraphType > & )
delete

◆ OptimizeGraphLayout()

template<typename GraphType >
void operations_research::LinearSumAssignment< GraphType >::OptimizeGraphLayout ( GraphType * graph)

Optimizes the layout of the graph for the access pattern our implementation will use.

REQUIRES for LinearSumAssignment template instantiation if a call to the OptimizeGraphLayout() method is compiled: GraphType is a dynamic graph, i.e., one that implements the GroupForwardArcsByFunctor() member template method.

If analogous optimization is needed for LinearSumAssignment instances based on static graphs, the graph layout should be constructed such that each node's outgoing arcs are sorted by head node index before the LinearSumAssignment<GraphType>::SetGraph() method is called.

The graph argument is only to give us a non-const-qualified handle on the graph we already have. Any different graph is nonsense.

Definition at line 1091 of file linear_assignment.h.

◆ SetArcCost()

template<typename GraphType >
void operations_research::LinearSumAssignment< GraphType >::SetArcCost ( ArcIndex arc,
CostValue cost )

Sets the cost of an arc already present in the given graph.

Definition at line 1010 of file linear_assignment.h.

◆ SetCostScalingDivisor()

template<typename GraphType >
void operations_research::LinearSumAssignment< GraphType >::SetCostScalingDivisor ( CostValue factor)
inline

Sets the cost-scaling divisor, i.e., the amount by which we divide the scaling parameter on each iteration.

Definition at line 257 of file linear_assignment.h.

◆ SetGraph()

template<typename GraphType >
void operations_research::LinearSumAssignment< GraphType >::SetGraph ( const GraphType * graph)
inline

Sets the graph used by the LinearSumAssignment instance, for use when the graph layout can be determined only after arc costs are set. This happens, for example, when we use a ForwardStarStaticGraph.

Definition at line 250 of file linear_assignment.h.

◆ StatsString()

template<typename GraphType >
std::string operations_research::LinearSumAssignment< GraphType >::StatsString ( ) const
inline

Definition at line 360 of file linear_assignment.h.


The documentation for this class was generated from the following file: