Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="projectFile"></param>
        /// <param name="PerformanceAnalysis"></param>
        public ModellerController(string projectFile, bool PerformanceAnalysis = false, string userInitials = "XTMF")
        {
            if (!projectFile.EndsWith(".emp") | !File.Exists(projectFile))
            {
                throw new XTMFRuntimeException(this.AddQuotes(projectFile) + " is not an existing Emme project file (*.emp)");
            }

            //Python invocation command:
            //[FullPath...python.exe] -u [FullPath...ModellerBridge.py] [FullPath...EmmeProject.emp] [User initials] [[Performance (optional)]]

            // Get the path of the Python executable
            string emmePath = Environment.GetEnvironmentVariable("EMMEPATH");

            if (String.IsNullOrWhiteSpace(emmePath))
            {
                throw new XTMFRuntimeException("Please make sure that EMMEPATH is on the system environment variables!");
            }
            string pythonDirectory = Path.Combine(emmePath, this.FindPython(emmePath));
            string pythonPath      = this.AddQuotes(Path.Combine(pythonDirectory, @"python.exe"));
            string pythonLib       = Path.Combine(pythonDirectory, "Lib");

            // Get the path of ModellerBridge
            // Learn where the modules are stored so we can find the python script
            // The Entry assembly will be the XTMF.GUI or XTMF.RemoteClient
            var    codeBase    = Assembly.GetEntryAssembly().CodeBase;
            string programPath = null;

            // make sure that the path is not relative
            try
            {
                programPath = Path.GetFullPath(codeBase);
            }
            catch
            {
                programPath = codeBase.Replace("file:///", String.Empty);
            }
            // Since the modules are always located in the ~/Modules subdirectory for XTMF,
            // we can just go in there to find the script
            var modulesDirectory = Path.Combine(Path.GetDirectoryName(programPath), "Modules");
            // When emme is installed it will link the .py to their python interpreter properly
            string argumentString = AddQuotes(Path.Combine(modulesDirectory, "ModellerBridge.py"));

            PipeName     = Guid.NewGuid().ToString();
            PipeFromEmme = new NamedPipeServerStream(PipeName, PipeDirection.In);
            //The first argument that gets passed into the Bridge is the name of the Emme project file
            argumentString += " " + this.AddQuotes(projectFile) + " " + userInitials + " " + (PerformanceAnalysis ? 1 : 0) + " \"" + PipeName + "\"";

            //Setup up the new process
            // When creating this process, we can not start in our own window because we are re-directing the I/O
            // and windows won't allow us to have a window and take its standard I/O streams at the same time
            this.Emme = new Process();
            var startInfo = new ProcessStartInfo(pythonPath, "-u " + argumentString);

            startInfo.EnvironmentVariables["PATH"] += ";" + pythonLib;
            this.Emme.StartInfo = startInfo;
            this.Emme.StartInfo.CreateNoWindow         = true;
            this.Emme.StartInfo.UseShellExecute        = false;
            this.Emme.StartInfo.RedirectStandardInput  = true;
            this.Emme.StartInfo.RedirectStandardOutput = true;
            this.Emme.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;

            //Start the new process
            try
            {
                Emme.Start();
            }
            catch
            {
                throw new XTMFRuntimeException("Unable to create a bridge to EMME to '" + this.AddQuotes(projectFile) + "'!");
            }
            // Give some short names for the streams that we will be using
            this.ToEmme = this.Emme.StandardInput;
            // no more standard out
            this.PipeFromEmme.WaitForConnection();
            //this.FromEmme = this.Emme.StandardOutput;
        }
Esempio n. 2
0
 public float ComplexErrorFunction(ParameterSetting[] parameters, Emme.TransitLine[] transitLine, Emme.TransitLine[] predicted, float[] aggToTruth)
 {
     throw new NotImplementedException();
 }