コード例 #1
0
 /// <summary>
 /// Disassociates an AgentProcess with the pool.
 /// </summary>
 /// <param name="Process">AgentProcess object to remove from the pool.</param>
 public void RemoveProcess(AgentProcess Process)
 {
     Process.Started  -= new EventHandler(Process_Started);
     Process.Stopped  -= new EventHandler(Process_Stopped);
     Process.Stopping -= new EventHandler(Process_Stopping);
     runningProcesses.Remove(Process);
 }
コード例 #2
0
ファイル: FinderPattern.cs プロジェクト: zaieda/TemPOS
        //obtain lines cross at the center of Finder Patterns

        internal static Line[] findLineCross(Line[] lineAcross)
        {
            System.Collections.ArrayList crossLines    = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            System.Collections.ArrayList lineNeighbor  = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            System.Collections.ArrayList lineCandidate = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            Line compareLine;

            for (int i = 0; i < lineAcross.Length; i++)
            {
                lineCandidate.Add(lineAcross[i]);
            }

            for (int i = 0; i < lineCandidate.Count - 1; i++)
            {
                lineNeighbor.Clear();
                lineNeighbor.Add(lineCandidate[i]);
                for (int j = i + 1; j < lineCandidate.Count; j++)
                {
                    if (Line.isNeighbor((Line)lineNeighbor[lineNeighbor.Count - 1], (Line)lineCandidate[j]))
                    {
                        lineNeighbor.Add(lineCandidate[j]);
                        compareLine = (Line)lineNeighbor[lineNeighbor.Count - 1];
                        if (lineNeighbor.Count * 5 > compareLine.Length && j == lineCandidate.Count - 1)
                        {
                            crossLines.Add(lineNeighbor[lineNeighbor.Count / 2]);
                            for (int k = 0; k < lineNeighbor.Count; k++)
                            {
                                lineCandidate.Remove(lineNeighbor[k]);
                            }
                        }
                    }
                    //terminate comparison if there are no possibility for found neighbour lines
                    else if (cantNeighbor((Line)lineNeighbor[lineNeighbor.Count - 1], (Line)lineCandidate[j]) || (j == lineCandidate.Count - 1))
                    {
                        compareLine = (Line)lineNeighbor[lineNeighbor.Count - 1];

                        /*
                         * determine lines across Finder Patterns when number of neighbour lines are
                         * bigger than 1/6 length of theirselves
                         */
                        if (lineNeighbor.Count * 6 > compareLine.Length)
                        {
                            crossLines.Add(lineNeighbor[lineNeighbor.Count / 2]);
                            for (int k = 0; k < lineNeighbor.Count; k++)
                            {
                                lineCandidate.Remove(lineNeighbor[k]);
                            }
                        }
                        break;
                    }
                }
            }

            Line[] foundLines = new Line[crossLines.Count];
            for (int i = 0; i < foundLines.Length; i++)
            {
                foundLines[i] = (Line)crossLines[i];
            }
            return(foundLines);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            System.Collections.ArrayList oList = new System.Collections.ArrayList();
            int[] x = new int[5];
            oList.Add(7);
            oList.Add(21);
            oList.Add(5);
            oList.Insert(1, 7);
            oList.Insert(2, 4);
            oList.Insert(3, 3);
            oList.Insert(4, 7);
            oList.Remove(8);

            foreach (int intCurrent in oList)
            {
                System.Console.WriteLine(intCurrent);
            }
            System.Console.ReadLine();



            while (oList.Contains(7))
            {
                oList.Remove(7);
            }

            foreach (int i in oList)
            {
                System.Console.WriteLine(i);
            }

            //for (int intIndex = 0; intIndex <= oList.Count - 1; intIndex++)
            //{

            //    if (oList.Contains(7))
            //    {
            //        oList.Remove(7);
            //    }
            //    System.Console.WriteLine(oList[intIndex]);

            //}


            System.Console.ReadLine();

            //int[] y = { 22, 3, 6, 3, 14, 2,3, 7 };
            //for (int i = 0; i < y.Length; i++)
            //{
            //    if (y[i]==3)
            //    {
            //        System.Console.WriteLine("yes");
            //    }
            //}

            //System.Console.ReadLine();
        }
コード例 #4
0
        internal static Line[] findLineCross(Line[] lineAcross)
        {
            System.Collections.ArrayList crossLines    = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            System.Collections.ArrayList lineNeighbor  = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            System.Collections.ArrayList lineCandidate = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            Line compareLine;

            for (int i = 0; i < lineAcross.Length; i++)
            {
                lineCandidate.Add(lineAcross[i]);
            }

            for (int i = 0; i < lineCandidate.Count - 1; i++)
            {
                lineNeighbor.Clear();
                lineNeighbor.Add(lineCandidate[i]);
                for (int j = i + 1; j < lineCandidate.Count; j++)
                {
                    if (Line.isNeighbor((Line)lineNeighbor[lineNeighbor.Count - 1], (Line)lineCandidate[j]))
                    {
                        lineNeighbor.Add(lineCandidate[j]);
                        compareLine = (Line)lineNeighbor[lineNeighbor.Count - 1];
                        if (lineNeighbor.Count * 5 > compareLine.Length && j == lineCandidate.Count - 1)
                        {
                            crossLines.Add(lineNeighbor[lineNeighbor.Count / 2]);
                            for (int k = 0; k < lineNeighbor.Count; k++)
                            {
                                lineCandidate.Remove(lineNeighbor[k]);
                            }
                        }
                    }
                    else if (cantNeighbor((Line)lineNeighbor[lineNeighbor.Count - 1], (Line)lineCandidate[j]) || (j == lineCandidate.Count - 1))
                    {
                        compareLine = (Line)lineNeighbor[lineNeighbor.Count - 1];
                        if (lineNeighbor.Count * 6 > compareLine.Length)
                        {
                            crossLines.Add(lineNeighbor[lineNeighbor.Count / 2]);
                            for (int k = 0; k < lineNeighbor.Count; k++)
                            {
                                lineCandidate.Remove(lineNeighbor[k]);
                            }
                        }
                        break;
                    }
                }
            }

            Line[] foundLines = new Line[crossLines.Count];
            for (int i = 0; i < foundLines.Length; i++)
            {
                foundLines[i] = (Line)crossLines[i];
            }
            return(foundLines);
        }
コード例 #5
0
 /// <summary>
 /// Checks the execution status of all batches.
 /// </summary>
 protected void MonitorBatches()
 {
     System.Collections.ArrayList l_ExeList = (System.Collections.ArrayList)m_ExeList.Clone();
     foreach (ExeBatch exe in l_ExeList)
     {
         try
         {
             if (exe.DPSW.DoneWith(exe.MappedDesc.Id))
             {
                 try
                 {
                     exe.MappedDesc = exe.DPSW.Result(exe.MappedDesc.Id);
                     lock (m_Queue)
                     {
                         m_ResultList.Add(new DataProcessingResult(exe.Desc, null, MainForm.ResultLiveTime));
                         m_Queue.Remove(exe.Desc);
                         m_ExeList.Remove(exe);
                     }
                 }
                 catch (SySal.DAQSystem.DataProcessingException retx)
                 {
                     lock (m_Queue)
                     {
                         m_ResultList.Add(new DataProcessingResult(exe.Desc, retx, MainForm.ResultLiveTime));
                         m_Queue.Remove(exe.Desc);
                         m_ExeList.Remove(exe);
                     }
                 }
                 catch (Exception x)
                 {
                     m_ExeList.Remove(exe);
                     try
                     {
                         EventLog.WriteEntry("Error handling batch " + exe.Desc.Id.ToString("X16") + "\r\n" + x.ToString(), System.Diagnostics.EventLogEntryType.Warning);
                     }
                     catch (Exception) { }
                 }
             }
         }
         catch (Exception x)
         {
             m_ExeList.Remove(exe);
             try
             {
                 EventLog.WriteEntry("Error handling batch " + exe.Desc.Id.ToString("X16") + "\r\n" + x.ToString(), System.Diagnostics.EventLogEntryType.Warning);
             }
             catch (Exception) { }
         }
     }
 }
コード例 #6
0
        public void remove(String host, String type, byte[] key)
        {
            bool _sync = false;

            for (int i = 0; i < pool.Count; i++)
            {
                HostKey hk = (HostKey)(pool[i]);
                if (host == null ||
                    (hk.getHost().Equals(host) &&
                     (type == null || (hk.getType().Equals(type) &&
                                       (key == null || key.SequenceEqual(hk.key))))))
                {
                    pool.Remove(hk);
                    _sync = true;
                }
            }
            if (_sync)
            {
                try {
                    sync();
                }
                catch {
                };
            }
        }
コード例 #7
0
 /// <summary>
 /// Removes a file path from the recent files list.
 /// </summary>
 /// <param name="fileName">
 /// Path of the file.
 /// </param>
 public static void RemoveFromRecentFiles(string fileName)
 {
     if (recentFilesList.Contains(fileName))
     {
         recentFilesList.Remove(fileName);
     }
 }
コード例 #8
0
 private void Reclaim()
 {
     try
     {
         while (ContinueReclaim)
         {
             lock (ClientSockets.SyncRoot)
             {
                 for (int x = ClientSockets.Count - 1; x >= 0; x--)
                 {
                     Object Client = ClientSockets[x];
                     if (!((ClientHandler)Client).Alive)
                     {
                         ClientSockets.Remove(Client);
                         ((ClientHandler)Client).Stop();
                     }
                 }
             }
             Thread.Sleep(200);
         }
     }
     catch (System.Exception ex)
     {
         Console.WriteLine(ex.Message);
         //SqlHelper.log.WriteLog(ex.Message);
     }
 }
コード例 #9
0
        static public void SetMessageSuppressed(MessageKey messageKey, bool value)
        {
            bool change = false;

            if (value)
            {
                if (!GetMessageSuppressed(messageKey))
                {
                    s_suppressMessages.Add(messageKey.ToString());
                    change = true;
                }
            }
            else
            {
                if (GetMessageSuppressed(messageKey))
                {
                    s_suppressMessages.Remove(messageKey.ToString());
                    change = true;
                }
            }
            if (change)
            {
                Util.AppSettings.SaveList(c_suppressMessagesSettingName, s_suppressMessages, false, MessageForm.Warn);
            }
        }
コード例 #10
0
        private void btnRandomize_Click(object sender, EventArgs e)
        {
            var random = new Random();
            var splitArray = new string[1];
            var list = new System.Collections.ArrayList();

            splitArray[0] = Environment.NewLine; // Used to split the list of owners in the textbox

            // Add contents of textbox to array
            list.AddRange(txtList.Text.Split(splitArray, StringSplitOptions.RemoveEmptyEntries));

            txtList.Clear();

            var length = list.Count;

            // Loop through list, randomly selecting an item, adding it to the output list,
            // then removing it from the list
            for (var x = 0; x < length; x++)
            {
                var index = random.Next(list.Count);

                txtList.Text +=  list[index] + Environment.NewLine;
                list.Remove(list[index].ToString());
            }

            // Add output to clipboard
            if (!String.IsNullOrEmpty(txtList.Text))
                Clipboard.SetText(txtList.Text);
        }
コード例 #11
0
ファイル: Form1.cs プロジェクト: ferganiki/LP2
        private void btnArray_Click(object sender, EventArgs e)
        {
            System.Collections.ArrayList Alunos = new System.Collections.ArrayList();

            Alunos.Add("Ana");
            Alunos.Add("André");
            Alunos.Add("Débora");
            Alunos.Add("Fátima");
            Alunos.Add("João");
            Alunos.Add("Janete");
            Alunos.Add("Otávio");
            Alunos.Add("Marcelo");
            Alunos.Add("Pedro");
            Alunos.Add("Thais");

            Alunos.Remove("Otávio");

            string nomes = "";

            foreach (string nome in Alunos)
            {
                nomes += nome + "\n";
            }
            MessageBox.Show(nomes);
        }
コード例 #12
0
 /// <summary>
 /// Removes a license from the list of licenses to be searched for.
 /// </summary>
 /// <param name="license">The number of the license to remove.</param>
 public void RemoveLicense(int license)
 {
     if (_licenses.Contains(license))
     {
         _licenses.Remove(license);
     }
 }
コード例 #13
0
ファイル: DumbAdapter.cs プロジェクト: henrikmbach/ownet
 /// <summary> Removes a <code>OneWireContainer</code> from the list of containers that
 /// this adapter object will find.
 ///
 /// </summary>
 /// <param name="c">represents a 1-Wire device that this adapter should no longer
 /// report as found by a search
 /// </param>
 public virtual void  removeContainer(OneWireContainer c)
 {
     lock (containers.SyncRoot)
     {
         containers.Remove(c);
     }
 }
コード例 #14
0
        public void RemoveCommand(string Command)
        {
            string[] CommandArray = Command.Split(' ');

            CommandArrayList.Remove(Command);
            ThePMHandler.RemoveCommand(CommandArray[0]);
        }
コード例 #15
0
 // Eliminamos un Sink en tiempo de ejecucion
 public void DeleteSink(Interface.IEventosRefri pSink)
 {
     if (listaSinks.Contains(pSink))
     {
         listaSinks.Remove(pSink);
     }
 }
コード例 #16
0
        /// <summary>
        /// Removes the first occurrence of a specific IActivity from this ActivityCollection.
        /// </summary>
        /// <param name="value">
        /// The IActivity value to remove from this ActivityCollection.
        /// </param>
        public virtual void Remove(IActivity value)
        {
            CheckParent();

            mList.Remove(value);

            value.Parent = null;
        }
コード例 #17
0
 /// <summary>
 /// Deletes this model element from its enclosing collection
 /// </summary>
 public virtual void Delete()
 {
     if (EnclosingCollection != null)
     {
         EnclosingCollection.Remove(this);
         setFather(null);
     }
 }
コード例 #18
0
        /// <summary>
        /// 获取存在的勋章
        /// </summary>
        /// <returns></returns>
        public static void UpdateMedalList(System.Collections.ArrayList medalFiles)
        {
            medalFiles.Remove("thumbs.db");
            DataTable dt = Data.Medals.GetExistMedalList();

            foreach (DataRow dr in dt.Rows)
            {
                medalFiles.Remove(dr["image"].ToString().ToLower());                                   //移除已经存在于勋章库中的勋章文件名
            }
            int newMedalBaseId = TypeConverter.ObjectToInt(dt.Rows[dt.Rows.Count - 1]["medalid"]) + 1; //获取新的Medalid的基数

            for (int i = 0; i < medalFiles.Count; i++)                                                 //将未入库的勋章入库
            {
                int newMedalId = newMedalBaseId + i;
                Medals.UpdateMedal(newMedalId, "Medal No." + newMedalId, medalFiles[i].ToString());
            }
            Discuz.Cache.DNTCache.GetCacheService().RemoveObject("/Forum/UI/MedalsList");
        }
コード例 #19
0
 public virtual void  removePlayer(Player p)
 {
     System.Object  temp_object;
     System.Boolean temp_boolean;
     temp_object  = p;
     temp_boolean = players.Contains(temp_object);
     players.Remove(temp_object);
     bool generatedAux = temp_boolean;
 }
コード例 #20
0
 public virtual void  removeSection(TournamentSection v)
 {
     System.Object  temp_object;
     System.Boolean temp_boolean;
     temp_object  = v;
     temp_boolean = sections.Contains(temp_object);
     sections.Remove(temp_object);
     bool generatedAux = temp_boolean;
 }
コード例 #21
0
ファイル: FtpServer.cs プロジェクト: emacslisp/cs
        private void handler_Closed(FtpSocketHandler handler)
        {
            m_apConnections.Remove(handler);

            if (ConnectionClosed != null)
            {
                ConnectionClosed(handler.Id);
            }
        }
コード例 #22
0
        static void Main(string[] args)
        {
            Person oPerson1 = new Person();

            oPerson1.Age      = 20;
            oPerson1.FullName = "Ali Reza Alavi";

            Person oPerson2 = new Person();

            oPerson2.Age      = 20;
            oPerson2.FullName = "Ali Reza Alavi";

            Person oPerson3 = new Person();

            oPerson3.Age      = 30;
            oPerson3.FullName = "Ali Reza Alavi";

            System.Console.WriteLine("\n----------");
            if (oPerson1.Equals(oPerson2))
            {
                System.Console.WriteLine("oPerson1 is equal to oPerson2");
            }
            else
            {
                System.Console.WriteLine("oPerson1 is not equal to oPerson2");
            }
            System.Console.WriteLine("----------");

            System.Console.WriteLine("----------");
            if (oPerson1.Equals(oPerson3))
            {
                System.Console.WriteLine("oPerson1 is equal to oPerson3");
            }
            else
            {
                System.Console.WriteLine("oPerson1 is not equal to oPerson3");
            }
            System.Console.WriteLine("----------\n");

            System.Collections.ArrayList oCollection = new System.Collections.ArrayList();

            oCollection.Add(new Person("Ali Reza Alavi", 20));
            oCollection.Add(new Person("Sara Ahmadi", 30));
            oCollection.Add(new Person("Sanaz Samimi", 40));

            oCollection.Remove(new Person("Ali Reza Alavi", 20));

            foreach (Person oPerson in oCollection)
            {
                oPerson.ShowInfo();
            }

            oCollection.Clear();

            System.Console.ReadLine();
        }
コード例 #23
0
        private void Form_Closed(object sender, System.EventArgs e)
        {
            DrawInfoItem myItem = GetItem((System.Windows.Forms.Form)sender);

            if (myItem != null)
            {
                myItems.Remove(myItem);
                InnerDraw(myItem, false);
            }
        }
コード例 #24
0
ファイル: VertexFitForm.cs プロジェクト: kryssb/SySal.NET
 private void OnClose(object sender, System.EventArgs e)
 {
     try
     {
         AvailableBrowsers.Remove(this);
         m_gdiDisplay.RemoveOwned(m_VF);
         m_TrackSelector.RaiseAddFit(this, null);
     }
     catch (Exception) { }
 }
コード例 #25
0
 /// <summary>
 /// Disconnects the client clientNum and removes it from the client list
 /// </summary>
 /// <param name="clientNum"></param>
 public void KickClient(int clientNum)
 {
     try
     {
         foreach (SocketPack socPak in clientArrayList)
         {
             if (socPak.clientID == clientNum)
             {
                 socPak.clientSocket.Close();
                 clientArrayList.Remove(socPak);
                 break;
             }
         }
     }
     catch (SocketException se)
     {
         throw new Exception("Exception caught from KickClient()" + se.ToString());
     }
 }
コード例 #26
0
ファイル: User.cs プロジェクト: mazuryv/Test_M
 public void DelPredmet(Predmet Predmet)
 {
     if (Predmet != null)
     {
         Predmets.Remove(Predmet);
     }
     else
     {
         System.Windows.Forms.MessageBox.Show("Класс Group! Удаляемый элемент не существует!");
     }
 }
コード例 #27
0
        private void Upt()
        {
            System.Collections.ArrayList al = new System.Collections.ArrayList(lvC.Items);

            foreach (String fp in Directory.GetFiles(BaseDir, "*" + Resources.FExt, SearchOption.AllDirectories))
            {
                String       relfp = fp.Substring(BaseDir.Length).TrimStart('\\');
                int          p     = lvC.Items.IndexOfKey(relfp);
                ListViewItem lvi   = (p < 0) ? new ListViewItem() : lvC.Items[p];
                lvi.Name     = relfp;
                lvi.Tag      = fp;
                lvi.ImageKey = "E";
                lvi.Text     = Path.GetFileNameWithoutExtension(relfp);

                try {
                    XmlSerializer xmls = new XmlSerializer(typeof(Conn));
                    Conn          conn;
                    using (FileStream fs = File.OpenRead(fp)) {
                        conn = (Conn)xmls.Deserialize(fs);
                    }
                    while (lvi.SubItems.Count < 3)
                    {
                        lvi.SubItems.Add("");
                    }
                    lvi.SubItems[1].Text = (conn.Host);
                    lvi.SubItems[2].Text = (conn.U);
                }
                catch (Exception err) {
                    lvi.ImageKey = "X";
                    lvi.SubItems.Add(err.Message);
                }

                al.Remove(lvi);

                if (p < 0)
                {
                    lvC.Items.Add(lvi);
                }
            }

            foreach (ListViewItem lvi in al)
            {
                lvi.Remove();
            }

            if (lvC.SelectedItems.Count == 0)
            {
                foreach (ListViewItem lvi in lvC.Items)
                {
                    lvi.Focused = lvi.Selected = true;
                    break;
                }
            }
        }
コード例 #28
0
 /// <summary>
 /// Removes a point from this shape.
 /// </summary>
 /// <param name="p">System.Drawing.Point to remove.</param>
 public void RemovePoint(System.Drawing.Point p)
 {
     try
     {
         m_Points.Remove(p);
     }
     catch
     {
         return;
     }
 }
コード例 #29
0
ファイル: User.cs プロジェクト: mazuryv/Test_M
 public void DelUser(User user)
 {
     if (user != null)
     {
         Students.Remove(user);
     }
     else
     {
         System.Windows.Forms.MessageBox.Show("Класс Group! Удаляемый элемент не существует!");
     }
 }
コード例 #30
0
ファイル: Form1.cs プロジェクト: hankshuangs/Visual-C
 public void Detach(iObserver observer)
 {
     observers.Remove(observer);
     if (observers.Count >= 1)
     {
         this.changed = true;
     }
     else
     {
         this.changed = false;
     }
 }
コード例 #31
0
 public void Remove(T obj)
 {
     mutex.WaitOne();
     try
     {
         array.Remove(obj);
     }
     finally
     {
         mutex.ReleaseMutex();
     }
 }
コード例 #32
0
ファイル: TestBTree2.cs プロジェクト: ekicyou/pasta
		/// <exception cref="System.Exception"></exception>
		internal virtual void BuildRandomArray(int[] array, System.Collections.IList elements
			, int currentPosition, int nbPossibilites)
		{
			if (elements.Count == 0)
			{
				Post(array);
			}
			for (int i = 0; i < nbPossibilites && i < elements.Count && nbSolutions < maxExecutions
				; i++)
			{
				System.Collections.IList myElements = new System.Collections.ArrayList(elements);
				int elementToPick = (int)(System.Math.Random() * elements.Count);
				int e = (int)myElements.Remove(elementToPick);
				array[currentPosition] = e;
				BuildRandomArray(array, myElements, currentPosition + 1, nbPossibilites);
			}
		}
コード例 #33
0
        static void Main(string[] args)
        {
            System.Collections.ArrayList M = new System.Collections.ArrayList();
            string s = System.Console.ReadLine();
            int N = int.Parse(s);
            char c;
            Int64 L;
            int x;
            for(int i=0;i<N;i++) {
                s = System.Console.ReadLine();
                c = s[0];
                L = Int64.Parse(s.Substring(2));
                M.Sort();
                switch (c) {
                    case 'I':
                        if (!M.Contains(L))
                        {
                            M.Insert(0, L);
                        }
                        break;
                    case 'D':
                        x = Array.BinarySearch(M.ToArray(), L);
                        if(x < 0) {
                             System.Console.WriteLine("BRAK");
                        } else {
                            System.Console.WriteLine("OK");
                            M.Remove(L);
                        }
                        break;
                    case 'U':
                        x = Array.BinarySearch(M.ToArray(), L);
                        if (x >= 0) {
                            System.Console.WriteLine(M[x]);
                        } else if (~x < 0) {
                            System.Console.WriteLine("BRAK");
                        } else if ((~x) >= M.ToArray().Length)
                        {
                            System.Console.WriteLine("BRAK");
                        }
                        else {
                            System.Console.WriteLine(M[~x].ToString());
                        }
                        break;
                    case 'L':
                        x = Array.BinarySearch(M.ToArray(), L);
                        if (x >= 0)
                        {
                            System.Console.WriteLine(M[x]);
                        }
                        else if (~x <= 0)
                        {
                            System.Console.WriteLine("BRAK");
                        }
                        else if ((~x) > M.ToArray().Length)
                        {
                            System.Console.WriteLine("BRAK");
                        }
                        else
                        {
                            System.Console.WriteLine(M[~x-1].ToString());
                        }

                        break;
                }
            }
        }
コード例 #34
0
ファイル: Astar.cs プロジェクト: stephenZh/l2net
       /* Standard A* */
       public bool Astar_start(AstarNode startNode, AstarNode targetNode)
       {
           System.Collections.ArrayList closedlist = new System.Collections.ArrayList();
           System.Collections.ArrayList openlist = new System.Collections.ArrayList();

           closedlist.Clear();
           openlist.Clear();
           startNode.fvalue = calcFvalue(startNode); //this sets g and h

           openlist.Add(startNode);

           while (openlist.Count > 0)
           {
               Globals.debugPath = pathNodes;
               AstarNode xNode;
               openlist.Sort();
               xNode = ((AstarNode)openlist[0]);
               if (xNode == targetNode)
               {
                   pathNodes.Add(xNode);
                   return true;
               }
               openlist.Remove(xNode);
               closedlist.Add(xNode);
               pathNodes.Add(xNode);
               findAdjacentNodes(xNode);

               foreach (AstarNode yNode in xNode.adjacentNodes)
               {
                   if (closedlist.Contains(yNode))
                       continue;
                   int tempGScore;
                   bool isBetter = false;

                   //todo add diagonals.
                   tempGScore = xNode.gvalue + HorizontalCost;
                   yNode.fvalue = calcFvalue(yNode);

                   if (openlist.Contains(yNode))
                   {
                       openlist.Add(yNode);
                       isBetter = true;
                   }
                   else if (tempGScore < yNode.gvalue)
                       isBetter = true;

                   else
                       isBetter = false;
                   if (isBetter)
                   {
                       yNode.gvalue = tempGScore;
                       yNode.hvalue = calcHvalue(yNode);
                       yNode.fvalue = yNode.gvalue + yNode.hvalue;
                   }
               }      
           }
           return false;
       }
コード例 #35
0
        static void Main(string[] args)
        {
            Car car1 = new Car();
             car1.Make = "Oldsmobile";
             car1.Model = "Cutlas Supreme";

             Car car2 = new Car();
             car2.Make = "Geo";
             car2.Model = "Prism";

             Book b1 = new Book();
             b1.Author = "Robert Tabor";
             b1.Title = "Microsoft .NET XML Web Services";
             b1.ISBN = "0-000-00000-0";

             //ArrayLists are dynamically sized, and support other
             // cool features like sorting, removing items, etc.

             System.Collections.ArrayList myArrayList = new System.Collections.ArrayList();
             myArrayList.Add(car1);
             myArrayList.Add(car2);
             myArrayList.Add(b1);
             myArrayList.Remove(b1);

             foreach (object o in myArrayList)
             {
            Console.WriteLine(((Car)o).Make);//have to cast to car but then wont work with book
                                             //strongly vs. weakly typed code
             }

             // Dictionaries allow you to save a key along with
             // the value, and also support cool features.
             // There are different dictionaries to choose from ...
             /*
             System.Collections.Specialized.ListDictionary myDictionary
            = new System.Collections.Specialized.ListDictionary();

             myDictionary.Add(car1.Make, car1);
             myDictionary.Add(car2.Make, car2);
             myDictionary.Add(b1.Author, b1);

             // Easy acces to an element using its key
             Console.WriteLine(((Car)myDictionary["Geo"]).Model);

             // But since its not strongly types we can easily break it
             // by adding a different type to the dictionary ...
             // Obviously, I'm trying to retrieve a book here, and then get its ... model?
             Console.WriteLine(((Car)myDictionary["Robert Tabor"]).Model);
             */

             /*
             //Generic collection List and we give it a type Car
             List<Car> myList = new List<Car>();

             myList.Add(car1);
             myList.Add(car2);
             //myList.Add(b1);

             foreach (Car car in myList)
             {
            // No casting!
            Console.WriteLine(car.Model);
             }
             */
             /*
             Dictionary<string, Car> myDictionary = new Dictionary<string, Car>();
             myDictionary.Add(car1.Make, car1);
             myDictionary.Add(car2.Make, car2);
             //myDictionary.Add(b1.Author, b1);

             Console.WriteLine(myDictionary["Geo"].Model); //No casting!
             */
             /*
             List<Car> myList = new List<Car>() // This is all one long statement, 2 new instances of car in
                                            // a new instance of the collection
             {
            new Car {Make = "Oldsmobile", Model = "Cutlas Supreme" },
            new Car {Make = "Geo", Model = "Prism"}
             };
             */
             Console.ReadLine();
        }
コード例 #36
0
        static void Main(string[] args)
        {
            Car car1 = new Car();
            car1.Make = "Oldsmobile";
            car1.Model = "Cutlas Supreme";

            Car car2 = new Car();
            car2.Make = "Geo";
            car2.Model = "Prism";

            Book book1 = new Book();
            book1.Author = "Robert Tabor";
            book1.Title = "Microsoft .NET XML Web Services";
            book1.ISBN = "0-000-00000-0";

            // ArrayLists are dynamically sized, and support other
            // cool features like sorting, removing items, etc.

            System.Collections.ArrayList myArrayList = new System.Collections.ArrayList();
            myArrayList.Add(car1);
            myArrayList.Add(car2);
            myArrayList.Add(book1);
            myArrayList.Remove(book1); // if not remove the book we get a error in foreach

            foreach (object o in myArrayList)
            {
                Console.WriteLine(((Car)o).Make);
            }

            Console.WriteLine("---------------------------------------------------------");

            // Dictionaries allow you to save a key along with
            // the value, and also support cool features.
            // There are different dictionaries to choose from ...

            System.Collections.Specialized.ListDictionary myDictionary
                = new System.Collections.Specialized.ListDictionary();
            myDictionary.Add(car1.Make, car1);
            myDictionary.Add(car2.Make, car2);
            myDictionary.Add(book1.Author, book1);

            // Easy access to an element using its key
            Console.WriteLine(((Car)myDictionary["Geo"]).Model);

            // But since its not strongly typed, we can easily break it
            // by adding a different type to the dictionary ...
            // Obviously, I'm trying to retrieve a book here, and then get its ... model?
            // Console.WriteLine(((Car)myDictionary["Robert Tabor"]).Model); <-- Error

            Console.WriteLine("---------------------------------------------------------");

            List<Car> myList = new List<Car>();
            myList.Add(car1);
            myList.Add(car2);
            // myList.Add(book1); <-- error

            foreach (Car car in myList)
            {
                Console.WriteLine(car.Model);
            }

            Console.WriteLine("---------------------------------------------------------");

            Dictionary<string, Car> myDictionary2 = new Dictionary<string, Car>();
            myDictionary2.Add(car1.Make, car1);
            myDictionary2.Add(car2.Make, car2);

            Console.WriteLine(myDictionary2["Geo"].Model);

            // instance values on initialization

            string[] names = { "Bob", "Steve", "Brian", "Chuck" };

            Car car3 = new Car() { Make = "Oldsmobile", Model = "Cutlas Supreme" };
            Car car4 = new Car() { Make = "Geo", Model = "Prism" };
            Car car5 = new Car() { Make = "Nissan", Model = "Altima" };

            List<Car> myList2 = new List<Car>() {
                new Car { Make = "Oldsmobile", Model = "Cutlas Supreme"},
                new Car { Make = "Geo", Model="Prism"},
                new Car { Make = "Nissan", Model = "Altima"}
            };

            Console.ReadLine();
        }
コード例 #37
0
ファイル: TestBTree2.cs プロジェクト: ekicyou/pasta
		/// <exception cref="System.Exception"></exception>
		internal virtual void BuildArray(int[] array, System.Collections.IList elements, 
			int currentPosition)
		{
			if (elements.Count == 0)
			{
				Post(array);
			}
			for (int i = 0; i < elements.Count; i++)
			{
				System.Collections.IList myElements = new System.Collections.ArrayList(elements);
				int e = (int)myElements.Remove(i);
				array[currentPosition] = e;
				BuildArray(array, myElements, currentPosition + 1);
			}
		}
コード例 #38
0
ファイル: Astar.cs プロジェクト: stephenZh/l2net
       /* Fringe Search 
        * Fringe search is a memory enchanced version of IDA* */
       public bool fringeSearch()
       {
           //initialize:
           System.Collections.ArrayList nowList = new System.Collections.ArrayList();
           System.Collections.ArrayList laterList = new System.Collections.ArrayList();
           System.Collections.ArrayList rejectedList = new System.Collections.ArrayList();
           int limit = calcHvalue(startNode);
           
           #if DEBUG
                Globals.l2net_home.Add_Debug("start limit:" + limit);
           #endif

           bool found = false;

           Globals.debugPath = nowList;
           nowList.Add(startNode);
           
           while (!found)
           {
              // Globals.l2net_home.Add_Debug("big loop...");
               
               int fmin = INFINITY;
               while (nowList.Count != 0)
               {
                   AstarNode head = ((AstarNode)nowList[0]);
                   head.fvalue = calcFvalue(head);
                   

                   #region check for goal
                   if (isNodeTarget(head, targetNode.x, targetNode.y))
                   {
                       found = true;
                       break;
                   }
                   #endregion

                   //check if head is over the limit
                   if (head.fvalue > limit)
                   {
                       
                       //transfer head from nowlist to laterlist.
                       nowList.Remove(head);
                       laterList.Add(head);

                       //find the minimum of the nodes we will look at 'later'
                       fmin = Util.MIN(fmin, head.fvalue);

                      
                   }           
                   else
                   {
                       #region expand head's children on to now list
                       expand(head); //nodes are sorted by insert sort in this function

                       bool addedChildren = false;
                       foreach (AstarNode child in head.adjacentNodes)
                       {
                           //dont allow children already on path or adjacent to path or walls...

                           if (!isNodeIn(nowList, child) && !isNodeIn(laterList, child) && !isNodeIn(rejectedList, child))
                           {
                               if (child.passable == true)
                               {
                                   //add child of head to front of nowlist 
                                   nowList.Insert(0, child);
                                   addedChildren = true;
                               }
                           }

                       }
                       if (!addedChildren)
                       {                        
                           nowList.Remove(head);
                           rejectedList.Add(head);

                       }
                       #endregion
                   }

               }
               if (found == true)
                   break;

               //set new limit
              // Globals.l2net_home.Add_Debug("new limit:" + fmin);
               limit = fmin;

               //set now list to later list.
               nowList = (System.Collections.ArrayList)laterList.Clone();
               nowList.Sort();
               Globals.debugPath = nowList;
               laterList.Clear();

           
           }

           if (found == true)
           {
#if DEBUG
               Globals.l2net_home.Add_Debug("found a path... building...");
#endif
               buildPathFromParents(((AstarNode)nowList[0]));
               return true;
           }

           return false;

       }