Tuesday, October 25, 2011

Coding for distributions (geometric/weibull)




#include
#include
#include

long fact(int n)
{
if(n<=0)
return 1;
else
return n*fact(n-1);
}


double geomean(int x,double p,double q)
{
if(x>0)
return pow(q,x-1)*p;
else
return 0;
}


double weibpdf(int x, double v, double a, double b)
{
if(x return 0;
else
{
return b/a*(pow((x-v)/a,b-1))*exp(-pow((x-v)/a,b));
}
}


double weibcdf(int x, double v, double a, double b)
{
if(x return 0;
else
{
return (1 - exp(-pow((x-v)/a,b)));
}
}

double poisson(int x, double a)
{
if(x<0)
return 0;
else
{
return (exp(-a)*pow(a,x))/fact(x) ;
}
}


double binom(int x,double p,double q,int n)
{
if(x>=0)
return fact(n)/(fact(x)*fact(n-x))*pow(p,x)*pow(q,n-x);
else
return 0;
}


int main()
{
int ch;
double p,q,v,a,b;
int x,n;
clrscr();


do
{
printf("\nExit.");
printf("\nGeometric Mean.");
printf("\nWeibull Distribution.");
printf("\nPoisson Distribution.");
printf("\nBinomial Distribution.");
printf("\nEnter your choice => ");
scanf("%d",&ch);
if(ch==1)
{
printf("\n\tEnter the value of x,p,q => ");
scanf("%d%lf%lf",&x,&p,&q);
printf("\n\tGeometric Mean = %lf",geomean(x,p,q));
}
else if(ch==2)
{
printf("\n\tEnter the value of x,v,a,b => ");
scanf("%d%lf%lf%lf",&x,&v,&a,&b);
printf("\n\tWeibull pdf, f(%d) = %lf",x,weibpdf(x,v,a,b));
printf("\n\n\tWeibull cdf, F(%d) = %lf",x,weibcdf(x,v,a,b));
}

else if(ch==3)
{
printf("\n\tEnter the value of x,a => ");
scanf("%d%lf",&x,&a);
printf("\n\tPoisson Distribution, p(%d) = %lf",x,poisson(x,a));

}
else if(ch==4)
{
printf("\n\tEnter the value of x,p,q,n => ");
scanf("%d%lf%lf%d",&x,&p,&q,&n);
printf("\n\tBinomial Distribution, p(%d) = %lf",x,binom(x,p,q,n));
}
}while(ch!=0);
getch();
return 0;
}


Astha
MCA 4510/09


Coding for M/M/1 server




#include
#include
void main()
{
int i,a,d,arrival[11],clock=0,inter[]={2,3,1,4,1,6,1,1,5,2,1},service[]= {2,5,4,3,3,5,6,6,6,3,2};
int wait[11],q=0,sum=0,avg,server;
arrival[0]=clock+inter[0];
d=clock+service[0];
server=1;
a=arrival[0];
wait[0]=0;
for(i=0;i<11;i++){arrival[i]=arrival[i-1]+inter[i];}printf("clock=%d (A=%d)(D=%d)(W=%d)",clock,a,d,wait[0]) ;i=1;while(clock<30){if(ad)
{wait[i]=0;
printf("clock=%d (A=%d)(D=%d)(W=%d)",clock,a,d,wait[1]) ;
i++;
}
else
if(da)
{
wait[i]=d-a;
}
printf("\nclock = %d (A,%d) (D,%d) (w,%d)",clock,a,d,wait[i]);
}
else
{
wait[i]=0;
printf("clock=%d (A=%d)(D=%d)(W=%d)",clock,a,d,wait[i]) ;
server=0;
}
}
else
{
clock=0;
a=arrival[i];
d=clock+service[i-q];
if(a{
wait[i]=d-a;
}
else
{
wait[i]=0;
i++;
printf("clock=%d (A=%d)(D=%d)(W=%d)",clock,a,d,wait[i]) ;
}
}
else
{
clock=0;
a=arrival[i];
d=clock+service[i];
wait[i]=d-a;
i++;
printf("clock=%d (A=%d)(D=%d)(W=%d)",clock,a,d,wait[i]) ;
for(i=0;i<11;i++)
{
sum+=wait[i];
}
avg=sum/11;
if (avg<1)
printf("efficient system");
else
printf("inefficient system");
getch();
}



neha bahadur
mca455309

Wednesday, October 19, 2011

Simulation & Modeling (ASSIGNMENTS) [LAB + Theory}

































Roll No. Assignments
2032,4501 Music Shop Inventory Problem,Simulation of computer system
4502,4506 Web Simulation,
4507,4568,4538 Food bazaar, Simulation of Queuing System and its applications e.g. Food Bazaar
4508,4536,4546
Simulating a banquet hall,Input Output modeling for simulation
4509
Random Number generation for simulation
4510,4525,4520 Telephone Simulation System, Application of Simulation for solving network flow problems
4511,4543 Simulating Car Parking
4513,4533,4531 Monte-carlo Simulation
4514 Simulating grocery Shop
4516,4535,4551/08 Traffic Simulation, Simulation of websites to improve traffic for a website
4515,4528,4529 Understanding GPSS
4518,4554,4566 Gaming Simulation
4519,4524 Conducing web simulation on e-commerce portals
4530,4551,4556 Simulating Delhi Metro, Understanding Object oriented simulation
4534,4557 Learning to solve Problems using simulation
4539,4542 Developing a Simulation Database: Studying case studies/FAQs
4540,4547,4543 Online Traffic Monitoring system
4541,4545,4555 Developing a Simulator for keyword analysis,Application of Simulation for Forecasting
4537,4532,4521 Random Number Generation in C++,Studying Simulation languages like SIMSCRIPT,GPSS,MODSIM
4550,4563 Solving problems for input modeling [17,18,20,21]
4523,4552 Study applications of random generators in simulation and other fields illustrating by solving problems [2,9,10,15]
4545660,4562 Application of Simulation for security and anti-spamming
4522,4526 Understanding DEVS
44532,4533,4568 Using general purpose simulation language for problem solving [pg 119 1,2,3,4,5)
4535,4538,4541 Developing simulation program in C [pros & cons] [Pg. 119 7,8,9,10]
4544,4548 Output Analysis for a single model
4549,4552 Comparison & Evaluation of Alternative system designs
4553,4558 Simulation of computer networks

Tuesday, October 18, 2011

Simulation & Modeling Software



We can understand computer simulation language as the language which describes operation of a simulation on a computer.

It can be broadly categorized in following two categories:

1. continuous
2. Discrete event

Many lnguages have a graphical interface and are capable of performing simple statistical analysis of the results.


While using discrete-event languages we can easily generate pseudo-random numbers and determine variables using different probability distributions.


Some of the Discrete event and continuous language packages have been listed below:


AutoMod
eM-Plant
Arena
ExtendSim simulation environment for discrete event, continuous, discrete-rate and agent-based simulation.[1]
GASP
GPSS
Plant Simulation
Simio software for discrete event, continuous, and agent-based simulation.[2]
SimPLE++
SimPy, an open-source package based on Python
SIMSCRIPT II.5, a well established commercial compiler
Simula
Java Modelling Tools, an open-source package with graphical user-interface[3]
Poses++, a discrete-event simulation system with Petri net based modeling
OMNeT++, a C++-based discrete-event simulation package.
Mirelle, a programming/scripting language with simulation support. [4]


Some of the Continuous simulation languages package are:


  1. Advanced Continuous Simulation Language (ACSL), which supports textual or graphical model specification
  2. Diesel Model Description Language
  3. DYNAMO
  4. SimApp, simple simulation of dynamic systems and control systems [6]
  5. Simgua, simulation toolbox and environment, supports Visual Basic [7]
  6. Simulation Language for Alternative Modeling (SLAM) (There used also be a Simulation Language for Analogue Modeling (SLAM))
  7. VisSim, a visually programmed block diagram language
    Hybrid, and other.
  8. LMS Imagine.Lab AMESim[8], simulation platform to model and analyze multi-domain systems and predict their performances
  9. Flowmaster V7[9] Software for the analysis of fluid mechanics within pipe networks using 1D Computational Fluid Dynamics
  10. AnyLogic multi-method simulation tool, which supports System dynamics, Discrete event simulation, Agent-based modeling
  11. Modelica: open-standard object-oriented language for modeling of complex physical systems
    Simulink: Continuous and discrete event capability
  12. Scicos: Continuous-time, discrete-time and event based simulation tool distributed with ScicosLab: It contains a block diagram editor, a compiler, simulator and code generation facilities: Free software.
  13. XMLlab: simulations with XML
  14. Flexsim:3D process simulation software for continuous, discrete event, or agent-based systems.
  15. Simio software for discrete event, continuous, and agent-based simulation.
  16. EICASLAB:Continuous, discrete and discrete event capability specifically devoted to support the automatic control design.




Source:http://en.wikipedia.org/wiki/Simulation_language

Monday, October 17, 2011

Simulation Software





Discuss the following periods in simulation history?


a. The period of Search: Simulation was conducted in FORTRAN and other gernal purpose languages. No specific simulation specific routines. Much effort was on expanding searcn for unifying concepts and the development of reusable routines to facilitate simulation(1955-60)

b Advent : It is the period of forerunners of SPL we use today(1961-65)

GPSS developd by Geoffery Gordon at IBM and appeared in 1961. General Purpose Simulation system was developed for quick simulation of communication and computer system. It is a block disgram based representation (similar to process flow diagram) and suited for queuing models.


Phillip J Kiviat developed GASP (General Activity based simulation program). Originally it was based on GPL ALGOL but later based on FORTRAN.

other SPL developed are SIhMULA(extension of ALGOL)

c. The Formative period (from 1966-1970)

Concepts were reviewed adn refined to promote more consistent representation of each language 's world view.

SIMSCRIPT II represents major advancement in SPLs. In its free form english like language.


d. The Expansion period (from 1971-1978)

Improvement in GPSS. Inclusion of interactive debugger. Efforts made to simplify modeling process. Using simula an attempt was made to develop system definition from high level user perspective that could be translated automatically in an executable format.

e. Consolidation and Regeneration

This period from 1979 GASP appeared SLAM II and SIMAN

SLAM II(Simulation language for alternative modeling) produced by Prisker and Associates.

for providing multiple modeling perspectives and combined modeling capabilities. Event scheduling persective and a noetwork world view and continuous component.

f. Integrated Environment

Availability of SPL for personal computers, GUI ,animation and other visulaization tools,input/output analyzers. use of process flow or block diagram and reducing need to remeber syntax. Availability of 2 D /3D scale drawings





SIMAN

Linear Congruential method ( Random Number generation )



#include
#include
#define true 1
#define false 0
void main()
{
int x[30];
int flag=true,i,a,c,m,x0;
float r[30];
printf("\n Enter a,c,m,x0");
scanf("%d%d%d%d",&a,&c,&m,&x0);
x[0]=x0;
i=1;
while(flag==true)
{
x[i]=(a*x[i-1]+c)%m;
r[i]=x[i]/(float)m;
if(x[i]==x[0])//Now onwards series will repeat
flag=false;
i++;
printf("x[i]=%d\n",x[i-1]);
}
getch();
}




omprakash sharma

4552/09

Weibull Distribution Implementation (Simulation and Modeling)




#include
#include
#include

double f(int x, double v, double a, double b)
{


if(x< v)
return 0;

else
{
return b/a*(pow((x-v)/a,b-1))*exp(-pow((x-v)/a,b));

}

}

double F(int x, double v, double a, double b)
{
if(xreturn 0;

else
{

return (1 - exp(-pow((x-v)/a,b)));

}



}


int main()
{

int x;
double v,a,b;
clrscr();



printf("enter d value of x, location, shape & scale: ");
scanf(" %d %lf %lf %lf",&x, &v, &b, &a);

printf(" f(%d) = %f",x,f(x,v,a,b));

printf(" F(%d) = %f",x,F(x,v,a,b));

getch();
return 0;
}


Pankaj kumar
mca4506/09

Future Event LIST (Simulation & Modeling)


BY NEHA BAHADUR MCA/4553/09

#include
#include
#include

int inter[9] = {1,1,6,3,7,5,2,4,1};
int service[9] = {4,2,5,4,1,5,4,1,4};
int i=0,j=0;

struct eventinfo
{
int type;
int time;
struct eventinfo *next;
} * header;


void addevent(int time, int type)
{
struct eventinfo * node = (struct eventinfo *)malloc(sizeof(struct eventinfo));
struct eventinfo *p, *q;
node->type = type;
node -> time = time;

if(header->next == NULL)
{
header ->next = node;
node->next = NULL;
return ;
}
p = header->next;
q = header;
while((p->time

Future Event LIST (Simulation & Modeling) (Linked list Implementation)


by Himanshu Singla

#include
#include
#include

int inter[9] = {1,1,6,3,7,5,2,4,1};
int service[9] = {4,2,5,4,1,5,4,1,4};
int i=0,j=0;

struct eventinfo
{
int type;
int time;
struct eventinfo *next;
} * header;


void addevent(int time, int type)
{
struct eventinfo * node = (struct eventinfo *)malloc(sizeof(struct eventinfo));
struct eventinfo *p, *q;
node->type = type;
node -> time = time;

if(header->next == NULL)
{
header ->next = node;
node->next = NULL;
return ;
}
p = header->next;
q = header;
while((p->time

Application of Weibull Distribution




#include
#include
#include

double f(int x, double v, double a, double b)
{


if(x< v)
return 0;

else
{
return b/a*(pow((x-v)/a,b-1))*exp(-pow((x-v)/a,b));

}

}

double F(int x, double v, double a, double b)
{
if(xreturn 0;

else
{

return (1 - exp(-pow((x-v)/a,b)));

}



}


int main()
{

int x;
double v,a,b;
clrscr();



printf("enter d value of x, location, shape & scale: ");
scanf(" %d %lf %lf %lf",&x, &v, &b, &a);

printf(" f(%d) = %f",x,f(x,v,a,b));

printf(" F(%d) = %f",x,F(x,v,a,b));

getch();
return 0;
}

Application of Poisson Distribution




#include
#include
#include

long fact(int n)
{

if(n<=0)
return 1;

else
return n*fact(n-1);

}

double poisson(int x, double a)
{

if(x<0)
return 0;

else
{
return (exp(-a)*pow(a,x))/fact(x) ;
}
}

int main()
{

int x;
double mean;
clrscr();



printf("enter d value of x & mean: ");
scanf(" %d %lf",&x, &mean);

printf(" p(%d) = %f",x,poisson(x,mean));

getch();
return 0;
}



by Amrender

Triangular Distribution




#include
#include
#include

double f(double x, double a, double b, double c)
{


if(a <= x && x <= b)
{

return (2*(x-a))/((b-a)*(c-a));
}
else if( b < x && x <= c)
{
return 2*(c-x)/((c-b)*(c-a));
}
else
return 0;

}

double F(double x, double a, double b, double c)
{
if(x<=a)
return 0;

else if( a{

return ( (x-a)*(x-a)/((b-a)*(c-a)) );

}
else if(b < x && x <= c )
{

return (1 - (c-x)*(c-x)/((c-b)*(c-a)));

}
else if(x>c)
return 1;
}


int main()
{

double x,a,b,c;
clrscr();



printf("enter d value of x, a, b & : ");
scanf(" %lf %lf %lf %lf",&x, &a, &b, &c);

printf(" f(%.2f) = %f",x,f(x,a,b,c));

printf(" F(%.2f) = %f",x,F(x,a,b,c));

getch();
return 0;
}

)
By Alka (4501/09)

Linear Congruential method ( Random Number generation )





#include
#include
#include
int main()
{
int a,c,x0,m,n1,n2,true;

clrscr();
printf(" enter a, c, x0, m : ");
scanf(" %d %d %d %d", &a, &c, &x0, &m);



n1 = x0;

while(true !=1)
{


n2 = (a*n1+c) % m;

printf(" %.2f\t",(float)n1/m );

if(n2 == x0)
true = 1;

n1 = n2;


}

getch();
return 0;
}

by Amrendra Kumar mca/4549/09

Future Event LIST (Simulation & Modeling)



Script for grocery shop with given inter-arrival/service time distribution assumed

by Amrendra Kumar mca/4549/09


#include
#include
#include
void addevent(int,int);
void depart();
void arrival();


struct eventinfo
{
int type;
int time;
struct eventinfo *next;
} * header;
int inter[9] = {1,1,6,3,7,5,2,4,1};
int service[9] = {4,2,5,4,1,5,4,1,4};
int i=0,j=0;

void main()
{
int t, eventtime;
clrscr();
header = (struct eventinfo *) malloc(sizeof(struct eventinfo));
header ->time=0;
header->next = NULL;
header->type = 0;
t =0;
addevent(0,1);
eventtime = header->next->time;
while(t<=60){if(t == eventtime){printf("\nt=%d ",t);if(header->next->type ==1)
arrival();
else
depart();
if(header->next != NULL)
eventtime = header->next->time;
else
eventtime = 100;
if(i>=9 || j>=9)
eventtime = 100;
}
t++;
if(t>eventtime)
t = eventtime;
}

getch();
}

void addevent(int time, int type)
{
struct eventinfo * node = (struct eventinfo *)malloc(sizeof(struct eventinfo));
struct eventinfo *p, *q;
node->type = type;
node -> time = time;
if(header->next == NULL)
{
header ->next = node;
node->next = NULL;
return ;
}
p = header->next;
q = header;
while((p->time