Exemplo n.º 1
0
main(){
  int events=10; // number of events to generate
  int n, i;

  char *options[]={
    "-seed=1 -user -sdec -raw -rw=0",
    "-seed=1 -user -Emu=1.e7 -Enm=1.e6 -Ene=1.e6 -sdec -raw",
    "-seed=1 -user -sdec -raw -prop"
  };

  double r, z1=0, z2=0, h1=0, h2=0, nx=0, ny=0, nz=0, e1=0, e2=0, ec=0;

  initJre();

  // setStderr("mmc.log");
  printf("\nRunning %s\n", "tfa/Amanda (1)");
  initMMC(options[0], 1);

  for(n=0; n<events; n++){
    printf("Event %i\n", n);
    setStart(1);
    name="mu-";
    x=1;    // [m]
    y=2;    // [m]
    z=1000; // [m]
    theta=0;
    phi=0;
    e=2000; // [GeV]
    t=0;    // [s]
    propagate(name, x*1.e2, y*1.e2, z*1.e2, 180-theta, phi<180?phi+180:phi-180, e*1.e3, t);

    resultsOut();

    r=getDouble("r", 1);
    e=getDouble("e", 1);
    z1=getDouble("z1", 2);
    z2=getDouble("z2", 2);
    h1=getDouble("h1", 2);
    h2=getDouble("h2", 2);
    nx=getDouble("nx", 2);
    ny=getDouble("ny", 2);
    nz=getDouble("nz", 2);
    e1=getDouble("e1", 2);
    e2=getDouble("e2", 2);
    ec=getDouble("ec", 2);

    r*=1.e-2; e*=1.e-3;
    printf("%g %g %g %g %g %g %g %g %g %g %g %g\n", r, e, z1, z2, h1, h2, nx, ny, nz, e1, e2, ec);
    setStart(0);
    printf("EVENT WEIGHT = %g at %g\n", getDouble("fw", 2), getDouble("hw", 2));
    endProp();
  }
  deleteMMC();

  printf("\nRunning %s\n", "gen/AtmFlux (2)");
  initMMC(options[1], 2);
  for(n=0; n<events; n++){
    createNext();
    resultsOut();
    endProp();
  }
  deleteMMC();

  printf("\nRunning %s\n", "gen/AtmFlux (3)");
  initMMC(options[2], 3);
  for(n=0; n<events; n++){
    printf("Event %i\n", n);

    name="nu_tau";
    x=1;    // [m]
    y=2;    // [m]
    z=-5e6; // [m]
    theta=180;
    phi=0;
    e=1.e8; // [GeV]
    t=0;    // [s]
    propagate(name, x*1.e2, y*1.e2, z*1.e2, 180-theta, phi<180?phi+180:phi-180, e*1.e3, t);

    resultsOut();
    endProp();
  }
  deleteMMC();

  stopJre();
}
Exemplo n.º 2
0
/**
 * The specified inference algorithm is run. First, the MLN and evidence files
 * are parsed and the database is filled. All evidence predicates are
 * closed-world by default (this can be changed with the -o option) and all
 * non-evidence predicates (query and hidden predicates) are open-world by
 * default (this can be changed with the -c option, however query atoms are
 * always open-world).
 */
int main(int argc, char* argv[])
{
    ///////////////////////////  read & prepare parameters ///////////////////////
    ARGS::parse(argc, argv, &cout);
    Timer timer;
    double begSec = timer.time();

    Array<Predicate *> queryPreds;
    Array<TruthValue> queryPredValues;

    ofstream resultsOut(aresultsFile);
    if (!resultsOut.good())
    {
        cout << "ERROR: unable to open " << aresultsFile << endl;
        return -1;
    }

    Domain* domain = NULL;
    Inference* inference = NULL;
    if (buildInference(inference, domain, aisQueryEvidence, queryPreds,
                       queryPredValues) > -1)
    {
        //for(int i=0;i<queryPreds.size();i++)
        //{
        //  queryPreds[i]->print(cout,domain);
        // cout<<endl;
        //}
        double initTime, runTime;
        Timer timer1;

        timer1.reset();
        inference->init();
        initTime = timer1.time();

        timer1.reset();

        // No inference, just output network
        if (aoutputNetwork)
        {
            cout << "Writing network to file ..." << endl;
            inference->printNetwork(resultsOut);
        }
        // Perform inference
        else
        {
            if (adecisionInfer)
            {
                BP* bp = dynamic_cast<BP*>(inference);
                if (bp) bp->runDecisionBP();
            }
            else
            {
                inference->infer();
            }

            runTime = timer1.time();
            cout<<"Time-Results: Init "<<initTime<<" Run "<<runTime<<" Total "<<(initTime+runTime)<<endl;


            if (aHybrid)
            {
                printResults(queryFile, queryPredsStr, domain, resultsOut, &queries,
                             inference, inference->getHState());
            }
            else
            {
                if (adecisionInfer)
                {
                    BP* bp = dynamic_cast<BP*>(inference);
                    if (bp) bp->printDecisionResults(resultsOut);
                }
                else
                {
                    printResults(queryFile, queryPredsStr, domain, resultsOut, &queries,
                                 inference, inference->getState());
                }
            }
        }
    }

    resultsOut.close();
    if (domain) delete domain;
    for (int i = 0; i < knownQueries.size(); i++)
        if (knownQueries[i]) delete knownQueries[i];
    if (inference) delete inference;

    cout << "total time taken = ";
    Timer::printTime(cout, timer.time()-begSec);
    cout << endl;
}