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

115
lab5/Codes/FSSB/FSSB.cpp Normal file
View File

@@ -0,0 +1,115 @@
/**
* @brief Flow shop with blocking
* @author doc. MSc. Donald Davendra Ph.D.
* @date 3.10.2013
*
* This is a simple class to calculate the makespan of the flowshop with blocking schedule.
*/
/*! \file FSSB.h
\brief A FSSB header file.
*/
#include "FSSB.h"
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
cFSSB::cFSSB(){
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();
}
cFSSB::~cFSSB(){
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 cFSSB::GetMachines(){
return m_Machines;
}
int cFSSB::GetJobs(){
return m_Jobs;
}
float cFSSB::Makespan(int *Schedule){
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]){
m_CompletionTime[j-1][i] = m_CompletionTime[j][i-1];
}
m_CompletionTime[j][i] = m_CompletionTime[j-1][i] + m_ProcessTime[j][Schedule[i]-1];
}
}
}
// Return the makespan.
return m_CompletionTime[m_Machines-1][m_Jobs-1];
}
void cFSSB::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/FSSB/FSSB.h Normal file
View File

@@ -0,0 +1,60 @@
/**
* @brief Flow shop with blocking
* @author doc. MSc. Donald Davendra Ph.D.
* @date 3.10.2013
*
* This is a simple class to calculate the makespan of the flowshop with blocking schedule.
*/
#ifndef __FSSB_H__
#define __FSSB_H__
class cFSSB{
public:
//! A constructor.
/*!
Constructs the FSSB class, and assigns the values.
*/
cFSSB();
//! A destructor.
/*!
Clears the memory.
*/
~cFSSB();
//! 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/FSSB/FSSB.o Normal file

Binary file not shown.

BIN
lab5/Codes/FSSB/bin/FSSB Executable file

Binary file not shown.

5
lab5/Codes/FSSB/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/FSSB/main.cpp Normal file
View File

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

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

Binary file not shown.

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

@@ -0,0 +1,27 @@
CC = g++
CFLAGS = -c -Wall -std=c99
LDFLAGS =
SOURCES := main.cpp FSSB.cpp
OBJECTS = $(SOURCES:.cpp=.o)
BINDIR = bin
EXECUTABLE = $(BINDIR)/FSSB
#-------------------------------------------------------------------------------
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)