<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>秦羽捷 ( Yujie QIN )&#039;s Blog &#187; 程序设计</title>
	<atom:link href="http://blog.qinyujie.net/zh/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.qinyujie.net</link>
	<description>在我心中有一个梦...... I have a dream...</description>
	<lastBuildDate>Sat, 19 Jun 2010 22:25:14 +0000</lastBuildDate>
	
	<language>zh</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>机器智能2的课程作业6 &#8211; ICA</title>
		<link>http://blog.qinyujie.net/zh/2010/06/19/368/</link>
		<comments>http://blog.qinyujie.net/zh/2010/06/19/368/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 22:25:14 +0000</pubDate>
		<dc:creator>Yujie QIN</dc:creator>
				<category><![CDATA[未分类]]></category>
		<category><![CDATA[学术]]></category>
		<category><![CDATA[程序设计]]></category>

		<guid isPermaLink="false">http://blog.qinyujie.net/?p=368</guid>
		<description><![CDATA[
最近在上一门机器智能的课程的第六次作业。
主要任务：用ICA作为工具，从两段被混合的音频中提取原始音频。

用MATLAB写了简单的程序，大家可以看看我做的文档。：）
Homework 6 of Machine Intelligence 2 &#8211; ICA

]]></description>
			<content:encoded><![CDATA[<div>
<p>最近在上一门机器智能的课程的第六次作业。</p>
<p>主要任务：用ICA作为工具，从两段被混合的音频中提取原始音频。</p>
<div id="attachment_369" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.qinyujie.net/wp-content/uploads/figure01.jpg"><img class="size-medium wp-image-369" title="Homework6 of Machine Intelligence 2 - ICA" src="http://blog.qinyujie.net/wp-content/uploads/figure01-300x167.jpg" alt="Homework6 of Machine Intelligence 2 - ICA" width="300" height="167" /></a><p class="wp-caption-text">Homework6 of Machine Intelligence 2 - ICA</p></div>
<p><span id="more-368"></span></p>
<p>用MATLAB写了简单的程序，大家可以看看我做的文档。：）</p>
<p><a href="http://blog.qinyujie.net/wp-content/uploads/Homework-6-of-Machine-Intelligence-2-ICA.pdf">Homework 6 of Machine Intelligence 2 &#8211; ICA</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.qinyujie.net/zh/2010/06/19/368/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>机器智能1的课程作业5 &#8211; NN-KNN-PW-RBF</title>
		<link>http://blog.qinyujie.net/zh/2010/03/18/327/</link>
		<comments>http://blog.qinyujie.net/zh/2010/03/18/327/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 10:26:09 +0000</pubDate>
		<dc:creator>Yujie QIN</dc:creator>
				<category><![CDATA[未分类]]></category>
		<category><![CDATA[学术]]></category>
		<category><![CDATA[程序设计]]></category>

		<guid isPermaLink="false">http://blog.qinyujie.net/?p=327</guid>
		<description><![CDATA[最近在上一门机器智能的课程的第五次作业。
任务1: 在神经网络中用分别用Gradient Decent方法、 Line Search方法和Conjungate Gradient方法进行优化比较。




任务2: 用KNN方法分类

任务3: 用Parzen Window方法分类

任务4: 用RBF网络分类

用MATLAB写了简单的程序，大家可以看看我做的文档。：）
Homework 5. of Machine Intelligence 1 &#8211; NN-KNN-PW-RBF
]]></description>
			<content:encoded><![CDATA[<p>最近在上一门机器智能的课程的第五次作业。</p>
<p>任务1: 在神经网络中用分别用Gradient Decent方法、 Line Search方法和Conjungate Gradient方法进行优化比较。</p>
<p><a href="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Machine-Intelligence-1-Result1.jpg"><img class="alignnone size-large wp-image-329" title="Homework 5. of Machine Intelligence 1 - Result1" src="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Machine-Intelligence-1-Result1-1024x657.jpg" alt="" width="512" height="329" /></a></p>
<p><span id="more-327"></span></p>
<p><a href="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Machine-Intelligence-1-Result2.jpg"><img class="alignnone size-large wp-image-330" title="Homework 5. of Machine Intelligence 1 - Result2" src="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Machine-Intelligence-1-Result2-1024x657.jpg" alt="" width="512" height="329" /></a></p>
<p><a href="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Machine-Intelligence-1-Result3.jpg"><img class="alignnone size-large wp-image-331" title="Homework 5. of Machine Intelligence 1 - Result3" src="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Machine-Intelligence-1-Result3-1024x657.jpg" alt="" width="512" height="329" /></a><br />
任务2: 用KNN方法分类</p>
<p><a href="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Machine-Intelligence-1-Result4.jpg"><img class="alignnone size-large wp-image-332" title="Homework 5. of Machine Intelligence 1 - Result4" src="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Machine-Intelligence-1-Result4-1024x657.jpg" alt="" width="512" height="329" /></a></p>
<p>任务3: 用Parzen Window方法分类</p>
<p><a href="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Machine-Intelligence-1-Result5.jpg"><img class="alignnone size-large wp-image-333" title="Homework 5. of Machine Intelligence 1 - Result5" src="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Machine-Intelligence-1-Result5-1024x657.jpg" alt="" width="512" height="329" /></a></p>
<p>任务4: 用RBF网络分类</p>
<p><a href="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Machine-Intelligence-1-Result6.jpg"><img class="alignnone size-large wp-image-334" title="Homework 5. of Machine Intelligence 1 - Result6" src="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Machine-Intelligence-1-Result6-1024x657.jpg" alt="" width="512" height="329" /></a></p>
<p>用MATLAB写了简单的程序，大家可以看看我做的文档。：）</p>
<p><a href="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Machine-Intelligence-1-NN-KNN-PW-RBF.pdf">Homework 5. of Machine Intelligence 1 &#8211; NN-KNN-PW-RBF</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.qinyujie.net/zh/2010/03/18/327/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>图像识别的作业3 &#8211; 边缘和道路桥梁检测</title>
		<link>http://blog.qinyujie.net/zh/2010/03/12/312/</link>
		<comments>http://blog.qinyujie.net/zh/2010/03/12/312/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 21:42:43 +0000</pubDate>
		<dc:creator>Yujie QIN</dc:creator>
				<category><![CDATA[未分类]]></category>
		<category><![CDATA[学术]]></category>
		<category><![CDATA[程序设计]]></category>

		<guid isPermaLink="false">http://blog.qinyujie.net/?p=312</guid>
		<description><![CDATA[最近在上一门图像识别的课程的第三次作业。
主题是边缘和道路桥梁检测(Extrema and Ridge Detection)，用来做一些简单的识别。
请看效果图：



这次作业的主要任务是检测图像中的边缘和道路桥梁。
用MATLAB写了简单的程序，大家可以看看我做的文档。：）
Homework 3. of Automatic Image Analysis – Extrema and Ridge Detection
]]></description>
			<content:encoded><![CDATA[<p>最近在上一门图像识别的课程的第三次作业。</p>
<p>主题是边缘和道路桥梁检测(Extrema and Ridge Detection)，用来做一些简单的识别。</p>
<p>请看效果图：</p>
<p><img title="Homework 3. of Automatic Image Analysis – Extrema and Ridge Detection - result1" src="http://blog.qinyujie.net/wp-content/uploads/Homework-3.-of-Automatic-Image-Analysis-–-Extrema-and-Ridge-Detection-result1.jpg" alt="" width="561" height="420" /></p>
<p><span id="more-312"></span></p>
<p><img title="Homework 3. of Automatic Image Analysis – Extrema and Ridge Detection - result2" src="http://blog.qinyujie.net/wp-content/uploads/Homework-3.-of-Automatic-Image-Analysis-–-Extrema-and-Ridge-Detection-result2.jpg" alt="" width="561" height="420" /></p>
<p>这次作业的主要任务是检测图像中的边缘和道路桥梁。</p>
<p>用MATLAB写了简单的程序，大家可以看看我做的文档。：）</p>
<p><a href="http://blog.qinyujie.net/wp-content/uploads/Homework-3.-of-Automatic-Image-Analysis-–-Extrema-and-Ridge-Detection.pdf">Homework 3. of Automatic Image Analysis – Extrema and Ridge Detection</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.qinyujie.net/zh/2010/03/12/312/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>计算机视觉作业5 &#8211; 三维重建 (3D Reconstruction)</title>
		<link>http://blog.qinyujie.net/zh/2010/01/21/274/</link>
		<comments>http://blog.qinyujie.net/zh/2010/01/21/274/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 19:57:07 +0000</pubDate>
		<dc:creator>Yujie QIN</dc:creator>
				<category><![CDATA[未分类]]></category>
		<category><![CDATA[学术]]></category>
		<category><![CDATA[程序设计]]></category>

		<guid isPermaLink="false">http://blog.qinyujie.net/?p=274</guid>
		<description><![CDATA[这学期我还参加了一门计算机视觉课，其中的练习并不复杂，但是却很有实践性，可以比较好的看到所学的理论的应用。
这里放上的是我第五次作业的效果图。

Figure 1.

Figure 2.

这次作业的主要任务是使用已知的对应点集和控制点集分别在投影空间和欧式空间进行三维重建。
在投影空间的重建过程：计算基础矩阵F，进而推导出两个投影矩阵P1P2(此处采用最简单的配置模式)，使用线性三角测量方法(linear triangulation method)计算出对应点集在投影空间的坐标&#8211;这也就是投影空间的三维重建。
在欧式空间的重建过程：使用投影空间重建的结果，并计算控制点集在投影空间的坐标。对控制点计算从投影空间坐标到欧式空间坐标的对应，并应用到所有的投影空间点，从而得到在欧式空间的三维重建。
用MATLAB写了简单的程序，大家可以看看我做的文档：）
Homework 5. of Photogrammetric Computer Vision &#8211; 3D Reconstruction
]]></description>
			<content:encoded><![CDATA[<p>这学期我还参加了一门计算机视觉课，其中的练习并不复杂，但是却很有实践性，可以比较好的看到所学的理论的应用。</p>
<p>这里放上的是我第五次作业的效果图。</p>
<p style="text-align: center;"><a href="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Photogrammetric-Computer-Vision-3D-Reconstruction-Final-result.png"><img title="Homework 5. of Photogrammetric Computer Vision - 3D Reconstruction - Final result" src="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Photogrammetric-Computer-Vision-3D-Reconstruction-Final-result-1024x517.png" alt="" width="500" height="250" /></a></p>
<p style="text-align: center;"><a href="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Photogrammetric-Computer-Vision-3D-Reconstruction-Final-result.png"></a>Figure 1.</p>
<p><a href="http://blog.qinyujie.net/wp-content/uploads/output2.png"><img title="Homework 5. of Photogrammetric Computer Vision - 3D Reconstruction - Final result 2" src="http://blog.qinyujie.net/wp-content/uploads/output2.png" alt="" width="500" height="400" /></a></p>
<p style="text-align: center;"><a href="http://blog.qinyujie.net/wp-content/uploads/output2.png"></a>Figure 2.</p>
<p style="text-align: center;"><span id="more-274"></span></p>
<p>这次作业的主要任务是使用已知的对应点集和控制点集分别在投影空间和欧式空间进行三维重建。</p>
<p>在投影空间的重建过程：计算基础矩阵F，进而推导出两个投影矩阵P1P2(此处采用最简单的配置模式)，使用线性三角测量方法(linear triangulation method)计算出对应点集在投影空间的坐标&#8211;这也就是投影空间的三维重建。</p>
<p>在欧式空间的重建过程：使用投影空间重建的结果，并计算控制点集在投影空间的坐标。对控制点计算从投影空间坐标到欧式空间坐标的对应，并应用到所有的投影空间点，从而得到在欧式空间的三维重建。</p>
<p>用MATLAB写了简单的程序，大家可以看看我做的文档：）</p>
<p><a href="http://blog.qinyujie.net/wp-content/uploads/Homework-5.-of-Photogrammetric-Computer-Vision-3D-Reconstruction.pdf">Homework 5. of Photogrammetric Computer Vision &#8211; 3D Reconstruction</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.qinyujie.net/zh/2010/01/21/274/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>图像识别的作业2 &#8211; 霍夫变换( Hough Transform )</title>
		<link>http://blog.qinyujie.net/zh/2009/12/18/126/</link>
		<comments>http://blog.qinyujie.net/zh/2009/12/18/126/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 01:25:24 +0000</pubDate>
		<dc:creator>Yujie QIN</dc:creator>
				<category><![CDATA[未分类]]></category>
		<category><![CDATA[学术]]></category>
		<category><![CDATA[程序设计]]></category>

		<guid isPermaLink="false">http://blog.qinyujie.net/2009/12/18/126/</guid>
		<description><![CDATA[<p>&#160;</p>
<p><span style="font-family: Verdana, SimSun, 'Microsoft Yahei', sans-serif; font-size: 12px; line-height: 19px; color: #4a4a4a;">最近在上一门图像识别的课程的第二次作业。</span></p>
<p><span style="font-family: Verdana, SimSun, 'Microsoft Yahei', sans-serif; color: #4a4a4a; font-size: small;"><span style="font-size: 12px; line-height: 19px;">主题是霍夫变换(Hough Transform)，用来做一些简单的识别。</span></span></p>
<p><span style="font-family: Verdana, SimSun, 'Microsoft Yahei', sans-serif; color: #4a4a4a; font-size: small;"><span style="font-size: 12px; line-height: 19px;">
</span></span></p>
<p style="margin-top: 8px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding: 0px;">用MATLAB写了简单的程序，大家可以看看我做的文档：）</p>
<p style="margin-top: 8px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding: 0px;">下载地址在</p>
<p style="margin-top: 8px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding: 0px;"><a style="color: #666666; text-decoration: none; padding: 0px; margin: 0px;" title="MATLAB程序描述" href="http://filer.blogbus.com/1316417/resource_131641712610748696.pdf" target="_blank">http://filer.blogbus.com/1316417/resource_131641712610748696.pdf</a></p>
<p>&#160;</p>
<p>&#160;</p>]]></description>
			<content:encoded><![CDATA[<p>最近在上一门图像识别的课程的第二次作业。</p>
<p>主题是霍夫变换(Hough Transform)，用来做一些简单的识别。</p>
<p>请看效果图：</p>
<p><span style="font-family: Verdana, SimSun, 'Microsoft Yahei', sans-serif; color: #4a4a4a; font-size: small;"><span><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; color: #000000; font-size: small;"><span><a href="http://blog.qinyujie.net/wp-content/uploads/part1.png"><img class="alignnone size-large wp-image-258" title="Homework 2. of Automatic Image Analysis – Hough Transform - Part 1" src="http://blog.qinyujie.net/wp-content/uploads/part1-1024x517.png" alt="" width="500" height="250" /></a></span></span></span></span><br />
<span id="more-126"></span><br />
<span style="font-family: Verdana, SimSun, 'Microsoft Yahei', sans-serif; color: #4a4a4a; font-size: small;"><span><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; color: #000000; font-size: small;"><span><a href="http://blog.qinyujie.net/wp-content/uploads/part2.png"><img class="alignnone size-large wp-image-259" title="Homework 2. of Automatic Image Analysis – Hough Transform - Part 2" src="http://blog.qinyujie.net/wp-content/uploads/part2-1024x517.png" alt="" width="500" height="250" /></a></span></span></span></span></p>
<p><span style="font-family: Verdana, SimSun, 'Microsoft Yahei', sans-serif; color: #4a4a4a; font-size: small;"><span><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; color: #000000; font-size: small;"><span><a href="http://blog.qinyujie.net/wp-content/uploads/part3.png"><img class="alignnone size-large wp-image-260" title="Homework 2. of Automatic Image Analysis – Hough Transform - Part 3" src="http://blog.qinyujie.net/wp-content/uploads/part3-1024x517.png" alt="" width="500" height="250" /></a></span></span></span></span></p>
<p>用MATLAB写了简单的程序，大家可以看看我做的文档：）</p>
<p>下载地址在:</p>
<p style="margin-top: 8px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding: 0px;"><a href="http://blog.qinyujie.net/wp-content/uploads/Homework-2.-of-Automatic-Image-Analysis-–-Hough-Transform.pdf">Homework 2. of Automatic Image Analysis – Hough Transform</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.qinyujie.net/zh/2009/12/18/126/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>图像识别的作业1 &#8211; 傅立叶变换( Fourier Descriptor )</title>
		<link>http://blog.qinyujie.net/zh/2009/11/04/124/</link>
		<comments>http://blog.qinyujie.net/zh/2009/11/04/124/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 04:10:12 +0000</pubDate>
		<dc:creator>Yujie QIN</dc:creator>
				<category><![CDATA[未分类]]></category>
		<category><![CDATA[学术]]></category>
		<category><![CDATA[程序设计]]></category>

		<guid isPermaLink="false">http://blog.qinyujie.net/2009/11/04/124/</guid>
		<description><![CDATA[<p>最近在上一门图像识别的课程，第一次作业就很好玩，发上来大家一起看看吧：）</p>
<p>
<p>只是借用了很简单的傅立叶变换，用归一化的Fourier Descriptor来比较。</p>
<p>用MATLAB写了简单的程序，大家可以看看：）</p>
<p>下载地址在</p>
<p><a title="MATLAB程序描述" href="http://filer.blogbus.com/1316417/resource_13164171257282568t.pdf" target="_blank">http://filer.blogbus.com/1316417/resource_13164171257282568t.pdf</a></p>
</p>]]></description>
			<content:encoded><![CDATA[<p>最近在上一门图像识别的课程，第一次作业就很好玩，发上来大家一起看看吧：）</p>
<p style="text-align: center;"><a href="http://blog.qinyujie.net/wp-content/uploads/finalreasult.png"><img class="size-large wp-image-254 aligncenter" title="Finalresult of Homework 1. of Automatic Image Analysis - Fourier Descriptor" src="http://blog.qinyujie.net/wp-content/uploads/finalreasult-1024x517.png" alt="" width="500" height="250" /></a><br />
<span id="more-124"></span></p>
<p style="text-align: left;">左边一列两片叶子是需要识别的两个类型的叶子，右上是目标图片，右下是识别结果。</p>
<p>只是借用了很简单的傅立叶变换，用归一化的Fourier Descriptor来比较。</p>
<p>用MATLAB写了简单的程序，大家可以看看：）</p>
<p>下载地址在</p>
<p><a href="http://blog.qinyujie.net/wp-content/uploads/Homework-1.-of-Automatic-Image-Analysis-Fourier-Descriptor.pdf">Homework 1. of Automatic Image Analysis &#8211; Fourier Descriptor</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.qinyujie.net/zh/2009/11/04/124/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>操作系统课程设计——交通灯管制模拟（Delphi版）</title>
		<link>http://blog.qinyujie.net/zh/2007/01/11/44/</link>
		<comments>http://blog.qinyujie.net/zh/2007/01/11/44/#comments</comments>
		<pubDate>Thu, 11 Jan 2007 15:04:03 +0000</pubDate>
		<dc:creator>Yujie QIN</dc:creator>
				<category><![CDATA[未分类]]></category>
		<category><![CDATA[程序设计]]></category>

		<guid isPermaLink="false">http://blog.qinyujie.net/2007/01/11/44/</guid>
		<description><![CDATA[2004年秋季学期，提前选了计算机专业的“操作系统”课程，gsshi老师授课，这是一次进程模拟的大作业，我第一个完成，也由此开始了将近三年的随gsshi老师学习的经历。]]></description>
			<content:encoded><![CDATA[<h1><strong>作业描述</strong></h1>
<p>一个十字路口，共有四组红绿灯，每个路口的车辆都遵循“红灯停、绿灯行”的原则，假设将每一台汽车都作为一个进程，请设计良好的机制，展示出合理的“十字路口交通管理”情况。<span id="more-44"></span></p>
<h3>作业要求</h3>
<p><strong>车辆数目：</strong>每个路口的车辆数目不超过5辆，程序能够提供参数来设定初始的车辆数目。</p>
<p><strong>交通灯设定：</strong>初始情况一个路口为红灯、一个路口为绿灯；红灯变为绿灯的间隔为3秒，必须保持十字路口交通灯的设定正确。</p>
<p><strong>车辆通行设定：</strong>路口宽度不限，对一个路口而言，只有当一辆车通过路口（越过对面路口的交通灯后）后，其后续车辆才能继续通过交通灯，车辆通过路口的时间可以固定、可以自行计算，但是不能为3秒。（即必须体现交通灯对通行的管制）。</p>
<p><strong>实现要求：</strong>本道作业可以在Windows平台或Minix平台实现，在两种平台下，都必须实现动态界面展示，Windows平台可以使用GUI界面或者文本字符界面，在Minix平台下，实现文本字符界面。</p>
<h2>解决方案</h2>
<p>设计两个类，分别为<a href="new.php?BlogID=1326694#_路口类classCross.pas">TTrafficCross</a>和<a href="new.php?BlogID=1326694#_车辆类classVehicle.pas">TVehicle</a>，分别为路口类和车辆类。</p>
<p>用TTime控件持续调用<a href="new.php?BlogID=1326694#_路口类classCross.pas">TTafficCross</a>的Refresh函数来保持路口的实时运行。</p>
<p>用<a href="new.php?BlogID=1326694#_路口类classCross.pas">TTafficCross</a>的VehicleCreate函数每秒按几率在各个方向生成车辆。</p>
<p>用datCrossOccupied作为路口占用的信号量，用以维护路口指挥同时被南北或东西方向占用。</p>
<p>用datLights储存各个路口交通灯的状态。</p>
<p>每个车辆<a href="new.php?BlogID=1326694#_车辆类classVehicle.pas">TVehicle</a>自身维护一个一维坐标系，作为自己在自己方向上的状态。</p>
<p>绘图是根据方向和车辆自身的坐标系坐标，转变为二维坐标绘制在datImage上。</p>
<p>车辆数量、交通灯时间也已经能够在界面设置。</p>
<h2>部分代码</h2>
<h3>窗体文件fromMain.pas</h3>
<p><strong>var</strong></p>
<p>TrafficCross: TTrafficCross;</p>
<p>IsCreated: bool;                                           //判定是否已经创建对象</p>
<p><strong>procedure</strong> Tfrmmain.FormCreate(Sender: TObject);</p>
<p>//初始化Timer及窗体</p>
<p><strong>procedure</strong> Tfrmmain.btnStartClick(Sender: TObject);</p>
<p>//读入初始化数据，并创建TrafficCross对象</p>
<p><strong>procedure</strong> Tfrmmain.btnFinishClick(Sender: TObject);</p>
<p>//释放TrafficCross对象</p>
<p><strong>procedure</strong> Tfrmmain.timerMainTimer(Sender: TObject);</p>
<p>//Timer触发事件，调用TrafficCross. Refresh</p>
<h3>路口类classCross.pas</h3>
<p><strong>TTrafficCross</strong>= <strong>class</strong></p>
<p><strong>public</strong></p>
<p><strong>constructor</strong> Create(var image: TImage; time_green,time_red,time_yellow: TLightsTime;</p>
<p>initialnum: TCrosses; timerinterval: TTime;</p>
<p>speed: TCoordinateSD; maxnum: TUInt; createprop: TUInt);</p>
<p>//initialnum记录初始交通状况，</p>
<p>车辆列队于道路外边界坐标依次 0, [1].long, [2].head+[2].long, &#8230;</p>
<p>//timerinterval记录外部timer的扫描周期</p>
<p><strong>procedure</strong> Refresh;</p>
<p><strong>private</strong></p>
<p>conTimerInterval: TTime;</p>
<p>conMaxVehicle: TUInt;                       //单向最大车辆数</p>
<p>conCreateProp: TUInt;                        //每秒车辆生成率</p>
<p>conTimeGreen, conTimeRed, conTimeYellow: TLightsTime;     //交通灯时间长度</p>
<p>conFrontier: TCrossesFrontier;</p>
<p>//各个车道外边缘左上角的坐标，用于绘制车辆时的参考坐标</p>
<p>datImage: TImage;                               //绘图区域，设为400*400</p>
<p>datTimeLights: array[0..3]of TTime;</p>
<p>// 从绿色开始的 绿黄红黄 一个循环的时间变更点</p>
<p>datVehicles: array[1..4,1..50] of TVehicle;</p>
<p>//各个方向的车辆列表  const_MaxVehicle=50</p>
<p>datVehiclesCount: TCrosses;</p>
<p>//当前各个方向的车辆数的计数器</p>
<p>datVehiclesColor: TCrosses;</p>
<p>//当前新创建车辆的颜色,在1&#8211;5之间循环</p>
<p>datVehiclesHead: array[1..4]of TCoordinateSD;</p>
<p>//当前新创建车的起始位置</p>
<p>datVehicleType: TVehicleType;</p>
<p>// 在初始化时定义的除了颜色外的标准化模型</p>
<p>datLights: TCrossLights;</p>
<p>// 对各个路口交通灯状态的记录，每次模拟都以1&#8211;3方向为绿灯开始</p>
<p>datLightTime: TTime;</p>
<p>//记录交通灯使用时间，以便更颜色</p>
<p>datCrossOccupied: TDirection;</p>
<p>// 路口占用信号量，只在0，1中取值，基数号路口为1，偶数号路口为0</p>
<p><strong>procedure</strong> VehicleMove;                     //判断车辆状态并移动车辆</p>
<p><strong>procedure</strong> VehicleCreate;                   //随机车辆生成器</p>
<p><strong>procedure</strong> VehicleFree;                      //车辆释放</p>
<p><strong>procedure</strong> Draw;                            //总的绘图</p>
<p><strong>procedure</strong> DrawRoad;                        //绘制路口和交通灯</p>
<p><strong>procedure</strong> ClockMove;                      //红绿灯变更</p>
<p><strong>procedure</strong> CrossOccupy;                    //路口占用信号亮变更</p>
<p><strong>procedure</strong> VehicleIncrease(direction: TCoordinateSD);    // 按几率生成车辆</p>
<p><strong>published</strong></p>
<p><strong>property</strong> Image: TImage read datImage;</p>
<p><strong>end</strong>;</p>
<h3>车辆类classVehicle.pas</h3>
<p><strong>TVehicle</strong>= class</p>
<p><strong>public</strong></p>
<p><strong>constructor</strong> Create(var image: TImage; vtype: TVehicleType; direction: TDirection; head: TCoordinateSD; timeinterval: TTime);</p>
<p>//head表示车头在自己道路上相距街道外边缘的距离，</p>
<p>正值表示在街道内，负职表示在街道外等候</p>
<p><strong>procedure</strong> Move;</p>
<p>//移动</p>
<p><strong>procedure</strong> Draw(frontier: TCoordinateDD);</p>
<p>//BoundaryCoordinate&#8211;各个路口外边线线左上角相对于canvas的坐标</p>
<p><strong>private</strong></p>
<p>datImage: TImage;</p>
<p>//绘图区域</p>
<p>datHead: TCoordinateSD;</p>
<p>//车头的相对坐标</p>
<p>datType: TVehicleType;</p>
<p>//车辆特点描述</p>
<p>datMoveable: TMoveable;</p>
<p>//判断能否移动</p>
<p>datRealSpeed: TCoordinateSD;</p>
<p>//每个时间周期的速度</p>
<p>conTimerInterval: TTime;</p>
<p>//扫描的时间周期</p>
<p>conDirection: TDirection;</p>
<p>//车辆方向</p>
<p>procedure setMoveable(moveable: TMoveable);</p>
<p>//用于改变Moveable的属性</p>
<p><strong>published</strong></p>
<p><strong>property</strong> Moveable: TMoveable read datMoveable write setMoveable;</p>
<p>//能否移动</p>
<p><strong>property</strong> Long: TCoordinateSD read datType.long;</p>
<p>//车长</p>
<p><strong>property</strong> Head: TCoordinateSD read datHead;</p>
<p>//车辆头坐标</p>
<p><strong>property</strong> Speed: TCoordinateSD read datRealSpeed;</p>
<p>//每个时间周期的速度</p>
<p><strong>end</strong>;</p>
<h3>常量及类型表unitConst.pas</h3>
<p>{   画布大小400*400</p>
<p>单个车道宽度20</p>
<p>车辆宽度10</p>
<p>车辆长度20</p>
<p>车辆据车道边界距离5</p>
<p>单边街道长度180</p>
<p>模拟从1-3方向通行开始</p>
<p>}</p>
<p><strong>//</strong><strong>自定义类型表 </strong></p>
<p><strong>Type </strong></p>
<p>TInt= integer;</p>
<p>TShort= shortint;</p>
<p>TUShort= byte;</p>
<p>TUInt= Word;</p>
<p>TULong= Longword;</p>
<p>TBool= boolean;</p>
<p>TLightColor= TUShort;</p>
<p>// green 0 , yellow 1 ,  red 2 ,  yellow 3</p>
<p>TCrossLights= array[1..4] of TLightColor;</p>
<p>TTime= TULong;</p>
<p>TLightsTime= array[1..4]of TTime;</p>
<p>//四个路口同一种信号灯的时间长度</p>
<p>TCrosses= array[1..4]of TUShort;</p>
<p>TDirection= TUShort;</p>
<p>TCrossesFrontier= array[1..4] of TCoordinateDD;</p>
<p>TMoveable= TBool;</p>
<p>TCoordinateSD= TInt;</p>
<p>//一维坐标</p>
<p>TCoordinateDD= record                     //二维坐标</p>
<p>x,y :TCoordinateSD;</p>
<p>end;</p>
<p>TVehicleType=record</p>
<p>speed: TCoordinateSD;</p>
<p>long, width: TCoordinateSD;</p>
<p>color: TColor;</p>
<p>end;</p>
<p><strong>//</strong><strong>自定义常熟表</strong></p>
<p><strong>Const </strong></p>
<p>const_Red: TLightColor= 2;</p>
<p>const_Green: TLightColor= 0;</p>
<p>const_Timer_Interval=50;</p>
<p>// 时钟周期，单位：毫秒</p>
<p>const_Light_Color: array[0..3]of TColor=(clGreen,clYellow,clRed,clYellow);</p>
<p>//交通灯颜色列表</p>
<p>const_Cross_WholeLong: TCoordinateSD= 400;</p>
<p>//  画布大小</p>
<p>const_Cross_StreetLong: TCoordinateSD= 180;</p>
<p>//   单边街道长度</p>
<p>const_Cross_HalfCrossLong: TCoordinateSD= 20;</p>
<p>// 单个车道宽度</p>
<p>const_Vehicle_Long: TCoordinateSD= 20;</p>
<p>//   车辆长度</p>
<p>const_Vehicle_Width: TCoordinateSD= 10;</p>
<p>//  车辆宽度</p>
<p>const_Vehicle_Colors: array[1..5]of TColor=(clSkyBlue,clYellow,clBlue,clLime,clRed);</p>
<p>//用于生成车辆的颜色表</p>
<p>const_MaxVehicle: TUInt= 50;</p>
<p>//单车道最大容量</p>
<p>const_PerTime= 1000;</p>
<p>//单位时间周期,为1秒,1000纳秒</p>
<h2>附件</h2>
<p>可执行文件和源代码包：<a href="http://blog.qinyujie.net/wp-content/uploads/TrafficLights.zip">TrafficLights</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.qinyujie.net/zh/2007/01/11/44/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->