-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstance.cpp
111 lines (90 loc) · 2.12 KB
/
instance.cpp
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
104
105
106
107
108
109
110
111
/*
* File: instance.cpp
* Author: diepeerk
*
* Created on 4 de octubre de 2010, 11:48 AM
*/
#include "instance.h"
#include <fstream>
#include <cstring>
#include <cstdlib>
using namespace std;
instance::instance() {
}
instance::instance(const instance& orig) {
}
/*libero memoria de matrices coverage y preference*/
instance::~instance() {
for(int cD=0; cD<days; cD++){
free(coverage[cD]);
}
for(int cN=0; cN<nurses;cN++){
free(preference[cN]);
}
free(coverage);
free(preference);
}
void instance::read(char* file)
{
ifstream data;
data.open(file);
data >> nurses >> days >> shifts;
/*asigno memoria dinamicamente a matriz de cobertura para obtener coverage[days][shifts] */
coverage = (int**)malloc(days*sizeof(int*));
for (int cD=0; cD<days; cD++){
coverage[cD] = (int*)malloc(shifts*sizeof(int*));
}
/*asigno memoria dinamicamente a matriz de preferencias para obtener preference[nurses][days*shifts] */
preference = (int**)malloc(nurses*sizeof(int*));
for(int cN=0; cN<nurses;cN++){
preference[cN] = (int*)malloc(days*shifts*sizeof(int*));
}
/*Lleno las matrices como corresponde*/
for(int i = 0; i < days; i++){
for(int j = 0; j < shifts; j++)
data >> coverage[i][j];
}
for(int i = 0; i < nurses; i++){
for(int j = 0; j < days*shifts; j++)
data >> preference[i][j];
}
data.close();
}
int instance::getNurses()
{
return nurses;
}
int instance::getDays()
{
return days;
}
int instance::getShifts()
{
return shifts;
}
int **instance::getCoverageMatrix(){
return coverage;
}
int **instance::getPreferenceMatrix(){
return preference;
}
void instance::printCoverageMatrix()
{
int cD, cS;
for(cD=0;cD<days;cD++){
printf("\n");
for(cS=0;cS<shifts;cS++){
printf("%d\t",coverage[cD][cS]);
}
}
}
void instance::printPreferenceMatrix()
{
int cN,cDS;
for(cN=0;cN<nurses;cN++){
printf("\n");
for(cDS=0;cDS<(shifts*days);cDS++){
printf("%d\t",preference[cN][cDS]);
}
}
}