//  -*-  C++  -*-
//
//======================================================================
//  File:          diagnose.c
//  Author:        Thomas G. Dietterich
//  Description:   Diagnose faults
//                 Implements the diagnostic algorithm by Heckerman,
//                 Breese, and Rommelse in CACM 38 (3) 49--57
//                 
//  Copyright (c) 1995 by Thomas G. Dietterich.  All Rights Reserved.
//       may be reproduced by any non-commercial purpose.
//======================================================================
//
//

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

int TRACE = 0;
extern int DEBUG;
extern "C" int getopt(int, char* [], char *);

#ifdef __GNUG__
template class list<varAndRatio>;
#endif

void printUsage()
{
  cerr << "Usage: diagnose [-d] [-t] network-file problem-file" << endl;
  cerr << "  -d: DEBUG  details of value computations" << endl;
  cerr << "  -t: TRACE  details of probability computations (voluminous)" << endl;
  cerr << "  network-file: name of file containing Bayes net" << endl;
  cerr << "  problem-file: name of file containing problem info" << endl;
}

int main(int argc, char *argv[])
{
  int optc;
  extern char *optarg;
  extern int optind;
  while (( optc = getopt(argc, argv, "dt")) != -1 ) {
    switch (optc) {
    case 'd':
      DEBUG = 1;
      break;
    case 't':
      TRACE = 1;
      break;
    default:
      printUsage();
      return -1;
    }
  }

  if (argc != optind + 2) {
    printUsage();
    return -1;
  }

  dxProblem problem(argv[optind], argv[optind+1]);
  int cost = problem.solve();
  cout << "Cost of solution was " << cost << endl;
  return 0;
}
