anpcpp 0.1.0
Analytic Network Process computational library
Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions
anpcpp Namespace Reference

Analytic Network Process computational library. More...

Classes

class  AnpCluster
 A group of nodes (and cluster-level pairwise comparisons). More...
 
class  AnpNetwork
 Root ANP model: structure, judgments, supermatrices, and priorities. More...
 
class  AnpNode
 A decision element within a cluster (may own a subnetwork). More...
 
struct  ConsistencyOptions
 Options for consistency. More...
 
struct  ConsistencyResult
 Full consistency analysis result. More...
 
class  ConvergenceError
 Thrown when power iteration fails to converge within max_iterations. More...
 
class  DimensionError
 Thrown when vector/matrix dimensions do not match an operation. More...
 
struct  DivideByConstantInterpreter
 Divide each raw value by a fixed positive constant. More...
 
struct  DivideByMaxInterpreter
 Divide each raw value by the max among present values. More...
 
struct  EigenOptions
 Options controlling principal eigen computation. More...
 
struct  EigenResult
 Result of principal_eigen. More...
 
struct  IdentityInterpreter
 Pass-through interpreter (values already in [0, 1]). More...
 
class  JsonIoError
 Thrown on JSON parse, validation, or I/O errors. More...
 
struct  LimitMatrixOptions
 Options for limit-matrix calculation. More...
 
class  Matrix
 Dense row-major matrix stored in a flat buffer. More...
 
struct  MinMaxNormalizeInterpreter
 Map the column's [min, max] onto [0, 1]. More...
 
struct  NodePrioritizerSlot
 Stores either pairwise or ratings judgments for one dest cluster. More...
 
class  PairwiseJudgments
 Square pairwise comparison table over a named list of alternatives. More...
 
struct  PiecewiseLinearInterpreter
 Piecewise-linear map from raw value to [0, 1] via sorted knots. More...
 
struct  RatingCategory
 A named rating category with an associated score in [0, 1]. More...
 
class  RatingsPrioritizer
 Ratings table over named alternatives for one (wrt node, dest cluster). More...
 
class  SynthesisError
 Thrown when synthesis or expression evaluation fails. More...
 
struct  SynthesisOptions
 Synthesis configuration for networks with subnetworks. More...
 
class  Vector
 One-dimensional array of doubles with element-wise arithmetic. More...
 

Typedefs

using ScoreInterpreter = std::variant< IdentityInterpreter, DivideByMaxInterpreter, DivideByConstantInterpreter, MinMaxNormalizeInterpreter, PiecewiseLinearInterpreter >
 Declarative raw-value → [0, 1] interpreter (JSON-serializable).
 

Enumerations

enum class  NodePrioritizerKind
 Active prioritizer kind for a node → destination-cluster link.
 
enum class  SynthesisKind { Additive , Multiplicative , Custom }
 How control-node subnetwork scores are combined. More...
 

Functions

Matrix harker_fix (const Matrix &mat)
 Applies Harker's fix for incomplete pairwise matrices.
 
EigenResult principal_eigen (const Matrix &mat, const EigenOptions &options={})
 Power iteration with sum-normalization (pyanp pri_eigen compatible).
 
Vector principal_eigenvector (const Matrix &mat, const EigenOptions &options={})
 Returns the principal eigenvector only.
 
double principal_eigenvalue (const Matrix &mat, const EigenOptions &options={})
 Returns the principal eigenvalue only.
 
double random_index (std::size_t n)
 Saaty random index (RI) for matrix order n.
 
double consistency_index (double lambda_max, std::size_t n)
 Consistency index CI = (lambda_max - n) / (n - 1).
 
double consistency_ratio (double lambda_max, std::size_t n)
 Consistency ratio CR = CI / RI.
 
ConsistencyResult consistency (const Matrix &mat, ConsistencyOptions options={})
 Computes Saaty CI and CR for a pairwise comparison matrix.
 
double consistency_index (const Matrix &mat, ConsistencyOptions options={})
 Consistency index from a matrix (throws on non-convergence).
 
double consistency_ratio (const Matrix &mat, ConsistencyOptions options={})
 Consistency ratio from a matrix (throws on non-convergence).
 
std::string network_to_json (const AnpNetwork &network)
 Serializes a network (including subnetworks and layout hints) to JSON.
 
std::unique_ptr< AnpNetworknetwork_from_json (const std::string &json_text)
 Parses JSON produced by network_to_json.
 
void save_network_file (const AnpNetwork &network, const std::string &path)
 Writes a network to a file.
 
std::unique_ptr< AnpNetworkload_network_file (const std::string &path)
 Loads a network from a file.
 
Matrix column_normalize (const Matrix &mat)
 Column-normalizes each column by its sum (pyanp normalize).
 
void column_normalize_inplace (Matrix &mat)
 In-place column_normalize.
 
Matrix hierarchy_formula (const Matrix &mat)
 Hierarchy limit formula: normalize(sum of W^k for k=1..n-1).
 
Matrix calculus_limit (const Matrix &mat, const LimitMatrixOptions &options={})
 SuperDecisions / pyanp calculus limit matrix.
 
Vector priority_from_limit (const Matrix &limit_matrix)
 Row sums of the limit matrix, L1-normalized (pyanp priority_from_limit).
 
std::vector< std::optional< double > > apply_score_interpreter (const ScoreInterpreter &interpreter, const std::vector< std::optional< double > > &raw)
 Apply interpreter to a column of optional raw values.
 
std::map< std::string, double > synthesize_additive (const std::map< std::string, double > &subnet_weights, const std::map< std::string, std::map< std::string, double > > &alt_scores)
 Weighted average synthesis (matches AnpNetwork::sum_subnetwork_formula).
 
std::map< std::string, double > synthesize_multiplicative (const std::map< std::string, double > &subnet_weights, const std::map< std::string, std::map< std::string, double > > &alt_scores)
 Multiplicative synthesis: product of score^weight per alt, then L1-normalize.
 
std::map< std::string, double > synthesize_custom (const std::string &expression, const std::map< std::string, std::map< std::string, double > > &alt_scores, const std::vector< std::string > &alt_order)
 Custom expression synthesis per alternative.
 
std::map< std::string, double > synthesize (const SynthesisOptions &options, const std::map< std::string, double > &subnet_weights, const std::map< std::string, std::map< std::string, double > > &alt_scores, const std::vector< std::string > &alt_order)
 Dispatches on SynthesisOptions::kind.
 
double eval_expression (const std::string &expression, const std::map< std::string, double > &variables)
 Evaluates a numeric expression with named variables.
 

Detailed Description

Analytic Network Process computational library.

Enumeration Type Documentation

◆ SynthesisKind

enum class anpcpp::SynthesisKind
strong

How control-node subnetwork scores are combined.

Enumerator
Additive 

Weighted average of subnet scores (pyanp default).

Multiplicative 

Product of subnet scores across control nodes, then normalize.

Custom 

Custom expression over subnet-host node names.

Function Documentation

◆ apply_score_interpreter()

std::vector< std::optional< double > > anpcpp::apply_score_interpreter ( const ScoreInterpreter interpreter,
const std::vector< std::optional< double > > &  raw 
)

Apply interpreter to a column of optional raw values.

Missing entries stay nullopt. Present entries become scores in [0, 1] (clamped). Interpreters that need column statistics ignore missing cells.

◆ calculus_limit()

Matrix anpcpp::calculus_limit ( const Matrix mat,
const LimitMatrixOptions options = {} 
)

SuperDecisions / pyanp calculus limit matrix.

Parameters
matColumn-stochastic supermatrix.
optionsIteration and hierarchy options.

◆ column_normalize()

Matrix anpcpp::column_normalize ( const Matrix mat)

Column-normalizes each column by its sum (pyanp normalize).

Returns
Normalized copy; zero columns remain zero.

◆ column_normalize_inplace()

void anpcpp::column_normalize_inplace ( Matrix mat)

In-place column_normalize.

Parameters
matMatrix to normalize.

◆ consistency()

ConsistencyResult anpcpp::consistency ( const Matrix mat,
ConsistencyOptions  options = {} 
)

Computes Saaty CI and CR for a pairwise comparison matrix.

Parameters
matSquare comparison matrix.
optionsHarker and eigen options.

◆ consistency_index() [1/2]

double anpcpp::consistency_index ( const Matrix mat,
ConsistencyOptions  options = {} 
)

Consistency index from a matrix (throws on non-convergence).

Parameters
matSquare comparison matrix.
optionsHarker and eigen options.

◆ consistency_index() [2/2]

double anpcpp::consistency_index ( double  lambda_max,
std::size_t  n 
)

Consistency index CI = (lambda_max - n) / (n - 1).

Returns
0 for n < 2.

◆ consistency_ratio() [1/2]

double anpcpp::consistency_ratio ( const Matrix mat,
ConsistencyOptions  options = {} 
)

Consistency ratio from a matrix (throws on non-convergence).

Parameters
matSquare comparison matrix.
optionsHarker and eigen options.

◆ consistency_ratio() [2/2]

double anpcpp::consistency_ratio ( double  lambda_max,
std::size_t  n 
)

Consistency ratio CR = CI / RI.

Returns
0 when RI == 0 (n <= 2).

◆ eval_expression()

double anpcpp::eval_expression ( const std::string &  expression,
const std::map< std::string, double > &  variables 
)

Evaluates a numeric expression with named variables.

Parameters
expressionInfix expression (+ - * / parentheses).
variablesName -> value substitutions.

◆ harker_fix()

Matrix anpcpp::harker_fix ( const Matrix mat)

Applies Harker's fix for incomplete pairwise matrices.

Each row diagonal becomes 1 + (number of zero off-diagonal entries in that row), enabling power iteration on incomplete comparisons.

Parameters
matSquare pairwise matrix.
Returns
Adjusted matrix.

◆ hierarchy_formula()

Matrix anpcpp::hierarchy_formula ( const Matrix mat)

Hierarchy limit formula: normalize(sum of W^k for k=1..n-1).

Returns
Empty matrix if mat is not a hierarchy.

◆ load_network_file()

std::unique_ptr< AnpNetwork > anpcpp::load_network_file ( const std::string &  path)

Loads a network from a file.

Parameters
pathInput file path.
Returns
Owned network tree.
Exceptions
JsonIoErroron read or parse failure.

◆ network_from_json()

std::unique_ptr< AnpNetwork > anpcpp::network_from_json ( const std::string &  json_text)

Parses JSON produced by network_to_json.

Parameters
json_textJSON document.
Returns
Owned network tree.
Exceptions
JsonIoErroron invalid or unsupported documents.

◆ network_to_json()

std::string anpcpp::network_to_json ( const AnpNetwork network)

Serializes a network (including subnetworks and layout hints) to JSON.

Parameters
networkNetwork to serialize.
Returns
JSON text (anpcpp format v1).

◆ principal_eigen()

EigenResult anpcpp::principal_eigen ( const Matrix mat,
const EigenOptions options = {} 
)

Power iteration with sum-normalization (pyanp pri_eigen compatible).

Non-convergence is reported via converged == false rather than throwing.

Parameters
matSquare matrix.
optionsIteration and Harker options.
Returns
Eigenvector, eigenvalue estimate, and convergence metadata.

◆ principal_eigenvalue()

double anpcpp::principal_eigenvalue ( const Matrix mat,
const EigenOptions options = {} 
)

Returns the principal eigenvalue only.

Exceptions
ConvergenceErrorif iteration does not converge.

◆ principal_eigenvector()

Vector anpcpp::principal_eigenvector ( const Matrix mat,
const EigenOptions options = {} 
)

Returns the principal eigenvector only.

Exceptions
ConvergenceErrorif iteration does not converge.

◆ random_index()

double anpcpp::random_index ( std::size_t  n)

Saaty random index (RI) for matrix order n.

n = 1,2: 0 (CR defined as 0). n = 3..15: Saaty table. n > 15: Alonso-Lamata approximation RI ≈ 1.98 * (n - 2) / n.

◆ save_network_file()

void anpcpp::save_network_file ( const AnpNetwork network,
const std::string &  path 
)

Writes a network to a file.

Parameters
networkNetwork to save.
pathOutput file path.
Exceptions
JsonIoErroron write failure.

◆ synthesize_additive()

std::map< std::string, double > anpcpp::synthesize_additive ( const std::map< std::string, double > &  subnet_weights,
const std::map< std::string, std::map< std::string, double > > &  alt_scores 
)

Weighted average synthesis (matches AnpNetwork::sum_subnetwork_formula).

Parameters
subnet_weightsWeight per control subnet (host node name -> weight).
alt_scoresPer-subnet alternative scores (subnet -> alt -> score).

◆ synthesize_custom()

std::map< std::string, double > anpcpp::synthesize_custom ( const std::string &  expression,
const std::map< std::string, std::map< std::string, double > > &  alt_scores,
const std::vector< std::string > &  alt_order 
)

Custom expression synthesis per alternative.

Parameters
expressionArithmetic expression with subnet-host names as variables.
alt_scoresPer-subnet alternative scores.
alt_orderOutput ordering of alternatives.