These are chat archives for bluescarni/pagmo_reborn

12th
May 2016
Feel free to add change and improve :)
Francesco Biscani
@bluescarni
May 12 2016 09:05
sounds pretty good
I was thinking that maybe the has_set_seed should just become is_stochastic everywhere, there's not much sense in having the two being synonymous
Francesco Biscani
@bluescarni
May 12 2016 09:10
using namespace pagmo;
std::vector<algorithm::base_ptr> algos;
algos.push_back(algorithm::de(gen,0.9,0.9,3).clone());
this does not look very right... it would probably make more sense to push back with a new pointer
Francesco Biscani
@bluescarni
May 12 2016 09:37
just saying that if that appears in a design document we should make sure it's the "correct" way of doing it :)
Francesco Biscani
@bluescarni
May 12 2016 09:43
@darioizzo so it looks like I might have misread the stuff in the pybind11 documentation
Marcus Märtens
@CoolRunning
May 12 2016 09:44
The namespaces part is a bit troublesome for me... because I have several hv-algorithms which should not be mixed up with the evolutionary algorithms. Thus, they live in their own namespace.
Francesco Biscani
@bluescarni
May 12 2016 09:45
I think it is possible to pass the population down by non-const reference, the problem raised in the pybind11 documentation regarded only STL containers which are autoconverted from python containers... but that would not be the case with the population class
@CoolRunning can you make a concrete example?
Marcus Märtens
@CoolRunning
May 12 2016 09:47
hv_indicator = hv4d.compute(points, ref_point); // special algorithm for 4-dimensions
hv_indicator2 = wfg.compute(points, ref_point); // algorithm for the general case, slower but gives same result
so those guys would be probably pagmo::hv_algorithms::hv4d and so on.
The question is also, if we want to provide them as public
Francesco Biscani
@bluescarni
May 12 2016 09:48
would it be ok to just call them pagmo::hv4d etc.?
if they are implementation details you can just put them into pagmo::detail and create as many namespaces as you want :)
Marcus Märtens
@CoolRunning
May 12 2016 09:49
Well...
I have some problems with that... for example pagmo::wfg
wfg stands for "walking fish group"
These guys put out the fastest algorithm for hypervolumes in the general case
But they also put out a benchmarksuite for multi-objective problems, also called "wfg" in the literature
I always wanted to implement those problems in PaGMO
But it is obviously confusing
Francesco Biscani
@bluescarni
May 12 2016 09:52
the benchmark suite would be a pagmo problem?
Marcus Märtens
@CoolRunning
May 12 2016 09:52
yes... you would do prob = pagmo::wfg(1, 20) or so to create the problem wfg1 with 20 dimensions
there are like 9 wfg problems
the signature would be different
Francesco Biscani
@bluescarni
May 12 2016 09:53
ok.. how about prepending then all the components related to hypervolume with hv_?
Marcus Märtens
@CoolRunning
May 12 2016 09:53
than from the hv algorithm
that could probably work
hv_wfg
doesn't sound so bad
Francesco Biscani
@bluescarni
May 12 2016 09:54
I think that we can make things understandable to the user by grouping "similar" things in doxygen groups
so that when you open the documentation you have classes and functions neatly categorized
Marcus Märtens
@CoolRunning
May 12 2016 09:54
But isn't it in general bad practice to put everything in one namespace? I always thought namespaces are your friends to keep your things organized?
Francesco Biscani
@bluescarni
May 12 2016 09:54
but when coding you don't have to bother with subnamespaces
yes and no, I am more for an evolutive approach in this... I tend to keep stuff in a single namespace unless it becomes clear a new one is absolutely needed
imagine that the standard library has vector in the same namespace as hash and nobody complains
Marcus Märtens
@CoolRunning
May 12 2016 09:56
I can see your point... I mean, I hate those endless chains of this::and::that::and::spam
Francesco Biscani
@bluescarni
May 12 2016 09:56
whereas they could've head std::containers::vector vs std::functional::hash
I am not totally against the idea, but what I have seen so far in practice is that there's a definite tendency of having too many rather than too few
of namespaces
Marcus Märtens
@CoolRunning
May 12 2016 09:57
On the other hand... if there is too much stuff in one hierarchy-level, I get confused. An example is networkx... there is so much stuff in their core namespace that it is sometimes hard to find what you need.
Francesco Biscani
@bluescarni
May 12 2016 09:58
that's why I say that we should start with 1 namespace and then eventually evolve to more
Marcus Märtens
@CoolRunning
May 12 2016 09:58
And for PaGMO I see a similar problem, as we have a hell of a lot of different problems, algorithms, islands, meta-stuff, etc.
Francesco Biscani
@bluescarni
May 12 2016 09:58
I don't think we'd have the capacity of evaluating our namespace needs before writing the code
Dario Izzo
@darioizzo
May 12 2016 09:59
Up to today the only clash I had was the null_algorithm null_problem. With namespces they both could have been called null. Without i had to change names.
Francesco Biscani
@bluescarni
May 12 2016 09:59
I see namespaces mostly as a tool to avoid name collisions rather than categorizing things
right.. you type the same as writing algorithm::null but then you have to type algorithm:: for all the other algorithms as well :)
Marcus Märtens
@CoolRunning
May 12 2016 10:00
But it is kinda convenient to know, what you are dealing with: pagmo::johnson could be a Johnson's problem... or Johnson's algorithm.
Francesco Biscani
@bluescarni
May 12 2016 10:01
you could write johnson_algorithm and johnson_problem and actually type less :)
Dario Izzo
@darioizzo
May 12 2016 10:02
The idea is, in any case, to only implement stuff that is solid and established in the core. Like MOEA/D or DE or Rastrigin or Ackley ..... there names will be quite self-explanotary
If johnson wants to write his problem and his algorithm he can do so in the affiliated projects :)
Marcus Märtens
@CoolRunning
May 12 2016 10:02
I still need to understand this affiliated projects design
Francesco Biscani
@bluescarni
May 12 2016 10:03
if a user wants to implement her hown problem, she does not have to use the pagmo namespace at all
Marcus Märtens
@CoolRunning
May 12 2016 10:03
But okay - I am not sure whether I like this or not, but lets reduce namespaces. I will put the hypervolume algorithms directly under pagmo
Francesco Biscani
@bluescarni
May 12 2016 10:04
let's give it a go... we can always add namespaces
Dario Izzo
@darioizzo
May 12 2016 10:04
use the hv_ if it helps
Marcus Märtens
@CoolRunning
May 12 2016 10:04
Ironically, I was the one who wanted to have hypervolume and everything in the root namespace, but Dario forced us, to move the shit into PyGMO.util at some point :D
Dario Izzo
@darioizzo
May 12 2016 10:04
:)
Marcus Märtens
@CoolRunning
May 12 2016 10:04
Now it seems opinions have flipped ^^
Dario Izzo
@darioizzo
May 12 2016 10:04
I have no opinion, I just follow Dart Scarni
Francesco Biscani
@bluescarni
May 12 2016 10:05
it's like the wind in holland, no matter in which direction you are cycling it always blows against you
Marcus Märtens
@CoolRunning
May 12 2016 10:05
I would never dare to oppose the design of the Scarni...
Francesco Biscani
@bluescarni
May 12 2016 10:05
you should not follow me
This message was deleted
Marcus Märtens
@CoolRunning
May 12 2016 10:06
I have the theory that the only direction, you would not encounter wind while cycling in Holland would be to cycle straight upwards, which is impossible due to gravity reasons.
Francesco Biscani
@bluescarni
May 12 2016 10:07
C++ namespaces were not intended to be a design mechanism - they are there simply to prevent name clashes. You really don't want or need to use nested namespaces in 99.99% of situations.
A good example of the correct use of namespaces in C++ is the C++ Standard Library. Everything in this quite large library is placed in a single namespace called std - there is no attempt or need to break the library up into (for example) an I/O sub-namespace, a math sub-namespace, a container sub-namespace etc.
Marcus Märtens
@CoolRunning
May 12 2016 10:07
At least your code looks profound. :smile:
Dario Izzo
@darioizzo
May 12 2016 10:08
where is the quote from?
Marcus Märtens
@CoolRunning
May 12 2016 10:08
From Francesco
Self-quotation for the win
Francesco Biscani
@bluescarni
May 12 2016 10:09
an anonymous source on stackoverflow clearly ;)
Dario Izzo
@darioizzo
May 12 2016 10:09
I put it in the design principle page
Marcus Märtens
@CoolRunning
May 12 2016 10:09
At least the nested chains of :::::::::::::::: will be reduced. That is something.
Anyway, back to my misery.
Dario Izzo
@darioizzo
May 12 2016 10:11
"I was thinking that maybe the has_set_seed should just become is_stochastic everywhere, there's not much sense in having the two being synonymous" -> syntactic sugar? I used is_stochastic as it was more "user-friendly" but has_set_seed is more consistent to the rest ....
Francesco Biscani
@bluescarni
May 12 2016 10:12
well the point is that has_set_seed is what is checked by the whole type traits machinery, to it's important that it is in problem/algorithm
and is_stochastic is just an alias for that
and it seems a bit confusing to have two things that do the same
but maybe not, I dunno
Dario Izzo
@darioizzo
May 12 2016 10:15
using namespace pagmo;
std::vector<algorithm::base_ptr> algos;
algos.push_back(algorithm::base_ptr(new de(gen,0.9,0.9,3)));
like this is better?
Francesco Biscani
@bluescarni
May 12 2016 10:16
algos.push_back(new de(gen,0.9,0.9,3)); why not this
I can't remember exactly
Dario Izzo
@darioizzo
May 12 2016 10:17
works? ok I trust you
Francesco Biscani
@bluescarni
May 12 2016 10:17
not sure
base_ptr is a boost shared ptr right?
Dario Izzo
@darioizzo
May 12 2016 10:17
I guess
Francesco Biscani
@bluescarni
May 12 2016 10:18
I think your version is needed in C++03
in C++11 you would write it with the emplace
luckily we don't have to do any of that now
Dario Izzo
@darioizzo
May 12 2016 10:19
yep ...
so i leave the clone? or new?
Francesco Biscani
@bluescarni
May 12 2016 10:19
algos.push_back(algorithm::base_ptr(new de(gen,0.9,0.9,3))); this should work... there's no reason to make an object and then clone it
Dario Izzo
@darioizzo
May 12 2016 10:21
done
I am working on tests for the algorithm which should roughly be finished as a class. Then I would say that:
  • Francesco: you must transfer ihs to the new pagmo. It is an historic piece of the whole story
  • Marcus: care to code an algorithm? pick your choice ... :)
Marcus Märtens
@CoolRunning
May 12 2016 10:33
NSGA-II
But after the hv stuff is ported half-ways. ;)
I have the hypervolume object by now, but next is the abstract class for hv_algorithm... followed by all the actual algorithms. Progressing slowly.
Francesco Biscani
@bluescarni
May 12 2016 11:01
I'd probably revise the guidelines regarding ctors and the rule of 5... I'd say that if you need to write one of 5, you probably need all of them implemented, otherwise you can avoid writing any
Dario Izzo
@darioizzo
May 12 2016 11:06
Yep ok, can you write it down?
I never really got the rule of 5 as deepely as I did the rest :)
Like meta-programming I now rule !
@CoolRunning Yes, we always say that this is a marathon not a sprint :)
Marcus Märtens
@CoolRunning
May 12 2016 11:09
Just trying to keep a bit of momentum at least. Upcoming weeks should be easier.
But the work is not super difficult. It merely boils down to merging the .h with the .cpp and refactoring a few things like boost-stuff which is no longer supported and so on.
Dario Izzo
@darioizzo
May 12 2016 11:10
Not scared about the pointer stuff?
I can already see that once you finish all, you run the tests and BOOM not passed ... :worried:
Marcus Märtens
@CoolRunning
May 12 2016 11:11
Francesco said that some pointers might be okay, as long as you do not use newor delete[] and stuff...
Dario Izzo
@darioizzo
May 12 2016 11:12
ah right ...
Francesco Biscani
@bluescarni
May 12 2016 11:12
ok edited
Dario Izzo
@darioizzo
May 12 2016 11:13
where?
Marcus Märtens
@CoolRunning
May 12 2016 11:13
Good thing is that Kiryx really did a good job in documenting and writing clean code. Makes things a lot easier for me.
Dario Izzo
@darioizzo
May 12 2016 11:14
one of our best GSoC students to date
Dario Izzo
@darioizzo
May 12 2016 11:42
@bluescarni In algorithm (and problem) we should not let extra_info be stored only once and for all at construction. Extra info may contain the print of some dynamic values such as the seed of the problem / algorithm which must be then updated at each call.
WOuld oyu agree?
Francesco Biscani
@bluescarni
May 12 2016 13:06
I don't see much danger in that... tough the only thing that can change the state of a problem is the set_seed (barring mutable), as all the other methods are const
Dario Izzo
@darioizzo
May 12 2016 13:07
for the algo we also have set_verbosity
and both seed and verbosity would be logged in extra_info
Francesco Biscani
@bluescarni
May 12 2016 13:08
you mean the default implementation of extra_info would log the verbosity/seed? or that the user could implement that?
btw did you see the comments on the commit
Francesco Biscani
@bluescarni
May 12 2016 13:26
we really need to start doing PRs, it's becoming hard to keep track of the changes
Dario Izzo
@darioizzo
May 12 2016 13:31
The user could implement it (and it will be good practice to, so examples and our problems algo will)
Francesco Biscani
@bluescarni
May 12 2016 13:36
so there's some backlog cleanup to do, just logging it here:
  • the is_stochastic/has_set_seed changes should go in problem as well
  • the elimination of the extra_info as a class member
  • problem copy ctor/assignment copies fevals
gonna try to give it another go at the python stuff
Dario Izzo
@darioizzo
May 12 2016 13:37
Yes the three were also logged in my "pensieri", but I am currently implementing algo tests ....
Francesco Biscani
@bluescarni
May 12 2016 13:37
that's why I wrote them down :)
scripta manent
Dario Izzo
@darioizzo
May 12 2016 13:58
@bluescarni mi aiuti un minuto? ho fatto qualche cazzata con extract and company,
tu ci metti 1 sec a capire cosa, io 3 ore ....
Francesco Biscani
@bluescarni
May 12 2016 13:58
dimmi
Dario Izzo
@darioizzo
May 12 2016 13:58
BOOST_AUTO_TEST_CASE(algorithm_copy_constructor_test)
{
    // We check the copy constructor
    algorithm algo{al_01{}};

    // We set the seed and verbosity so that the default values are changed
    algo.set_seed(1u);
    algo.set_verbosity(1u);

    // We call the copy constructor
    algorithm algo_copy(algo);
    // We extract the user algorithm
    auto a1 = algo.extract<al_01>();
    auto a2 = algo_copy.extract<al_01>();

    // 1 - We check the resources pointed to by m_ptr have different address
    BOOST_CHECK(a1!=0);
    BOOST_CHECK(a2!=0);
    BOOST_CHECK(a1!=a2);
    // 2 - We check that the other members are copied
    BOOST_CHECK(algo.get_name() == algo_copy.get_name());
    BOOST_CHECK(algo.has_set_seed() == algo_copy.has_set_seed());
    BOOST_CHECK(algo.has_set_verbosity() == algo_copy.has_set_verbosity());
}
qui a2 e' 0 !!! e il test fallisce
Francesco Biscani
@bluescarni
May 12 2016 13:59
non hai letto i commenti che ti avevo fatto sul commit?
Dario Izzo
@darioizzo
May 12 2016 13:59
in qualche modo extract fallisce.
credo di si. ma forse mi sono fermato troppo presto?
fammi vedere ....
Francesco Biscani
@bluescarni
May 12 2016 14:00
se non hai modificato l'extract dell'algoritmo sta ancora cercando di estrarre un prob_inner...
Dario Izzo
@darioizzo
May 12 2016 14:00
ah no, certo quello lo avevo gia' fatto ...
Francesco Biscani
@bluescarni
May 12 2016 14:01
sulla mia copia locale vedo ancora prob_inner
Dario Izzo
@darioizzo
May 12 2016 14:01
hai fatto pull?
nota che a1 viene estratto correttamente ...
e' a2 (dopo la chiamata al copy) che fallisce
Francesco Biscani
@bluescarni
May 12 2016 14:05
algorithm algo_copy(algo);
non hai disabilitato il generic ctor con l'enabler
quello sta creando un nuovo algoritmo usando algo come problema concreto
Dario Izzo
@darioizzo
May 12 2016 14:06
ma non e disabilitato dalla sfinae?
Francesco Biscani
@bluescarni
May 12 2016 14:07
    public:
        /// Constructor
        template <typename T>
        explicit algorithm(T &&x):m_ptr(::new detail::algo_inner<std::decay_t<T>>(std::forward<T>(x)))
non c'e' niente che disabilita qui
Dario Izzo
@darioizzo
May 12 2016 14:07
a cazzo mi sono scordato di chiamare il disabler ..
E cia avevo pure pensato.
Pero avevo messo un print nel copy per verificare che venisse chiamato ....
forse c'e' una copia sopra da qualche parte
ok grazie
scusa per l'interruzione
Francesco Biscani
@bluescarni
May 12 2016 14:08
la copia viene fatta come parte della costruzione di algo_inner
np
This one is almost as scary as Francesco ...
Marcus Märtens
@CoolRunning
May 12 2016 14:18
those are the dudes
Funny how puzzled he is at the end
Dario Izzo
@darioizzo
May 12 2016 14:22
The guy can type talk and eat at the same time :)
the talk is interesting for me to understand GIL and python cuncurrency problems....
Marcus Märtens
@CoolRunning
May 12 2016 14:28
Can you help a bit? Why was it, that you should use rather processes than threads in python?
(Asking, because a colleague is working now with multi-threading in Python and encounters problems. But he has a "lucky" hand with Python... always encountering the nasty bits for some reason)
Dario Izzo
@darioizzo
May 12 2016 14:30
Well If you use threads, you will always only really be using one core as the GIL avoids that one instance of the python interpreter satisfies multiple requests
So, while you may think to be parallelizing you are not. Threads in python are only to allow for concurrency, not for speed.
GIL -> Global Interpreter Lock
So if you are into parallel programming using python you only have one way: spawn other interpreters and send/receive from them computational instructions. Thats the only way
Marcus Märtens
@CoolRunning
May 12 2016 14:33
Ahh... I see, I remember
What do you think about the object orientation in Python? I never really find myself using it (with few exceptions)
Dario Izzo
@darioizzo
May 12 2016 14:35
I am not really entitled to an opinion here ..... @bluescarni may have a better take
Marcus Märtens
@CoolRunning
May 12 2016 14:35
But since my colleague is from a Java background, he wants to stick to this paradigm, resulting in pretty strange Python code in my eyes :D
Dario Izzo
@darioizzo
May 12 2016 14:35
I did code some classes in python in the past ... what problem do you have with it?
I did not find it particularly ugly ..... was your moonscore not a class?
Marcus Märtens
@CoolRunning
May 12 2016 14:35
They feel a bit akward with the "self" all the time.
True - there are exceptions ^^
Dario Izzo
@darioizzo
May 12 2016 14:36
Ah well that is actually a good visual distinction between functions and methods. It allows to add methods at any point
Marcus Märtens
@CoolRunning
May 12 2016 14:36
The good thing is, you can just make a few classes and roll with them, rather than turning everything into classes and objects, because the language forces you to do.
Dario Izzo
@darioizzo
May 12 2016 14:37
You can add a method to a class wothout inheriting ... how cool is that no?
Marcus Märtens
@CoolRunning
May 12 2016 14:38
pretty sick
could you create a bunch of objects from a class, than augment the class by a new method and all the objects would roll with it?
Dario Izzo
@darioizzo
May 12 2016 14:38
yeah!!
Marcus Märtens
@CoolRunning
May 12 2016 14:39
Just imagine all the bugs you could create with that technique! :smile:
Dario Izzo
@darioizzo
May 12 2016 14:39
because you would anyway be passing self
Francesco Biscani
@bluescarni
May 12 2016 14:39
it's called monkey patching
Dario Izzo
@darioizzo
May 12 2016 14:39
Thats another discussion: language misuse
Marcus Märtens
@CoolRunning
May 12 2016 14:39
A.k.a. Duck Punching
I did monkey patching frequently in Javascript when I was hacking at Opera... my supervisor did not like me doing that :D
Francesco Biscani
@bluescarni
May 12 2016 14:40
object orientation is just a tool, works for some problems but you don't have to hammer it into everything
aka java
there's absolutely no good reason why cos() should be a method of any class for instance
but in java you can't have that...
Marcus Märtens
@CoolRunning
May 12 2016 14:42
:+1:
Francesco Biscani
@bluescarni
May 12 2016 14:42
that's one thing I like about python and C++, that they are multi paradigm and let you choose different ways of doing things
instead it seems like in the software industry every 5 years there's a new fashion about how to do things "correctly" once and for all
in the 90's it was object oriented programming, that gifted us with a generation of engineers educated in java that make the main() function as a static function of a class
for a while we had functional programming and the haskell fanatics, with their monoids, stateless programs, etc.
but that seems to be fading nowadays as well
who knows what exciting bullshit the future will bring!
Dario Izzo
@darioizzo
May 12 2016 14:45
go julia?
Marcus Märtens
@CoolRunning
May 12 2016 14:45
The era of Erlang.
Dario Izzo
@darioizzo
May 12 2016 14:45
Finally!
Francesco Biscani
@bluescarni
May 12 2016 14:45
ah yeah, the multidispatching fanatics
Dario Izzo
@darioizzo
May 12 2016 14:46
WHats your guys take on c# ?
Francesco Biscani
@bluescarni
May 12 2016 14:46
there are many new ideas which are interesting, but it's idiotic to think that you can solve everything with 1 programming paradigm
Marcus Märtens
@CoolRunning
May 12 2016 14:46
I agree. Multi-paradigm ftw!
Francesco Biscani
@bluescarni
May 12 2016 14:46
ideas that are not even new anyway, as most computer science was solved by the 70s :)
Marcus Märtens
@CoolRunning
May 12 2016 14:47
C# is pretty focused on .NET and the whole Windows environment, if I recall?
Dario Izzo
@darioizzo
May 12 2016 14:47
SOme say its the most portable language ever .... the mono stuff is c#
goes on osx linux and windows ... (some say)
Francesco Biscani
@bluescarni
May 12 2016 14:48
C is the most portable language ever :)
Marcus Märtens
@CoolRunning
May 12 2016 14:48
Really? I always thought it was C++ for .NET
Looked as bloated as Java to me from what I saw, but I really have no strong opinion on C#
its cross platform as Java is as it uses a virtual env (I guess) and yes its very linked to .NET
What is .NET anyway?
But for graphics many say its super easy to program. ...
Francesco Biscani
@bluescarni
May 12 2016 14:49
python is arguably more portable, or at least it was... I remember when the first 64 bit machines came out Python could run immediately on them, Java (the MOST PORTABLE language according to the echo chamber) took years before they had 64 bit VMs
this was back in 2004/2005 era
Marcus Märtens
@CoolRunning
May 12 2016 14:50
.NET is framework for Windows stuff. A big blob of all the things you see in Windows, that you might wanna use for your own applications.
It is also a common ground for multiple languages... like Java-bytecode which is not only produced by Java but can be produced by other languages as well.
As it ships with a lot of stuff, it is "easy" to assemble applications with it... i.e. building GUIs and so on or webapplications etc.
You kinda click them together with Visual Studio if you are a Microsoft buff.
Dario Izzo
@darioizzo
May 12 2016 14:54
And you must use c# to talk to it?
Marcus Märtens
@CoolRunning
May 12 2016 14:54
nope
You could use Visual Basic as well :P
Dario Izzo
@darioizzo
May 12 2016 14:54
wow
Marcus Märtens
@CoolRunning
May 12 2016 14:56
There is also Python for .NET
Francesco Biscani
@bluescarni
May 12 2016 14:56
need to pack, catch you later
Dario Izzo
@darioizzo
May 12 2016 14:57
c u
Marcus Märtens
@CoolRunning
May 12 2016 14:57
ciao
Dario Izzo
@darioizzo
May 12 2016 15:03
I am also taking off
Marcus Märtens
@CoolRunning
May 12 2016 15:07
allright - ciao
Marcus Märtens
@CoolRunning
May 12 2016 18:49
This is the old clone-method. Will this still be needed/implemented? If so, any changes?
/// Clone method.
base_ptr hv2d::clone() const
{
    return base_ptr(new hv2d(*this));
}
Dario Izzo
@darioizzo
May 12 2016 18:55
Do you have a base class?
The reasons to have classes inheriting from a base class can be twofold
  • You want to share some code across types
  • You want to be able to achieve polymorphism (that is, roughly, having different types act as if they were one, for example in a method call such as shape.area() where shape can be a rectangle or a circle and is thus required to call different code)
Which is the case for you? (can be both)
Dario Izzo
@darioizzo
May 12 2016 19:01
If you want to achieve polymorphism using the "standard" inheritance trick, then yes, you will need the clone. (the type erasure can achieve the same without needing the clone). If you just want to share some code across classes, then no clone is needed.
Marcus Märtens
@CoolRunning
May 12 2016 19:03
I think polymorphism is needed. You basically can give the hypervolume object anything that can be derived from hv_algorithm::base and it should work.
Dario Izzo
@darioizzo
May 12 2016 19:03
so the hypervolume object contains a base_ptr ?
Marcus Märtens
@CoolRunning
May 12 2016 19:04
the compute-method of the hypervolume object needs a base_ptr to an hv_algorithm
Dario Izzo
@darioizzo
May 12 2016 19:04
which is stored as a member of hypervolume?
Marcus Märtens
@CoolRunning
May 12 2016 19:05
nope
The only thing hypervolume stores are points
Dario Izzo
@darioizzo
May 12 2016 19:05
Then its in the prototype of compute?
Marcus Märtens
@CoolRunning
May 12 2016 19:06
yes
it allows to specify the method of computation
it is also not arbitrary... there is a version of the method were you do not specify this... in that case, a clever decision is made which hv_algorithm to instantiate based on some properties of the stored points (dimensionality, etc.)
Dario Izzo
@darioizzo
May 12 2016 19:06
and how does the algorithm access the points? as arguments ?
@bluescarni is this not an std::function use case?
Marcus Märtens
@CoolRunning
May 12 2016 19:08
the algorithm accesses the points by arguments
Francesco Biscani
@bluescarni
May 12 2016 19:09
I am not sure I understand without a specific pointer to the code
Marcus Märtens
@CoolRunning
May 12 2016 19:09
basically, it accesses a copy of the points
return hv_algorithm->compute(points_cpy, r_point);
Where shall I point you? ^^
Francesco Biscani
@bluescarni
May 12 2016 19:10
and hv_algorithm is a base ptr?
Marcus Märtens
@CoolRunning
May 12 2016 19:10
yes
Francesco Biscani
@bluescarni
May 12 2016 19:10
ok... is it passed in as a function, is it stored as a member in a class...
Marcus Märtens
@CoolRunning
May 12 2016 19:10
This is the old compute-method of the hypervolume object:
double hypervolume::compute(const fitness_vector &r_point, hv_algorithm::base_ptr hv_algorithm) const
{
    if (m_verify) {
        verify_before_compute(r_point, hv_algorithm);
    }

    // copy the initial set of points, as the algorithm may alter its contents
    if (m_copy_points) {
        std::vector<fitness_vector> points_cpy(m_points.begin(), m_points.end());
        return hv_algorithm->compute(points_cpy, r_point);
    } else {
        return hv_algorithm->compute(const_cast<std::vector<fitness_vector> &>(m_points), r_point);
    }
}
It basically pushes all the work to the specific compute-method of hv_algorithm
The user can specify a base_ptr to any hv_algorithm he wants to use for computation.
Dario Izzo
@darioizzo
May 12 2016 19:12
Looking at the orginal class ... the design does not make sense to me ... :(
Marcus Märtens
@CoolRunning
May 12 2016 19:12
The design makes sense
Dario Izzo
@darioizzo
May 12 2016 19:12
What is the clone doing?
Is it ever used?
Marcus Märtens
@CoolRunning
May 12 2016 19:13
The clone-method was something you asked us to implement by default if I remember correctly?
Dario Izzo
@darioizzo
May 12 2016 19:13
In derived class that need polymorphism .. in this class makes no sense, but then I am not in any position to say ...
Marcus Märtens
@CoolRunning
May 12 2016 19:13
wait no - it is used
Dario Izzo
@darioizzo
May 12 2016 19:13
where?
Marcus Märtens
@CoolRunning
May 12 2016 19:14
/// Choose the best hypervolume algorithm for given task
    /**
    * Returns the best method for given hypervolume computation problem.
    * As of yet, only the dimension size is taken into account.
    */
    hv_algorithm::base_ptr hypervolume::get_best_compute(const fitness_vector &r_point) const
    {
        unsigned int fdim = r_point.size();
        unsigned int n = m_points.size();
        if (fdim == 2) {
            return hv_algorithm::hv2d().clone();
        }
        else if (fdim == 3) {
            return hv_algorithm::hv3d().clone();
        }
        else if (fdim == 4) {
            return hv_algorithm::hv4d().clone();
        }
        else if (fdim == 5 && n < 80) {
            return hv_algorithm::fpl().clone();
        }
        else {
            return hv_algorithm::wfg().clone();
        }
    }
Dario Izzo
@darioizzo
May 12 2016 19:15
but thats the clone of the derived class not of hypervolume
Marcus Märtens
@CoolRunning
May 12 2016 19:15
no, hypervolume has no clone
hv_algorithm (the base class) has
Dario Izzo
@darioizzo
May 12 2016 19:15
hypervolume_ptr clone() const;
this is in hypervolume no?
Marcus Märtens
@CoolRunning
May 12 2016 19:16
nope
Francesco Biscani
@bluescarni
May 12 2016 19:16
so in general it would be better to avoid inheritance for us, in the sense that 1) it forces pointer semantics, which we are avoiding and 2) it complicates the exposition to python
Marcus Märtens
@CoolRunning
May 12 2016 19:16
there are two different things
  1. hypervolume (interface, computes nothing)
  1. hv_algorithm (actual algorithm, does the job)
hypervolume is just a container for points
Dario Izzo
@darioizzo
May 12 2016 19:17
I see pagmo::util::hypervolume::clone do you?
Marcus Märtens
@CoolRunning
May 12 2016 19:17
no?
Marcus Märtens
@CoolRunning
May 12 2016 19:17
mhh - let me look in the old src
ah this... that was never implemented
I kicked it out.
Dario Izzo
@darioizzo
May 12 2016 19:18
it is implemented see the cpp file
Marcus Märtens
@CoolRunning
May 12 2016 19:18
is it?
Dario Izzo
@darioizzo
May 12 2016 19:18
But yes makes no sense
Anyway as @bluescarni said
Marcus Märtens
@CoolRunning
May 12 2016 19:18
its no longer :)
Dario Izzo
@darioizzo
May 12 2016 19:19
I think this can be done easily without inheritance
Marcus Märtens
@CoolRunning
May 12 2016 19:19
Then I need some enlightment from him
Dario Izzo
@darioizzo
May 12 2016 19:19
FOr the benefit of our life in Python.
Francesco Biscani
@bluescarni
May 12 2016 19:20
I agree, but for the moment I'd make sure first that the code works with the current structure
I would not try to change too many things at a time
Dario Izzo
@darioizzo
May 12 2016 19:20
So transfer as it is (without the nonsense)
Which means you will need the clone methods in the hv_stuff
Marcus Märtens
@CoolRunning
May 12 2016 19:20
The reason why I asked was the dreaded new in the clone method
which is one of the red flags I am looking out for while refactoring/porting the old sources
Dario Izzo
@darioizzo
May 12 2016 19:21
There its ok ... but will indeed disappear if we remove this inheritance thing later
Francesco Biscani
@bluescarni
May 12 2016 19:21
in this case it's ok for now, just move the definition of base_ptr to std::shared_ptr
Dario Izzo
@darioizzo
May 12 2016 19:21
need to go later
Marcus Märtens
@CoolRunning
May 12 2016 19:22
I did this already :D
Francesco Biscani
@bluescarni
May 12 2016 19:22
laters
cool ok :)
Marcus Märtens
@CoolRunning
May 12 2016 19:22
it is now called std::shared_ptr<base>
Francesco Biscani
@bluescarni
May 12 2016 19:25
was the hypervolume functionality wrapped in PyGMO?
Marcus Märtens
@CoolRunning
May 12 2016 19:26
Sure was
Marcus Märtens
@CoolRunning
May 12 2016 20:03
It was exhausting, but now the first hypervolume has been correctly computed with the new PaGMO :sparkles: :sparkles: :sparkles:
Francesco Biscani
@bluescarni
May 12 2016 20:03
great! :+1:
Marcus Märtens
@CoolRunning
May 12 2016 20:03
:)
Its value was 3. Just for the protocol.
Francesco Biscani
@bluescarni
May 12 2016 20:04
awww I was expecting 42 :)
Marcus Märtens
@CoolRunning
May 12 2016 20:05
I will write a testcase for that next