Example #1
0
        public Breaker(string _name, int _lineId, IVariable _zenonVariable = null)
        {
            children = new LinkedList <Breaker>();
            name     = _name;
            lineId   = _lineId;

            string[] sn = _name.Split('_');
            if (sn.Count() > 1)
            {
                shortName = sn[1];
            }
            else
            {
                shortName = sn[0];
            }
            parent = null;

            zenonVariable = _zenonVariable;
            if (_zenonVariable == null || !_zenonVariable.IsOnline())
            {
                status     = -1;
                lineStatus = -1;
            }
            else
            {
                name   = _zenonVariable.Name;
                status = Int32.Parse(_zenonVariable.get_Value(0).ToString());
                InitializeLineStatus();
            }
        }
Example #2
0
        public void DFS(Graph <Node> G)
        {
            Stack <Node> stack = new Stack <Node>();

            stack.Push(G.head);
            bool            newLine      = false;
            Stack <Breaker> breakerStack = new Stack <Breaker>();

            breakerStack.Push(G.breakerGraph.head);

            List <Position> geom = new List <Position>();

            while (stack.Count != 0)
            {
                Node current = stack.Pop();
                if (newLine)
                {
                    newLine = false;
                    geom.Clear();
                    geom.Add(current.parent.position);
                }
                geom.Add(current.position);
                if (current.isBreaker)
                {
                    newLine = true;
                    Breaker top = breakerStack.Pop();
                    CreateLineFeature(G.name, geom, top);

                    Breaker aux = current.breaker;
                    aux.parent = top;
                    foreach (Node child in current.children)
                    {
                        breakerStack.Push(aux);
                    }
                    //why it is repeated
                    breakerHash.Add(aux.lineId, aux);

                    top.children.AddFirst(aux);
                    var bfeature = CreateBreakerFeature(G.name, aux);
                    //lineFeatures.Features.Add(bfeature);
                    breakerFeatures.Features.Add(bfeature);
                }
                else if (current.children.Count != 1)
                {
                    newLine = true;
                    Breaker top = breakerStack.Pop();
                    CreateLineFeature(G.name, geom, top);

                    foreach (Node child in current.children)
                    {
                        breakerStack.Push(top);
                    }
                }
                foreach (Node child in current.children)
                {
                    stack.Push(child);
                }
            }
        }
Example #3
0
        public Feature CreateBreakerFeature(string feeder, Breaker breaker)
        {
            var geom  = new Point(breaker.node.position);
            var props = new Dictionary <string, object>
            {
                //{ "type", "breaker" },
                { "feed", feeder },
                { "name", breaker.name },
                { "short", breaker.shortName },
            };
            var feature = new Feature(geom, props);

            return(feature);
        }
Example #4
0
        public void CreateLineFeature(string feeder, List <Position> geom, Breaker breaker)
        {
            if (geom.Count() < 2)
            {
                return;
            }
            var lineString = new LineString(geom);
            var props      = new Dictionary <string, object>
            {
                //{ "type", "mv_line" },
                { "feed", feeder },
                { "name", breaker.name },
            };
            var feature = new GeoJSON.Net.Feature.Feature(lineString, props);

            lineFeatures.Features.Add(feature);
        }
Example #5
0
        public List <ShortBreaker> GetTouchedBreakers(Breaker b, ref List <ShortSub> shortsubs)
        {
            //HERE change type of variable for zenon variables values
            UpdateLineStatusByGraph(b);

            //her we should work with a hash where the key is the id substation and the value is its state
            //Dictionary<int,int> subs = b.GetSubstationsAffected();
            Dictionary <int, int> subs            = new Dictionary <int, int>();
            List <ShortBreaker>   TouchedBreakers = new List <ShortBreaker>();

            foreach (Breaker br in breakerHash.Values)
            {
                if (br.lineStatus == 0)
                {   // just take the opened breakers
                    // just take the substations of openened breakers
                    GetSubstationsAffected(br, subs);
                    TouchedBreakers.Add(new ShortBreaker(br.name));
                }
            }
            shortsubs = GetShortSubs(subs);
            return(TouchedBreakers);
        }
Example #6
0
        public void UpdateLineStatusByGraph(Breaker b)
        {
            Stack <Breaker> stack = new Stack <Breaker>();

            stack.Push(b);
            while (stack.Count != 0)
            {
                Breaker current = stack.Pop();
                if (current.parent == null)
                {
                    current.lineStatus = current.status;
                }
                else
                {
                    current.lineStatus = current.parent.lineStatus * current.status;
                }

                foreach (Breaker child in current.children)
                {
                    stack.Push(child);
                }
            }
        }
Example #7
0
        public void GetSubstationsAffected(Breaker b, Dictionary <int, int> substationStateHash)
        {
            string[] sn     = b.name.Split('_');
            string   feeder = sn[0];
            // hash all the lines in feeder, codigotraa with the codigotra
            Dictionary <int, List <int> > lineHash = new Dictionary <int, List <int> >();
            DataTable lines = ExecuteSelectQuery("select * from tramo where codali = '" + feeder + "'");

            for (int i = 0; i < lines.Rows.Count; ++i)
            {
                int source = Int32.Parse(lines.Rows[i]["codigotraa"].ToString());
                int end    = Int32.Parse(lines.Rows[i]["codigotra"].ToString());
                if (!lineHash.TryGetValue(source, out List <int> list))
                {
                    list = new List <int>();
                    lineHash.Add(source, list);
                }
                list.Add(end);
            }
            // hash all substation in feeder
            Dictionary <int, int> subHash = new Dictionary <int, int>();
            DataTable             sub     = ExecuteSelectQuery("select * from sed where codali ='" + feeder + "' and codsed not like '%[-]%' ");

            for (int i = 0; i < sub.Rows.Count; ++i)
            {
                int lineId = Int32.Parse(sub.Rows[i]["nodo"].ToString());
                int subId  = Int32.Parse(sub.Rows[i]["codsed"].ToString());
                subHash[lineId] = subId;
            }

            //below code is working
            //Stack<int> lineIds = new Stack<int>();
            //lineIds.Push(b.lineId);
            //while (lineIds.Count != 0)
            //{
            //    int current = lineIds.Pop();
            //    if (lineHash.TryGetValue(current, out List<int> nextLine))
            //    {
            //        foreach (int line in nextLine)
            //        {
            //            if (subHash.TryGetValue(line, out int subId))
            //            {
            //                ShortSub s = new ShortSub(subId.ToString());
            //                //subs.Add(s);
            //                substationStateHash[subId] = b.lineStatus;
            //            }
            //            lineIds.Push(line);
            //        }
            //    }
            //}

            //complete dfs
            Stack <LineStatus> lineStatusStack = new Stack <LineStatus>();

            lineStatusStack.Push(new LineStatus(b.lineId, b.lineStatus));
            while (lineStatusStack.Count != 0)
            {
                LineStatus current = lineStatusStack.Pop();
                if (lineHash.TryGetValue(current.lineId, out List <int> nextLine))
                {
                    foreach (int line in nextLine)
                    {
                        if (subHash.TryGetValue(line, out int subId))
                        {
                            ShortSub s = new ShortSub(subId.ToString());
                            //subs.Add(s);
                            // this line is for aviding next updates from different breaker that affect the same subtation
                            if (!substationStateHash.ContainsKey(subId))
                            {
                                substationStateHash[subId] = current.lineStatus;
                            }
                        }
                        //if lineId is found take the linestatur from the current
                        //if lineId is found as a breaker take the linestatus from the breaker
                        int ls = current.lineStatus;
                        if (breakerHash.TryGetValue(line, out Breaker foundBreaker))
                        {
                            ls = foundBreaker.lineStatus;
                        }
                        lineStatusStack.Push(new LineStatus(line, ls));
                    }
                }
            }
            //return substationStateHash;
        }
Example #8
0
        public void Generate()
        {
            //DataTable feeders = ExecuteSelectQuery("select distinct codali,nodoi,vany1,vanx1 from tramo where nodoi = 0");
            DataTable feeders = ExecuteSelectQuery("select distinct codali,codigotraa,vany1,vanx1 from tramo where nodoi = 0");

            for (int i = 0; i < feeders.Rows.Count; ++i)
            {
                string feeder = feeders.Rows[i][0].ToString();
                //int id = Int32.Parse(feeders.Rows[i]["nodoi"].ToString());}
                int       id      = Int32.Parse(feeders.Rows[i]["codigotraa"].ToString());
                Position  pos     = new Position(feeders.Rows[i]["vany1"].ToString(), feeders.Rows[i]["vanx1"].ToString());
                IVariable zfeeder = GetVariableFromZenon(feeder);

                Graph <Node>    nodes    = new Graph <Node>(feeder);
                Graph <Breaker> breakers = new Graph <Breaker>();

                //create the start breaker for each feeder
                Node    headNode    = new Node(pos, true);
                Breaker headBreaker = new Breaker(feeder, id, zfeeder);

                feederHash[feeder] = nodes;
                nodes.head         = headNode;
                nodes.breakerGraph = breakers;
                nodes.nodeHash[id] = headNode;

                headNode.breaker = headBreaker;
                headBreaker.node = headNode;

                breakers.head = headBreaker;
            }

            //fill the hashes of each feeder
            Node      sourceNode = new Node();
            Node      endNode    = new Node();
            DataTable lines      = ExecuteSelectQuery("select * from tramo where nodoi != nodof");

            for (int i = 0; i < lines.Rows.Count; ++i)
            {
                string    feeder      = lines.Rows[i][1].ToString();
                int       source      = Int32.Parse(lines.Rows[i]["codigotraa"].ToString());
                int       end         = Int32.Parse(lines.Rows[i]["codigotra"].ToString());
                bool      isBreaker   = Convert.ToBoolean(Int32.Parse(lines.Rows[i]["EquipProt"].ToString()));
                string    breakerName = feeder + "_" + lines.Rows[i]["Etiprot"].ToString();
                IVariable zbreaker    = GetVariableFromZenon(breakerName);
                Breaker   br          = new Breaker(breakerName, source, zbreaker);

                Graph <Node>           G        = feederHash[feeder];
                Dictionary <int, Node> NodeHash = G.nodeHash;
                if (!NodeHash.TryGetValue(source, out sourceNode))
                {
                    Position pos = new Position(lines.Rows[i]["vany1"].ToString(), lines.Rows[i]["vanx1"].ToString());
                    sourceNode = new Node(pos, isBreaker);
                    NodeHash.Add(source, sourceNode);
                    sourceNode.breaker = br;
                    br.node            = sourceNode;
                }
                else
                {
                    sourceNode.isBreaker = isBreaker;
                    sourceNode.breaker   = br;
                    br.node = sourceNode;
                }
                if (!NodeHash.TryGetValue(end, out endNode))
                {
                    Position pos = new Position(lines.Rows[i]["vany2"].ToString(), lines.Rows[i]["vanx2"].ToString());
                    endNode = new Node(pos, false);
                    NodeHash.Add(end, endNode);
                }
                endNode.parent = sourceNode;
                sourceNode.children.AddFirst(endNode);
            }

            foreach (Graph <Node> G in feederHash.Values)
            {
                DFS(G);
            }

            //File.WriteAllText(@"C:\cygwin64\home\tony\giscada\mv_line.geojson", JsonConvert.SerializeObject(lineFeatures));
            //File.WriteAllText(@"C:\cygwin64\home\tony\giscada\breaker.geojson", JsonConvert.SerializeObject(breakerFeatures));
        }