/*
   File:        diar.h
   Author:      Andrew W. Moore
   Created:     Mon Sep 21 16:26:05 EDT 1992
   Description: Header for Diary to record partitions and worst-histories

   Copyright (C) 1992, Andrew W. Moore
*/

typedef struct diary_struct
{
  worst_hist worst_hist;
  part *first_part;
  part *next_part;
  part *third_part;
} diary;

typedef struct seq_node_struct
{
  float *nstate;
  worst *local_goal;
  struct seq_node_struct *next;
} seq_node;

/*
   Meaning of seq_nodes. They are the PRECISE sequence of states moved
   through within the running mode of the system. We will be replaying these
   sequences to decide if new partitionings are going to work.

   If a member of the sequence contains nstate NULL (and local goal NULL)
   this denotes a change of modes or a user halt.
   The trajectory jumped from outside of the
   system's view.

   either both nstate and localgoal are null, or neither are.
*/

typedef struct state_sequence_struct
{
  seq_node *start;
  seq_node *end;
} state_sequence;

typedef struct trajes_struct
{
  seq_node *seq_node;
  struct trajes_struct *next;
} trajes;

/**** HISTORICAL OUTCOMES (histos) ****/

/* The historical outcomes of a part are the sanitized version
   of the trajes of the part. They let us know about the important
   transitions of the part...those seq_node segments when the part was left,
   or those seq_node segments where we decided the part was stuck.
*/

#define HISTOS_STUCK 1
#define HISTOS_DEPART 2

typedef struct histos_struct
{
  int histos_type;
  worst *local_goal;
  float *depart_nstate;
  struct histos_struct *next;
} histos;

extern void empty_diary();                    /* (di) */
extern void init_diary();                     /* (di) */
extern void add_to_diary();                   /* (wld,ts,di,wst) */
extern bool is_diary_transition();            /* (wld,ts,di,psource,pdest) */

extern void init_state_sequence();            /* (ssq) */
extern void add_to_state_sequence();          /* (ssq,nst,lgoal) */
extern void print_seq_node();                 /* (wld,sn,run_mode) */
extern void print_seq_nodes();                /* (wld,sn,run_mode) */

extern void draw_seq_nodes();                 /* (gp,sn,run_mode) */
extern void draw_state_sequence();            /* (gp,ssq,(int)run_mode) */
extern void augment_state_sequence_from_history();  
                                       /* (wld,whist,run_mode,lgoal,ssq) */

extern trajes *add_to_trajes();               /* (sn,tjs) */
extern trajes *add_experience_data();            /* (ts,wld,run_mode,
                                      old_seq_node,old_seq_node_included) */
extern trajes *append_trajes();               /* (t1,t2) */
extern void free_all_traj_nodes();            /* (tjs) */
extern trajes *part_trajes();                 /* (pt) */
extern void add_to_part_trajes();             /* (pt,sn) */
extern void insert_trajes();                  /* (ts,wld,run_mode,tjs) */
extern void draw_trajes();                    /* (gp,wld,pt) */
extern void print_trajes();                   /* (wld,pt) */

extern histos *add_to_histos();          /*(histos_type,local_goal,nstate,hs)*/
extern void add_to_running_worst_hist(); /*(wh,nstate,run_mode,dim)*/
extern histos *histos_from_trajes_node();/*(ts,wld,run_mode,pt,tj,reap_eps)*/
extern histos *append_histos();          /*(h1,h2)*/
extern void append_histos_to_part();     /*(pt,hs)*/
extern void print_histos();              /*(wld,run_mode,hs)*/
extern void draw_histos();               /*(gp,wld,run_mode,hs)*/
extern void free_all_histos();           /*(hs)*/
extern void free_histos_of_part();       /*(pt)*/
extern void histos_from_trajes();        /*(ts,wld,run_mode,tjs,reap_eps)*/

#define MAX_TRIALS 200

typedef struct profile_struct
{
  char *name;
  int trials;
  int steps_in_trial[MAX_TRIALS];
  int number_partitions[MAX_TRIALS];
  tess *tess;
  world *world;
  state_sequence *state_sequence;
  gproj *gproj;
} profile;

extern void init_profile();                   /* (prof,name,ts,wld,ss,gp) */
extern void add_to_profile();                 /* (prof) */
extern void produce_profile();                /* (prof) */

