Final lab

This commit is contained in:
2016-12-05 03:39:36 -08:00
parent 001a46260a
commit 4336cb30e9
161 changed files with 4086 additions and 0 deletions

BIN
lab5/Codes/FSSNW/.DS_Store vendored Normal file

Binary file not shown.

124
lab5/Codes/FSSNW/FSSNW.cpp Normal file
View File

@@ -0,0 +1,124 @@
/**
* @brief Flow shop scheduling with no wait
* @author doc. MSc. Donald Davendra Ph.D.
* @date 3.10.2013
*
* This is a simple class to calculate the makespan of the flowshop with no wait schedule.
*/
/*! \file FSSNW header
\brief A FSSNW header file.
*/
#include "FSSNW.h"
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
cFSSNW::cFSSNW(){
ifstream infile;
infile.open("fss.txt");
if(!infile.is_open()) {
cout << "Error Opening File.\n";
exit(1);
}
else {
infile >> m_Machines;
infile >> m_Jobs;
m_ProcessTime = new float*[m_Machines];
for (int i = 0; i < m_Machines; i++) {
m_ProcessTime[i] = new float[m_Jobs];
}
for (int i = 0; i < (m_Machines); i++) {
for (int j = 0; j < m_Jobs; j++) {
infile >> m_ProcessTime[i][j];
}
}
m_CompletionTime = new float*[m_Machines];
for (int i = 0; i < m_Machines; i++) {
m_CompletionTime[i] = new float[m_Jobs];
}
}
infile.close();
}
cFSSNW::~cFSSNW(){
for (int i = 0; i < m_Machines; i++) {
delete [] m_ProcessTime[i];
}
delete [] m_ProcessTime;
for (int i = 0; i < m_Machines; i++) {
delete [] m_CompletionTime[i];
}
delete [] m_CompletionTime;
}
int cFSSNW::GetMachines(){
return m_Machines;
}
int cFSSNW::GetJobs(){
return m_Jobs;
}
float cFSSNW::Makespan(int *Schedule){
int offset;
double sum = 0;
Initialize();
// Calculate processing time for all jobs on first machine
m_CompletionTime[0][0] = m_ProcessTime[0][Schedule[0]-1];
for (int i = 1; i < m_Machines; i++) {
m_CompletionTime[i][0] = (m_CompletionTime[i-1][0] + m_ProcessTime[i][Schedule[0]-1]);
}
// Calculate for each subsequent job
for (int i = 1; i < m_Jobs; i++) {
for (int j = 0; j < m_Machines; j++) {
if(j == 0){
m_CompletionTime[j][i] = m_CompletionTime[j][i-1] + m_ProcessTime[j][Schedule[i]-1];
}
else{
if(m_CompletionTime[j-1][i] < m_CompletionTime[j][i-1]){
offset = m_CompletionTime[j][i-1] - m_CompletionTime[j-1][i];
for (int k = j - 1; k >= 0; k --) {
m_CompletionTime[k][i] = m_CompletionTime[k][i] + offset;
}
}
m_CompletionTime[j][i] = m_CompletionTime[j-1][i] + m_ProcessTime[j][Schedule[i]-1];
}
}
}
// Calculate the flowtime.
for (int i = 0 ; i < m_Jobs; i++) {
sum += m_CompletionTime[m_Machines - 1][i];
}
return sum;
}
void cFSSNW::Initialize(){
for (int i = 0; i < m_Machines; i++) {
for (int j = 0; j < m_Jobs; j++) {
m_CompletionTime[i][j] = 0;
}
}
}

60
lab5/Codes/FSSNW/FSSNW.h Normal file
View File

@@ -0,0 +1,60 @@
/**
* @brief Flow shop scheduling with no wait
* @author doc. MSc. Donald Davendra Ph.D.
* @date 3.10.2013
*
* This is a simple class to calculate the makespan of the flowshop with no wait schedule.
*/
#ifndef __FSSNW_H__
#define __FSSNW_H__
class cFSSNW{
public:
//! A constructor.
/*!
Constructs the FSSNW class, and assigns the values.
*/
cFSSNW();
//! A destructor.
/*!
Clears the memory.
*/
~cFSSNW();
//! A normal member taking in the schedule and returning the cost.
/*!
\param A flowshop schedule
\return The makespan value
*/
float Makespan(int *Schedule);
//! Returns the number of jobs.
/*!
\param no parameters
\return The number of jobs
*/
int GetJobs();
//! Returns the number of machines.
/*!
\param no parameters
\return The number of machines
*/
int GetMachines();
void Initialize();
private:
//! The processing time matrix.
float** m_ProcessTime;
//! The completion time matrix.
float** m_CompletionTime;
//! The number of jobs.
int m_Jobs;
//! The number of machines.
int m_Machines;
};
#endif

BIN
lab5/Codes/FSSNW/FSSNW.o Normal file

Binary file not shown.

BIN
lab5/Codes/FSSNW/bin/FSSNW Executable file

Binary file not shown.

5
lab5/Codes/FSSNW/fss.txt Normal file
View File

@@ -0,0 +1,5 @@
4 5
5 5 3 6 3
4 4 2 4 4
4 4 3 4 1
3 6 3 2 5

49
lab5/Codes/FSSNW/main.cpp Normal file
View File

@@ -0,0 +1,49 @@
/**
* @brief Flow shop scheduling with no wait
* @author doc. MSc. Donald Davendra Ph.D.
* @date 3.10.2013
*
* This is a simple class to calculate the makespan of the flowshop with no wait schedule.
*/
#include <iostream>
#include "FSSNW.h"
using namespace std;
void JobMakespan(cFSSNW *FSS);
//! the main function.
/*!
\return 0 for successful completion
*/
int main ()
{
//! Initialization of the FSSNW class
cFSSNW* FSSNW = new cFSSNW();
//! Calculate a simple schedule
JobMakespan(FSSNW);
return 0;
}
//! Function to calculate a simple schedule.
/*!
\return no return value
*/
void JobMakespan(cFSSNW *FSSNW){
//! Initilaize a schedule
int *Schedule = new int[FSSNW->GetJobs()];
//! Fill the schedule sequentially
for (int i = 0; i < FSSNW->GetJobs(); i++) {
Schedule[i] = i+1;
}
//! Calculate the makespan of the simple schedule and display it in standard output
cout << "The makespan is: " << FSSNW->Makespan(Schedule) << endl;
//! Delete the schedule
delete [] Schedule;
}

BIN
lab5/Codes/FSSNW/main.o Normal file

Binary file not shown.

27
lab5/Codes/FSSNW/makefile Normal file
View File

@@ -0,0 +1,27 @@
CC = g++
CFLAGS = -c -Wall -std=c99
LDFLAGS =
SOURCES := main.cpp FSSNW.cpp
OBJECTS = $(SOURCES:.cpp=.o)
BINDIR = bin
EXECUTABLE = $(BINDIR)/FSSNW
#-------------------------------------------------------------------------------
ifdef DEBUG
CFLAGS += -DDEBUG=1
endif
#-------------------------------------------------------------------------------
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
-mkdir -p $(BINDIR)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
#-------------------------------------------------------------------------------
.c.o:
$(CC) $(CFLAGS) $< -o $@
clean:
rm -f *.o
rm -r $(BINDIR)