/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package woc.classinstances;


import Datastructure.Rete.HeadNode;
import Datastructure.Rete.Rete;
import Datastructure.Rewriting.Rewriter_easy;
import Datastructure.Rewriting.Rewriter_easyMCS;
import Datastructure.choice.ChoiceUnitRewrite;
import Entity.*;
import Exceptions.FactSizeException;
import Exceptions.RuleNotSafeException;
import Interfaces.Term;
import Manager.Manager;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import parser.Parser;
import parser.ParserRewrite;
import parser.antlr.*;


/**
 *
 * @author User
 */
public class main_FINAL_NormalASP {

    
    private static String filter;
    private static int rewriting;
    private static String filename;
    private static Integer answersets;
    private static boolean outprint;
    
    public static void main(String args[]) /*throws FactSizeException, RuleNotSafeException*/{
        long start = System.currentTimeMillis();
        /*filename = args[0];
        for(String s: args){
            System.out.println(s);
        }*/
        
        //filename = "birds_ASPERIX_nbb=100.txt";
        //filename = "StableMarriage/01-stable_marriage-0-0.txt";
        //filename = "funcTermTest.txt";
       // filename = "Hanoi\\00-hanoi.txt";
        //filename = "maze generation\\00-maze_genearation.txt";
        //filename = "maze generation\\01-maze_generation-0-0.txt";
        //filename = "Partner Units Polynomial/00-partner.txt";
        //filename = "Partner Units Polynomial/07-partner_units_polynomial-28-0.txt";
        //filename = "graph colouring/00-graph-colouring.txt";
        //filename ="single_import_pos.txt";
        //filename ="single_import_neg.txt";
        //filename = "Xir2.txt";
        //filename = "scholarship.txt";
        filename = "WOC - EXAMPLES/WOC - EXAMPLES/reachability/reach5.txt";
        rewriting = 1;
        answersets = 600;
        filter = null;
        outprint =false;
        
        //GlobalSettings.getGlobalSettings().setStringbasedHashCode(true); // try non-string hash codes
        
        // create context
        ContextASPMCSRewriting ctx = new ContextASPMCSRewriting();
        ContextASPRewriting rewctx = null;
        // parsing with ANTLR
        long parsing_time = 0;
        try {
            // setting up lexer and parser
            wocLexer lex = new wocLexer(new ANTLRFileStream(filename));
            CommonTokenStream tokens = new CommonTokenStream(lex);
            wocParser parser = new wocParser(tokens);
        
            // set context
            parser.setContext(ctx);
            
            try {
                try {
                    // parse input
                    long start_parsing_time = System.currentTimeMillis();
                    parser.woc_program();
                    parsing_time = System.currentTimeMillis() - start_parsing_time;
                    System.out.println("Parsed program, starting rewriting...");
                    
                    Rewriter_easy rewriter = new Rewriter_easy();
                    rewctx = rewriter.rewrite(ctx);
                    
                    //System.out.println("Read in program is: ");
                    //ctx.printContext();
                } catch (RuleNotSafeException ex) {
                    Logger.getLogger(main_FINAL_NormalASP.class.getName()).log(Level.SEVERE, null, ex);
                } catch (FactSizeException ex) {
                    Logger.getLogger(main_FINAL_NormalASP.class.getName()).log(Level.SEVERE, null, ex);
                }
                
                
            } catch (RecognitionException ex) {
                Logger.getLogger(main_FINAL_NormalASP.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        } catch (IOException ex) {
            Logger.getLogger(main_FINAL_NormalASP.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
        //File input = new File(filename);


        
        System.out.println("STARTING: " + filename + "Answersets2Derive: " + answersets + "rewriting="+rewriting + "-filter= " + filter + " StartingTime: " + System.currentTimeMillis());
        
        
        Manager m = new Manager(rewctx);
        long beforeCalc = System.currentTimeMillis();
        m.calculate(answersets,outprint,filter);

        System.out.println("Termianted final Calculation");
        System.out.println("Time needed for parsing: "+(parsing_time/1000.0f));
        System.out.println("Time needed overAll: " + (1.0F*(System.currentTimeMillis()-start)/1000));
        System.out.println("Time needed for calculation: " +(1.0F*(System.currentTimeMillis()-beforeCalc)/1000));
    }
    
    private static void help(){
        System.out.println("java -jar woc <filename> [-answersets=X, -filter=predicateName -rewriting=0-2 | 0=No rewriting, 1=Rewriting, 2=AlreadyRewritten]");
    }
    
}

@@ -1235,115 +1235,8 @@
     
- /*filename = args%5B0%5D;%0A        for(String s: args)%7B%0A            System.out.println(s);%0A        %7D*/%0A        
 %0A   
@@ -1374,20 +1374,19 @@
  = %22
-funcTermTest
+scholarship
 .txt
@@ -1937,24 +1937,33 @@
 rship.txt%22;%0A
+        %0A
         file
@@ -1973,63 +1973,15 @@
 e = 
-%22WOC - EXAMPLES/WOC - EXAMPLES/reachability/reach5.txt%22
+args%5B0%5D
 ;%0A  
@@ -2026,11 +2026,9 @@
 s = 
-600
+1
 ;%0A  
@@ -2070,14 +2070,124 @@
 nt =
-false;
+true;%0A        %0A        if (args.length == 2)%0A        %7B%0A            answersets = Integer.parseInt(args%5B1%5D);%0A        %7D
 %0A   

Read from args.