esa / pagmo

A C++ / Python platform to perform parallel computations of optimisation tasks (global and local) via the asynchronous generalized island model. State of the art optimization algorithms are included. A common interface is provided to other optimization frameworks/algorithms such as NLOPT, SciPy, SNOPT, IPOPT, GSL
GNU General Public License v3.0
269 stars 87 forks source link

Build errors using VS2015 #178

Open kmsomebody opened 8 years ago

kmsomebody commented 8 years ago

So, this is more of an enhancement than an actual issue, since I solved it myself, but wanted you people to know:

I was trying to compile pagmo just with boost in VS2015, Windows 10, x64. There was a compiler error (C3848), "[...] would lose some const-volatile qualifiers [...]" somewhere in "xtree" (which is located in the VS directory).

So, here is how I fixed it: In hv3d.cpp / hv3d.h change this function

bool hv3d::hycon3d_tree_cmp::operator()(const std::pair<fitness_vector, int> &a, const std::pair<fitness_vector, int> &b)

to const.

bool hv3d::hycon3d_tree_cmp::operator()(const std::pair<fitness_vector, int> &a, const std::pair<fitness_vector, int> &b) const

Also, there was another error in inverover.cpp line 266, saying that abs is ambiguous.

stop = (abs(pos1_c1-pos1_c2)==1 || static_cast<problem::base::size_type>(abs(pos1_c1- pos1_c2))==Nv-1);

Casting the parameters to long long fixed it.

stop = (abs((long long)pos1_c1-(long long)pos1_c2)==1 || static_cast<problem::base::size_type>(abs((long long)pos1_c1- (long long)pos1_c2))==Nv-1); 

I hope I could help, if anyone had the same problem. Of course, if anyone has a better solution, I would like to know.

p-snft commented 5 years ago

I second this (for VS2017/ MSVC14.1). However, I suggest to use

static_cast<ptrdiff_t>(pos1_cN)

instead of

(long long)pos1_cN

as pos1_cN are size_t.