• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cyclus / cyclus / 22921176376

10 Mar 2026 07:44PM UTC coverage: 36.502%. First build
22921176376

Pull #1937

github

web-flow
Merge c90a08f4d into 32dbe028c
Pull Request #1937: Changing the DRE's Objective function to Surplus Maximization

249 of 283 new or added lines in 26 files covered. (87.99%)

52424 of 143618 relevant lines covered (36.5%)

74129.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

36.84
/src/exchange_solver.cc
1
#include "exchange_solver.h"
2

3
#include <vector>
4
#include <map>
5
#include <limits>
6

7
#include "context.h"
8
#include "exchange_graph.h"
9
#include "error.h"
10

11
namespace cyclus {
12

13
double ExchangeSolver::Cost(const Arc& a, ExchangeGraph* graph, bool exclusive_orders) {
560,638✔
14
  // Use stored arc weight from pref() which is set during translation.
15
  double arc_weight = a.pref();
16
  
17
  if (exclusive_orders && a.exclusive()) {
560,638✔
18
    // For exclusive arcs, scale by excl_val if needed
19
    return arc_weight * (a.excl_val() > 0 ? 1.0 / a.excl_val() : 1.0);
61✔
20
  }
21
  return arc_weight;
22
}
23

NEW
24
double ExchangeSolver::ArcWeight(const Arc& a, double shift, bool exclusive_orders) {
×
25
  // The base arc weight (MC - MU + shift) is stored in pref() after translation.
26
  double arc_weight = a.pref();
27
  
NEW
28
  if (exclusive_orders && a.exclusive()) {
×
29
    // For exclusive arcs, scale by excl_val if needed
NEW
30
    return arc_weight * (a.excl_val() > 0 ? 1.0 / a.excl_val() : 1.0);
×
31
  }
32
  return arc_weight;
33
}
34

35
double ExchangeSolver::PseudoCost() {
9,029✔
36
  return PseudoCost(1e-1);
9,029✔
37
}
38

39
double ExchangeSolver::PseudoCost(double cost_factor) {
9,029✔
40
  return PseudoCostByPref(cost_factor);
9,029✔
41
}
42

43
double ExchangeSolver::PseudoCostByCap(double cost_factor) {
×
44
  std::vector<ExchangeNode::Ptr>::iterator n_it;
45
  std::map<Arc, std::vector<double>>::iterator c_it;
46
  std::map<Arc, double>::iterator p_it;
47
  std::vector<RequestGroup::Ptr>::iterator rg_it;
48
  std::vector<ExchangeNodeGroup::Ptr>::iterator sg_it;
49
  double min_cap, pref, coeff;
50

51
  double max_coeff = std::numeric_limits<double>::min();
52
  double min_unit_cap = std::numeric_limits<double>::max();
53

54
  for (sg_it = graph_->supply_groups().begin();
×
55
       sg_it != graph_->supply_groups().end();
×
56
       ++sg_it) {
57
    std::vector<ExchangeNode::Ptr>& nodes = (*sg_it)->nodes();
58
    for (n_it = nodes.begin(); n_it != nodes.end(); ++n_it) {
×
59
      // update min_unit_cap
60
      std::map<Arc, std::vector<double>>::iterator c_it;
61
      std::map<Arc, std::vector<double>>& caps = (*n_it)->unit_capacities;
62
      for (c_it = caps.begin(); c_it != caps.end(); ++c_it) {
×
63
        std::vector<double>& ucaps = c_it->second;
64
        if (!ucaps.empty()) {
×
65
          min_cap = *std::min_element(ucaps.begin(), ucaps.end());
×
66
          if (min_cap < min_unit_cap) min_unit_cap = min_cap;
×
67
        }
68
      }
69
    }
70
  }
71

72
  for (rg_it = graph_->request_groups().begin();
×
73
       rg_it != graph_->request_groups().end();
×
74
       ++rg_it) {
75
    std::vector<ExchangeNode::Ptr>& nodes = (*rg_it)->nodes();
76
    for (n_it = nodes.begin(); n_it != nodes.end(); ++n_it) {
×
77
      // update min_unit_cap
78
      std::map<Arc, std::vector<double>>::iterator c_it;
79
      std::map<Arc, std::vector<double>>& caps = (*n_it)->unit_capacities;
80
      for (c_it = caps.begin(); c_it != caps.end(); ++c_it) {
×
81
        std::vector<double>& ucaps = c_it->second;
82
        if (!ucaps.empty()) {
×
83
          min_cap = *std::min_element(ucaps.begin(), ucaps.end());
×
84
          if (min_cap < min_unit_cap) min_unit_cap = min_cap;
×
85
        }
86
      }
87

88
      // update max_coeff by checking all arcs connected to this node
NEW
89
      std::vector<Arc>& node_arcs = graph_->node_arc_map()[*n_it];
×
NEW
90
      for (std::vector<Arc>::iterator arc_it = node_arcs.begin(); 
×
NEW
91
           arc_it != node_arcs.end(); ++arc_it) {
×
NEW
92
        coeff = ArcCost(*arc_it);
×
93
        if (coeff > max_coeff) max_coeff = coeff;
×
94
      }
95
    }
96
  }
97

98
  return max_coeff / min_unit_cap * (1 + cost_factor);
×
99
}
100

101
double ExchangeSolver::PseudoCostByPref(double cost_factor) {
9,029✔
102
  double max_cost = 0;
9,029✔
103
  std::vector<Arc>& arcs = graph_->arcs();
9,029✔
104
  for (int i = 0; i != arcs.size(); i++) {
563,662✔
105
    const Arc& a = arcs[i];
106
    // remove exclusive value factor from costs for preferences that are less
107
    // than unity. otherwise they can artificially raise the maximum cost.
108
    // Guard excl_val > 0 to avoid division by zero (excl_val can be 0 when
109
    // request/bid quantities don't match).
110
    double factor =
111
        (a.exclusive() && a.excl_val() > 0 && a.excl_val() < 1) ? 1 / a.excl_val() : 1.0;
554,633✔
112
    max_cost = std::max(max_cost, ArcCost(a) * factor);
555,445✔
113
  }
114
  return max_cost * (1 + cost_factor);
9,029✔
115
}
116

117
}  // namespace cyclus
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc