Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precision fixes in stat averages #5518

Merged
merged 2 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conf/core/ConfigOptions.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6045,7 +6045,7 @@ Examples that will be kept if the value is `true` include:

=== token.min.size

* Data Type: double
* Data Type: int
* Default Value: `3`

This is the minimum string size that the string tokenizer should accept as a token. If the string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ bool WayDiscretizer::discretize(double spacing, vector<WayLocation>& result) con
Meters wayLength = ElementToGeometryConverter(_map).convertToLineString(_way)->getLength();
LOG_VART(wayLength);

int count = ceil(wayLength / spacing);
int count = static_cast<int>(ceil(wayLength / spacing));
LOG_VART(count);
spacing = wayLength / double(count);
LOG_VART(spacing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ WayPtr WayString::copySimplifiedWayIntoMap(const ElementProvider& map, OsmMapPtr
// add all the pre-existing nodes that we can.
for (size_t i = formeri; i <= latteri; ++i)
{
long nid = oldWay->getNodeId(i);
long nid = oldWay->getNodeId(static_cast<int>(i));
newNids.push_back(nid);
destination->addNode(std::make_shared<Node>(*map.getNode(nid)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ namespace hoot
{

IntegerProgrammingSolver::IntegerProgrammingSolver()
: _lp(glp_create_prob()),
_timeLimit(-1)
{
_lp = glp_create_prob();
_timeLimit = -1;
}

IntegerProgrammingSolver::~IntegerProgrammingSolver()
Expand Down Expand Up @@ -80,7 +80,7 @@ void IntegerProgrammingSolver::solveBranchAndCut()
iocp.br_tech = GLP_BR_PCH;
// Setup the time limit if necessary
if (_timeLimit > 0)
iocp.tm_lim = _timeLimit * 1000.0 + 0.5;
iocp.tm_lim = static_cast<int>(_timeLimit * 1000.0 + 0.5);
// Setup message level
if (Log::getInstance().getLevel() <= Log::Trace)
iocp.msg_lev = GLP_MSG_ON;
Expand Down Expand Up @@ -117,7 +117,7 @@ void IntegerProgrammingSolver::solveSimplex()
glp_init_smcp(&smcp);
// Setup the time limit if necessary
if (_timeLimit > 0)
smcp.tm_lim = _timeLimit * 1000.0 + 0.5;
smcp.tm_lim = static_cast<int>(_timeLimit * 1000.0 + 0.5);
// Setup message level
if (Log::getInstance().getLevel() <= Log::Trace)
smcp.msg_lev = GLP_MSG_ON;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2015, 2017, 2019, 2020, 2021 Maxar (http://www.maxar.com/)
* @copyright Copyright (C) 2015, 2017, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/)
*/
#ifndef INTEGERPROGRAMMINGSOLVER_H
#define INTEGERPROGRAMMINGSOLVER_H
Expand Down Expand Up @@ -81,7 +81,7 @@ class IntegerProgrammingSolver
*/
void loadMatrix(const std::vector<int>& i, const std::vector<int>& j, const std::vector<double>& r)
{
glp_load_matrix(_lp, i.size() - 1, &(i[0]), &(j[0]), &(r[0]));
glp_load_matrix(_lp, static_cast<int>(i.size() - 1), &(i[0]), &(j[0]), &(r[0]));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ Mat DirectSequentialSimulation::_gm2dPerturb2(geos::geom::Envelope env, Meters s
// effects
env.expandBy(3 * _gridSpacing);

int rows = max<int>(2, ceil(env.getHeight() / _gridSpacing) + 1);
int cols = max<int>(2, ceil(env.getWidth() / _gridSpacing) + 1);
int rows = max<int>(2, static_cast<int>(ceil(env.getHeight() / _gridSpacing)) + 1);
int cols = max<int>(2, static_cast<int>(ceil(env.getWidth() / _gridSpacing)) + 1);

double r = exp(-_gridSpacing / _D);
double s = exp(-_gridSpacing / _D);
Expand Down
4 changes: 2 additions & 2 deletions hoot-core/src/main/cpp/hoot/core/algorithms/perty/PertyOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class ShiftMapVisitor : public ElementOsmMapVisitor
Vec2d result;

// calculate the grid cell that this point falls in.
int r = (p.y - _e.getMinY()) / _gridSpacing;
int c = (p.x - _e.getMinX()) / _gridSpacing;
int r = static_cast<int>((p.y - _e.getMinY()) / _gridSpacing);
int c = static_cast<int>((p.x - _e.getMinX()) / _gridSpacing);
double dx = p.x - (_e.getMinX() + c * _gridSpacing);
double dy = p.y - (_e.getMinY() + r * _gridSpacing);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ namespace hoot
int LargeWaySplitter::logWarnCount = 0;

LargeWaySplitter::LargeWaySplitter(double threshold)
: _threshold(threshold)
{
_threshold = threshold;
}

void LargeWaySplitter::apply(const std::shared_ptr<OsmMap>& map)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2021 Maxar (http://www.maxar.com/)
* @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/)
*/

#include "WaySplitter.h"
Expand All @@ -31,25 +31,25 @@
#include <geos/geom/LineString.h>

// Hoot
#include <hoot/core/elements/OsmMap.h>
#include <hoot/core/algorithms/FindNodesInWayFactory.h>
#include <hoot/core/algorithms/linearreference/WayLocation.h>
#include <hoot/core/algorithms/linearreference/WaySubline.h>
#include <hoot/core/elements/OsmMap.h>
#include <hoot/core/elements/Way.h>
#include <hoot/core/ops/ReplaceElementOp.h>
#include <hoot/core/ops/RemoveWayByEid.h>
#include <hoot/core/geometry/ElementToGeometryConverter.h>
#include <hoot/core/algorithms/FindNodesInWayFactory.h>
#include <hoot/core/ops/RemoveWayByEid.h>
#include <hoot/core/ops/ReplaceElementOp.h>

using namespace geos::geom;
using namespace std;

namespace hoot
{

WaySplitter::WaySplitter(const OsmMapPtr& map, WayPtr way) :
_map(map),
_way(way),
_nf(std::make_shared<FindNodesInWayFactory>(_way))
WaySplitter::WaySplitter(const OsmMapPtr& map, WayPtr way)
: _map(map),
_way(way),
_nf(std::make_shared<FindNodesInWayFactory>(_way))
{
}

Expand All @@ -70,14 +70,12 @@ vector<WayPtr> WaySplitter::createSplits(const vector<WayLocation>& wl) const
result[i] = WaySubline(last, curr).toWay(_map, _nf);
result[i]->setPid(_way->getId());
if (result[i]->getNodeCount() == 0)
{
result[i].reset();
}
}
last = curr;
}

WayLocation end(_map, _way, _way->getNodeCount() - 1, 0.0);
WayLocation end(_map, _way, static_cast<int>(_way->getNodeCount()) - 1, 0.0);
if (last.compareTo(end) != 0)
{
WayPtr w = WaySubline(last, end).toWay(_map, _nf);
Expand Down Expand Up @@ -105,10 +103,8 @@ void WaySplitter::split(const OsmMapPtr& map, const WayPtr& w, double maxSize)
WayLocation wl (map, w, l / 2.0);
vector<WayPtr> children = WaySplitter(map, w).split(wl);

for (size_t i = 0; i < children.size(); i++)
{
split(map, children[i], maxSize);
}
for (const auto& child : children)
split(map, child, maxSize);
}
}

Expand All @@ -117,13 +113,11 @@ vector<WayPtr> WaySplitter::split(const WayLocation& splitPoint) const
vector<WayPtr> result;

if (splitPoint.isFirst() || splitPoint.isLast())
{
result.push_back(_way);
}
else
{
WayLocation first(_map, _way, 0, 0.0);
WayLocation last(_map, _way, _way->getNodeCount() - 1, 0.0);
WayLocation last(_map, _way, static_cast<int>(_way->getNodeCount()) - 1, 0.0);

result.push_back(WaySubline(first, splitPoint).toWay(_map, _nf, true));
result.push_back(WaySubline(splitPoint, last).toWay(_map, _nf, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2021 Maxar (http://www.maxar.com/)
* @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2021, 2022 Maxar (http://www.maxar.com/)
*/

#ifndef WAYSPLITTER_H
#define WAYSPLITTER_H

// Hoot
#include <hoot/core/util/Units.h>
#include <hoot/core/elements/OsmMap.h>
#include <hoot/core/elements/Way.h>
#include <hoot/core/util/Units.h>

namespace hoot
{

class WaySubline;
class FindNodesInWayFactory;
class WayLocation;
class WaySubline;

/**
* @brief The WaySplitter class splits ways.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ double SqliteWordWeightDictionary::getWeight(const QString& word) const
c = _reader.readCount(normalized);
if (c > 0)
_weights[normalized] = c;
return c;
return static_cast<double>(c);
}
else
c = it->second;

return c / (double)_count;
return static_cast<double>(c) / static_cast<double>(_count);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void TextFileWordWeightDictionary::_loadFile(const QString& path)

first.replace(totalWordCount, "");
bool ok;
_count += first.toDouble(&ok);
_count += static_cast<long>(first.toDouble(&ok));
if (!ok)
throw HootException("Bad double value in total word count: " + first);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const vector<WayLocation>& MaximalNearestSubline::getInterval()
// Heuristic #1: use every vertex of B as a test point
for (size_t ib = 0; ib < _b->getNodeCount(); ib++)
{
ConstNodePtr node = _map->getNode(_b->getNodeId((long)ib));
ConstNodePtr node = _map->getNode(_b->getNodeId(static_cast<int>(ib)));
LOG_VART(node.get());
if (node)
{
Expand All @@ -138,7 +138,7 @@ const vector<WayLocation>& MaximalNearestSubline::getInterval()
LocationOfPoint bPtLocator(_map, _b);
for (size_t ia = 0; ia < _a->getNodeCount(); ia++)
{
ConstNodePtr node = _map->getNode(_a->getNodeId((long)ia));
ConstNodePtr node = _map->getNode(_a->getNodeId(static_cast<int>(ia)));
LOG_VART(node.get());
if (node)
{
Expand Down Expand Up @@ -280,12 +280,12 @@ vector<WayPtr> MaximalNearestSubline::splitWay(OsmMapPtr map, int& mnsIndex)
// if this is a or b
if (end.getSegmentIndex() < (int)_a->getNodeCount() - 1 || end.getSegmentFraction() < 1.0)
{
WayPtr way3 = WaySubline(end, WayLocation(map, _a, _a->getNodeCount() - 1, 0.0)).toWay(map, nf);
WayPtr way3 = WaySubline(end, WayLocation(map, _a, static_cast<int>(_a->getNodeCount()) - 1, 0.0)).toWay(map, nf);

double l = ElementToGeometryConverter(map).convertToLineString(way3)->getLength();
// if the way is too short, round to the first way.
if (l < _minSplitSize)
end = WayLocation(map, _a, _a->getNodeCount() - 1, 0.0);
end = WayLocation(map, _a, static_cast<int>(_a->getNodeCount()) - 1, 0.0);
else
result.push_back(way3);
}
Expand All @@ -296,7 +296,7 @@ vector<WayPtr> MaximalNearestSubline::splitWay(OsmMapPtr map, int& mnsIndex)
// if the way is big enough then add it on.
if (l > _minSplitSize)
{
mnsIndex = result.size();
mnsIndex = static_cast<int>(result.size());
result.push_back(way2);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ cv::Mat MaximalSubline::_createConstraintMatrix(const vector<int>& starts, const
if ((size_t)ends[last] != pairs.size() - 1)
{
finalStarts.push_back(ends[last] - (ends[last] - starts[last]) / 3);
finalEnds.push_back(pairs.size() - 1);
finalEnds.push_back(static_cast<int>(pairs.size()) - 1);
}

LOG_TRACE("finalStarts: " << finalStarts);
Expand Down
2 changes: 1 addition & 1 deletion hoot-core/src/main/cpp/hoot/core/algorithms/zindex/BBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BBox
BBox(const geos::geom::Envelope& envelope);
virtual ~BBox();

int getDimensions() const { return _max.size(); }
int getDimensions() const { return static_cast<int>(_max.size()); }

std::vector<double> getMax() const { return _max; }
std::vector<double> getMin() const { return _min; }
Expand Down
4 changes: 2 additions & 2 deletions hoot-core/src/main/cpp/hoot/core/algorithms/zindex/LongBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2016, 2017, 2018, 2019, 2021 Maxar (http://www.maxar.com/)
* @copyright Copyright (C) 2016, 2017, 2018, 2019, 2021, 2022 Maxar (http://www.maxar.com/)
*/
#ifndef LONGBOX_H
#define LONGBOX_H
Expand Down Expand Up @@ -55,7 +55,7 @@ class LongBox

LongBox expand(int size) const;

int getDimensions() const { return getMin().size(); }
int getDimensions() const { return static_cast<int>(getMin().size()); }

std::vector<long int> getMax() const { return _max; }
std::vector<long int> getMin() const { return _min; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ long int ZValue::calculateComponent(double v, int d)
{
if (d >= (int)_min.size() || d >= (int)_max.size())
throw HootException("Input vector size is greater than min or max size.");
return round(((v - _min[d]) / (_max[d] - _min[d])) * _range);
return round(((v - _min[d]) / (_max[d] - _min[d])) * static_cast<double>(_range));
}

void ZValue::decompose(long int v, vector<long int>& point) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ void ConflateExecutor::conflate(const QString& input1, const QString& input2, co
double timingOutput = _taskTimer.getElapsedAndRestart();
double totalElapsed = totalTime.getElapsed();
_stats.append(SingleStat("(Dubious) Initial Elements Processed per Second",
initialElementCount / totalElapsed));
static_cast<double>(initialElementCount) / totalElapsed));
_stats.append(SingleStat("(Dubious) Final Elements Processed per Second",
(double)map->getElementCount() / totalElapsed));
static_cast<double>(map->getElementCount()) / totalElapsed));
_stats.append(SingleStat("Write Output Time (sec)", timingOutput));
_stats.append(SingleStat("Final Element Count", (double)map->getElementCount()));
_stats.append(SingleStat("Final Element Count", static_cast<double>(map->getElementCount())));
_stats.append(SingleStat("Total Time Elapsed (sec)", totalElapsed));
_stats.append(IoSingleStat(IoSingleStat::RChar));
_stats.append(IoSingleStat(IoSingleStat::WChar));
Expand Down Expand Up @@ -567,7 +567,7 @@ void ConflateExecutor::_writeChangesetStats()

float ConflateExecutor::_getTaskWeight() const
{
return 1.0 / (float)_numTotalTasks;
return 1.0f / (float)_numTotalTasks;
}

float ConflateExecutor::_getJobPercentComplete(const int currentTaskNum) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ void DiffConflator::_removeRefData(const bool removeSnapped)
RemoveElementsVisitor removeRef1Visitor;
removeRef1Visitor.setRecursive(true);
removeRef1Visitor.addCriterion(removeCrit);
const int mapSizeBefore = _map->size();
const int mapSizeBefore = static_cast<int>(_map->size());
_map->visitRw(removeRef1Visitor);
MemoryUsageChecker::getInstance().check();
OsmMapWriterFactory::writeDebugMap(_map, className(), "after-removing-ref-elements");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ NodePtr Roundabout::getNewCenter(OsmMapPtr pMap)
lat += pNode->getY();
}

count = _roundaboutNodes.size();
count = static_cast<double>(_roundaboutNodes.size());
lat = lat / count;
lon = lon / count;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void MatchConflicts::calculateMatchConflicts(const std::vector<ConstMatchPtr>& m
matchSet.clear();
}

matchSet.push_back(it->second);
matchSet.push_back(static_cast<int>(it->second));
lastEid = it->first;

eidToMatchCount++;
Expand Down
Loading