示例#1
0
        protected override void ReadInFile(string inFile)
        {
            List <string> allLines = new List <string>();

            try
            {
                allLines = File.ReadAllLines(inFile).ToList();
            }
            catch (Exception e)
            {
                Logger.Error("Error! Hunt-Fill Tracor:\n" + e.ToString() + "\nCannot read data from existing " + inFile);
            }

            // outputLine format:
            // sa teta clpsFlg slope slopRat dvrgFlg stage endTime nn
            foreach (var line in allLines)
            {
                var lineList = line.Split(' ').ToList();
                var pnt      = new IdaPoint
                {
                    Im              = Convert.ToDouble(lineList[0]),
                    Edp             = Convert.ToDouble(lineList[1]),
                    CollapseFlag    = Convert.ToBoolean(lineList[2]),
                    Slope           = Convert.ToDouble(lineList[3]),
                    RelSlope        = Convert.ToDouble(lineList[4]),
                    DivergFlag      = Convert.ToBoolean(lineList[5]),
                    AnalysisEndTime = Convert.ToDouble(lineList[6])
                };
                UpdateStatus(ref pnt, SingleRunJob.Status.Recieved);
            }
        }
示例#2
0
        protected virtual string FormatOutput(IdaPoint pnt)
        {
            var line = string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8}", pnt.Im, pnt.Edp, pnt.CollapseFlag,
                                     pnt.Slope, pnt.RelSlope, pnt.DivergFlag, pnt.AnalysisEndTime, pnt.StringOut, pnt.Order);

            return(line);
        }
示例#3
0
        protected virtual void EndStatusUpdate(IdaPoint pnt)
        {
            // to be called by UpdateStatus() after each round of updating
            InsertPointInGraph(pnt);
            var line = FormatOutput(pnt) + Environment.NewLine;

            File.AppendAllText(OutFile, line);
        }
示例#4
0
        public void IssueCollapse(IdaPoint pnt)
        {
            if (pnt == null)
            {
                pnt = TheGraph[0];
            }
            var newFilename = OutFile.Replace("IDA.txt", "Collapse.txt");
            var line        = FormatOutput(pnt);

            File.WriteAllText(newFilename, line);
        }
        protected override void ReadInFile(string inFile)
        {
            List <string> allLines = new List <string>();

            try
            {
                allLines = File.ReadAllLines(inFile).ToList();
            }
            catch (Exception e)
            {
                Logger.Log("Hunt-Fill Tracor:");
                Logger.Log(e.ToString());
                Logger.Log("Cannot read data from existing " + inFile);
            }

            // outputLine format:
            // sa teta clpsFlg slope slopRat dvrgFlg stage endTime nn
            int nn = 1;

            foreach (var line in allLines)
            {
                var      lineList = line.Split(' ').ToList();
                IdaPoint pnt      = new IdaPoint();
                var      im       = Convert.ToDouble(lineList[0]);
                pnt.Im              = im;
                pnt.Edp             = Convert.ToDouble(lineList[1]);
                pnt.CollapseFlag    = Convert.ToBoolean(lineList[2]);
                pnt.Slope           = Convert.ToDouble(lineList[3]);
                pnt.RelSlope        = Convert.ToDouble(lineList[4]);
                pnt.DivergFlag      = Convert.ToBoolean(lineList[5]);
                pnt.AnalysisEndTime = Convert.ToDouble(lineList[6]);
                TheGraph.Add(nn, pnt);
                if (pnt.CollapseFlag)
                {
                    ImCollapse = pnt.Im;
                }
                else
                {
                    ImStable  = pnt.Im;
                    EdpStable = pnt.Edp;
                    if (CurStage == Stage.Hunt)
                    {
                        NLastStable = TheGraph.Count; //to support for file continuation
                    }
                }
                CurStage = lineList[6] == "0" ? Stage.Hunt : (lineList[6] == "1" ? Stage.Bracket : Stage.Fill);
                if (nn >= MaxIdaPnts)
                {
                    Continue = false;
                }
                nn++;
            }
        }
示例#6
0
        private void InsertPointInGraph(IdaPoint pnt)
        {
            var nn   = pnt.Order;
            var maxN = 0;

            if (TheGraph.Count != 0)
            {
                maxN = TheGraph.Keys.Max();
            }
            for (var n = maxN; n >= nn; n--)
            {
                TheGraph[n + 1] = TheGraph[n];
            }
            TheGraph[nn] = pnt;
        }
示例#7
0
 public void SetResult(SingleRunJob job, IdaPoint resPnt, out bool cancelPool, out bool deleteMe)
 {
     NWorkers--;
     _theTracer.UpdateStatus(ref resPnt, job.TheStatus);
     deleteMe   = false;
     cancelPool = false;
     if (NWorkers <= 1)
     {
         deleteMe = true;
         _theTracer.EndTracing();
         return;
     }
     if (_theTracer.StageChanged)
     {
         //we must delete posted jobs before execution
         cancelPool = true;
     }
 }
示例#8
0
 //update StageChanged and other stage variables
 public virtual void StartTracing(string outFile)
 {
     OutFile     = outFile;
     TheGraph    = new Dictionary <int, IdaPoint>();
     TheGraph[0] = new IdaPoint(0, 0, 0, 0, 0, false, false);
     if (File.Exists(outFile))
     {
         // the file exists and IDA must be continued
         // the arrays are filled and the status variables are updated
         // according to previous recording
         ReadInFile(outFile);
         try
         {
             File.Copy(outFile, outFile + "_old", true);
             File.Delete(outFile);
         }
         catch (Exception e)
         {
             Logger.Error(e.ToString() + "\nFailed to open " + outFile + " for writing; exiting");
             Thread.CurrentThread.Abort();
         }
     }
 }
        public override void UpdateStatus(ref IdaPoint pnt, SingleRunJob.Status theStatus)
        {
            //iterate through all points to find the order
            var im      = pnt.Im;
            var edp     = pnt.Edp;
            var dvrgFlg = pnt.DivergFlag;
            var nn      = TheGraph.TakeWhile(kvp => kvp.Value.Im < im).Count();

            StageChanged = false;
            var stage0 = CurStage;

            if (CurStage != Stage.Fill)
            {
                pnt.Slope = (pnt.Im - ImStable) / (edp - EdpStable);
                pnt.Slope = Math.Abs(pnt.Slope);
                if (nn == 1 && Math.Abs(InitSlope) < 1e-3)
                {
                    InitSlope = pnt.Slope;
                }
                pnt.RelSlope = pnt.Slope / InitSlope;
                if (edp > TetaLimit || pnt.RelSlope < 0.2 || dvrgFlg)
                {
                    pnt.CollapseFlag = true;
                    CurStage         = Stage.Bracket;
                    if (pnt.Im < ImCollapse)
                    {
                        ImCollapse   = pnt.Im;
                        ImForNexts   = ImStable + (ImCollapse - ImStable) / 3;
                        StageChanged = true;
                    }
                }
                else
                {
                    if (pnt.Im > ImStable)
                    {
                        ImStable  = pnt.Im;
                        EdpStable = edp;
                    }
                    if (CurStage == Stage.Hunt)
                    {
                        NLastStable = nn;
                    }
                }
                if (CurStage == Stage.Bracket)
                {
                    var clpseRsln = (ImCollapse - ImStable) / ImStable;
                    if (clpseRsln < MaxClpsRsltn)
                    {
                        CurStage     = Stage.Fill;
                        StageChanged = true;
                        ImForNexts   = (TheGraph[NLastStable].Im + TheGraph[NLastStable - 1].Im) / 2.0;
                        NLastStable--;
                        if (NLastStable < 1)
                        {
                            Continue = false;
                        }
                    }
                }
            }
            pnt.StringOut = string.Format("{0} {1}", CurStage, theStatus);
            pnt.Order     = nn;
            EndStatusUpdate(pnt);
        }
示例#10
0
        public static bool SetResultString(string result, out SingleRunJob job, out IdaPoint pnt)
        {
            // model record im edp endTime dvrgFlg
            job = null;
            pnt = null;
            var resList = result.Split(' ').ToList();

            if (resList.Count < 2)
            {
                return(false);
            }
            var model = resList[0];
            var rec   = resList[1];
            var im    = Convert.ToDouble(resList[2]);

            job = JobPool.GetJob(model, rec, im);
            if (job.TheStatus != SingleRunJob.Status.Cancelled)
            {
                job.TheStatus = SingleRunJob.Status.Recieved;
            }
            else
            {
                job.TheStatus = SingleRunJob.Status.CancelRecieved;
            }

            pnt = new IdaPoint
            {
                Im              = Convert.ToDouble(resList[2]),
                Edp             = Convert.ToDouble(resList[3]),
                AnalysisEndTime = Convert.ToDouble(resList[4]),
                DivergFlag      = Convert.ToInt16(resList[5]) != 0
            };
            IdaJob toDelete = null;
            var    jobList  = IdaJobPool.Where(idajob => idajob.Model == model && idajob.Record == rec).ToArray();

            if (!jobList.Any())
            {
                throw new Exception("IDAJob not found");
            }
            var  idaJob = jobList.ElementAt(0);
            bool cancel;
            bool deleteMe;

            idaJob.SetResult(job, pnt, out cancel, out deleteMe);
            if (cancel)
            {
                JobPool.CancelJobs(idaJob);
            }
            if (deleteMe)
            {
                toDelete = idaJob;
                Logger.LogIdaFinished(idaJob);
            }
            if (toDelete != null)
            {
                IdaJobPool.Remove(toDelete);
                if (LoadedJobsPool.Count == 0)
                {
                    return(IdaJobPool.Count == 0);
                }
                IdaJobPool.Add(LoadedJobsPool[0]);
                LoadedJobsPool.RemoveAt(0);
            }
            return(IdaJobPool.Count == 0);
        }
示例#11
0
 public abstract void UpdateStatus(ref IdaPoint pnt, SingleRunJob.Status theStatus);
示例#12
0
 public static void LogResultRecieved(SingleRunJob job, IdaPoint pnt)
 {
     //Log(string.Format("New result (model= {0}, record= {1}, IM= {2})", job.Model, job.Record, job.Im));
 }