LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
state.h File Reference

Port of the MATLAB +State package: the encoding that turns a station's state row into marginal job counts. More...

#include <algorithm>
#include <map>
#include <cmath>
#include <cstddef>
#include <limits>
#include <vector>
#include "line/lang/lang_types.h"
#include "line/api/pfqn/pfqn_comb_common.h"
#include "line/lang/qn/network_struct.h"
#include "line/lang/qn/polling_info.h"
#include "line/util/error.h"
#include "line/util/matrix.h"
Include dependency graph for state.h:

Go to the source code of this file.

Classes

struct  line::qn::Marginal< T >
 What State.toMarginal returns for one station and one state row. More...
struct  line::qn::NetState< T >
 One network state: the per-stateful-node local rows it is composed of. More...

Namespaces

namespace  line
namespace  line::qn

Functions

template<class T>
Marginal< T > line::qn::to_marginal (const NetworkStruct< T > &sn, std::size_t ist, const std::vector< T > &state_i, const std::vector< std::size_t > &phasesz, const std::vector< std::size_t > &phaseshift, std::size_t nvar=0)
 Port of State.toMarginal for a STATION, one state row at a time.
template<class T>
std::vector< double > line::qn::station_populations (const NetworkStruct< T > &sn, const std::vector< std::vector< T > > &local)
 Total jobs held by every STATION at one network state, indexed by station.
template<class T>
Matrix< T > line::qn::rt_state (const NetworkStruct< T > &sn, const std::vector< std::vector< T > > &local)
 Port of sn.rtfun: the routing over the stateful nodes AT ONE STATE.
template<class T>
std::vector< std::vector< T > > line::qn::cartesian (const std::vector< std::vector< T > > &a, const std::vector< std::vector< T > > &b)
 Port of State.cartesian: pair every row of a with every row of b.
template<class T>
std::vector< std::vector< T > > line::qn::space_closed_single (std::size_t m, std::size_t n)
 Port of State.spaceClosedSingle: the ways to place n jobs over m phases.
template<class T>
void line::qn::space_closed_single_capped_rec (std::size_t m, long n, const std::vector< long > &caps, std::size_t off, std::vector< T > &row, std::vector< std::vector< T > > &out)
 space_closed_single with a PER-SLOT bound, the reference's spaceClosedSingle(M, N, caps).
template<class T>
std::vector< std::vector< T > > line::qn::space_closed_single_capped (std::size_t m, std::size_t n, const std::vector< long > &caps)
std::vector< std::vector< std::size_t > > line::qn::pas_multiset_perms (const std::vector< std::size_t > &vec)
 Port of matlab/util/multiset_perms.m on an ASCENDING multiset, ROW ORDER INCLUDED.
template<class T>
std::vector< std::vector< T > > line::qn::from_marginal_core (const NetworkStruct< T > &sn, std::size_t ist, const std::vector< std::size_t > &n, const std::vector< std::size_t > &phases)
 Port of State.fromMarginal for the station families CTMC enumerates: every local state in which station ist holds exactly n[r] class-r jobs.
template<class T>
std::vector< std::vector< T > > line::qn::polling_blocks (const PollingInfo< T > &pi, std::size_t srvclass, const std::vector< std::size_t > &nbuf)
 Port of State.pollingBlocks + State.pollingProject: every controller configuration compatible with one (buffer, server) row.
template<class T>
std::vector< std::vector< T > > line::qn::append_local_vars (const NetworkStruct< T > &sn, std::size_t ist, std::vector< std::vector< T > > rows, const std::vector< std::size_t > &n, const std::vector< std::size_t > &phases)
 Append the trailing local-variable block to every row the core builders produce, which is what makes a state row as wide as nvars_of declares.
template<class T>
std::vector< std::vector< T > > line::qn::from_marginal (const NetworkStruct< T > &sn, std::size_t ist, const std::vector< std::size_t > &n, const std::vector< std::size_t > &phases)
template<class T>
std::vector< std::vector< T > > line::qn::from_marginal_and_started_core (const NetworkStruct< T > &sn, std::size_t ist, const std::vector< std::size_t > &n, const std::vector< std::size_t > &s, const std::vector< std::size_t > &phases)
 Port of State.fromMarginalAndStarted: ONE state realizing both a per-class occupancy n and a per-class STARTED count s.
template<class T>
std::vector< std::vector< T > > line::qn::from_marginal_and_started (const NetworkStruct< T > &sn, std::size_t ist, const std::vector< std::size_t > &n, const std::vector< std::size_t > &s, const std::vector< std::size_t > &phases)
 State.fromMarginalAndStarted with the trailing local-variable block appended, i.e.
template<class T>
std::vector< std::vector< T > > line::qn::from_marginal_node (const NetworkStruct< T > &sn, std::size_t ind, const std::vector< std::size_t > &n, const std::vector< std::size_t > &phases)
 Port of State.fromMarginal at its OWN signature: the reference indexes by NODE, not by station, and derives the station internally.
template<class T>
std::vector< std::vector< T > > line::qn::from_marginal_node_and_started (const NetworkStruct< T > &sn, std::size_t ind, const std::vector< std::size_t > &n, const std::vector< std::size_t > &s, const std::vector< std::size_t > &phases)
 Port of State.fromMarginalAndStarted at its OWN signature, which indexes by NODE rather than by station, mirroring from_marginal_node.
template<class T>
std::vector< std::vector< T > > line::qn::from_marg_node (const NetworkStruct< T > &sn, std::size_t ind, std::size_t ntot, const std::vector< std::size_t > &phases)
 Port of State.fromMarg: the state space with a given TOTAL queue length.
template<class T>
std::vector< std::vector< T > > line::qn::from_marg_node_started (const NetworkStruct< T > &sn, std::size_t ind, std::size_t ntot, std::size_t stot, const std::vector< std::size_t > &phases)
 Port of State.fromMargAndStarted: the states with a given TOTAL queue length AND a given TOTAL number of started jobs.
template<class T>
bool line::qn::from_marginal_node_first (const NetworkStruct< T > &sn, std::size_t ind, const std::vector< std::size_t > &n, const std::vector< std::size_t > &phases, std::vector< T > &out)
 The FIRST row from_marginal_node emits, BUILT rather than enumerated.
template<class T>
std::vector< std::vector< T > > line::qn::space_closed_multi (std::size_t M, const std::vector< std::size_t > &N, const std::vector< std::vector< long > > &caps=std::vector< std::vector< long > >())
 Port of State.spaceClosedMulti: how N[r] class-r jobs distribute over M stateful nodes, for every class, as the cartesian fold of the per-class placements.
template<class T>
std::vector< std::vector< T > > line::qn::space_closed_multi_cs (std::size_t M, const std::vector< std::size_t > &N, const std::vector< std::vector< bool > > &chains, const std::vector< std::vector< long > > &caps=std::vector< std::vector< long > >())
 Port of State.spaceClosedMultiCS: the same, but a CHAIN's population is shared among its classes, so the split between them is itself enumerated.
template<class T>
std::size_t line::qn::state_initial_occupancy (const NetworkStruct< T > &sn, std::size_t ind, std::size_t r)
 Port of State.initialOccupancy: the class-r jobs node ind holds in the DECLARED initial state, or 0 when there is none.
template<class T>
std::vector< std::vector< std::size_t > > line::qn::space_capacity_c (const NetworkStruct< T > &sn, const std::vector< std::size_t > &cutoff, const std::vector< std::vector< std::size_t > > &cutoff_mat=std::vector< std::vector< std::size_t > >())
 Port of the capacityc table of State.spaceGeneratorNodes: the largest class-r marginal node ind may hold in the enumerated space.
template<class T>
std::vector< NetState< T > > line::qn::space_generator (const NetworkStruct< T > &sn, const std::vector< std::size_t > &cutoff, std::size_t maxst=3000000, const std::vector< std::vector< std::size_t > > &cutoff_mat=std::vector< std::vector< std::size_t > >())
 Port of State.spaceGenerator: every network state, reachable or not.

Detailed Description

Port of the MATLAB +State package: the encoding that turns a station's state row into marginal job counts.

WHAT A STATE ROW IS. For a station the row is [buffer | server | vars]: nvars(ind,:) local-variable slots at the end, sum(phasesz) server slots before them (one per class-phase pair, laid out by phaseshift), and whatever remains at the front is the buffer. The buffer encoding is NOT uniform across disciplines – FCFS/LCFS store a CLASS TAG per waiting position, so class-r jobs are counted by matching the tag, while SIRO, POLLING, SEPT, LEPT and SRPT store a per-class COUNT in column r. Reading one as the other silently produces a plausible number, which is why the discipline switch below is transcribed case by case rather than collapsed.

THE EXT SENTINEL. to_marginal returns nir = +Inf for a Source, and that is deliberate: a Source is an infinite reservoir and the value describes the ENCODING, not a queue length. A caller that treats it as a queue length gets Inf, which is exactly the defect that reached SolverCTMC's averagers in MATLAB (see _kb/07-cross-language-parity.md, the Source-row section). Any consumer must test is_source before using nir, not clamp the Inf away.

Definition in file state.h.