chiark / gitweb /
wip debugging newplanning
authorian <ian>
Sun, 18 May 2008 19:41:11 +0000 (19:41 +0000)
committerian <ian>
Sun, 18 May 2008 19:41:11 +0000 (19:41 +0000)
hostside/movpos.c
hostside/safety.c
hostside/safety.h

index 624705210c9c2c7e250af3efbc293909e8e91145..84e3996ebaa19c104b2266bb848355c825e21db2 100644 (file)
@@ -67,14 +67,14 @@ struct Method {
    */
 };
 
-static const char *posnpname(Segment *move, MovPosComb poscomb) {
+const char *movpos_pname(Segment *move, MovPosComb poscomb) {
   return poscomb<0 ? "?" : move->i->poscombs[poscomb].pname;
 }
 
 static void ouposn_moving(Change *chg) {
   Segment *move= chg->move;
   oprintf(UPO, "movpos %s position %s moving\n",
-         move->i->pname, posnpname(move, chg->actual));
+         move->i->pname, movpos_pname(move, chg->actual));
 }
 
 static void motion_done(Segment *move, MovPosComb actual) {
@@ -82,7 +82,7 @@ static void motion_done(Segment *move, MovPosComb actual) {
   move->motion= 0;
   move->movposcomb= actual;
   oprintf(UPO, "movpos %s position %s stable\n",
-         move->i->pname, posnpname(move, move->movposcomb));
+         move->i->pname, movpos_pname(move, move->movposcomb));
 }
 
 static void ignore_all_abandon(Method *m) { }
@@ -268,7 +268,7 @@ static ErrorCode fsq_check_plan(FsqMethod *m) {
       continue;
     }
     oprintf(UPO, "%s/%s[%d@t+%d]", whichr->h.move->i->pname,
-           posnpname(whichr->h.move, whichr->h.intent),
+           movpos_pname(whichr->h.move, whichr->h.intent),
            whichr->n_motions, whichwhen);
     if (future > whichwhen) {
       oprintf(UPO,"!...bad\n");
@@ -728,13 +728,13 @@ static int evaluate_target(Segment *move, MovPosComb target,
   const MovFeatInfo *feati;
   MovFeatKind kind;
 
-  oprintf(DUPO("movpos/eval") "%s/%s <-%s\n",
-         move->i->pname, posnpname(move,target), posnpname(move,startpoint));
+  oprintf(DUPO("movpos/eval") "%s/%s <-%s\n", move->i->pname,
+         movpos_pname(move,target), movpos_pname(move,startpoint));
 
   if (startpoint<0) {
     startpoint= movpos_poscomb_actual(move);
     oprintf(DUPO("movpos/eval") "  actual <-%s\n",
-           posnpname(move,startpoint));
+           movpos_pname(move,startpoint));
   }
 
   for (feat=0, feati=movei->movfeats, tchanges=0, kind= mfk_none;
@@ -805,11 +805,11 @@ ErrorCode movpos_change(Segment *move, MovPosComb target,
   }
 
   oprintf(DUPO("movpos/change") "%s/%s maxdelay=%dms actual=%s\n",
-         move->i->pname, posnpname(move,target),
-         maxdelay_ms, posnpname(move, actual));
+         move->i->pname, movpos_pname(move,target),
+         maxdelay_ms, movpos_pname(move, actual));
   if (chg) oprintf(DUPO("movpos/change") " chg=%s:%s/%s\n",
                   chg->meth->pname, chg->move->i->pname,
-                  posnpname(chg->move, chg->intent));
+                  movpos_pname(chg->move, chg->intent));
 
   { /* provide horizon for visibility of motions[] */
     int n_motions=0;
@@ -864,8 +864,8 @@ movpos_reserve(Segment *move, int maxdelay_ms, MovPosChange **res_r,
   int nchanges;
 
   oprintf(DUPO("movpos/reserve") "%s/%s maxdelay=%dms startpoint=%s\n",
-         move->i->pname, posnpname(move,target),
-         maxdelay_ms, posnpname(move,startpoint));
+         move->i->pname, movpos_pname(move,target),
+         maxdelay_ms, movpos_pname(move,startpoint));
 
   nchanges= evaluate_target(move,target,startpoint,&kind);
   if (nchanges==-1) return EC_MovFeatKindsCombination;
@@ -890,7 +890,7 @@ void movpos_unreserve(MovPosChange *res) {
   if (!res) return;
   oprintf(DUPO("movpos/unreserve") "%s:%s/%s\n",
          res->meth->pname, res->move->i->pname,
-         posnpname(res->move, res->intent));
+         movpos_pname(res->move, res->intent));
   res->meth->destroy(res->meth, res);
 }
 
index 8c0d1b9d22748785156ba2ef7bc8c96369f1ee04..f4941731fb1967dde7f2214bcf1969fc9dabd71f 100644 (file)
@@ -167,26 +167,45 @@ Segment *segments;
  *                                        now_present
  *                                              | pred_present
  *                                              |/ vacated
- *                                              ||/                motion &&
- *                                              |||                !moving
- *                                              NPV  until         means
+ *                                              ||/
+ *                                              |||
+ *                                              NPV  until
  *
  *   has never been here as far as we know      ---  undef
- *   here now, prediction has it still here     NP-  arrival = 0   old, defer
- *   here now, but predicted to have departed   N-V  departure     old, defer
- *   pred. to have arrived here                         -P-  arrival       to do now
- *   pred. to have arrived and departed                 --V  departure     to do now
- *   here now, pred. to have dep'd and ret'd    NPV  re-arrival    new, defer
- *   now absent, pred. to have arr, dep & ret'd         -PV  re-arrival    forbidden
+ *   here now, prediction has it still here     NP-  arrival = 0
+ *   here now, but predicted to have departed   N-V  departure
+ *   pred. to have arrived here                         -P-  arrival
+ *   pred. to have arrived and departed                 --V  departure
+ *   here now, pred. to have dep'd and ret'd    NPV  re-arrival
+ *   now absent, pred. to have arr, dep & ret'd         -PV  re-arrival
  *
  *  seg->tr_backwards records the sense of the _first_ passage of the train.
  *
  *  invalid/impossible combination:
  *   train here now but never in prediction     N--
  *
- *   `old' means a motion reservation which is part of the path we
- *   committed to in an earlier prediction but which we have not yet
- *   reached in this prediction.
+ * Meanings of moving, motion and motion_newplan:
+ * For segments NPV==000, no plan made yet:
+ *
+ *     moving  motion  _newplan
+ *     0       0       0        segment is entirely stable
+ *     0       non-0   0        existing plan has deferred motion
+ *     1       non-0   0        currently moving - as planned if owned
+ *
+ *     1       0       ?        always forbidden
+ *     ?       ?       non-0    forbidden for not-yet-planned segments
+ *
+ * For segments with NPV!=0, some kind of planning done:
+ * 
+ *     moving  motion  _newplan         new plan involves
+ *     0       0       0         no motion, segment is entirely stable
+ *     0       non-0   0         abandoning planned deferred motion
+ *     0       0       non-0     new motion, perhaps deferred
+ *     any     non-0   =motion   same motion as before
+ *     any     non-0  !=motion   different motion
+ *
+ *     1       0       ?         always forbidden
+ *     1       non-0   0         forbidden: need explicit motion to cancel
  *
  * (These are the values when not in the middle of nose_nextseg.)
  */
@@ -253,7 +272,7 @@ typedef struct {
     need_polarise:1, /* when we commit */
     train_polarity_inverted:1, /* right now, or if know_best, the best */
     know_best_polarity:1, /* longest-lasting into the future */
-    alwaysusemotions:1; /* for report_train_ownerships only */
+    alwaysusemotions:1; /* for report_train_ownerships, uses ->motion */
   TrackLocation nose, fdet, tail;
   TrackAdvanceContext nosec, tailc, fdetc;
   TimeInterval elapsed; /* from now, minimum */
@@ -316,6 +335,11 @@ static ErrorCode predict_problem(PredictUserContext *u, Segment *seg,
   return ec;
 }
 
+static const char *motion_pname(Segment *seg, MovPosChange *motion) {
+  if (!motion) return "";
+  return movpos_pname(seg, movpos_change_intent(motion));
+}
+
 static void pred_callback_debug(const char *what, TrackLocation *t,
                                struct TrackAdvanceContext *c,
                                const TrackLocation *before) {
@@ -323,8 +347,9 @@ static void pred_callback_debug(const char *what, TrackLocation *t,
   
   oprintf(DUPO("safety") " predict   %s"
          " %c%s dist=%-4d until=%-4ld %c%c%c.%c (was %s%s..%d dist=%-4d)"
-         "  %c%c%c.%c%c%c%c"
-         " elapsed=%ld nit=%d,%d\n",
+         "  %c%c%c.%c%c%c%c elapsed=%ld"
+         " %s/%s %c%s >%s"
+         " nit=%d,%d\n",
          what,
 
          " -"[t->backwards],
@@ -352,8 +377,14 @@ static void pred_callback_debug(const char *what, TrackLocation *t,
          "-n"[ u->need_polarise ],
          "-i"[ u->train_polarity_inverted ],
          "-b"[ u->know_best_polarity ],
-
          (long)u->elapsed,
+
+         t->seg->i->pname,
+         movpos_pname(t->seg, t->seg->movposcomb),
+         "!~"[ t->seg->moving ],
+         motion_pname(t->seg, t->seg->motion),
+         motion_pname(t->seg, t->seg->motion_newplan),
+
          u->noninv_tally[0], u->noninv_tally[1]);
 }
 
@@ -363,9 +394,13 @@ static int pred_getmovpos(TrackLocation *t, TrackAdvanceContext *c,
                          MovPosComb *use_io) {
   PredictUserContext *u= c->u;
   if (u->usecurrentposn) return 0;
-  if (t->seg->motion)
-    if (t->seg->moving || t->seg->pred_vacated || u->alwaysusemotions)
+  if (u->alwaysusemotions) {
+    if (t->seg->motion)
       *use_io= movpos_change_intent(t->seg->motion);
+  } else if (t->seg->moving || t->seg->pred_vacated) {
+    if (t->seg->motion_newplan)
+      *use_io= movpos_change_intent(t->seg->motion_newplan);
+  }
   if (*use_io<0) safety_panic(u->train, t->seg,
                              "track route unexpectedly not known");
   return 0;
@@ -636,7 +671,7 @@ static int optunwind_nextseg(TrackLocation *t, TrackAdvanceContext *c,
   pred_callback_debug("optunwind_nextseg",t,c,before);
 
   if (t->seg == u->furthest ||
-      t->seg->motion)
+      t->seg->motion_newplan)
     return EC_SignallingHorizonReached;
 
   t->seg->pred_present= 0;
index a7cabf8d26b2317f9cf89fc04d5d2ae1757fbec9..907e4d236081b53b13a8917bb63338506b76c395 100644 (file)
@@ -216,6 +216,8 @@ MovPosComb movpos_change_intent(MovPosChange *chg);
   *                       and/or current situation
   */
 
+const char *movpos_pname(Segment *move, MovPosComb poscomb);
+
 /*========== speed.c ==========*/
 
 ErrorCode speedmanager_speedchange_request(Train *tra, int step,