Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AEPractico
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gonzalo Menendez Berch
AEPractico
Commits
2f93a4ef
Commit
2f93a4ef
authored
6 years ago
by
Lucas Hernan Bruzzone Rodriguez
Browse files
Options
Downloads
Patches
Plain Diff
Update newGA.req.cc
parent
fa523a16
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
malva/rep/GA/newGA.req.cc
+87
-18
87 additions, 18 deletions
malva/rep/GA/newGA.req.cc
with
87 additions
and
18 deletions
malva/rep/GA/newGA.req.cc
+
87
−
18
View file @
2f93a4ef
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#define INC_REQ_newGA
#define INC_REQ_newGA
#include
"newGA.hh"
#include
"newGA.hh"
#include
<math.h>
#include
<math.h>
#include
<sstream>
skeleton
newGA
skeleton
newGA
{
{
...
@@ -20,16 +20,81 @@ skeleton newGA
...
@@ -20,16 +20,81 @@ skeleton newGA
istream
&
operator
>>
(
istream
&
is
,
Problem
&
pbm
)
istream
&
operator
>>
(
istream
&
is
,
Problem
&
pbm
)
{
{
/*
FILE
*
stream
=
fopen
(
"ejercicio1_cantidad_tareas"
,
"r"
);
char buffer[MAX_BUFFER];
char buffer[MAX_BUFFER];
int i;
int i;
is
.
getline
(
buffer
,
MAX_BUFFER
,
'\n'
);
is.getline(buffer,MAX_BUFFER,'\n');
sscanf(buffer,"%d",&pbm._dimension);
sscanf(buffer,"%d",&pbm._dimension);
*/
string
line
;
ifstream
cantTareasFile
(
"datos_cantidad_tareas.txt"
);
getline
(
cantTareasFile
,
line
);
pbm
.
_dimension
=
stoi
(
line
);
//string line;
ifstream
cantEmpleadosFile
(
"datos_cantidad_empleados.txt"
);
getline
(
cantEmpleadosFile
,
line
);
pbm
.
_cantEmpleados
=
stoi
(
line
);
string
line23
;
ifstream
datosEmpleadosFile
(
"datos_empleados.txt"
);
getline
(
datosEmpleadosFile
,
line23
);
getline
(
datosEmpleadosFile
,
line23
);
int
i1
;
int
counter1
=
0
;
stringstream
os
(
line23
);
/*Rarray<Empleado> tempEmpleados*/
pbm
.
_empleados
=
Rarray
<
Empleado
>
(
pbm
.
_cantEmpleados
);
//pbm._empleados = tempEmpleados;
for
(
int
zz
=
0
;
zz
<
pbm
.
_cantEmpleados
;
zz
++
)
{
//+pbm._empleados[zz] = new Empleado;
pbm
.
_empleados
[
zz
].
_sueldo
=
0
;
pbm
.
_empleados
[
zz
].
_habilidad
=
0
;
pbm
.
_empleados
[
zz
].
_horas
=
0
;
}
while
(
os
>>
i1
)
{
pbm
.
_empleados
[
counter1
].
_horas
=
i1
;
cout
<<
pbm
.
_empleados
[
counter1
].
_horas
<<
endl
;
counter1
+=
1
;
}
getline
(
datosEmpleadosFile
,
line
);
float
f1
;
int
counter2
=
0
;
stringstream
os2
(
line
);
while
(
os2
>>
f1
)
{
pbm
.
_empleados
[
counter2
].
_habilidad
=
f1
;
counter2
+=
1
;
}
getline
(
datosEmpleadosFile
,
line
);
int
i2
;
int
counter3
=
0
;
stringstream
os3
(
line
);
while
(
os3
>>
i2
)
{
pbm
.
_empleados
[
counter3
].
_sueldo
=
i2
;
counter3
+=
1
;
}
//string line;
ifstream
datosTareasFile
(
"datos_tareas.txt"
);
getline
(
datosTareasFile
,
line
);
pbm
.
_cantDias
=
stoi
(
line
);
getline
(
datosTareasFile
,
line
);
getline
(
datosTareasFile
,
line
);
int
i3
;
int
counter4
=
0
;
stringstream
os4
(
line
);
while
(
os4
>>
i3
)
{
pbm
.
_tareasEsf
[
counter4
]
=
i3
;
counter4
+=
1
;
}
cout
<<
buffer
[
3
]
<<
buffer
[
4
]
<<
endl
;
assert
(
false
);
return
is
;
return
is
;
}
}
...
@@ -61,15 +126,18 @@ skeleton newGA
...
@@ -61,15 +126,18 @@ skeleton newGA
Problem
::~
Problem
()
Problem
::~
Problem
()
{
{
}
}
int
Problem
::
cantDias
()
const
Rarray
<
Empleado
>&
Problem
::
empleadoss
()
{
return
_cantDias
;
}
Rarray
<
Empleado
>
Problem
::
empleados
()
const
{
{
return
_empleados
;
return
_empleados
;
}
}
Rarray
<
int
>
&
Problem
::
tareas
Diass
()
Rarray
<
int
>
Problem
::
tareas
Esf
()
const
{
{
return
_tareas
Dias
;
return
_tareas
Esf
;
}
}
// Solution --------------------------------------------------------------
// Solution --------------------------------------------------------------
...
@@ -136,16 +204,17 @@ skeleton newGA
...
@@ -136,16 +204,17 @@ skeleton newGA
void
Solution
::
initialize
()
void
Solution
::
initialize
()
{
{
for
(
int
i
=
0
;
i
<
_pbm
.
dimension
();
i
++
)
for
(
int
i
=
0
;
i
<
_pbm
.
dimension
();
i
++
)
_
t
ar
easSolucion
[
i
]
=
rand
()
%
_cantEmpleados
+
1
;
//numero random entre 1 y CANT EMPLEADOS
_
v
ar
[
i
]
=
rand
()
%
_
pbm
.
cantEmpleados
()
+
1
;
//numero random entre 1 y CANT EMPLEADOS
}
}
double
Solution
::
fitness
()
double
Solution
::
fitness
()
{
{
double
fitness
=
0.0
;
double
fitness
=
0.0
;
Rarray
<
Empleado
>
grupo
=
_pbm
.
empleados
();
for
(
int
i
=
0
;
i
<
_tareasSolucion
.
size
();
i
++
)
{
Rarray
<
int
>
soFun
=
_pbm
.
tareasEsf
();
int
tipo
=
empleadoss
[
i
];
for
(
int
i
=
0
;
i
<
_var
.
size
();
i
++
)
{
fitness
+=
tipo
.
sueldo
()
*
tareasDiass
[
i
];
Empleado
tipo
=
grupo
[
i
];
fitness
+=
tipo
.
_sueldo
*
soFun
[
i
];
}
}
return
fitness
;
return
fitness
;
}
}
...
@@ -292,7 +361,7 @@ skeleton newGA
...
@@ -292,7 +361,7 @@ skeleton newGA
{
{
int
i
=
0
;
int
i
=
0
;
Rarray
<
int
>
aux
(
sol1
.
pbm
().
dimension
());
Rarray
<
int
>
aux
(
sol1
.
pbm
().
dimension
());
aux
=
sol2
.
_tareasSolucion
();
aux
=
sol2
.
array_var
();
int
limit
=
rand_int
((
sol1
.
pbm
().
dimension
()
/
2
)
+
1
,
sol1
.
pbm
().
dimension
()
-
1
);
int
limit
=
rand_int
((
sol1
.
pbm
().
dimension
()
/
2
)
+
1
,
sol1
.
pbm
().
dimension
()
-
1
);
int
limit2
=
rand_int
(
0
,
limit
-
1
);
int
limit2
=
rand_int
(
0
,
limit
-
1
);
...
@@ -357,7 +426,7 @@ skeleton newGA
...
@@ -357,7 +426,7 @@ skeleton newGA
{
{
if
(
rand01
()
<=
probability
[
1
])
if
(
rand01
()
<=
probability
[
1
])
{
{
sol
.
var
(
i
)
=
rand
()
%
cantEmpleados
+
1
;
sol
.
var
(
i
)
=
rand
()
%
sol
.
pbm
().
cantEmpleados
()
+
1
;
//if (sol.var(i)==1) sol.var(i)=0;
//if (sol.var(i)==1) sol.var(i)=0;
//else sol.var(i)=1;
//else sol.var(i)=1;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment