//  -*- C++  -*- 
//
//======================================================================
//  File:          driver.c
//  Author:        Thomas G. Dietterich
//  Description:   This program reads in a bayes net and then permits
//                 the user to pose queries and make observations.  I
//                 used it for debugging the network code.  It prints
//                 the entire network after each query, which makes it
//                 hard to use for large nets.
//                 
//  Copyright (c) 1995 by Thomas G. Dietterich.  All Rights Reserved.
//       may be reproduced by any non-commercial purpose.
//======================================================================

#include "bayes.h"
#include <iostream.h>
#include <fstream.h>

int TRACE = 0;

int main(int argc, char * argv[])
{
  bayesNet network;
  {
    ifstream str(argv[1]);
    str >> network;
  }

  int var;
  int value;

  while (1) {
    cout << "Network: " << network << endl;
    cout << "Observe (o), fullQuery(f), query (q), reset (r), trace (t), untrace(u),  or exit (x): ";
    char command;
    cin >> command;
    switch (command) {
    case 'f':
      cout << "Enter variable to query: ";
      cin >> var;
      cout << "Enter value to query: ";
      cin >> value;
      cout << "P(var " << var << " = " << value << ") = " <<
	network.fullQuery(var, value) << endl;
      break;
    case 'o':
      cout << "Variable to observe: ";
      cin >> var;
      cout << "Value observed: ";
      cin >> value;
      network.observe(var, value);
      break;
    case 'q':
      cout << "Enter variable to query: ";
      cin >> var;
      cout << "Enter value to query: ";
      cin >> value;
      cout << "P(var " << var << " = " << value << ") = " <<
	network.query(var, value) << endl;
      break;
    case 'r':
      network.reset();
      break;
    case 't':
      TRACE = 1;
      break;
    case 'u':
      TRACE = 0;
      break;
    case 'x':
      return 0;
    default:
      cout << "Unknown command.  Try again." << endl;
    }
  }
  return -1;
}


  
