summaryrefslogtreecommitdiff
path: root/SA_POP/LogFileOut.cpp
blob: ab1af922a16f405f8b8d048ec2717f91a76c575a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// -*- C++ -*-
// $Id$

//=============================================================================
/**
 * @file  LogFileOut.cpp
 *
 * This file contains the LogFileOut class implementation for the output adapter
 * that logs plan changes to a file.
 *
 * @author  John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu>
 */
//=============================================================================

#include <fstream>
#include <time.h>
#include "SA_POP_Types.h"
#include "LogFileOut.h"
#include "Planner.h"

using namespace SA_POP;

// Constructor.
LogFileOut::LogFileOut (const char *filename)
: outfile_ (filename)
{
  if (this->outfile_ == 0){
    std::string msg = "Unable to open ";
    msg += filename;
    msg += " for writing.";
    throw msg;
  }
};

// Destructor.
LogFileOut::~LogFileOut (void)
{
  this->outfile_.close ();
};

// Notify about task future expected utility changes.
void LogFileOut::notify_eu (SA_POP::Planner *planner)
{
  time_t cur_time = time(0);
  this->outfile_ << std::endl;
  this->outfile_ << "EU Changes (" << ctime (&cur_time) << "):" << std::endl;

  TaskEUMap eu_changes = planner->get_eu_changes ();
  for (TaskEUMap::iterator iter = eu_changes.begin ();
    iter != eu_changes.end ();
    iter++)
  {
    this->outfile_ << "Task " << iter->first << " = " << iter->second;
    this->outfile_ << std::endl;
  }
};

// Notify about plan changes.
void LogFileOut::notify_plan (SA_POP::Planner *planner)
{
  Plan plan = planner->get_plan ();

  time_t cur_time = time(0);

  this->outfile_ << std::endl;
  this->outfile_ << "Plan (" << plan.name << ") Changed at " << std::endl;
  this->outfile_ << ctime (&cur_time) << std::endl;
  this->outfile_ << "ID: " << plan.plan_id << std::endl;

  this->outfile_ << "Start Window: [" << plan.start_window.first << ", ";
  this->outfile_ << plan.start_window.second << "]" << std::endl;

  this->outfile_ << "End Window: [" << plan.end_window.first << ", ";
  this->outfile_ << plan.end_window.second << "]" << std::endl;
  
  for (PlanInstSet::iterator inst_iter = plan.task_insts.begin ();
    inst_iter != plan.task_insts.end ();
    inst_iter++)
  {
    PlanTaskInst inst = *inst_iter;
    this->outfile_ << "Task Instance (" << inst.name << "):" << std::endl;

    this->outfile_ << "  ID: " << inst.inst_id << std::endl;

    this->outfile_ << "  Start Window: [" << inst.start_window.first << ", ";
    this->outfile_ << inst.start_window.second << "]" << std::endl;

    this->outfile_ << "  End Window: [" << inst.end_window.first << ", ";
    this->outfile_ << inst.end_window.second << "]" << std::endl;

    this->outfile_ << " Task ID: " << inst.task_id << std::endl;

    this->outfile_ << " Task Type: " << inst.type_id << std::endl;

    this->outfile_ << " Suggested Implementation: ";
    this->outfile_ << inst.suggested_impl << std::endl;
  }

  this->outfile_ << std::endl;

  for (PlanConnSet::iterator conn_iter = plan.connections.begin ();
    conn_iter != plan.connections.end ();
    conn_iter++)
  {
    PlanConnection conn = *conn_iter;
    this->outfile_ << "Data Connection:" << std::endl;
    this->outfile_ << "  " << conn.first_task_inst << " (";
    this->outfile_ << planner->get_task_name (
      planner->get_task_from_inst (conn.first_task_inst)) << "--";
    this->outfile_ << conn.first_port << ")  -";
    this->outfile_ << "(" << planner->get_cond_name (conn.cond) << ")-> ";
    this->outfile_ << conn.second_task_inst << " (";
    this->outfile_ << planner->get_task_name (
      planner->get_task_from_inst (conn.second_task_inst)) << "--";
    this->outfile_ << conn.second_port << ")" << std::endl;
  }

  this->outfile_ << std::endl;

  for (CLSet::iterator cl_iter = plan.causal_links.begin ();
    cl_iter != plan.causal_links.end ();
    cl_iter++)
  {
    CausalLink clink = *cl_iter;
    this->outfile_ << "Causal Link:" << std::endl;
    this->outfile_ << "  " << clink.first << " (";
    this->outfile_ << planner->get_task_name (
      planner->get_task_from_inst (clink.first)) << ") -";
    this->outfile_ << "(" << planner->get_cond_name (clink.cond.id) << ")-> ";
    this->outfile_ << clink.second << " (";
    this->outfile_ << planner->get_task_name (
      planner->get_task_from_inst (clink.second)) << ")" << std::endl;
  }

  this->outfile_ << std::endl;

  for (SchedLinkSet::iterator sched_iter = plan.sched_links.begin ();
    sched_iter != plan.sched_links.end ();
    sched_iter++)
  {
    SchedLink sched_link = (*sched_iter);
    this->outfile_ << "Scheduling Link:" << std::endl;
    this->outfile_ << "  " << sched_link.first  << " (";
    this->outfile_ << planner->get_task_name (
      planner->get_task_from_inst (sched_link.first)) << ") -> ";
    this->outfile_ << sched_link.second  << " (";
    this->outfile_ << planner->get_task_name (
      planner->get_task_from_inst (sched_link.second)) << ")" << std::endl;

  }

  this->outfile_ << std::endl;

  for (ThreatLinkSet::iterator threat_iter = plan.threat_links.begin ();
    threat_iter != plan.threat_links.end ();
    threat_iter++)
  {
    ThreatLink threat_link = (*threat_iter);
    this->outfile_ << "Threat Link:" << std::endl;
    this->outfile_ << "  " << threat_link.first  << " (";
    this->outfile_ << planner->get_task_name (
      planner->get_task_from_inst (threat_link.first)) << ") -> ";
    this->outfile_ << threat_link.second  << " (";
    this->outfile_ << planner->get_task_name (
      planner->get_task_from_inst (threat_link.second)) << ")" << std::endl;

  }

  this->outfile_ << std::endl;
};