Commit e8332bb3 authored by Fabien Grzeskowiak's avatar Fabien Grzeskowiak

fix UMANS for linux

parent b2c010be
/* UMANS: Unified Microscopic Agent Navigation Simulator
** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettré
** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
......@@ -26,21 +26,29 @@
#include <core/crowdSimulator.h>
#include <algorithm>
#include <omp.h>
#include <cstring>
#include <string>
#include <unistd.h>
extern "C" {
extern "C"
{
CrowdSimulator* cs;
AgentData* agentData;
size_t agentDataSize;
API_FUNCTION bool StartSimulation(const char* configFileName, int numberOfThreads)
{
std::setlocale(LC_NUMERIC, "en_US.UTF-8");
omp_set_num_threads(numberOfThreads);
// initialize a new crowd simulation; we'll fill it with the contents of the given config file
cs = CrowdSimulator::FromConfigFile(configFileName, false);
if (cs == nullptr)
{
return false;
}
cs->GetWorld()->SetNumberOfThreads(numberOfThreads);
......
/* UMANS: Unified Microscopic Agent Navigation Simulator
** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettré
** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
......@@ -23,12 +23,10 @@
#ifdef WIN32
#define API_FUNCTION __declspec(dllexport)
#else
#define API_FUNCTION __attribute__((visibility("default")))
#define API_FUNCTION
#endif
#endif
extern "C"
{
/// <summary>A struct that describes the status of a single agent in the simulation.
/// This struct is used for communication between the UMANS library and external applications.</summary>
struct AgentData
......@@ -48,18 +46,18 @@ extern "C"
/// <summary>Sets up a simulation based on a configuration file.
/// After this function call, the simulation will be ready for its first time step.</summary>
/// <returns>true if the operation was successful; false otherwise, e.g. if the configuration file is invalid.</returns>
API_FUNCTION bool StartSimulation(const char* configFileName, int nrThreads);
API_FUNCTION extern "C" bool StartSimulation(const char* configFileName, int nrThreads);
/// <summary>Gets the step size of the simulation, in seconds.</summary>
/// <param ref="result_dt">[out] Will store the step size of the simulation.</param>
/// <returns>true if the operation was successful; false otherwise, i.e. if the simulation has not been initialized (correctly) yet.</returns>
API_FUNCTION bool GetSimulationTimeStep(float& result_dt);
API_FUNCTION extern "C" bool GetSimulationTimeStep(float& result_dt);
/// <summary>Performs the given number of simulation steps.
/// To obtain the resulting status of the simulation, use the GetAgentPositions() function.</summary>
/// <param ref="nrSteps">The number of steps to perform.</param>
/// <returns>true if the operation was successful; false otherwise, i.e. if the simulation has not been initialized (correctly) yet.</returns>
API_FUNCTION bool DoSimulationSteps(int nrSteps);
API_FUNCTION extern "C" bool DoSimulationSteps(int nrSteps);
/// <summary>Gets the current status of all agents in the simulation.</summary>
/// <param ref="result_agentData">[out] Will store a reference to an array of AgentData objects,
......@@ -67,13 +65,13 @@ extern "C"
/// <param ref="result_nrAgents">[out] Will store the number of agents in the simulation,
/// i.e. the number of useful entries in the AgentData array.</param>
/// <returns>true if the operation was successful; false otherwise, i.e. if the simulation has not been initialized (correctly) yet.</returns>
API_FUNCTION bool GetAgentPositions(AgentData*& result_agentData, int& result_nrAgents);
API_FUNCTION extern "C" bool GetAgentPositions(AgentData*& result_agentData, int& result_nrAgents);
/// <summary>Overrides the position of some or all agents in the simulation. You can decide for yourself which agents are affected.</summary>
/// <param ref="agentData">A reference to an array of AgentData objects, where each object describes the position of a single agent that you want to set.</param>
/// <param ref="nrAgents">The number of entries in the AgentData array.</param>
/// <returns>true if the operation was successful; false otherwise, i.e. if the simulation has not been initialized (correctly) yet.</returns>
API_FUNCTION bool SetAgentPositions(AgentData* agentData, int nrAgents);
API_FUNCTION extern "C" bool SetAgentPositions(AgentData* agentData, int nrAgents);
/// <summary>Tries to add a new agent to the simulation.</summary>
/// <param ref="x">The x-coordinate of the agent's starting position.</param>
......@@ -88,13 +86,13 @@ extern "C"
/// otherwise, the simulation will assign a different ID.</param>
/// <returns>true if the operation was successful; false otherwise,
/// i.e. if the simulation has not been initialized (correctly) yet, or if the agent with the given ID does not exist.</returns>
API_FUNCTION bool AddAgent(float x, float y, float radius, float prefSpeed, float maxSpeed, float maxAcceleration, int policyID, int& result_id, int desiredID = -1);
API_FUNCTION extern "C" bool AddAgent(float x, float y, float radius, float prefSpeed, float maxSpeed, float maxAcceleration, int policyID, int& result_id, int desiredID = -1);
/// <summary>Tries to remove a specific agent from the simulation.</summary>
/// <param ref="id">The ID of the agent to remove.</param>
/// <returns>true if the operation was successful; false otherwise,
/// i.e. if the simulation has not been initialized (correctly) yet, or if the agent with the given ID does not exist.</returns>
API_FUNCTION bool RemoveAgent(int id);
API_FUNCTION extern "C" bool RemoveAgent(int id);
/// <summary>Changes the goal of a single agent in the simulation.</summary>
/// <param ref="id">The ID of the agent to change.</param>
......@@ -102,9 +100,8 @@ extern "C"
/// <param ref="y">The y-coordinate of the agent's new goal.</param>
/// <returns>true if the operation was successful; false otherwise,
/// i.e. if the simulation has not been initialized (correctly) yet, or if the agent with the given ID does not exist.</returns>
API_FUNCTION bool SetAgentGoal(int id, float x, float y);
API_FUNCTION extern "C" bool SetAgentGoal(int id, float x, float y);
/// <summary>Cleans up some objects related to the simulation. Call this method just before you finish using the UMANS library.</summary>
/// <returns>true if the operation was successful; false otherwise, i.e. if the simulation has not been initialized (correctly) yet.</returns>
API_FUNCTION bool CleanUp();
}
\ No newline at end of file
API_FUNCTION extern "C" bool CleanUp();
......@@ -20,7 +20,7 @@
cmake_minimum_required( VERSION 2.8 )
project( UMANS )
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD 17)
#set(EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})
......@@ -48,7 +48,7 @@ endif (UMANS_USE_MULTITHREADING)
# === Linux compatibility compiler option
if (NOT MSVC)
add_definitions(-fPIC)
add_definitions(-O3 -lstdc++fs -fPIC -shared)
endif()
# === Engine project: a static library that performs the simulation
......
/* UMANS: Unified Microscopic Agent Navigation Simulator
** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettré
** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
......
/* UMANS: Unified Microscopic Agent Navigation Simulator
** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr
** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
......@@ -219,7 +219,7 @@ inline float counterClockwiseAngle(const Vector2D& va, const Vector2D& vb)
#pragma endregion
template<typename T> T clamp(T v, T min, T max)
template<typename T> T v2D_clamp(T v, T min, T max)
{
if (v < min)
return min;
......@@ -228,7 +228,7 @@ template<typename T> T clamp(T v, T min, T max)
return v;
}
inline Vector2D clamp(const Vector2D& v, float maxLength)
inline Vector2D v2D_clamp(const Vector2D& v, float maxLength)
{
float mag = v.magnitude();
if (mag <= maxLength)
......
/* UMANS: Unified Microscopic Agent Navigation Simulator
** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr
** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
......@@ -42,7 +42,7 @@ float Importance(float ttc)
float t0 = 5, I0 = 10, a = -I0 / t0;
float I = a * ttc + I0;
return clamp(I, 0.1f, 10.f);
return v2D_clamp(I, 0.1f, 10.f);
//return 1;
}
......@@ -125,9 +125,9 @@ Vector2D FOEAvoidance::GetGradient(const Vector2D& velocity, Agent* agent, const
// TODO: check neighboring obstacles
// ...
gradtheta = clamp(gradtheta, -0.1f, 0.1f);
gradtheta = v2D_clamp(gradtheta, -0.1f, 0.1f);
//gradtheta = -gradtheta;
//gradv = clamp(gradv, -1.f, 1.f);
//gradv = v2D_clamp(gradv, -1.f, 1.f);
//gradv = 0;
return -1 * R*(velocity.magnitude()*Vector2D(sin(gradtheta), 1 - cos(gradtheta)) + Vector2D(0, gradv));
......
/* UMANS: Unified Microscopic Agent Navigation Simulator
** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr
** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
......@@ -229,7 +229,7 @@ Vector2D TtcaDca::GetGradient(const Vector2D& velocity, Agent* agent, const Worl
GradS += GradThS_movement.second;
// clamp the change in angle
//GradTh = clamp(GradTh, -1.f, 1.f);
//GradTh = v2D_clamp(GradTh, -1.f, 1.f);
Vector2D Gradient;
......
/* UMANS: Unified Microscopic Agent Navigation Simulator
** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettré
** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
......@@ -61,10 +61,10 @@ Vector2D Policy::ComputeNewVelocity(Agent* agent, WorldBase * world)
}
// clamp to a maximum acceleration
acceleration = clamp(acceleration, agent->getMaximumAcceleration());
acceleration = v2D_clamp(acceleration, agent->getMaximumAcceleration());
// use this to compute a new velocity, clamped to a maximum speed
return clamp(currentVelocity + acceleration * dt, agent->getMaximumSpeed());
return v2D_clamp(currentVelocity + acceleration * dt, agent->getMaximumSpeed());
}
Vector2D Policy::getAccelerationFromGradient(Agent* agent, WorldBase * world)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment