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
cbcac453
Commit
cbcac453
authored
6 years ago
by
Lucas Hernan Bruzzone Rodriguez
Browse files
Options
Downloads
Patches
Plain Diff
Update newGA.req.cc
parent
ec73b562
No related branches found
Branches containing commit
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
+32
-14
32 additions, 14 deletions
malva/rep/GA/newGA.req.cc
with
32 additions
and
14 deletions
malva/rep/GA/newGA.req.cc
+
32
−
14
View file @
cbcac453
...
...
@@ -20,12 +20,16 @@ skeleton newGA
istream
&
operator
>>
(
istream
&
is
,
Problem
&
pbm
)
{
FILE
*
stream
=
fopen
(
"ejercicio1_cantidad_tareas"
,
"r"
);
char
buffer
[
MAX_BUFFER
];
int
i
;
is
.
getline
(
buffer
,
MAX_BUFFER
,
'\n'
);
is
.
getline
(
buffer
,
MAX_BUFFER
,
'\n'
);
sscanf
(
buffer
,
"%d"
,
&
pbm
.
_dimension
);
cout
<<
buffer
[
3
]
<<
buffer
[
4
]
<<
endl
;
assert
(
false
);
return
is
;
}
...
...
@@ -42,19 +46,31 @@ skeleton newGA
Direction
Problem
::
direction
()
const
{
return
maximize
;
//
return minimize;
//
return maximize;
return
minimize
;
}
int
Problem
::
dimension
()
const
{
return
_dimension
;
}
int
Problem
::
cantEmpleados
()
const
{
return
_cantEmpleados
;
}
Problem
::~
Problem
()
{
}
Rarray
<
Empleado
>&
Problem
::
empleadoss
()
{
return
_empleados
;
}
Rarray
<
int
>&
Problem
::
tareasDiass
()
{
return
_tareasDias
;
}
// Solution --------------------------------------------------------------
Solution
::
Solution
(
const
Problem
&
pbm
)
:
_pbm
(
pbm
),
_var
(
pbm
.
dimension
())
...
...
@@ -120,16 +136,18 @@ skeleton newGA
void
Solution
::
initialize
()
{
for
(
int
i
=
0
;
i
<
_pbm
.
dimension
();
i
++
)
_var
[
i
]
=
rand_int
(
0
,
1
);
iSecret
=
rand
()
%
10
+
1
;
_var
[
i
]
=
rand
()
%
EMPLEADOS
+
1
;
//numero random entre 1 y CANT EMPLEADOS
}
double
Solution
::
fitness
()
{
double
fitness
=
0.0
;
for
(
int
i
=
0
;
i
<
_var
.
size
();
i
++
)
fitness
+=
_var
[
i
];
for
(
int
i
=
0
;
i
<
_var
.
size
();
i
++
)
{
int
tipo
=
_var
[
i
];
fitness
+=
tipo
.
getSueldo
()
*
dias
[
i
];
}
return
fitness
;
}
...
...
@@ -340,8 +358,9 @@ skeleton newGA
{
if
(
rand01
()
<=
probability
[
1
])
{
if
(
sol
.
var
(
i
)
==
1
)
sol
.
var
(
i
)
=
0
;
else
sol
.
var
(
i
)
=
1
;
sol
.
var
(
i
)
=
rand
()
%
EMPLEADOS
+
1
;
//if (sol.var(i)==1) sol.var(i)=0;
//else sol.var(i)=1;
}
}
}
...
...
@@ -409,4 +428,3 @@ skeleton newGA
}
}
#endif
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