Class AgWire
ONE CLASS ON PURPOSE. The coordinator and the worker are different processes and, in the MATLAB and Python clients, different languages; a protocol written twice is a protocol that drifts, and the failure it produces is a wrong number rather than a parse error. Everything either side puts on the wire is built here.
The transport is newline-delimited JSON over a plain TCP socket: one JSON object per line, request then reply, no framing beyond the newline. It is deliberately NOT the existing LineWebSocket protocol, whose unit is a whole model and whose first line is a CLI argument vector -- the unit here is one agent, and the per-sweep message is a vector of reversed rates.
Messages:
- assign
{"op":"assign","agents":[...]}carries the STATIC half of each agent -- its local rate matrix and the passive/active matrices of the actions it takes part in. Sent once per solve, because none of it changes across the fixed point. Reply{"op":"assigned","k":[...]}. - sweep
{"op":"sweep","x":[...]}carries the reversed rates, one double per action -- the entire coupling between agents. Reply{"op":"swept","agents":[{"k":..,"pi":[..]}]}. - bye
{"op":"bye"}closes the session.
Matrices travel as [row, col, value] triplets with 0-based indices,
because an action's matrices touch one level transition and are nearly empty;
a dense N-by-N payload would be almost all zeros.
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.google.gson.JsonObjectagent(int k, Matrix[] Aa, Matrix[] Pb, Matrix[] L, int[] ACT, int[] PSV, int numActions, int[] N, RCATModel rcat) The static description of agent k, as the worker needs it.static MatrixfromTriplets(com.google.gson.JsonArray a, int n) Rebuild an n-by-n matrix from the triplets written bytriplets(jline.util.matrix.Matrix).static com.google.gson.JsonArrayThe reversed-rate vector, the whole per-sweep payload.toIntList(com.google.gson.JsonArray a) static MatrixtoRates(com.google.gson.JsonArray a) The inverse ofrates(jline.util.matrix.Matrix), as the column vector the solver uses.static MatrixtoVector(com.google.gson.JsonArray a) The inverse ofvector(jline.util.matrix.Matrix).static com.google.gson.JsonArrayNon-zero entries of M as a JSON array of [row, col, value] triplets.static com.google.gson.JsonArrayA stationary vector as a JSON array.
-
Method Details
-
triplets
Non-zero entries of M as a JSON array of [row, col, value] triplets. -
fromTriplets
Rebuild an n-by-n matrix from the triplets written bytriplets(jline.util.matrix.Matrix). -
agent
public static com.google.gson.JsonObject agent(int k, Matrix[] Aa, Matrix[] Pb, Matrix[] L, int[] ACT, int[] PSV, int numActions, int[] N, RCATModel rcat) The static description of agent k, as the worker needs it. -
rates
The reversed-rate vector, the whole per-sweep payload. -
vector
A stationary vector as a JSON array. -
toVector
The inverse ofvector(jline.util.matrix.Matrix). -
toRates
The inverse ofrates(jline.util.matrix.Matrix), as the column vector the solver uses. -
toIntList
-