if cons.offlineData:
    print "ExSTraCS Offline Environment Mode Initiated."
    if cons.internalCrossValidation == 0 or cons.internalCrossValidation == 1:  # No internal Cross Validation
        # Engage Timer - tracks run time of algorithm and it's components.
        timer = Timer()  # TIME
        cons.referenceTimer(timer)
        cons.timer.startTimeInit()
        # Initialize the Environment object - this manages the data presented to ExSTraCS
        env = Offline_Environment()
        cons.referenceEnv(
            env
        )  # Send reference to environment object to constants - to access from anywhere in ExSTraCS
        cons.parseIterations()

        # Instantiate ExSTraCS Algorithm
        algorithm = ExSTraCS()

        if cons.onlyRC:
            cons.timer.stopTimeInit()
            algorithm.runRConly()
        else:
            if cons.onlyEKScores:
                cons.timer.stopTimeInit()
                EK = ExpertKnowledge(cons)
                print "Algorithm Run Complete"
            else:  # Run the ExSTraCS algorithm.
                if (
                    cons.useExpertKnowledge
                ):  # Transform EK scores into probabilities weights for covering. Done once. EK must be externally provided.
                    cons.timer.startTimeEK()
                    EK = ExpertKnowledge(cons)
def ExSTraCS_Main(configurationFile):
    helpstr = """
    WARNING: Some error has caused ExSTraCS to fail.  Please ensure that a properly formatted configuration file is available, and the 
    respective file path has been given as an argument to ExSTraCS. Also ensure that you run parameters within the configuration file 
    have been set correctly.  If this fails to solve the issue, please examine standard out/error to track down the issue.
    """
    try: 
        #Initialize the Parameters object - this will parse the configuration file and store all constants and parameters.
        ConfigParser(configurationFile)
        if cons.offlineData:
            if cons.internalCrossValidation == 0 or cons.internalCrossValidation == 1:  #No internal Cross Validation
                #Engage Timer - tracks run time of algorithm and it's components.
                timer = Timer() #TIME
                cons.referenceTimer(timer)    
                cons.timer.startTimeInit()
                #Initialize the Environment object - this manages the data presented to ExSTraCS 
                env = Offline_Environment()
                cons.referenceEnv(env) #Send reference to environment object to constants - to access from anywhere in ExSTraCS
                cons.parseIterations()
    
                #Instantiate ExSTraCS Algorithm
                algorithm = ExSTraCS()
                
                if cons.onlyRC:
                    cons.timer.stopTimeInit()
                    algorithm.runRConly()
                else: 
                    if cons.onlyEKScores:
                        cons.timer.stopTimeInit()
                        EK = ExpertKnowledge(cons)
                        print "Algorithm Run Complete"
                    else: #Run the ExSTraCS algorithm.
                        if cons.useExpertKnowledge: #Transform EK scores into probabilities weights for covering. Done once. EK must be externally provided.
                            cons.timer.startTimeEK()
                            EK = ExpertKnowledge(cons)
                            cons.referenceExpertKnowledge(EK)
                            #cons.makeExpert() #stores the calculated EK probabilities in ExSTraCS_Constants.
                            cons.timer.stopTimeEK()
                            
                        
                        if cons.doAttributeTracking:
                            cons.timer.startTimeAT()
                            AT = AttributeTracking(True)
                            cons.timer.stopTimeAT()
                        else:
                            AT = AttributeTracking(False)
                        cons.referenceAttributeTracking(AT)
                        cons.timer.stopTimeInit()
                        algorithm.runExSTraCS()
                        
            else: #Run internal Cross Validation
                for part in range(cons.internalCrossValidation):
                    cons.updateFileNames(part)            
                    #Initialize new ExSTraCS run----------------------------------------------------------------------------------------
                    #Engage Timer - tracks run time of algorithm and it's components.
                    timer = Timer() #TIME
                    cons.referenceTimer(timer)    
                    cons.timer.startTimeInit()
                    
                    #Initialize the Environment object - this manages the data presented to ExSTraCS 
                    env = Offline_Environment()
                    cons.referenceEnv(env) #Send reference to environment object to constants - to access from anywhere in ExSTraCS
                    cons.parseIterations()
                     
                    #Instantiate ExSTraCS Algorithm
                    algorithm = ExSTraCS()
                    
                    if cons.onlyRC:
                        cons.timer.stopTimeInit()
                        algorithm.runRConly()
                    else: 
                        if cons.onlyEKScores:
                            cons.runFilter()
                            print "Algorithm Run Complete"
                        else: #Run the ExSTraCS algorithm.
                            if cons.useExpertKnowledge: #Transform EK scores into probabilities weights for covering. Done once. EK must be externally provided.
                                cons.timer.startTimeEK()
                                EK = ExpertKnowledge(cons)
                                cons.referenceExpertKnowledge(EK)
                                cons.timer.stopTimeEK()
                                
                            if cons.doAttributeTracking:
                                cons.timer.startTimeAT()
                                AT = AttributeTracking(True)
                                cons.timer.stopTimeAT()
                            else:
                                AT = AttributeTracking(False)
                            cons.referenceAttributeTracking(AT)
                            cons.timer.stopTimeInit()
                            algorithm.runExSTraCS()
    
        else: #Online Dataset (Does not allow Expert Knowledge, Attribute Tracking, Attribute Feedback, or cross-validation)
            #Engage Timer - tracks run time of algorithm and it's components.
            timer = Timer() #TIME
            cons.referenceTimer(timer)
            cons.timer.startTimeInit()
            cons.overrideParameters()
            
            #Initialize the Environment object - this manages the data presented to ExSTraCS 
            env = Online_Environment() #Multiplexer is currently hard coded (Users may add code for different online environments of interest)
            cons.referenceEnv(env) #Send reference to environment object to constants - to access from anywhere in ExSTraCS
            cons.parseIterations() 
            
            #Instantiate ExSTraCS Algorithm
            cons.timer.stopTimeInit()
            algorithm = ExSTraCS()
            
            cons.timer.stopTimeInit()
            if cons.onlyRC:
                algorithm.runRConly()
            else: 
                algorithm.runExSTraCS()
            
    except Exception, ex:
        logging.exception(helpstr)
        sys.exit()