예제 #1
0
 /// <summary>
 /// recursive algorithm to generate a Tree.
 /// </summary>
 /// <param name="?">data structure getting built incrementally.</param>
 public void getTree(TreeData.TreeDataTableDataTable treeSoFar)
 {
     treeSoFar.AddTreeDataTableRow(id, parent.id, name, "");
     foreach (ACNode n in children)
     {
         n.getTree(treeSoFar);
     }
 }
예제 #2
0
        private void AddPurposeData(float[][] driveData, TreeData <float[][]> current, SparseArray <float> production, FloatList purposeDrive, FloatList purposeOther)
        {
            var cat = current.Children;

            if (cat != null)
            {
                var length = cat.Length;
                for (int i = 0; i < length; i++)
                {
                    AddPurposeData(driveData, cat[i], production, purposeDrive, purposeOther);
                }
            }
            else
            {
                // we only add in end nodes
                var zones         = Root.ZoneSystem.ZoneArray.GetFlatData();
                var numberOfZones = zones.Length;
                var data          = current.Result;
                // shortcut invalid modes
                if (data == null)
                {
                    return;
                }
                var flatProduction = production.GetFlatData();
                if (driveData == data)
                {
                    // Auto drive case
                    Parallel.For(0, numberOfZones, new ParallelOptions {
                        MaxDegreeOfParallelism = Environment.ProcessorCount
                    }, delegate(int i)
                    {
                        if (!InverseLookup(zones[i].RegionNumber, out int regionIndex))
                        {
                            // if this zone isn't part of a region we are processing just continue
                            return;
                        }
                        flatProduction[i] += purposeDrive[regionIndex] * SumWentHere(current, i);
                    });
                }
                else
                {
                    // not auto drive case
                    Parallel.For(0, numberOfZones, new ParallelOptions {
                        MaxDegreeOfParallelism = Environment.ProcessorCount
                    }, delegate(int i)
                    {
                        if (!InverseLookup(zones[i].RegionNumber, out int regionIndex))
                        {
                            // if this zone isn't part of a region we are processing just continue
                            return;
                        }
                        flatProduction[i] += purposeOther[regionIndex] * SumWentHere(current, i);
                    });
                }
            }
        }
예제 #3
0
        private bool GatherUtility(TreeData <float[]> treeData, IModeChoiceNode node, int o, int d, IZone[] zones)
        {
            var cat   = node as IModeCategory;
            int index = o * zones.Length + d;

            if (!node.Feasible(zones[o], zones[d], SimulationTime))
            {
                treeData.Result[index] = float.NaN;
                return(false);
            }
            if (cat == null)
            {
                treeData.Result[index] = node.CurrentlyFeasible > 0 ? (float)Math.Exp(node.CalculateV(zones[o], zones[d], SimulationTime)) : float.NaN;
                return(!float.IsNaN(treeData.Result[index]));
            }
            else if (cat.Correlation > 0)
            {
                bool  hasAlternatives = false;
                float totalUtility    = 0;
                var   treeChildren    = treeData.Children;
                var   catChildren     = cat.Children;
                for (int i = 0; i < treeData.Children.Length; i++)
                {
                    if (GatherUtility(treeChildren[i], catChildren[i], o, d, zones))
                    {
                        hasAlternatives = true;
                        totalUtility   += treeChildren[i].Result[index];
                    }
                }
                if (hasAlternatives)
                {
                    if (totalUtility >= this.MinLogSumToE)
                    {
                        var localUtility = cat.CalculateCombinedV(zones[o], zones[d], SimulationTime);
                        if (cat.Correlation == 1f)
                        {
                            if (localUtility == 0f)
                            {
                                treeData.Result[index] = (float)(totalUtility);
                            }
                            else
                            {
                                treeData.Result[index] = (float)(totalUtility * Math.Exp(localUtility));
                            }
                        }
                        else
                        {
                            treeData.Result[index] = (float)(Math.Pow(totalUtility, cat.Correlation) * Math.Exp(localUtility));
                        }
                        return(true);
                    }
                }
            }
            treeData.Result[index] = float.NaN;
            return(false);
        }
 private CSharpStructuredTriviaFormatEngine(
     SyntaxTrivia trivia,
     int initialColumn,
     AnalyzerConfigOptions options,
     ChainedFormattingRules formattingRules,
     SyntaxToken token1,
     SyntaxToken token2
     ) : base(TreeData.Create(trivia, initialColumn), options, formattingRules, token1, token2)
 {
 }
예제 #5
0
파일: TreeData.cs 프로젝트: jscstc007/MoTa
 /// <summary> 移除一个子节点 </summary>
 public void RemoveChildNode(TreeData <T> node)
 {
     if (null != ChildDataList)
     {
         if (ChildDataList.Contains(node))
         {
             ChildDataList.Remove(node);
         }
     }
 }
예제 #6
0
            private static int GetInDirectChildren(TreeData root)
            {
                if (root == null || root.InCycle)
                {
                    return(0);
                }

                return(root.Children.Count + root.Children.Where(child => child.Children.Count > 0)
                       .Sum(GetInDirectChildren));
            }
예제 #7
0
        private void AttachDataToTree(float[][] data)
        {
            TreeData <float[][]> spot = GetAutoModeData(Flows);

            if (spot == null)
            {
                throw new XTMFRuntimeException(this, "The mode '" + AutoModeName + "' was not found to attach the results to it from '" + Name + "'!;");
            }
            spot.Result = data;
        }
예제 #8
0
        public static TreeData GetTree(HtmlNode documentNode)
        {
            TreeData firstTreeNode = new TreeData();

            firstTreeNode.Text = "...";

            SetTreeUsingNextNode(firstTreeNode, documentNode);

            return(firstTreeNode);
        }
        protected TreeDataViewModel(TreeData treeData, TreeDataViewModel parent)
        {
            _parent   = parent;
            _treeData = treeData;

            _children = new ReadOnlyCollection <TreeDataViewModel>(
                (from child in _treeData.Children
                 select new TreeDataViewModel(child, this))
                .ToList());
        }
예제 #10
0
    static void GenerateGoTree(ref TreeData <Transform> treeParent, Transform current)
    {
        TreeData <Transform> data = new TreeData <Transform> (current);

        data.SetParent(treeParent);
        for (int i = 0; i < current.childCount; i++)
        {
            GenerateGoTree(ref data, current.GetChild(i));
        }
    }
예제 #11
0
 /// <summary>
 /// 刷新树的数据
 /// </summary>
 /// <param name="data"></param>
 void RefreshTreeData(TreeData data)
 {
     treeData     = data;
     MaxTreeID    = data.max_tree;
     TreeIDs      = data.have_trees;
     HelpNum      = data.help_num;
     TreeLeftTime = data.cost_time;
     HelpSelf     = data.help_self;
     HelpList     = data.help_list;
 }
예제 #12
0
 public void execute(ref TreeData tree)
 {
     for (int i = 0; i < nb_it; i++)
     {
         foreach (ITreeGenComp step in m_steps)
         {
             step.execute(ref tree);
         }
     }
 }
예제 #13
0
        TreeData CreateRootNode(string path)
        {
            TreeData root = new TreeData()
            {
                Name = path, Path = path, IsExpanded = false
            };

            FillItemByTag(root);
            return(root);
        }
예제 #14
0
        public PartialViewResult ClearTree()
        {
            bTree    = new BTree <int>(3);
            treeData = new TreeData
            {
                data = new List <LeafData>()
            };

            return(PartialView("Index"));
        }
        public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs)
        {
            TreeData ds = new TreeData();

            global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
            global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
            global::System.Xml.Schema.XmlSchemaAny         any      = new global::System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
            if (xs.Contains(dsSchema.TargetNamespace))
            {
                global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                try
                {
                    global::System.Xml.Schema.XmlSchema schema = null;
                    dsSchema.Write(s1);
                    for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                    {
                        schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                        s2.SetLength(0);
                        schema.Write(s2);
                        if ((s1.Length == s2.Length))
                        {
                            s1.Position = 0;
                            s2.Position = 0;
                            for (; ((s1.Position != s1.Length) &&
                                    (s1.ReadByte() == s2.ReadByte()));)
                            {
                                ;
                            }
                            if ((s1.Position == s1.Length))
                            {
                                return(type);
                            }
                        }
                    }
                }
                finally
                {
                    if ((s1 != null))
                    {
                        s1.Close();
                    }
                    if ((s2 != null))
                    {
                        s2.Close();
                    }
                }
            }
            xs.Add(dsSchema);
            return(type);
        }
 public AddLocationViewModel()
 {
     TreeDatasData = new TreeData();
     Repository    = new Repository();
     _treeDatas    = new ObservableCollection <TreeData>();
     MeasureTrees  = new ObservableCollection <MeasureTrees>();
     for (var i = 0; i < 4; i++)
     {
         MeasureTrees.Add(new MeasureTrees());
     }
 }
예제 #17
0
    /// <summary>
    /// Boundsを元にオブジェクトを登録
    /// </summary>
    /// <param name="bounds"></param>
    /// <returns></returns>
    public bool Register(Bounds bounds, TreeData <T> data)
    {
        float left   = bounds.min.x;
        float right  = bounds.max.x;
        float top    = bounds.max.y;
        float bottom = bounds.min.y;
        float front  = bounds.min.z;
        float back   = bounds.max.z;

        return(Register(left, top, right, bottom, front, back, data));
    }
예제 #18
0
 private void CountNumberOfModes(TreeData <float[][]> treeData, ref int index)
 {
     index++;
     if (treeData.Children != null)
     {
         for (int i = 0; i < treeData.Children.Length; i++)
         {
             CountNumberOfModes(treeData.Children[i], ref index);
         }
     }
 }
예제 #19
0
파일: Cell.cs 프로젝트: shignu/MortonOrder
    /// <summary>
    /// TreeDataが抜ける際に通知を送ってもらう
    /// </summary>
    /// <param name="data">抜けるTreeDataオブジェクト</param>
    /// <returns>処理に成功したらtrue</returns>
    public bool OnRemove(TreeData <T> data)
    {
        if (_latestData != data)
        {
            return(false);
        }

        _latestData = data.Next;

        return(true);
    }
예제 #20
0
 public override DataTable GetTableSource(TreeNode Node)
 {
     if (Node.Parent == null)
     {
         return(TreeData.TableData("parent", "^" + Node.Name + "$"));
     }
     else
     {
         return(TreeData.TableData("code", "^" + Node.Name + @"\S{2}$"));
     }
 }
 private void TreeViewChangedMethod(object obj)
 {
     if (obj != null)
     {
         TreeData SelTreeData = (TreeData)obj;
         if (SelTreeData.Children.Count == 0)
         {
             mainSequence.TreeViewData(SelTreeData);
         }
     }
 }
예제 #22
0
 private static void CreateMirroredTree <T>(TreeData <T> node, IModeChoiceNode mode)
 {
     if (mode is IModeCategory asCat && asCat.Children != null)
     {
         node.Children = new TreeData <T> [asCat.Children.Count];
         for (int j = 0; j < node.Children.Length; j++)
         {
             node.Children[j] = new TreeData <T>();
             CreateMirroredTree(node.Children[j], asCat.Children[j]);
         }
     }
 }
예제 #23
0
        public IActionResult InlineEditing()
        {
            var order = TreeData.GetDefaultData();

            ViewBag.dataSource = order;
            List <Object> DropDownData = new List <object>();

            DropDownData.Add(new { id = "CellEditing", name = "Cell Editing" });
            DropDownData.Add(new { id = "RowEditing", name = "Row Editing" });
            ViewBag.DropDownData = DropDownData;
            return(View());
        }
예제 #24
0
        public static void SetTreeUsingNextNode(TreeData parentNode, HtmlNode newDoc)
        {
            foreach (HtmlNode htmlNode in newDoc.ChildNodes)
            {
                /*Unnecessary tree data*/
                if (CrawlingHelper.IsText(htmlNode.Name) &&
                    htmlNode.InnerText.Trim() == "")
                {
                    continue;
                }

                /*Set parent text*/
                if (CrawlingHelper.IsText(htmlNode.Name) &&
                    htmlNode.InnerText.Trim() != "")
                {
                    parentNode.Text += " " + WebUtility.HtmlDecode(newDoc.InnerText);
                    //return;
                }

                /*New tree data*/
                TreeData treeNode = new TreeData();
                if (htmlNode.Attributes.Count == 0)
                {
                    treeNode.Text = WebUtility.HtmlDecode(htmlNode.Name);
                    treeNode.Tag  = new NodeTag(
                        htmlNode.Name,
                        htmlNode.Attributes.Count,
                        htmlNode.ChildNodes.Count);
                    //treeNode.Parent = parentNode;
                }
                else
                {
                    treeNode.Text = WebUtility.HtmlDecode(htmlNode.Name + CrawlingHelper.ConvertAttrToText(htmlNode));
                    treeNode.Tag  = new NodeTag(
                        htmlNode.Name + CrawlingHelper.ConvertAttrToTag(htmlNode),
                        htmlNode.Attributes.Count,
                        htmlNode.ChildNodes.Count);
                    //treeNode.Parent = parentNode;
                }

                /*Next Tree*/
                if (htmlNode.ChildNodes.Count == 0)
                {
                    treeNode.Text += WebUtility.HtmlDecode(" " + htmlNode.InnerText);
                    parentNode.Children.Add(treeNode);
                }
                else
                {
                    parentNode.Children.Add(treeNode);
                    SetTreeUsingNextNode(treeNode, htmlNode);
                }
            }
        }
예제 #25
0
    public TreeData <string> AddNewTree(string treeName = DEFAULT_TREE_NAME, string gender = DEFAULT_TREE_GENDER)
    {
        var treeData = new TreeData <string>()
        {
            Name = treeName, Gender = gender
        };

        cachedData.trees.Add(treeData);
        Save();

        return(treeData);
    }
예제 #26
0
 public BTreeController(RedisClient redisClient)
 {
     _redisClient = redisClient;
     if (bTree == null)
     {
         bTree    = new BTree <int>(4);
         treeData = new TreeData
         {
             data = new List <LeafData>()
         };
     }
 }
        public IActionResult PagingAPI()
        {
            ViewBag.dropdata = new List <object>()
            {
                new { id = "All", mode = "All" },
                new { id = "Root", mode = "Root" }
            };
            var order = TreeData.GetDefaultData();

            ViewBag.dataSource = order;
            return(View());
        }
예제 #28
0
 public void execute(ref TreeData tree)
 {
     for (int i = tree.skeleton.levels.Count - 1; i >= 0; i--)
     {
         List <Node <Bud> > list = tree.skeleton.levels[i];
         for (int j = 0; j < list.Count; j++)
         {
             Node <Bud> node = list[j];
             updateBranchWidth(ref node);
         }
     }
 }
예제 #29
0
        public ActionResult ManagerJsonTree()
        {
            //var key = SqlTextClear(Request["key"]);
            var sb = new System.Text.StringBuilder();

            sb.AppendFormat("select * from ArcConcentratorInfo ");
            //if (key.IsNotNullOrEmpty())
            //{
            //    sb.AppendFormat(" where IntID in (select IntConID from ArcMeterInfo ");
            //    sb.AppendFormat(" where VcAddr='{0}' or NvcName like '%{0}%' ", key);
            //    sb.AppendFormat(" or IntCustNO in  ");
            //    sb.AppendFormat(" (select IntNo from ArcCustomerInfo ");
            //    sb.AppendFormat(" where IntNo like '%{0}%' or NvcName = '{0}' or NvcAddr like '%{0}%' ", key);
            //    sb.AppendFormat(" or NvcVillage like '%{0}%' or VcMobile = '{0}' or VcTelNo = '{0}')) ", key);
            //    sb.AppendFormat(" or VcAddr like '%{0}%' or NvcName like '%{0}%' or NvcAddr like '%{0}%' or VcSimNo='{0}' ", key);
            //}
            var dt       = baseBLL.SqlTable(sb.ToString());
            var children = new List <TreeData>();
            var drs      = dt.Select("intUpID=0");

            foreach (DataRow item in drs)
            {
                var d        = new TreeData();
                var isOnline = item["IntOnline"].ToString() == "1";
                if (isOnline)
                {
                    d.iconCls = "icon-online";
                }
                else
                {
                    d.iconCls = "icon-offline";
                }
                d.id               = item["VcAddr"].ToString();
                d.text             = item["NvcName"].ToString();
                d.IntConID         = item["IntID"].ToString().ToInt32();
                d.ConcentratorAddr = item["VcAddr"].ToString();
                d.children         = getTreeChildren2(d.IntConID, dt, isOnline);
                children.Add(d);
            }

            var list = new List <TreeData>();
            var root = new TreeData();

            root.iconCls          = "icon-house";
            root.id               = "0";
            root.text             = "根";
            root.IntConID         = 0;
            root.ConcentratorAddr = "";
            root.children         = children;
            list.Add(root);

            return(ToJsonContentDate(list));
        }
예제 #30
0
 public PartialViewResult InitTree(int m)
 {
     if (m >= 2)
     {
         bTree    = new BTree <int>(m);
         treeData = new TreeData
         {
             data = new List <LeafData>()
         };
     }
     return(PartialView("Index"));
 }
예제 #31
0
 public void ConstructData()
 {
     if (Data == null)
     {
         return;
     }
     TreeData.Clear();
     foreach (var items in Data)
     {
         ExtractItems(TreeData, items, null, 0);
     }
 }
예제 #32
0
 private void ProcessMode(TreeData<float[][]> treeData, int i, int j, float flow, IModeChoiceNode node, int matrixNumber)
 {
     var cat = node as IModeCategory;
     if ( cat != null )
     {
         // then go 1 level deeper
         for ( int m = cat.Children.Count - 1; m >= 0; m-- )
         {
             ProcessMode( treeData.Children[m], i, j, flow, cat.Children[m], matrixNumber );
         }
         // then sum
         var sum = 0f;
         for ( int m = cat.Children.Count - 1; m >= 0; m-- )
         {
             var res = treeData.Children[m].Result;
             if ( res == null || res[i] == null ) continue;
             sum += res[i][j];
         }
         SetData( treeData.Result, i, j, sum );
     }
     else
     {
         for ( int dataIndex = 0; dataIndex < this.Data.Count; dataIndex++ )
         {
             if ( this.Data[dataIndex].Mode == node )
             {
                 var zones = this.Root.ZoneSystem.ZoneArray.GetFlatData();
                 var data = this.Data[dataIndex].Data;
                 if ( data == null )
                 {
                     throw new XTMFRuntimeException( "In '" + this.Name + "' we tried to access the data for mode split from mode '" + this.Data[dataIndex].ModeName + "' however it was not initialized!" );
                 }
                 if ( treeData.Result == null )
                 {
                     lock ( treeData )
                     {
                         Thread.MemoryBarrier();
                         if ( treeData.Result == null )
                         {
                             treeData.Result = new float[zones.Length][];
                         }
                     }
                 }
                 SetData( treeData.Result, i, j, flow * data.GetDataFrom( zones[i].ZoneNumber, zones[j].ZoneNumber, matrixNumber ) );
             }
         }
     }
 }
예제 #33
0
 private void InitializeResults()
 {
     var numberOfZones = this.Zones.Length;
     var numberOfModes = this.Root.Modes.Count;
     if ( this.CurrentUtility == null )
     {
         this.CurrentUtility = new float[numberOfZones * numberOfZones * numberOfModes];
     }
     // in all cases reset this value
     for ( int i = 0; i < this.CurrentUtility.Length; i++ )
     {
         this.CurrentUtility[i] = float.NaN;
     }
     if ( this.Results == null )
     {
         this.Results = new TreeData<float[][]>[numberOfModes];
         for ( int i = 0; i < this.Results.Length; i++ )
         {
             this.Results[i] = new TreeData<float[][]>();
             this.Results[i].Result = new float[numberOfZones][];
         }
     }
 }
예제 #34
0
 private void WriteModeSplit(TreeData<float[][]> split, IModeChoiceNode modeNode, string directoryName)
 {
     if ( !Directory.Exists( directoryName ) )
     {
         Directory.CreateDirectory( directoryName );
     }
     Task writeTask = new Task( delegate()
         {
             using ( StreamWriter writer = new StreamWriter( Path.Combine( directoryName, modeNode.ModeName + ".csv" ) ) )
             {
                 var header = true;
                 var zones = this.Root.ZoneSystem.ZoneArray.GetFlatData();
                 for ( int i = 0; i < zones.Length; i++ )
                 {
                     if ( header )
                     {
                         header = false;
                         writer.Write( "Zones O\\D" );
                         for ( int j = 0; j < zones.Length; j++ )
                         {
                             writer.Write( ',' );
                             writer.Write( zones[j].ZoneNumber );
                         }
                         writer.WriteLine();
                     }
                     var row = split.Result == null ? null : split.Result[i];
                     writer.Write( zones[i].ZoneNumber );
                     for ( int j = 0; j < zones.Length; j++ )
                     {
                         writer.Write( ',' );
                         writer.Write( row == null ? 0 : row[j] );
                     }
                     writer.WriteLine();
                 }
             }
         } );
     writeTask.Start();
     if ( split.Children != null )
     {
         for ( int i = 0; i < split.Children.Length; i++ )
         {
             WriteModeSplit( split.Children[i], ( (IModeCategory)modeNode ).Children[i], directoryName );
         }
     }
     writeTask.Wait();
 }
예제 #35
0
 private void AddPurposeData(float[][] driveData, TreeData<float[][]> current, SparseArray<float> production, FloatList purposeDrive, FloatList purposeOther)
 {
     var cat = current.Children;
     if ( cat != null )
     {
         var length = cat.Length;
         for ( int i = 0; i < length; i++ )
         {
             AddPurposeData( driveData, cat[i], production, purposeDrive, purposeOther );
         }
     }
     else
     {
         // we only add in end nodes
         var zones = this.Root.ZoneSystem.ZoneArray.GetFlatData();
         var numberOfZones = zones.Length;
         var data = current.Result;
         // shortcut invalid modes
         if ( data == null ) return;
         var flatProduction = production.GetFlatData();
         if ( driveData == data )
         {
             // Auto drive case
             Parallel.For( 0, numberOfZones, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }, delegate(int i)
             {
                 var increment = 0f;
                 int regionIndex;
                 if ( !this.InverseLookup( zones[i].RegionNumber, out regionIndex ) )
                 {
                     // if this zone isn't part of a region we are processing just continue
                     return;
                 }
                 increment = purposeDrive[regionIndex] * SumWentHere( current, i );
                 flatProduction[i] += increment;
             } );
         }
         else
         {
             // not auto drive case
             Parallel.For( 0, numberOfZones, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }, delegate(int i)
             {
                 var increment = 0f;
                 int regionIndex;
                 if ( !this.InverseLookup( zones[i].RegionNumber, out regionIndex ) )
                 {
                     // if this zone isn't part of a region we are processing just continue
                     return;
                 }
                 increment = purposeOther[regionIndex] * SumWentHere( current, i );
                 flatProduction[i] += increment;
             } );
         }
     }
 }
예제 #36
0
 private float[][] GetResult(TreeData<float[][]> node, int modeIndex, ref int current)
 {
     if ( modeIndex == current )
     {
         return node.Result;
     }
     current++;
     if ( node.Children != null )
     {
         for ( int i = 0; i < node.Children.Length; i++ )
         {
             float[][] temp = GetResult( node.Children[i], modeIndex, ref current );
             if ( temp != null )
             {
                 return temp;
             }
         }
     }
     return null;
 }
예제 #37
0
 private static void InitializeTree(TreeData<float[]> tree, int arrayLength)
 {
     var treechildren = tree.Children;
     if ( treechildren != null )
     {
         var length = treechildren.Length;
         for ( int i = 0; i < length; i++ )
         {
             InitializeTree( treechildren[i], arrayLength );
         }
     }
     var data = tree.Result = new float[arrayLength];
     Parallel.For( 0, (int)Math.Ceiling( arrayLength / 100f ), delegate(int section)
     {
         var start = section * 100;
         var end = start + 100;
         for ( int i = start; i < end & i < arrayLength; i++ )
         {
             data[i] = float.NaN;
         }
     } );
 }
예제 #38
0
 private void GatherModes(List<TreeData<float[][]>> flatModes, TreeData<float[][]> treeData)
 {
     if ( treeData.Result != null )
     {
         flatModes.Add( treeData );
     }
     var children = treeData.Children;
     if ( children != null )
     {
         for ( var i = 0; i < children.Length; i++ )
         {
             GatherModes( flatModes, children[i] );
         }
     }
 }
예제 #39
0
 private static void TransposeMatrix(TreeData<float[][]> treeData)
 {
     // no need to code this in parallel since we are doing all of them in parallel
     var matrix = treeData.Result;
     var length = matrix.Length;
     var halfLength = length / 2;
     // fill in the array
     for ( int i = 0; i < length; i++ )
     {
         if ( matrix[i] == null )
         {
             matrix[i] = new float[length];
         }
     }
     for ( int i = 0; i < length; i++ )
     {
         for ( int j = 0; j < halfLength; j++ )
         {
             var temp = matrix[i][j];
             matrix[i][j] = matrix[j][i];
             matrix[j][i] = temp;
         }
     }
 }
예제 #40
0
 private TreeData<float[][]> GetAutoModeData(TreeData<float[][]> tree, IModeChoiceNode mode)
 {
     if ( mode.ModeName == this.AutoModeName )
     {
         return tree;
     }
     else
     {
         var cat = mode as IModeCategory;
         if ( cat == null )
         {
             return null;
         }
         var treeChildren = tree.Children;
         var modeChildren = cat.Children;
         // make sure that it actually contains children first
         if ( treeChildren == null | modeChildren == null )
         {
             return null;
         }
         for ( int i = 0; i < treeChildren.Length; i++ )
         {
             var temp = GetAutoModeData( treeChildren[i], modeChildren[i] );
             if ( temp != null )
             {
                 return temp;
             }
         }
     }
     return null;
 }
예제 #41
0
 private void Reconstitute(TreeData<float[][]> treeData, float ratio)
 {
     var data = treeData.Result;
     if ( data != null )
     {
         Parallel.For( 0, data.Length, delegate(int i)
         {
             var row = data[i];
             if ( row == null ) return;
             for ( int j = 0; j < data.Length; j++ )
             {
                 row[j] *= ratio;
             }
         } );
     }
     if ( treeData.Children != null )
     {
         for ( int i = 0; i < treeData.Children.Length; i++ )
         {
             Reconstitute( treeData.Children[i], ratio );
         }
     }
 }
예제 #42
0
 private float SumWentHere(TreeData<float[][]> current, int flatZoneIndex)
 {
     var data = current.Result;
     // fast way to ditch modes
     if ( data == null ) return 0;
     var length = data.Length;
     var count = 0f;
     for ( int i = 0; i < length; i++ )
     {
         if ( data[i] != null )
         {
             count += data[i][flatZoneIndex];
         }
     }
     return count;
 }
예제 #43
0
 private void ConvertToFlow(TreeData<float[]> treeData, IZone[] zones, int o, int d, float flow)
 {
     int index = o * zones.Length + d;
     float totalUtility = 0f;
     var length = treeData.Children.Length;
     int feasibleChoices = 0;
     var children = treeData.Children;
     for ( int i = 0; i < length; i++ )
     {
         var res = children[i].Result[index];
         if ( !float.IsNaN( res ) )
         {
             feasibleChoices++;
             totalUtility += children[i].Result[index];
         }
     }
     if ( feasibleChoices == 0 )
     {
         return;
     }
     // inverse the total utility
     if ( totalUtility == 0 || float.IsInfinity( ( totalUtility = 1 / totalUtility ) ) )
     {
         // if there was no utility break it up evenly
         totalUtility = 1f / feasibleChoices;
     }
     for ( int i = 0; i < length; i++ )
     {
         children[i].Result[index] = flow * ( children[i].Result[index] * totalUtility );
     }
     // now see if we have children
     for ( int i = 0; i < length; i++ )
     {
         if ( children[i].Children != null && !float.IsNaN( children[i].Result[index] ) )
         {
             ConvertToFlow( children[i], zones, o, d, children[i].Result[index] );
         }
     }
 }
예제 #44
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="TreeData"></param>
 public TreeBuilder(TreeData.TreeDataTableDataTable TreeData)
 {
     dtTree = TreeData;
 }
예제 #45
0
 private double GatherSumOfTrees(TreeData<float[][]> treeData)
 {
     double ret = 0;
     if ( treeData.Children != null )
     {
         for ( int i = 0; i < treeData.Children.Length; i++ )
         {
             ret += GatherSumOfTrees( treeData.Children[i] );
         }
     }
     else
     {
         // only add things if they are leaf nodes
         var data = treeData.Result;
         if ( data != null )
         {
             var length = data.Length;
             for ( int i = 0; i < length; i++ )
             {
                 if ( data[i] != null )
                 {
                     ret += data[i].Sum();
                 }
             }
         }
     }
     return ret;
 }
예제 #46
0
 private bool GatherUtility(TreeData<float> treeData, IModeChoiceNode node, int o, int d, IZone[] zones)
 {
     var cat = node as IModeCategory;
     treeData.Result = float.NaN;
     if ( !node.Feasible( zones[o], zones[d], SimulationTime ) )
     {
         treeData.Result = float.NaN;
         return false;
     }
     if ( cat == null )
     {
         treeData.Result = ( node.CurrentlyFeasible > 0 ? (float)Math.Exp( node.CalculateV( zones[o], zones[d], SimulationTime ) ) : float.NaN );
         return !float.IsNaN( treeData.Result );
     }
     else if ( cat.CurrentlyFeasible > 0 )
     {
         bool hasAlternatives = false;
         float totalUtility = 0;
         var treeChildren = treeData.Children;
         var catChildren = cat.Children;
         for ( int i = 0; i < treeData.Children.Length; i++ )
         {
             if ( GatherUtility( treeChildren[i], catChildren[i], o, d, zones ) )
             {
                 hasAlternatives = true;
                 totalUtility += treeChildren[i].Result;
             }
         }
         if ( hasAlternatives )
         {
             if ( totalUtility >= this.MinLogSumToE )
             {
                 var localUtility = cat.CalculateCombinedV( zones[o], zones[d], SimulationTime );
                 treeData.Result = (float)( Math.Pow( totalUtility, cat.Correlation ) * Math.Exp( localUtility ) );
                 return true;
             }
         }
     }
     treeData.Result = float.NaN;
     return false;
 }
예제 #47
0
 private void WriteModeSplit(TreeData<float[][]> split, IModeChoiceNode modeNode, string directoryName)
 {
     if ( !Directory.Exists( directoryName ) )
     {
         Directory.CreateDirectory( directoryName );
     }
     using ( StreamWriter writer = new StreamWriter( Path.Combine( directoryName, modeNode.ModeName + ".csv" ) ) )
     {
         var header = true;
         var zones = this.Root.ZoneSystem.ZoneArray.GetFlatData();
         for(int i = 0; i < zones.Length; i++)
         {
             var first = true;
             if ( header )
             {
                 header = false;
                 for(int j = 0; j < zones.Length; j++)
                 {
                     if ( first )
                     {
                         first = false;
                         writer.Write( "Zones O\\D," );
                         writer.Write( zones[j].ZoneNumber );
                     }
                     else
                     {
                         writer.Write( ',' );
                         writer.Write( j );
                     }
                 }
                 writer.WriteLine();
                 first = true;
             }
             for ( int j = 0; j < zones.Length; j++ )
             {
                 var s = split.Result[i][j];
                 if ( first )
                 {
                     first = false;
                     writer.Write( i );
                     writer.Write( ',' );
                     writer.Write( s );
                 }
                 else
                 {
                     writer.Write( ',' );
                     writer.Write( s );
                 }
             }
             writer.WriteLine();
         }
     }
     if ( split.Children != null )
     {
         for ( int i = 0; i < split.Children.Length; i++ )
         {
             WriteModeSplit( split.Children[i], ( (IModeCategory)modeNode ).Children[i], directoryName );
         }
     }
 }
예제 #48
0
 void Awake()
 {
     instance = this;
 }
예제 #49
0
 private void CountNumberOfModes(TreeData<float[][]> treeData, ref int index)
 {
     index++;
     if ( treeData.Children != null )
     {
         for ( int i = 0; i < treeData.Children.Length; i++ )
         {
             CountNumberOfModes( treeData.Children[i], ref index );
         }
     }
 }
예제 #50
0
 public void EndInterativeModeSplit()
 {
     this.Results = null;
     this.CurrentUtility = null;
 }
예제 #51
0
 private void LoadFlows(TreeData<float[][]> ourNode, TreeData<float[][]> copyNode, ref int index)
 {
     if ( ourNode.Children != null )
     {
         var length = ourNode.Children.Length;
         for ( int i = 0; i < length; i++ )
         {
             LoadFlows( ourNode.Children[i], copyNode, ref index );
         }
     }
     var otherData = copyNode.Result;
     if ( otherData == null ) return;
     var numberOfZones = otherData.Length;
     var data = new float[numberOfZones][];
     for ( int j = 0; j < numberOfZones; j++ )
     {
         data[j] = new float[numberOfZones];
     }
     this.Progress = (float)index / this.NumberOfModes;
     index++;
     Parallel.For( 0, numberOfZones, delegate(int i)
     {
         var row = otherData[i];
         if ( row == null ) return;
         for ( int j = 0; j < numberOfZones; j++ )
         {
             data[j][i] = row[j];
         }
     } );
     ourNode.Result = data;
 }
예제 #52
0
 private void ConvertToFlow(TreeData<float> treeData, IZone[] zones, int o, int d, float flow)
 {
     float totalUtility = 0f;
     var length = treeData.Children.Length;
     int feasibleChoices = 0;
     var children = treeData.Children;
     for ( int i = 0; i < length; i++ )
     {
         var res = children[i].Result;
         if ( !float.IsNaN( res ) )
         {
             feasibleChoices++;
             totalUtility += children[i].Result;
         }
     }
     if ( feasibleChoices == 0 )
     {
         return;
     }
     if ( totalUtility == 0 )
     {
         totalUtility = 1f / feasibleChoices;
     }
     else
     {
         // inverse the total utility
         totalUtility = 1 / totalUtility;
     }
     for ( int i = 0; i < length; i++ )
     {
         var result = children[i].Result;
         if ( float.IsNaN( result ) )
         {
             children[i].Result = 0;
         }
         else
         {
             children[i].Result = flow * ( result * totalUtility );
         }
     }
     // now see if we have children
     for ( int i = 0; i < length; i++ )
     {
         if ( children[i].Children != null && !float.IsNaN( children[i].Result ) )
         {
             ConvertToFlow( children[i], zones, o, d, children[i].Result );
         }
     }
 }
예제 #53
0
 private void SaveResults(TreeData<float> utility, TreeData<float[][]> ret, int o, int d, int numberOfZones)
 {
     // if the memory has not been allocated yet, allocate it
     if ( ret.Result == null )
     {
         lock ( ret )
         {
             Thread.MemoryBarrier();
             if ( ret.Result == null )
             {
                 ret.Result = new float[numberOfZones][];
                 Thread.MemoryBarrier();
             }
         }
     }
     // if we have a utility then add us in
     if ( !float.IsNaN( utility.Result ) )
     {
         if ( ret.Result[o] == null )
         {
             lock ( ret )
             {
                 Thread.MemoryBarrier();
                 if ( ret.Result[o] == null )
                 {
                     ret.Result[o] = new float[numberOfZones];
                     Thread.MemoryBarrier();
                 }
             }
         }
         ret.Result[o][d] += utility.Result;
         // and if we did check our children as well
         if ( utility.Children != null )
         {
             var length = utility.Children.Length;
             for ( int i = 0; i < length; i++ )
             {
                 SaveResults( utility.Children[i], ret.Children[i], o, d, numberOfZones );
             }
         }
     }
 }