Blog Archive

Thursday, December 30, 2010

python reference

python reference

Study Python: http://diveintopython.org/
Study Numpy: http://numpy.scipy.org/,
http://www.scipy.org/Tentative_NumPy_Tutorial

Wednesday, December 29, 2010

2011 SPRING newbie picking housing assignment noitce - Online Spreadsheets - EditGrid

2011 SPRING newbie picking housing assignment noitce - Online Spreadsheets - EditGrid

2011 SPRING newbie picking housing assignment noitce - Online Spreadsheets - EditGrid

2011 SPRING newbie picking housing assignment noitce - Online Spreadsheets - EditGrid: "Yao Hu"

Reproducing the feature outputs of common programs in Matlab using melfcc.m

Reproducing the feature outputs of common programs in Matlab using melfcc.m

Dan's ICSI Projects page

Dan's ICSI Projects page

Speech Signal Processing

http://home.iitk.ac.in/~rhegde/ee627_2010/schedule.html

Reproducing the feature outputs of common programs in Matlab using melfcc.m

Reproducing the feature outputs of common programs in Matlab using melfcc.m: "hen I decided to implement my own version of warped-frequency cepstral features (such as MFCC) in Matlab, I wanted to be able to dupli"

Friday, December 24, 2010

linux top命令详解 - Marvin - CSDN博客

linux top命令详解

top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器。下面详细介绍它的使用方法。

top - 01:06:48 up 1:22, 1 user, load average: 0.06, 0.60, 0.48
Tasks: 29 total, 1 running, 28 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.3% us, 1.0% sy, 0.0% ni, 98.7% id, 0.0% wa, 0.0% hi, 0.0% si
Mem: 191272k total, 173656k used, 17616k free, 22052k buffers
Swap: 192772k total, 0k used, 192772k free, 123988k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1379 root 16 0 7976 2456 1980 S 0.7 1.3 0:11.03 sshd
14704 root 16 0 2128 980 796 R 0.7 0.5 0:02.72 top
1 root 16 0 1992 632 544 S 0.0 0.3 0:00.90 init
2 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/0

统计信息区
前五行是系统整体的统计信息。第一行是任务队列信息,同 uptime 命令的执行结果。其内容如下:

01:06:48 当前时间
up 1:22 系统运行时间,格式为时:分
1 user 当前登录用户数
load average: 0.06, 0.60, 0.48 系统负载,即任务队列的平均长度。
三个数值分别为 1分钟、5分钟、15分钟前到现在的平均值。

第二、三行为进程和CPU的信息。当有多个CPU时,这些内容可能会超过两行。内容如下:

Tasks: 29 total 进程总数
1 running 正在运行的进程数
28 sleeping 睡眠的进程数
0 stopped 停止的进程数
0 zombie 僵尸进程数
Cpu(s): 0.3% us 用户空间占用CPU百分比
1.0% sy 内核空间占用CPU百分比
0.0% ni 用户进程空间内改变过优先级的进程占用CPU百分比
98.7% id 空闲CPU百分比
0.0% wa 等待输入输出的CPU时间百分比
0.0% hi
0.0% si

最后两行为内存信息。内容如下:

Mem: 191272k total 物理内存总量
173656k used 使用的物理内存总量
17616k free 空闲内存总量
22052k buffers 用作内核缓存的内存量
Swap: 192772k total 交换区总量
0k used 使用的交换区总量
192772k free 空闲交换区总量
123988k cached 缓冲的交换区总量。
内存中的内容被换出到交换区,而后又被换入到内存,但使用过的交换区尚未被覆盖,
该数值即为这些内容已存在于内存中的交换区的大小。
相应的内存再次被换出时可不必再对交换区写入。

进程信息区
统计信息区域的下方显示了各个进程的详细信息。首先来认识一下各列的含义。

序号 列名 含义
a PID 进程id
b PPID 父进程id
c RUSER Real user name
d UID 进程所有者的用户id
e USER 进程所有者的用户名
f GROUP 进程所有者的组名
g TTY 启动进程的终端名。不是从终端启动的进程则显示为 ?
h PR 优先级
i NI nice值。负值表示高优先级,正值表示低优先级
j P 最后使用的CPU,仅在多CPU环境下有意义
k %CPU 上次更新到现在的CPU时间占用百分比
l TIME 进程使用的CPU时间总计,单位秒
m TIME+ 进程使用的CPU时间总计,单位1/100秒
n %MEM 进程使用的物理内存百分比
o VIRT 进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
p SWAP 进程使用的虚拟内存中,被换出的大小,单位kb。
q RES 进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
r CODE 可执行代码占用的物理内存大小,单位kb
s DATA 可执行代码以外的部分(数据段+栈)占用的物理内存大小,单位kb
t SHR 共享内存大小,单位kb
u nFLT 页面错误次数
v nDRT 最后一次写入到现在,被修改过的页面数。
w S 进程状态。
D=不可中断的睡眠状态
R=运行
S=睡眠
T=跟踪/停止
Z=僵尸进程
x COMMAND 命令名/命令行
y WCHAN 若该进程在睡眠,则显示睡眠中的系统函数名
z Flags 任务标志,参考 sched.h

默认情况下仅显示比较重要的 PID、USER、PR、NI、VIRT、RES、SHR、S、%CPU、%MEM、TIME+、COMMAND 列。可以通过下面的快捷键来更改显示内容。

更改显示内容
通过 f 键可以选择显示的内容。按 f 键之后会显示列的列表,按 a-z 即可显示或隐藏对应的列,最后按回车键确定。

按 o 键可以改变列的显示顺序。按小写的 a-z 可以将相应的列向右移动,而大写的 A-Z 可以将相应的列向左移动。最后按回车键确定。

按大写的 F 或 O 键,然后按 a-z 可以将进程按照相应的列进行排序。而大写的 R 键可以将当前的排序倒转。

命令使用

1. 工具(命令)名称
top
2.工具(命令)作用
显示系统当前的进程和其他状况; top是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户终止该程序为止. 比较准确的说,top命令提供了实时的对系统处理器的状态监视.它将显示系统中CPU最“敏感”的任务列表.该命令可以按CPU使用.内存使用和执行时间对任务进行排序;而且该命令的很多特性都可以通过交互式命令或者在个人定制文件中进行设定.
3.环境设置
在Linux下使用。
4.使用方法
4.1使用格式
top [-] [d] [p] [q] [c] [C] [S] [s] [n]
4.2参数说明
d 指定每两次屏幕信息刷新之间的时间间隔。当然用户可以使用s交互命令来改变之。
p 通过指定监控进程ID来仅仅监控某个进程的状态。
q该选项将使top没有任何延迟的进行刷新。如果调用程序有超级用户权限,那么top将以尽可能高的优先级运行。
S 指定累计模式
s 使top命令在安全模式中运行。这将去除交互命令所带来的潜在危险。
i 使top不显示任何闲置或者僵死进程。
c 显示整个命令行而不只是显示命令名
4.3其他
  下面介绍在top命令执行过程中可以使用的一些交互命令。从使用角度来看,熟练的掌握这些命令比掌握选项还重要一些。这些命令都是单字母的,如果在命令行选项中使用了s选项,则可能其中一些命令会被屏蔽掉。
  Ctrl+L 擦除并且重写屏幕。
  h或者? 显示帮助画面,给出一些简短的命令总结说明。
  k 终止一个进程。系统将提示用户输入需要终止的进程PID,以及需要发送给该进程什么样的信号。一般的终止进程可以使用15信号;如果不能正常结束那就使用信号9强制结束该进程。默认值是信号15。在安全模式中此命令被屏蔽。
  i 忽略闲置和僵死进程。这是一个开关式命令。
  q 退出程序。
  r 重新安排一个进程的优先级别。系统提示用户输入需要改变的进程PID以及需要设置的进程优先级值。输入一个正值将使优先级降低,反之则可以使该进程拥有更高的优先权。默认值是10。
  S 切换到累计模式。
  s 改变两次刷新之间的延迟时间。系统将提示用户输入新的时间,单位为s。如果有小数,就换算成m s。输入0值则系统将不断刷新,默认值是5 s。需要注意的是如果设置太小的时间,很可能会引起不断刷新,从而根本来不及看清显示的情况,而且系统负载也会大大增加。
  f或者F 从当前显示中添加或者删除项目。
  o或者O 改变显示项目的顺序。
  l 切换显示平均负载和启动时间信息。
  m 切换显示内存信息。
  t 切换显示进程和CPU状态信息。
  c 切换显示命令名称和完整命令行。
  M 根据驻留内存大小进行排序。
  P 根据CPU使用百分比大小进行排序。
  T 根据时间/累计时间进行排序。
W 将当前设置写入~/.toprc文件中。这是写top配置文件的推荐方法。

Monday, December 13, 2010

Noise Robustness resources CODE, toolkit, tutorial

Some resources for noise-robust and channel-robust speech processing

This page is a collection of links to software and data resources related to research on automatic speech recognition (ASR) that is robust to background noise and convolutional distortions such as reverberation. Some of the links pointed to by this page are also relevant to research on enhancing speech for human listening. This page has now been replaced by the Resources listings at www.isca-students.org. However, this page should stay up, because the URL for this page has been referenced in at least one published paper. (In that paper, in IEEE Trans. Speech and Audio Processing in 2006, it was referenced as the place to download the Qualcomm-ICSI-OGI tools.) As of February 2007 there are no working links on this page which are not included in the ISCA listings (although there are a few dead links which might start working again), and there are a lot of links in the ISCA listings which are not included on this page.
Successful approaches to robust ASR may combine more than one robustness technique. Because of the simple data flow of much signal processing code, different tools can often be used together simply by running them in sequence, using pipes or intermediate files. Two convenient choices for intermediate file formats are HTK feature files, and waveforms. Many of the tools online here operate on HTK feature files, or can output HTK feature files. The HTK format is a useful intermediate file format for feature files because it is simple to read, write, and convert to other formats, and because of the popularity of HTK. Also, some algorithms can be used with other tools without any modification to those other tools by having the algorithms run speech-enhancement-style, outputting processed waveforms which the other tools treat as they would any other audio input file. Using processed waveforms as an intermediate format also allows listening, waveform plotting, and spectrogram plotting, which may lead to useful insights. If using processed waveforms as an intermediate format, it is often safest to store these processed waveforms in floating point, rather than the usual 16-bit integer storage format, to reduce roundoff error and eliminate the risk of overflow (numbers too large to represent in the 16-bit format) or underflow (numbers too small to represnt in the 16-bit format). Since processing algorithms may increase the loudness of some waveforms or introduce quiet details such as noise floors, there is a risk of overflow or underflow with a 16-bit integer format even if the original waveforms were well scaled for that format.

Enhancement/compensation software for ASR and human listening:



Software for ASR:



Software for signal quality measurement:



Software and data for reproducing or simulating acoustic conditions:



Other:

VOICEBOX

The VOICEBOX Matlab toolbox for audio processing includes a noise reduction routine (specsubm), routines to read and write audio files from Matlab, and many other things.

Beamforming Toolkit

The Karlsruhe beamforming toolkit: "btk is a toolkit that provides a basis for the implementation of powerful beamforming algorithms. btk uses Python as a scripting language for ease of control and modification. The capacity to efficiently perform advanced numerical computations is provided by Numeric Python (NumPy), the GNU Scientific Library (GSL), as well as a few extra algorithms we've implemented ourselves."

Qualcomm-ICSI-OGI front end, speech detection, and noise reduction

Click here for an archive containing source code and documentation for the Qualcomm-ICSI-OGI noise-robust front end described in the ICSLP 2002 paper by Adami et al. The archive also contains tools for using the speech detection, Wiener filter noise reduction, or nonspeech frame dropping features of the front end independently of other features. The noise reduction can be used independently of other components to produce noise-reduced waveforms.

Matlab noise reduction tools by Patrick Wolfe

Matlab source code for various noise reduction algorithms is available here.

UCL Enhance

Software and literature references for this speech enhancement tool are available here.

CtuCopy

CtuCopy is an open source tool for speech enhancement and ASR feature extraction. "CtuCopy acts as a filter with speech waveform file(s) at the input and either a speech waveform file(s) or feature file(s) at the output." As of version 3.0.7, it can be used for several different noise reduction techniques in the spectral subtraction family, and several ASR feature extraction algorithms. It was written by Petr Fousek of the Czech Technical University in Prague's Speech Processing and Signal Analysis Group. As of this writing CtuCopy version 3.07 is available at http://www.idiap.ch/~fousek/ctucopy/ and in the future it should be available in the download section at http://noel.feld.cvut.cz/speechlab (there is currently an older version of CtuCopy at the second link).

Trausti Kristjansson

Trausti Kristjansson created this page (while at the University of Toronto) which provides Matlab source code for (1) spectral subtraction noise removal, (2) the Algonquin variational inference algorithm for removing noise and channel effects, and (3) the Recognition Analyzer diagnostic tool which displays features, HTK log likelihoods, and HTK state sequences and can create resynthesized audio from MFCC features.

Marc Ferras' code for multi-microphone speech enhancement

This page provides source code for several blind multi-microphone speech enhancement techniques. These were implemented by Marc Ferras while pursuing his masters thesis on multi-microphone signal processing for automatic speech recognition in meeting rooms.

The RESPITE CASA Toolkit

The RESPITE CASA Toolkit is a toolkit for Computational Auditory Scene Analysis (CASA). This includes a tutorial on using the toolkit for missing data speech recognition.

Seneff auditory model

This page has source code for an implementation of Stephanie Seneff's auditory model front end for ASR.

RASTA and MSG

C/C++ implementations of the RASTA and MSG (modulation-filtered spectrogram) algorithms for robust feature extraction are available as part of this ICSI speech software package. There is also this older page for RASTA at ICSI. There is a MATLAB implementation of RASTA at Dan Ellis' Matlab page.

MVA (Mean, Variance, ARMA)

This page provides source code for this technique proposed by Chia-Ping Chen and Jeff Bilmes which post-processes noisy cepstra by doing mean and variance normalization (M for mean, V for variance) and bandpass modulation filtering (A for ARMA).

Gabor filter analysis for speech recognition

This page provides articles, filter definitions, software tools, and discussion related to automatic speech recognition (ASR) with Gabor filters. A Matlab package for feature selection using the Feature Finding Neural Networks (FFNN) approach proposed by Tino Gramß (Gramss) is available as well. (This FFNN package was used to select Gabor filters for ASR.)

NIST Speech Quality Assurance Package (SPQA)

The SPQA package includes SNR measurement tools which do not require a clean audio reference.

Objective Speech Quality Assessment

The CSLU Robust Speech Processing Laboratory software repository page hosts the Objective Speech Quality Assessment package (developed by Bryan Pellom, and analyzed in an ICSLP 98 paper by Hansen and Pellom) which calculates various metrics of speech quality based on comparing clean audio with noisy or noise-reduced audio.

CTU snr tool

This open source tool can be used both to measure the SNR of signals and to mix noise into signals at a specified SNR. It is available from the Czech Technical University in Prague's Speech Processing and Signal Analysis Group in the download section at http://noel.feld.cvut.cz/speechlab.

FaNT tool for adding noise or telephone characteristics to speech

The FaNT (Filtering and Noise-adding Tool) tool can be used to add noise to speech recordings at a desired SNR (signal-to-noise ratio). The SNR can be calculated using frequency weighting (G.712 or A-weighting), and the speech energy is calculated following ITU recommendation P.56. The tool can also be used to filter speech with certain frequency characteristics defined by the ITU for telephone equipment. This tool was used to create the noisy data for the popular AURORA 2 speech recognition corpus.

Acoustic impulse responses

This page, created by James Hopgood, is a collection of acoustic impulse responses for simulating convolutional distortion. The focus is on hands-free / far-field acoustic conditions. Some past speech recognition work (by Shire, Kingsbury, Avendano, Palomaki, Morgan, Chen, Gelbart, possibly others) has been done using a set of impulse responses collected using four mics and various degress of reverberation in the varechoic chamber at Bell Labs. They can be downloaded here. Another set of impulse responses from the Bell Labs varechoic chamber, using 31 speaker positions and a linear 22-element microphone array, has been made available by Aki Harma here. More acoustic impulse responses from various rooms, including microphone array situations, are available as part of the Sound Scene Database in Real Acoustical Environments from the Real World Computing Partnership, here. The site noisevault.com has acoustic impulse responses as well as links to software and documents regarding impulse response measurement and acoustic simulation; it seems aimed at audio engineers and audio engineering hobbyists. Three impulse responses measured in two meeting rooms are available as part ofITU-T G.191 Annex A, also known as the ITU-T Software Tools Library (STL). These impulse responses are in the 2005 STL release (STL2005) but not in earlier releases. The acoustics of the meeting rooms are described in the STL users manual.

University of Kentucky Microphone Array Processing Toolbox

This Matlab toolbox allows simulation of different room geometries, microphone locations, and speaker locations. It also includes routines for microphone array sound processing, microphone placement calculation, measuring RT60, and measuring sound velocity.

Room acoustics simulator

The AudioGroup at the University of Patras have placed public domain room acoustics simulators online here.

Additive Noise Sources

The CSLU Robust Speech Processing Laboratory software repository page hosts a package named Additive Noise Sources which contains noise files for use in simulating additive noise.

NOISEX noises

This page at Rice has a set of downloadable noises. I think these are from the NOISEX-92 collection, but I don't know if this is the complete collection. I am not trying to give a comprehensive list of corpora on this page, but this page in the comp.speech FAQ has some links.

ShATR multiple simultaneous speaker corpus

Here. "ShATR is a corpus of overlapped speech collected by the University of Sheffield Speech and Hearing Research Group in collaboration with ATR in order to support research into computational auditory scene analysis. The task involved four participants working in pairs to solve two crosswords. A fifth participant acted as a hint-giver. Eight channels of audio data were recorded from the following sensors: one close microphone per speaker, one omnidirectional microphone, and the two channels of a binaurally-wired mannekin. Around 41% of the corpus contains overlapped speakers. In addition, a variety of other audio data was collected from each participant. The entire corpus, which has a duration of around 37 minutes, has been segmented and transcribed at 5 levels, from subtasks down to phones. In addition, all nonspeech sounds have been marked."

Meeting room digits recordings

Here is a set of connected digits (like TIDIGITS) recordings made with table-top microphones in a conference room at the International Computer Science Institute. (This audio data is also available from the LDC as part of the ICSI Meeting Corpus.)

Pitch and Voicing Estimates for Aurora 2

The Pitch and Voicing Estimates for Aurora 2 archive from Microsoft Research "consists of a set of pitch period and voicing estimates for utterances found in the Aurora 2 corpus". The algorithm used was described in J. Droppo and A. Acero, "Maximum a Posteriori Pitch Tracking" in ICSLP 1998.

A brief list of resources that are not specific to noise and channel robustness

ISCA resources pageWaveSurfer speech visualization tool (view waveforms, spectrograms, formant tracks, pitch tracks) and other KTH-hosted softwareHTK recognizerSPHINX recognizer JULIUS recognizerEdinburgh Speech Tools LibraryISIP recognizer and ISIP Foundation Classes for speech processingCSLR SONIC recognizerCMU-Cambridge Statistical Language Modeling toolkitSRILM - The SRI Language Modeling Toolkit, ICSI speech software package (link above under "RASTA and MSG"), COLEA Matlab Tool for Speech Analysis, some more links to tools here. For collections of speech recordings: Linguistic Data ConsortiumEuropean Language Resources Association (despite the name they have non-European languages too), Corpora Group at CSLUVoxForge (recordings available at no cost), LibriVox (recordings available at no cost), VoxForge's list of corpora, and also see the Corpora listings on the ISCA Students web siteA list of phonetics tutorials and speech processing tutorials and software

MFCC based feature vectors of my music collection – 32leaves

MFCC based feature vectors of my music collection – 32leaves: "A"

Friday, December 10, 2010

Gaussian Mixture Selection Top 20

Gaussian Mixture Selection

Quick Tip:

1) Reason: Save time

2) How:

For a test utterance feature, say, MFCC,
for each frame of MFCC, we have a set of mixtures
for another frame, we may have a different set of mixure components

In most case, top 20 is enough for an UBM with 1024 mixture.

Tuesday, December 7, 2010

RUN MATLAB COMPUTATIONS ON A SUN GRIDENGINE CLUSTER

RUN MATLAB COMPUTATIONS ON A SUN GRIDENGINE CLUSTER

perl goto example

#!/usr/bin/perl

#        http://www.tutorialspoint.com/perl/perl_goto.htm
$count = 0;

START:
$count = $count + 1;

if( $count > 4 ){
        print "Exiting program\n";
}else{
    print "Count = $count, Jumping to START:\n";
    goto START;
}

Thursday, December 2, 2010

Programming Wiki: Programming Languages and Resources

Programming Wiki: Programming Languages and Resources

matlab中常见英文词含义_Alextoy_新浪博客

matlab中常见英文词含义_Alextoy_新浪博客: "fprintf('需要输出地文字信息%f',变量名)"

How to get input from keyboard in matlab

function get_option
%UNTITLED Summary of this function goes here
% Detailed explanation goes here

intV=input('input the value of First Paratmer(must be digit): '); %作用是输入a的数据,此数据必须是数字形式的。
strV=input('input the value of Second Paratmer(must be string): ','s'); %作用是输入a的数据,此数据必须是字符形式的

fprintf('Firt Parameter= %d\n', intV);
fprintf('\nSecond Parameter= %s\n', strV);

Wednesday, December 1, 2010

7个习惯 让你成为高效能人士

7个习惯 让你成为高效能人士

dijktra's algorithm


#include "stdafx.h"

#include
#include
#include
#define infi 999

using namespace::std;
class queue
{
private:
int q[100];
int front, rear;
protected:
queue()
{
front=rear=-1;
}
int isempty()
{
if((front==-1 && rear==-1) || (front>rear))
{
front=rear=-1;
return 1;
}
return 0;
}
void push(int a)
{
if(isempty())
front++;
q[++rear]=a;
};
int del()
{
return q[front++];
}
};
class dj :public queue
{
private:
int mat[10][10], dist[10], path[10];
public:
int n;
void input()
{
cout<<"Enter number of nodes:\n"; cin>>n;
cout<<"\n\nEnter adjacency matrix\n"<>mat[i][j];
}
void init(int m)
{
push(m);
dist[m]=0;
for(int i=1;i<=n;i++)
{
if(i!=m)
{
push(i);
dist[i]=infi;
}
path[i]=0;
}
}
void min_dist(int m)
{
int v, w;
init(m);
while(!(isempty()))
{
v=del();
for(int i=1;i<=n;i++)
{
if(mat[v][i]!=0)
{
w=i;
if((dist[v]+mat[v][w])<(dist[w]))
{
dist[w]=dist[v]+mat[v][w];
path[w]=v;
}
}
}
}
}
void disp_path(int m)
{
int p=path[m];
if(p==0)
return;
disp_path(p);
cout<<" "< }
void disp_dist(int m)
{
cout<<"Cost: "< }
};
void main()
{
system("cls");
int c=0;
dj a;
a.input();
cout<<"\n\nPress any key to continue"< getch();
system("cls");
for(int i=1;i<=a.n;i++)
{
a.min_dist(i);
for(int j=1;j<=a.n;j++)
{
if(i!=j)
{
if(++c==10)
{
cout<<"\n\nPress any key to continue"< getch();
system("cls");
c=0;
}
cout<<"From "< cout<<"------------"< cout<<"Minimum distance route: ("< a.disp_path(j);
cout<<")"< a.disp_dist(j);
}
}
}
cout<<"\n\nPress any key to exit"< getch();
}

/*Output:

Enter number of nodes:
4


Enter adjacency matrix

0 1 5 4
1 0 2 6
5 2 0 3
4 6 3 0


From 1 to 2:
------------
Minimum distance route: (1 2)
Cost: 1

From 1 to 3:
------------
Minimum distance route: (1 2 3)
Cost: 3

From 1 to 4:
------------
Minimum distance route: (1 4)
Cost: 4

From 2 to 1:
------------
Minimum distance route: (2 1)
Cost: 1

From 2 to 3:
------------
Minimum distance route: (2 3)
Cost: 2

From 2 to 4:
------------
Minimum distance route: (2 1 4)
Cost: 5

From 3 to 1:
------------
Minimum distance route: (3 2 1)
Cost: 3

From 3 to 2:
------------
Minimum distance route: (3 2)
Cost: 2

From 3 to 4:
------------
Minimum distance route: (3 4)
Cost: 3

From 4 to 1:
------------
Minimum distance route: (4 1)
Cost: 4

From 4 to 2:
------------
Minimum distance route: (4 1 2)
Cost: 5

From 4 to 3:
------------
Minimum distance route: (4 3)
Cost: 3
*/









dijkstra's algorithm in C++

//dijktra's algorithm


#include "stdafx.h"

#include
#include
#include
#define infi 999

using namespace::std;
class queue
{
private:
int q[100];
int front, rear;
protected:
queue()
{
front=rear=-1;
}
int isempty()
{
if((front==-1 && rear==-1) || (front>rear))
{
front=rear=-1;
return 1;
}
return 0;
}
void push(int a)
{
if(isempty())
front++;
q[++rear]=a;
};
int del()
{
return q[front++];
}
};
class dj :public queue
{
private:
int mat[10][10], dist[10], path[10];
public:
int n;
void input()
{
cout<<"Enter number of nodes:\n";
cin>>n;
cout<<"\n\nEnter adjacency matrix\n"< for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>mat[i][j];
}
void init(int m)
{
push(m);
dist[m]=0;
for(int i=1;i<=n;i++)
{
if(i!=m)
{
push(i);
dist[i]=infi;
}
path[i]=0;
}
}
void min_dist(int m)
{
int v, w;
init(m);
while(!(isempty()))
{
v=del();
for(int i=1;i<=n;i++)
{
if(mat[v][i]!=0)
{
w=i;
if((dist[v]+mat[v][w])<(dist[w]))
{
dist[w]=dist[v]+mat[v][w];
path[w]=v;
}
}
}
}
}
void disp_path(int m)
{
int p=path[m];
if(p==0)
return;
disp_path(p);
cout<<" "< }
void disp_dist(int m)
{
cout<<"Cost: "< }
};
void main()
{
system("cls");
int c=0;
dj a;
a.input();
cout<<"\n\nPress any key to continue"< getch();
system("cls");
for(int i=1;i<=a.n;i++)
{
a.min_dist(i);
for(int j=1;j<=a.n;j++)
{
if(i!=j)
{
if(++c==10)
{
cout<<"\n\nPress any key to continue"< getch();
system("cls");
c=0;
}
cout<<"From "< cout<<"------------"< cout<<"Minimum distance route: ("< a.disp_path(j);
cout<<")"< a.disp_dist(j);
}
}
}
cout<<"\n\nPress any key to exit"< getch();
}

/*Output:

Enter number of nodes:
4


Enter adjacency matrix

0 1 5 4
1 0 2 6
5 2 0 3
4 6 3 0


From 1 to 2:
------------
Minimum distance route: (1 2)
Cost: 1

From 1 to 3:
------------
Minimum distance route: (1 2 3)
Cost: 3

From 1 to 4:
------------
Minimum distance route: (1 4)
Cost: 4

From 2 to 1:
------------
Minimum distance route: (2 1)
Cost: 1

From 2 to 3:
------------
Minimum distance route: (2 3)
Cost: 2

From 2 to 4:
------------
Minimum distance route: (2 1 4)
Cost: 5

From 3 to 1:
------------
Minimum distance route: (3 2 1)
Cost: 3

From 3 to 2:
------------
Minimum distance route: (3 2)
Cost: 2

From 3 to 4:
------------
Minimum distance route: (3 4)
Cost: 3

From 4 to 1:
------------
Minimum distance route: (4 1)
Cost: 4

From 4 to 2:
------------
Minimum distance route: (4 1 2)
Cost: 5

From 4 to 3:
------------
Minimum distance route: (4 3)
Cost: 3
*/