Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
FIC_DK_P GA Solving
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
6
Issues
6
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
M3TAL
FIC_DK_P GA Solving
Commits
7d89bfd1
Commit
7d89bfd1
authored
May 15, 2020
by
Alexis Lebis
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding TMP builder for tmp object, as well as ID overflow protection.
Solve the
#5
issue
parent
48b01b2e
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
101 additions
and
2 deletions
+101
-2
main.cpp
application/main.cpp
+1
-0
competency.cpp
src/model/competency.cpp
+33
-0
competency.h
src/model/competency.h
+5
-0
prerequisitesConstraints.cpp
src/model/constraints/prerequisitesConstraints.cpp
+1
-1
professionConstraints.cpp
src/model/constraints/professionConstraints.cpp
+1
-1
course.cpp
src/model/course.cpp
+27
-0
course.h
src/model/course.h
+4
-0
idOverflowException.h
src/model/exception/idOverflowException.h
+25
-0
tools.h
src/model/tools.h
+4
-0
No files found.
application/main.cpp
View file @
7d89bfd1
...
...
@@ -8,6 +8,7 @@
#include <model/problem.h>
#include <model/profession.h>
#include <model/magnitude.h>
#include <model/tools.h>
#include <model/ea/cursus.h>
#include <model/ea/initializer.h>
...
...
src/model/competency.cpp
View file @
7d89bfd1
...
...
@@ -2,11 +2,14 @@
#include "competency.h"
#include "magnitude.h"
#include "tools.h"
#include "exception/magnitudeException.h"
#include "exception/competencyEvolvingException.h"
#include "exception/idOverflowException.h"
int
Competency
::
COMPETENCY_COUNTER
=
0
;
int
Competency
::
COMPETENCY_TMP_COUNTER
=
ID_RANGE_FOR_OBJECT
+
1
;
// === FACTORY
...
...
@@ -37,6 +40,24 @@ Competency Competency::build(double d = 0, std::string name)
}
}
Competency
Competency
::
buildTMP
(
double
d
,
std
::
string
name
)
{
int
id
=
Competency
::
assignID4TMP
();
if
(
name
.
empty
())
name
=
"Competency#"
+
std
::
to_string
(
id
);
try
{
Magnitude
m
=
Magnitude
::
build
(
d
);
return
Competency
(
id
,
m
,
name
);
}
catch
(
MagnitudeException
&
e
)
{
e
.
getMagnitude
().
rebase
();
throw
CompetencyEvolvingException
(
new
Competency
(
id
,
e
.
getMagnitude
(),
name
));
}
}
// === CONSTRUCTOR
Competency
::
Competency
(
int
id
,
Magnitude
m
,
std
::
string
s
)
...
...
@@ -49,9 +70,21 @@ Competency::Competency(int id, Magnitude m, std::string s)
int
Competency
::
assignID
()
{
if
(
Competency
::
COMPETENCY_COUNTER
+
1
>
ID_RANGE_FOR_OBJECT
)
throw
idOverflowException
(
"assignID()@Competency.cpp"
);
return
++
Competency
::
COMPETENCY_COUNTER
;
}
int
Competency
::
assignID4TMP
()
{
if
(
Competency
::
COMPETENCY_TMP_COUNTER
+
1
>
ID_RANGE_FOR_TEMPORARY_OBJECT
)
{
std
::
cout
<<
"INFO: COMPETENCY_TMP_COUNTER was about to overflow: restored to ID_RANGE_OBJECT + 1"
<<
std
::
endl
;
COMPETENCY_TMP_COUNTER
=
ID_RANGE_FOR_OBJECT
+
1
;
}
return
++
Competency
::
COMPETENCY_TMP_COUNTER
;
}
// === FUNCTION
void
Competency
::
evolveTowards
(
Magnitude
&
m
)
...
...
src/model/competency.h
View file @
7d89bfd1
...
...
@@ -24,10 +24,15 @@ class Competency
//STATIC
static
int
COMPETENCY_COUNTER
;
static
int
COMPETENCY_TMP_COUNTER
;
static
int
assignID
();
static
int
assignID4TMP
();
//Called by the tmp builder
public
:
static
Competency
build
(
Magnitude
&
,
std
::
string
s
=
""
);
static
Competency
build
(
double
,
std
::
string
=
""
);
///This builder should be used for TMP element
static
Competency
buildTMP
(
double
,
std
::
string
);
Competency
()
=
default
;
// === FUNCTION
...
...
src/model/constraints/prerequisitesConstraints.cpp
View file @
7d89bfd1
...
...
@@ -96,7 +96,7 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
}
else
{
compByTF
.
at
(
currentTF
).
push_back
(
Competency
::
build
(
currentCompetency
.
c_magnitude
().
value
(),
currentCompetency
.
c_name
()));
compByTF
.
at
(
currentTF
).
push_back
(
Competency
::
build
TMP
(
currentCompetency
.
c_magnitude
().
value
(),
currentCompetency
.
c_name
()));
}
}
}
...
...
src/model/constraints/professionConstraints.cpp
View file @
7d89bfd1
...
...
@@ -16,7 +16,7 @@ std::pair<bool, double> ConstraintsProfession::integrityCheck(Cursus indiv)
for
(
int
i
=
0
;
i
<
this
->
_job
.
prerequisites
().
size
();
i
++
)
{
std
::
string
name
=
this
->
_job
.
prerequisites
().
at
(
i
).
c_name
();
compToAnswer
.
push_back
(
Competency
::
build
(
0
,
name
));
//same name to exploit the Competency::operator== on name equality
compToAnswer
.
push_back
(
Competency
::
build
TMP
(
0
,
name
));
//same name to exploit the Competency::operator== on name equality
}
Course
current
;
...
...
src/model/course.cpp
View file @
7d89bfd1
...
...
@@ -11,8 +11,10 @@
#include "exception/courseECTSException.h"
#include "exception/courseTemporalFrameException.h"
#include "exception/notImplementedException.h"
#include "exception/idOverflowException.h"
int
Course
::
COURSE_COUNTER
=
0
;
int
Course
::
COURSE_TMP_COUNTER
=
ID_RANGE_FOR_OBJECT
+
1
;
// === FACTORY
Course
Course
::
build
(
int
ects
,
std
::
string
name
)
...
...
@@ -27,6 +29,19 @@ Course Course::build(int ects, std::string name)
else
return
Course
(
id
,
ects
,
name
);
}
Course
Course
::
buildTMP
(
int
ects
,
std
::
string
name
)
{
int
id
=
Course
::
assignID4TMP
();
if
(
name
.
empty
())
name
=
"Course#"
+
std
::
to_string
(
id
);
if
(
ects
<
0
)
throw
CourseECTSException
(
new
Course
(
id
,
ects
,
name
));
else
return
Course
(
id
,
ects
,
name
);
}
// === END FACTORY
// === CONSTRUCTOR
...
...
@@ -269,6 +284,18 @@ bool Course::operator==(const Course & c) const
/// Course counter
int
Course
::
assignID
()
{
if
(
Course
::
COURSE_COUNTER
+
1
>
ID_RANGE_FOR_OBJECT
)
throw
idOverflowException
(
"assignID()@Course.cpp"
);
return
++
Course
::
COURSE_COUNTER
;
}
int
Course
::
assignID4TMP
()
{
if
(
Course
::
COURSE_TMP_COUNTER
+
1
>
ID_RANGE_FOR_TEMPORARY_OBJECT
)
{
std
::
cout
<<
"INFO: COURSE_TMP_COUNTER was about to overflow: restored to ID_RANGE_OBJECT + 1"
<<
std
::
endl
;
COURSE_TMP_COUNTER
=
ID_RANGE_FOR_OBJECT
+
1
;
}
return
++
COURSE_TMP_COUNTER
;
}
// === END STATIC
\ No newline at end of file
src/model/course.h
View file @
7d89bfd1
...
...
@@ -55,13 +55,17 @@ class Course
// Static
static
int
COURSE_COUNTER
;
static
int
COURSE_TMP_COUNTER
;
static
int
assignID
();
static
int
assignID4TMP
();
// Constructor
//Course();
Course
(
int
id
,
int
ects
,
std
::
string
name
);
public
:
static
Course
build
(
int
ects
=
0
,
std
::
string
name
=
""
);
static
Course
buildTMP
(
int
ects
=
0
,
std
::
string
name
=
""
);
/// Default constructor. Use Course::build instead !
Course
()
=
default
;
...
...
src/model/exception/idOverflowException.h
0 → 100644
View file @
7d89bfd1
#ifndef SRD_MODEL_EXCEPTION_ID_OVERFLOW_EXCEPTION_H_
#define SRD_MODEL_EXCEPTION_ID_OVERFLOW_EXCEPTION_H_
#include <exception>
#include <string>
class
idOverflowException
:
public
std
::
exception
{
private
:
std
::
string
_msg
;
public
:
idOverflowException
(
std
::
string
buildInfo
)
throw
()
{
this
->
_msg
=
"The id of an object has overflow the maximal value. Where: "
+
buildInfo
;
}
virtual
const
char
*
what
()
const
throw
()
{
return
this
->
_msg
.
c_str
();
}
};
#endif //SRD_MODEL_EXCEPTION_ID_OVERFLOW_EXCEPTION_H_
\ No newline at end of file
src/model/tools.h
View file @
7d89bfd1
...
...
@@ -6,6 +6,10 @@
#include <algorithm>
#include <queue>
#include <random>
#include <limits>
static
const
int
ID_RANGE_FOR_OBJECT
=
10000
;
static
const
int
ID_RANGE_FOR_TEMPORARY_OBJECT
=
std
::
numeric_limits
<
int
>::
max
();
template
<
typename
T
>
/** Searches into vec the element findMe. The class T must have T() defined ( T()=default; is OK) */
...
...
Alexis Lebis
@alexis.lebis
mentioned in issue
#5 (closed)
·
May 15, 2020
mentioned in issue
#5 (closed)
mentioned in issue #5
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment