Created
May 2, 2009 16:43
-
-
Save raptium/105618 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r c7fe4a7e8021 .hgignore | |
--- a/.hgignore Sat May 02 23:06:23 2009 +0800 | |
+++ b/.hgignore Sun May 03 00:48:04 2009 +0800 | |
@@ -7,3 +7,4 @@ syntax: glob | |
*~ | |
simulation | |
*.dSYM | |
+*.dat | |
diff -r c7fe4a7e8021 lst.c | |
--- a/lst.c Sat May 02 23:06:23 2009 +0800 | |
+++ b/lst.c Sun May 03 00:48:04 2009 +0800 | |
@@ -27,34 +27,37 @@ void AddElment(LIST list, void *value) { | |
node->value = value; | |
node->next = NULL; | |
- if (list->head == NULL) | |
- list->head = node; | |
- else if (list->tail == NULL) | |
+ if (list->tail == NULL) | |
list->tail = node; | |
else { | |
list->tail->next = node; | |
list->tail = node; | |
} | |
+ if (list->head == NULL) { | |
+ list->head = node; | |
+ } | |
} | |
LIST GetRestList(LIST list) { | |
+ LIST new_list; | |
if (list == NULL) | |
return NULL; | |
- if (list->head->next == list->tail) { | |
- list->head = list->tail; | |
- list->tail = NULL; | |
- return list; | |
+ if (list->head == list->tail) { | |
+ return NULL; | |
} | |
- list->head = list->head->next; | |
+ new_list = (LIST)malloc(sizeof(ListCDT)); | |
+ new_list->head = list->head->next; | |
+ new_list->tail = list->tail; | |
return list; | |
} | |
int CountList(LIST list) { | |
- LIST temp = list; | |
+ NODE node; | |
int length = 0; | |
- while (temp != NULL) { | |
+ node = list->head; | |
+ while (node) { | |
length++; | |
- temp = GetRestList(temp); | |
+ node = node->next; | |
} | |
return length; | |
} | |
@@ -64,6 +67,7 @@ LIST AddEvent(LIST evtlist, EVENT evt) { | |
LIST tmplist, tmplist2; | |
tmpevent = (EVENT)malloc(sizeof(EventCDT)); | |
if (evtlist == NULL) { | |
+ tmplist = CreateList(); | |
AddElment(evtlist, evt); | |
return evtlist; | |
} | |
diff -r c7fe4a7e8021 makefile | |
--- a/makefile Sat May 02 23:06:23 2009 +0800 | |
+++ b/makefile Sun May 03 00:48:04 2009 +0800 | |
@@ -1,8 +1,9 @@ | |
CFLAGS=-Wall -g | |
+CC=gcc | |
all: simulation | |
simulation: simulation.c lst.o | |
clean: | |
- rm *.o simulation | |
+ rm *.o simulation | |
\ No newline at end of file | |
diff -r c7fe4a7e8021 simulation.c | |
--- a/simulation.c Sat May 02 23:06:23 2009 +0800 | |
+++ b/simulation.c Sun May 03 00:48:04 2009 +0800 | |
@@ -42,6 +42,7 @@ int main(void) { | |
gets(machFileName); | |
printf("Please input the product file's name:"); | |
gets(prdFileName); | |
+ | |
//get data | |
GetMachine(machFileName); | |
GetProduct(prdFileName); | |
@@ -119,6 +120,7 @@ void GetProduct(char *file_name) { | |
fscanf(pFile, "%d", &pdtSum); | |
pdtList = CreateList(); | |
tmpProduct = (PRODUCT)malloc(sizeof(ProductCDT)); | |
+ tmpProcess = (PROCESS)malloc(sizeof(ProcessCDT)); | |
while (!feof(pFile)) { | |
fscanf(pFile, "%d,%s,%f,%f,%f", &tmpProduct->pdt_id, tmpProduct->pdt_name, &tmpProduct->mArrTime, &tmpProduct->dueDate_lower, &tmpProduct->dueDate_upper); | |
tmpProduct->pcssQueue = CreateList(); //product process queue | |
@@ -142,12 +144,15 @@ void GetProduct(char *file_name) { | |
AddElment(pdtList, tmpProduct); | |
} | |
fclose(pFile); | |
+ free(tmpProcess); | |
+ free(tmpProduct); | |
} | |
void InitializeEvent() { | |
int i; | |
//event of product arrival | |
+ tmpEvent = (EVENT)malloc(sizeof(EventCDT)); | |
tmpList = pdtList; | |
for (i = 0; i < pdtSum; i++) { | |
tmpProduct = (PRODUCT)tmpList->head->value; | |
@@ -175,11 +180,11 @@ void InitializeEvent() { | |
AddEvent(evtList, tmpEvent); | |
tmpList = GetRestList(tmpList); | |
} | |
+ free(tmpEvent); | |
} | |
void ProductArrival() { | |
int i; | |
- PROCESS tmpProccess; | |
//wait time | |
tmpList = machList; | |
@@ -213,7 +218,7 @@ void ProductArrival() { | |
newEvent = (EVENT)malloc(sizeof(EventCDT)); | |
newEvent->evtProduct = tmpEvent->evtProduct; | |
newEvent->pcssQueue = newEvent->evtProduct->pcssQueue; | |
- tmpProccess = (PROCESS)newEvent->pcssQueue->head; | |
+ tmpProcess = (PROCESS)newEvent->pcssQueue->head; | |
newEvent->evtMachine = tmpProcess->pcssMachine; | |
newEvent->pcssTime = Exponential(tmpProcess->pcssTime); | |
newEvent->dueTime = tmpEvent->dueTime; | |
@@ -407,7 +412,7 @@ void seed() { | |
float randf() { | |
- return (float)rand() / RAND_MAX; | |
+ return (float)rand() / RAND_MAX; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment