Tuesday, March 15, 2011

Wee Willy Widget Shop ( Discrete Event System Simulation )

Problem: The Wee Willy Widget Shop overhauls and repair all types of widgets. The shop consists of five work stations, and the flow of jobs through the shop is as depicted here:
Regular jobs arrive at station A at the rate of one every 15 ± 13 minutes. Rush jobs arrive every 4 ± 3 hours and are given a higher priority except at station C, where they are put on a conveyor and sent through a cleaning and degreasing operation along with all other jobs. For jobs the first time through a station, processing and repair times are as follows:




The times listed above hold for all jobs that follow one of the two sequences A → B → C → D → E or A → B → D → E. However, about 10% of the jobs coming out of station D are sent back to B for further work (which takes 30 ± 10 minutes) and then are sent to D and finally to E.
Every 2 hours, beginning 1 hour after opening, the degreasing station C shuts down for routine maintenance, which takes 10 ± 1 minute. However, this routine maintenance does not begin until the current widget, if any, has completed its processing.
(a) Make three independent replications of the simulation model, where one replication equals an 8-hour simulation run, preceded by a 2-hour initialization run. The three sets of output represent three typical days. The main performance measure of interest is mean response time per job, where a response time is the total time a job spends in the shop. The shop is never empty in the morning, but the model will be empty without the initialization phase. So run the model for a 2-hour initialization period and collect statistics from time 2 hours to time 10 hours. This "warm-up" period will reduce the downward bias in the estimate of mean response time. Note that the 2-hour warm-up is a device to load a simulation model to some more realistic level than empty. From each of the three independent replications, obtain an estimate of mean response time. Also obtain an overall estimate, the sample average of the three estimates.
(b) Management is considering putting one additional worker at the busiest station (A, B, D, or E). Would this significantly improve mean response time?
(c) As an alternative to part (b), management is considering replacing machine C with a faster one that processes a widget in only 14 minutes. Would this significantly improve mean response time?


Solution: Code is written in C++ and there is also a pdf file containing the analysis for all three parts of this problem. It is available here.

Catenary - shape of a chain hanging from two points

Problem: Given a chain (string) or length L and it is hanged somewhere by fixed its both endpoints, but the euclidean distance between endpoints in 3D is less than L. And the chain have μ mass per unit length. Determine the shape of the resulting curve.


Commentary: Shape formed is known as Catenary in literature. Solution of this problem is precisely the shape of garlands hanging in weddings or temples. Mathematical treatment of this problem leads to some very interesting insight into the physical characteristics of these types of curves.


Analysis: A nearly complete analysis of this problem is given at http://en.wikipedia.org/wiki/Catenary#Alternative_analysis

Coding: Even though the equations are given on wikipedia page, it is unclear how to code to get the shape of curve given two endpoints and length of the string. But this problem was thoroughly discussed in NSDE lecture 04 (12-01-2011) by Prof. Atanu Mohanty. He gave some hints regarding how to implement it in C.
If you are interested in seeing the code it is available here.

Result:

Tuesday, September 7, 2010

Plotting a basic 2D graph using C + gnuplot (Tutorial)

In this tutorial we will learn how to draw a graph using ANSI C language with the help of gnuplot utility.

Step 1 write a c program using any editor. (here file name is plot.c) 

/*
 *      file: plot.c
 *
 *      Copyright 2010 Rooparam Choudhary <rooparam@rishi.serc.iisc.ernet.in>
 *
 *      Date : 07.09.2010
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *    
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *    
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 *
 */


#include <stdio.h>

double func ( double x ) {
    if ( x < 0 )
        return 0 ;
    if ( x < 2 )
        return x * x ;

    return 16.0 / ( x * x ) ;
}

/*
 * output will be in 2 coloumns
 * 1 column contains x-axis values
 * 2 column contains y-axis {or f(x) } values corresponding to x-value
 */

int main ( ) {
    double x = 0.0;     // initial value
    double x_max = 5.0;
    double step = 0.01;
   
    printf ( "# x \t f(x) \n" );

    while ( x <= x_max ) {
        printf ( "%.3f \t %.3f \n", x, func(x) );
        x += step;
    }

    return 0;
}


Step 2 compile it and run it and grab the output in plot.txt file

            $ cc plot.c
            $ ./a.out >plot.txt

Step 3 Draw using gnuplot

            $ gnuplot
gnuplot> plot "./plot.txt" with lines



OK folks.
Tutorial is over.

This was just an introduction for plotting basic graphs. For more plotting tutorials and advanced plotting, just visit gnuplot .

See ya later.