<commit_before>#ifndef CYCLUS_GREEDY_SOLVER_H_
#define CYCLUS_GREEDY_SOLVER_H_

#include "exchange_graph.h"
#include "exchange_solver.h"
#include "greedy_preconditioner.h"

namespace cyclus {

/// @brief A comparison function for sorting a container of Arcs by the
/// requester's (unode's) preference, in decensing order (i.e., most preferred
/// Arc first)
inline bool ReqPrefComp(const Arc& l, const Arc& r) {
  return l.unode()->prefs[l] > r.unode()->prefs[r];
}

/// @brief A comparison function for sorting a container of Nodes by the nodes
/// preference in decensing order (i.e., most preferred Node first)
inline bool AvgPrefComp(ExchangeNode::Ptr l, ExchangeNode::Ptr r) {
  return AvgPref(l) > AvgPref(r);
}
  
class ExchangeGraph;
class GreedyPreconditioner;

/// @brief the capacity of the arc
///
/// @throws StateError if either ExchangeNode does not have a ExchangeNodeGroup
/// @param a the arc
/// @param u_curr_qty the current quantity assigned to the unode (if solving
/// piecemeal)
/// @param v_curr_qty the current quantity assigned to the vnode (if solving
/// piecemeal)
/// @return The minimum of the unode and vnode's capacities
//@{
double Capacity(const Arc& a, double u_curr_qty, double v_curr_qty);
double Capacity(const Arc& a) {return Capacity(a, 0, 0);}
//@}

/// @brief the capacity of a node
///
/// @throws StateError if ExchangeNode does not have a ExchangeNodeGroup
/// @param n the node
/// @param min_cap whether to use the minimum or maximum capacity value. In general,
/// nodes that represent bids use the minimum (i.e., the capacities represents a
/// less-than constraint) and nodes that represent requests use the maximum
/// value (i.e., the capacities represents a greater-than constraint).
/// @param curr_qty the currently allocated node quantity (if solving piecemeal)
/// @return The minimum of the node's nodegroup capacities / the node's unit
/// capacities, or the ExchangeNode's remaining qty -- whichever is smaller. 
//@{
double Capacity(ExchangeNode::Ptr n, const Arc& a, bool min_cap = true,
                double curr_qty = 0.0);
double Capacity(ExchangeNode::Ptr n, const Arc& a, bool min_cap) {
  return Capacity(n, a, min_cap, 0.0);
}
double Capacity(ExchangeNode::Ptr n, const Arc& a, double curr_qty) {
  return Capacity(n, a, true, curr_qty);
}
double Capacity(ExchangeNode::Ptr n, const Arc& a) {
  return Capacity(n, a, true, 0.0);
}
//@}
  
/// @brief The GreedySolver provides the implementation for a "greedy" solution
/// to a resource exchange graph.
///
/// Given an ExchangeGraph, the greedy solver will march through each
/// RequestGroup in the graph, matching request nodes "greedily" with supply
/// nodes. Each request node will attempt to be supplied by supplier arcs as<commit_msg>made functions inline because of a linking error<commit_after>#ifndef CYCLUS_GREEDY_SOLVER_H_
#define CYCLUS_GREEDY_SOLVER_H_

#include "exchange_graph.h"
#include "exchange_solver.h"
#include "greedy_preconditioner.h"

namespace cyclus {

/// @brief A comparison function for sorting a container of Arcs by the
/// requester's (unode's) preference, in decensing order (i.e., most preferred
/// Arc first)
inline bool ReqPrefComp(const Arc& l, const Arc& r) {
  return l.unode()->prefs[l] > r.unode()->prefs[r];
}

/// @brief A comparison function for sorting a container of Nodes by the nodes
/// preference in decensing order (i.e., most preferred Node first)
inline bool AvgPrefComp(ExchangeNode::Ptr l, ExchangeNode::Ptr r) {
  return AvgPref(l) > AvgPref(r);
}

class ExchangeGraph;
class GreedyPreconditioner;

/// @brief the capacity of the arc
///
/// @throws StateError if either ExchangeNode does not have a ExchangeNodeGroup
/// @param a the arc
/// @param u_curr_qty the current quantity assigned to the unode (if solving
/// piecemeal)
/// @param v_curr_qty the current quantity assigned to the vnode (if solving
/// piecemeal)
/// @return The minimum of the unode and vnode's capacities
//@{
double Capacity(const Arc& a, double u_curr_qty, double v_curr_qty);
inline double Capacity(const Arc& a) {return Capacity(a, 0, 0);}
//@}

/// @brief the capacity of a node
///
/// @throws StateError if ExchangeNode does not have a ExchangeNodeGroup
/// @param n the node
/// @param min_cap whether to use the minimum or maximum capacity value. In general,
/// nodes that represent bids use the minimum (i.e., the capacities represents a
/// less-than constraint) and nodes that represent requests use the maximum
/// value (i.e., the capacities represents a greater-than constraint).
/// @param curr_qty the currently allocated node quantity (if solving piecemeal)
/// @return The minimum of the node's nodegroup capacities / the node's unit
/// capacities, or the ExchangeNode's remaining qty -- whichever is smaller. 
//@{
double Capacity(ExchangeNode::Ptr n, const Arc& a, bool min_cap,
                double curr_qty);
inline double Capacity(ExchangeNode::Ptr n, const Arc& a, bool min_cap) {
  return Capacity(n, a, min_cap, 0.0);
}
inline double Capacity(ExchangeNode::Ptr n, const Arc& a, double curr_qty) {
  return Capacity(n, a, true, curr_qty);
}
inline double Capacity(ExchangeNode::Ptr n, const Arc& a) {
  return Capacity(n, a, true, 0.0);
}
//@}
  
/// @brief The GreedySolver provides the implementation for a "greedy" solution
/// to a resource exchange graph.
///
/// Given an ExchangeGraph, the greedy solver will march through each
/// RequestGroup in the graph, matching request nodes "greedily" with supply
/// nodes. Each request node will attempt to be supplied by supplier arcs as
{'fraction_non_alphanumeric': 0.11021505376344086, 'fraction_numerical': 0.0025089605734767025, 'mean_word_length': 3.9785905441570026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3471363', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1642, 'n_words': 686}