mageec  0.1.0
MAchine Guided Energy Efficient Compilation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
update.c
Go to the documentation of this file.
1 /*************************************************************************/
2 /* */
3 /* Copyright 2010 Rulequest Research Pty Ltd. */
4 /* */
5 /* This file is part of C5.0 GPL Edition, a single-threaded version */
6 /* of C5.0 release 2.07. */
7 /* */
8 /* C5.0 GPL Edition is free software: you can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License as */
10 /* published by the Free Software Foundation, either version 3 of the */
11 /* License, or (at your option) any later version. */
12 /* */
13 /* C5.0 GPL Edition is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
16 /* General Public License for more details. */
17 /* */
18 /* You should have received a copy of the GNU General Public License */
19 /* (gpl.txt) along with C5.0 GPL Edition. If not, see */
20 /* */
21 /* <http://www.gnu.org/licenses/>. */
22 /* */
23 /*************************************************************************/
24 
25 
26 
27 /*************************************************************************/
28 /* */
29 /* Routines that provide information on progress */
30 /* --------------------------------------------- */
31 /* */
32 /*************************************************************************/
33 
34 
35 #include "defns.i"
36 #include "extern.i"
37 
38 
39 FILE *Uf=0; /* File to which update info written */
40 
41 
42 /*************************************************************************/
43 /* */
44 /* There are several stages (see messages in Progress() below) */
45 /* Record stage and open update file if necessary */
46 /* */
47 /*************************************************************************/
48 
49 
50 void NotifyStage(int S)
51 /* ----------- */
52 {
53  Now = S;
54  if ( S == 1 )
55  {
56  if ( ! (Uf = GetFile(".tmp", "w")) ) Error(NOFILE, "", E_ForWrite);
57  }
58 }
59 
60 
61 
62 /*************************************************************************/
63 /* */
64 /* Print progress message. This routine is called in two ways: */
65 /* * negative Delta = measure of total effort required for stage */
66 /* * positive Delta = increment since last call */
67 /* */
68 /*************************************************************************/
69 
70 
71 void Progress(float Delta)
72 /* -------- */
73 {
74  static float Total, Current=0;
75  static int Twentieth=0, LastStage=0;
76  int p;
77  static char *Message[]={ "",
78  "Reading training data ",
79  "Winnowing attributes ",
80  "Constructing decision tree ",
81  "Simplifying decision tree ",
82  "Forming rules ",
83  "Selecting final rules ",
84  "Evaluating on training data",
85  "Reading test data ",
86  "Evaluating on test data ",
87  "Cleaning up ",
88  "Allocating tables ",
89  "Preparing results " },
90  Tell[]={ 0,0,0,1,1,1,1,0,0,0,0,0,0 },
91 
92  *Done=">>>>>>>>>>>>>>>>>>>>",
93  *ToDo="....................";
94 
95  if ( LastStage == Now && ! Tell[Now] )
96  {
97  return;
98  }
99 
100  LastStage = Now;
101 
102  if ( Delta <= -1 )
103  {
104  Total = -Delta;
105  Current = 0;
106  Twentieth = -1;
107  }
108  else
109  {
110  Current = Min(Total, Current + Delta);
111  }
112 
113  if ( (p = rint((20.0 * Current) / Total)) != Twentieth )
114  {
115  Twentieth = p;
116 assert(p >= 0 && p <= 20);
117  fprintf(Uf, "%s", Message[Now]);
118  if ( Tell[Now] )
119  {
120  fprintf(Uf, " %s%s (%d %s)",
121  Done + (20 - Twentieth), ToDo + Twentieth,
122  (int) (Current+0.5),
123  ( Now == SIFTRULES ?
124  "refinements" : "cases covered" ));
125  }
126  fprintf(Uf, "\n");
127  fflush(Uf);
128  }
129 }