Repository navigation
Expand file tree
/
Copy pathsis1.c
More file actions
executable file
·103 lines (88 loc) · 4.2 KB
/
Copy pathsis1.c
File metadata and controls
executable file
·103 lines (88 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* ------------------------------------------------------------------------- *
* This program simulates a simple (s,S) inventory system using demand read *
* from a text file. Backlogging is permitted and there is no delivery lag. *
* The output statistics are the average demand and order per time interval *
* (they should be equal), the relative frequency of setup and the time *
* averaged held (+) and short (-) inventory levels. *
* *
* NOTE: use 0 <= MINIMUM < MAXIMUM, i.e., 0 <= s < S. *
* *
* Name : sis1.c (Simple Inventory System, version 1) *
* Authors : Steve Park & Dave Geyer *
* Language : ANSI C *
* Latest Revision : 12-08-95 *
* ------------------------------------------------------------------------- */
#include <stdio.h>
#include <stdlib.h>
#define FILENAME "sis1.dat" /* input data file */
#define MINIMUM 20 /* 's' inventory policy parameter */
#define MAXIMUM 80 /* 'S' inventory policy parameter */
#define sqr(x) ((x) * (x))
/* ======================== */
static long GetDemand(FILE *fp)
/* ======================== */
{
long d;
if (fscanf(fp, "%ld\n", &d) != 1) {
fprintf(stderr, "Error: unreadable demand in data file.\n");
exit(EXIT_FAILURE);
}
return (d);
}
/* ============== */
int main(void)
/* ============== */
{
FILE *fp; /* demand data file */
long index = 0; /* time interval index */
long inventory = MAXIMUM; /* current inventory level */
long demand; /* amount of demand */
long order; /* amount of order */
struct { /* sum of ... */
double setup; /* setup instances */
double holding; /* inventory held (+) */
double shortage; /* inventory short (-) */
double order; /* orders */
double demand; /* demands */
} sum = { 0.0, 0.0, 0.0, 0.0, 0.0 };
fp = fopen(FILENAME, "r");
if (fp == NULL) {
fprintf(stderr, "Cannot open input file %s\n", FILENAME);
return (1);
}
while (!feof(fp)) {
index++;
if (inventory < MINIMUM) { /* place an order */
order = MAXIMUM - inventory;
sum.setup++;
sum.order += order;
}
else /* no order */
order = 0;
inventory += order; /* there is no delivery lag */
demand = GetDemand(fp);
sum.demand += demand;
if (inventory > demand)
sum.holding += (inventory - 0.5 * demand);
else {
sum.holding += sqr(inventory) / (2.0 * demand);
sum.shortage += sqr(demand - inventory) / (2.0 * demand);
}
inventory -= demand;
}
if (inventory < MAXIMUM) { /* force the final inventory to */
order = MAXIMUM - inventory; /* match the initial inventory */
sum.setup++;
sum.order += order;
inventory += order;
}
printf("\nfor %ld time intervals ", index);
printf("with an average demand of %6.2f\n", sum.demand / index);
printf("and policy parameters (s, S) = (%d, %d)\n\n", MINIMUM, MAXIMUM);
printf("average order ............ = %6.2f\n", sum.order / index);
printf("setup frequency .......... = %6.2f\n", sum.setup / index);
printf("average holding level .... = %6.2f\n", sum.holding / index);
printf("average shortage level ... = %6.2f\n", sum.shortage / index);
fclose(fp);
return (0);
}