Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSMOn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Peter Frank Perroni
CSMOn
Commits
529d40c5
Commit
529d40c5
authored
7 years ago
by
Peter Frank Perroni
Browse files
Options
Downloads
Patches
Plain Diff
Updated project files
parent
48a2c9da
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
Makefile
+17
-0
17 additions, 0 deletions
Makefile
cpp/Makefile
+13
-0
13 additions, 0 deletions
cpp/Makefile
cpp/pso_example.cpp
+118
-0
118 additions, 0 deletions
cpp/pso_example.cpp
python/Makefile
+5
-3
5 additions, 3 deletions
python/Makefile
python/pso_example.py
+1
-1
1 addition, 1 deletion
python/pso_example.py
with
154 additions
and
4 deletions
Makefile
0 → 100644
+
17
−
0
View file @
529d40c5
.PHONY
:
all clean
all
:
CSMOn CSMOn_wrapper cpp_example
CSMOn
:
$(
MAKE
)
-C
cpp
CSMOn_wrapper
:
$(
MAKE
)
-C
python
cpp_example
:
cpp/pso_example.cpp
g++
-o
cpp/pso_example cpp/pso_example.cpp cpp/PSO.o cpp/CSMOn.o
-Wall
-pedantic-errors
clean
:
$(
MAKE
)
-i
-C
cpp clean
$(
MAKE
)
-i
-C
python clean
This diff is collapsed.
Click to expand it.
cpp/Makefile
0 → 100644
+
13
−
0
View file @
529d40c5
FONTS
=
PSO.cpp CSMOn.cpp
OBJECTS
=
$(
FONTS:.cpp
=
.o
)
FLAGS
=
-Wall
-pedantic-errors
.PHONY
:
all clean
all
:
$(OBJECTS)
%.o
:
%.cpp
g++
$<
-c
-o
$@
$(
FLAGS
)
-fPIC
clean
:
rm
$(
OBJECTS
)
This diff is collapsed.
Click to expand it.
cpp/pso_example.cpp
0 → 100644
+
118
−
0
View file @
529d40c5
/*
* Copyright (c) 2017, Peter Frank Perroni (pfperroni@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Additionally, if used for any scientific purpose, the following reference
* must be cited:
*
* Peter Frank Perroni, Daniel Weingaertner, and Myriam Regattieri Delgado.
* 2017. Estimating Stop Conditions of Swarm Based Stochastic Metaheuristic
* Algorithms. In Proceedings of GECCO '17, Berlin, Germany, July 15-19, 2017,
* pg 43-50. DOI: http://dx.doi.org/10.1145/3071178.3071326
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* @file
*
* This file provides an implementation example to call CSMOn.
*
* @date 02/Jul/2017
* @author Peter Frank Perroni (pfperroni@gmail.com)
*/
#include
<stdio.h>
#include
<string.h>
#include
<iostream>
#include
"PSO.hpp"
#include
"CSMOn.hpp"
using
namespace
std
;
double
fitnessFunction
(
double
*
x
,
int
n
);
int
main
(
int
argc
,
char
*
argv
[]){
// Replicate (and adapt) this block of code for each different search method you want to develop.
// Begin template.
if
(
argc
>=
11
&&
strcmp
(
argv
[
1
],
"pso"
)
==
0
){
double
w
,
c1
,
c2
,
s1
,
s2
,
R
;
int
i
,
n
,
p
,
M
;
// Read input parameters to be sent to the search method.
for
(
i
=
2
;
i
<
19
;
i
+=
2
){
if
(
strcmp
(
argv
[
i
],
"-w"
)
==
0
)
w
=
atof
(
argv
[
i
+
1
]);
else
if
(
strcmp
(
argv
[
i
],
"-c1"
)
==
0
)
c1
=
atof
(
argv
[
i
+
1
]);
else
if
(
strcmp
(
argv
[
i
],
"-c2"
)
==
0
)
c2
=
atof
(
argv
[
i
+
1
]);
else
if
(
strcmp
(
argv
[
i
],
"-n"
)
==
0
)
n
=
atoi
(
argv
[
i
+
1
]);
else
if
(
strcmp
(
argv
[
i
],
"-p"
)
==
0
)
p
=
atoi
(
argv
[
i
+
1
]);
else
if
(
strcmp
(
argv
[
i
],
"-s1"
)
==
0
)
s1
=
atof
(
argv
[
i
+
1
]);
else
if
(
strcmp
(
argv
[
i
],
"-s2"
)
==
0
)
s2
=
atof
(
argv
[
i
+
1
]);
else
if
(
strcmp
(
argv
[
i
],
"-M"
)
==
0
)
M
=
atoi
(
argv
[
i
+
1
]);
else
if
(
strcmp
(
argv
[
i
],
"-R"
)
==
0
)
R
=
atof
(
argv
[
i
+
1
]);
}
cout
<<
"[CSMOn] Called search method PSO with parameters: s1="
<<
s1
<<
", s2="
<<
s2
<<
", w="
<<
w
<<
", c1="
<<
c1
<<
", c2="
<<
c2
<<
", n="
<<
n
<<
", p="
<<
p
<<
", M="
<<
M
<<
", R="
<<
R
<<
endl
;
// Search method instantiation.
PSO
*
pso
=
new
PSO
(
fitnessFunction
,
s1
,
s2
,
p
,
n
,
w
,
c1
,
c2
);
// CSMOn instantiation and execution.
CSMOn
*
csmon
=
new
CSMOn
(
pso
,
M
,
R
,
0
);
csmon
->
run
();
// Read the final results.
double
*
bestPos
=
new
double
[
n
];
csmon
->
getBestPos
(
bestPos
);
cout
<<
endl
<<
"[ "
;
for
(
i
=
0
;
i
<
n
;
i
++
){
// Send the final result back to Python caller.
cout
<<
bestPos
[
i
]
<<
", "
;
}
cout
<<
" ]"
<<
endl
;
// Send any parameter you want back to Python caller.
cout
<<
"nEvals: "
<<
csmon
->
getNEvals
()
<<
", Fitness: "
<<
csmon
->
getFitness
()
<<
endl
;
// Remind to clear any object that is not owned by Python caller.
delete
bestPos
;
delete
pso
;
delete
csmon
;
}
// End template.
else
{
cout
<<
"Wrong Parameters !"
<<
endl
;
cout
<<
"Options:"
<<
endl
;
cout
<<
" pso -w <w-value> -c1 <c1-value> -c2 <c2-value> -n <n-dimensions> -p <n-particles> -s1 <lower_bound> -s2 <upper-bound> -M <max-evals> -R <relaxation>"
<<
endl
;
}
return
0
;
}
/**
* @brief Fitness function implementation.
*
* Put your fitness function here.
*/
double
fitnessFunction
(
double
*
x
,
int
n
){
double
s
=
0
;
for
(
int
i
=
0
;
i
<
n
;
i
++
){
s
+=
(
x
[
i
]
+
2
)
*
(
x
[
i
]
+
2
)
-
10
*
cos
(
2
*
PI
*
(
x
[
i
]
+
2
));
}
return
10
*
n
+
s
;
}
This diff is collapsed.
Click to expand it.
python/Makefile
+
5
−
3
View file @
529d40c5
FONTES
=
../cpp/PSO.cpp ../cpp/CSMOn.cpp CSMOn_wrapper.cpp
FONTS
=
CSMOn_wrapper.cpp
OBJECTS
=
$(
FONTES:.cpp
=
.o
)
DEPENDENCIES
=
../cpp/PSO.o ../cpp/CSMOn.o
OBJECTS
=
$(
FONTS:.cpp
=
.o
)
FLAGS
=
-Wall
-pedantic-errors
-fPIC
FLAGS
=
-Wall
-pedantic-errors
-fPIC
.PHONY
:
all clean
.PHONY
:
all clean
...
@@ -7,10 +8,11 @@ FLAGS=-Wall -pedantic-errors -fPIC
...
@@ -7,10 +8,11 @@ FLAGS=-Wall -pedantic-errors -fPIC
all
:
CSMOn_wrapper
all
:
CSMOn_wrapper
CSMOn_wrapper
:
$(OBJECTS)
CSMOn_wrapper
:
$(OBJECTS)
g++
-o
$@
.so
$^
$(
FLAGS
)
-shared
g++
-o
$@
.so
$^
$(
DEPENDENCIES
)
$(
FLAGS
)
-shared
%.o
:
%.cpp
%.o
:
%.cpp
g++
-I
../cpp
$<
-c
-o
$@
$(
FLAGS
)
g++
-I
../cpp
$<
-c
-o
$@
$(
FLAGS
)
clean
:
clean
:
rm
$(
OBJECTS
)
CSMOn.pyc fitnessFunction.pyc
rm
$(
OBJECTS
)
CSMOn.pyc fitnessFunction.pyc
This diff is collapsed.
Click to expand it.
python/pso_example.py
+
1
−
1
View file @
529d40c5
...
@@ -41,7 +41,7 @@ s1=Param("s1", d=-5.12)
...
@@ -41,7 +41,7 @@ s1=Param("s1", d=-5.12)
s2
=
Param
(
"
s2
"
,
d
=
5.12
)
s2
=
Param
(
"
s2
"
,
d
=
5.12
)
w
=
Param
(
"
w
"
,
d
=-
0.5
)
w
=
Param
(
"
w
"
,
d
=-
0.5
)
c1
=
Param
(
"
c1
"
,
d
=
0.2
)
c1
=
Param
(
"
c1
"
,
d
=
0.2
)
c2
=
Param
(
"
c2
"
,
d
=
0.
2
)
c2
=
Param
(
"
c2
"
,
d
=
0.
35
)
n
=
Param
(
"
n
"
,
i
=
100
)
n
=
Param
(
"
n
"
,
i
=
100
)
p
=
Param
(
"
p
"
,
i
=
30
)
p
=
Param
(
"
p
"
,
i
=
30
)
M
=
Param
(
"
M
"
,
i
=
50000
)
M
=
Param
(
"
M
"
,
i
=
50000
)
...
...
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