Class AgWire

java.lang.Object
jline.solvers.ag.AgWire

public final class AgWire extends Object
The ag-worker wire protocol, encoder and decoder in one place.

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 Details

    • triplets

      public static com.google.gson.JsonArray triplets(Matrix m)
      Non-zero entries of M as a JSON array of [row, col, value] triplets.
    • fromTriplets

      public static Matrix fromTriplets(com.google.gson.JsonArray a, int n)
      Rebuild an n-by-n matrix from the triplets written by triplets(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

      public static com.google.gson.JsonArray rates(Matrix x)
      The reversed-rate vector, the whole per-sweep payload.
    • vector

      public static com.google.gson.JsonArray vector(Matrix pi)
      A stationary vector as a JSON array.
    • toVector

      public static Matrix toVector(com.google.gson.JsonArray a)
    • toRates

      public static Matrix toRates(com.google.gson.JsonArray a)
      The inverse of rates(jline.util.matrix.Matrix), as the column vector the solver uses.
    • toIntList

      public static List<Integer> toIntList(com.google.gson.JsonArray a)