5#ifndef LINE_SOLVERS_LDES_LDES_CACHE_H
6#define LINE_SOLVERS_LDES_LDES_CACHE_H
50 std::vector<std::list<std::size_t>>
lists;
71 for (std::size_t l = 0; l <
lists.size(); ++l)
72 for (std::size_t v :
lists[l])
100 std::vector<std::vector<HeldRequest>>
held;
118 int find(std::size_t item)
const {
119 for (std::size_t l = 0; l <
lists.size(); ++l)
120 for (std::size_t v :
lists[l])
121 if (v == item)
return static_cast<int>(l);
160 const std::size_t up = (at + 1 < cs.
lists.size()) ? at + 1 : at;
163 cs.
lists[at].remove(item);
164 cs.
lists[at].push_front(item);
168 std::list<std::size_t>& lo = cs.
lists[at];
169 std::list<std::size_t>& hi = cs.
lists[up];
177 const std::size_t victim =
179 ? *std::next(hi.begin(),
static_cast<std::ptrdiff_t
>(
180 std::min<std::size_t>(hi.size() - 1,
181 static_cast<std::size_t
>(
182 u_random * hi.size()))))
189 if (hi_after > cs.
cap_of(up) || (cs.
cap_of(at) >= 0.0 && lo_after > cs.
cap_of(at)))
return;
191 auto slot = std::find(lo.begin(), lo.end(), item);
192 slot = lo.erase(slot);
196 lo.push_front(victim);
198 lo.insert(slot, victim);
203 if (cs.
lists.empty())
return;
204 const std::size_t target = 0;
205 std::list<std::size_t>& list = cs.
lists[target];
206 const std::size_t cap = cs.
capacity[target];
211 const std::size_t pos =
212 std::min<std::size_t>(list.size() - 1,
static_cast<std::size_t
>(u_random * list.size()));
213 auto it = std::next(list.begin(),
static_cast<std::ptrdiff_t
>(pos));
222 if (list.size() + 1 > cap && !list.empty()) resulting -= cs.
size_of(list.back());
223 if (resulting > cs.
cap_of(target))
return;
225 list.push_front(item);
226 if (list.size() > cap) list.pop_back();
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
ReplacementStrategy
Cache replacement policies, with the values of MATLAB ReplacementStrategy.
@ HLRU
h-LRU / LRU(m): h lists, promote i -> i+1 on a hit
@ QLRU
q-LRU: LRU with probabilistic admission on a miss
void cache_hit(CacheState &cs, std::size_t item, std::size_t at, double u_random)
Serve a HIT in list at.
void cache_miss(CacheState &cs, std::size_t item, double u_admit, double u_random)
Serve a MISS: insert into the entry list, evicting if it is full.
bool cache_refreshes(lang::ReplacementStrategy p)
True for the policies that refresh recency on a hit.
Conservation laws of a layered queueing network, enumerated from its structure.
A request parked while its item was being fetched.
double t_sys
its system arrival time, for response time
std::size_t cls
the ACCESS class that read the cache
double hold_time
when it was parked
Live state of one Cache node.
std::vector< double > misses
per access class
double cap_of(std::size_t l) const
int find(std::size_t item) const
The list holding item, or -1.
void accumulate(double now)
Integrate the current contents up to now; call before every content change and at export.
std::vector< int > hit_class
std::vector< double > item_size
empty = unconstrained
bool has_retrieval
Cache.setRetrievalSystem: a miss FETCHES the item through a sub-network instead of being served at on...
double delayed_wait
summed parked time over all releases
double size_of(std::size_t item) const
double qlru
q-LRU admission probability on a miss
std::vector< double > cost_cap
empty = unconstrained
double list_cost(std::size_t l) const
std::vector< std::list< std::size_t > > lists
per list, most recent at the front
std::vector< double > delayed
per access class, delayed-hit count
std::vector< std::vector< double > > hits_per_list
(access class x list) hits served in that list
int fetches_item(std::size_t cls) const
The item cls fetches, or -1.
std::vector< int > miss_class
0-based destination class, -1 = unset
std::size_t retrieval_of(std::size_t item, std::size_t cls) const
The retrieval class of item for access class cls, or 0.
lang::ReplacementStrategy policy
std::vector< double > fetch_start
per item, when that fetch began
std::vector< std::vector< double > > popularity
Per access class: the item popularity, as a cumulative law.
std::vector< std::size_t > capacity
per list
std::vector< int > retrieval_class_to_item
Per class: the item it fetches, or -1 when it is not a retrieval class.
double total_fetch_time
summed fetch duration
std::vector< std::vector< double > > item_level_time
(item x list) time the item spent in that list, integrated up to occ_last: the itemProb and listCost ...
std::vector< double > hits
std::vector< char > in_flight
per item, a fetch is outstanding
std::vector< std::vector< std::size_t > > retrieval_class
(nitems x nclasses) the per-item retrieval class, 0 = none.
std::vector< std::vector< HeldRequest > > held
per item