diff --git a/.gitignore b/.gitignore index f130899..8f76a1e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ # ===================================================================== # RoboCon 2027 · BR 机器人代�仓库 —— 根目录 .gitignore -# 现仓库��留 sru_ws/(ROS 2 Humble 自主导航工作区)。 +# 现仓库�留两个工作区: +# sru_ws/ —— Odin1 + 深度 RL 导航(ROS 2 Humble,�包交付) +# minco_ws/ —— MID360 + Point-LIO + SCAN/MINCO 导航(ROS 2 Humble,19 个包) # 规则:�收录「构建产物 / �行期数� / 本地环境 / �人工具状��, # ����置�文档�模型一律�留。 # ===================================================================== diff --git a/minco_ws/.gitignore b/minco_ws/.gitignore new file mode 100644 index 0000000..fa08ddd --- /dev/null +++ b/minco_ws/.gitignore @@ -0,0 +1,23 @@ +# ---- 构建产物:��入库 ---- +build/ +install/ +log/ + +# ---- Python ---- +__pycache__/ +*.py[cod] +*.egg-info/ + +# ---- 点云地图:共 155 MB,5 个文件,�独用 rsync/U 盘传 ---- +# src/perception/icp_relocalization/pcd/cloudlab_processed*.pcd (~92 MB) +# src/navigation/navi2_bringup/maps/pcd/{2026rmuc,111}.pcd (~63 MB) +# 这些是场地/地图数�,�场地就��,放在仓库里�会让�次 clone �慢。 +*.pcd +*.bag +*.db3 + +# ---- 编辑器 / 系统 ---- +.vscode/ +.idea/ +*.swp +.DS_Store diff --git a/minco_ws/docs/DEPLOY_ROBOT.md b/minco_ws/docs/DEPLOY_ROBOT.md new file mode 100644 index 0000000..53f67ee --- /dev/null +++ b/minco_ws/docs/DEPLOY_ROBOT.md @@ -0,0 +1,390 @@ +# �机开�:开�机编译 → 机器人�电脑部署 + +> 结论先放这儿:**�,必须在自己电脑上先编一�**。但编出�的东西**�能直接拷到机器人上**。 +> 本文说清「为什么编�「什么能拷�「机器人上还��什么�。 + +## 0. 目标机画�(已确认) + +| 项 | 值 | 影� | +|---|---|---| +| 机器 | **GMKtec NucBox M6**(迷你主机) | — | +| CPU | AMD Ryzen 5 **6600H** 或 **7640HS**,6 核 12 线程 | 编译比开�机慢约 2–3 �,��接� | +| 架构 | **x86_64** ✅ 与开�机一致 | **�存在 ARM/x86 二进制�兼容问题** | +| 内存 | 16 / 32 GB �选 | 16 GB 足够,�用加 swap | +| 网� | **� 2.5G**(Realtek 8125) | 一个专供雷达�一个走调试,**�需�交�机** | +| 出厂系统 | Windows 11 | ��装/�系统 Ubuntu 22.04(Humble �认它) | +| 供电 | DC 19 V / 120 W | 车上�有 19 V �压或逆� | + +> 结论:**架构��系统� ⇒ �赖包��编译错误�PCL/Eigen 版本全一致**, +> 开�机上排干净的�,�过去�会�犯。这是最�事的一�移�组�。 + +--- + +## 1. 为什么�在开�机上先编译 + +| �由 | 具体数字 / 事实 | +|---|---| +| **首编一定有问题** | 19 个包�16 个 C++ 包�约 **28 万行 C++**(minco_planner 8.1 万 + minco_controller 6.9 万 + rog_map 3.4 万 + livox 驱动 2.4 万 + Point-LIO 1.5 万);从未构建过,CMake �赖错误�头文件缺失一定会有 | +| **编译轮次便宜** | 这�机 24 核,全�构建约 **8–12 分钟**;M6(6 核 12 线程)约 **20–30 分钟**。关键是:在桌上排错,比蹲在场地边排错便宜得多 | +| **环境一致,错误就是真错误** | 这�机 `Ubuntu 22.04.5 + ROS 2 Humble + x86_64`,与机器人�一�行版 ⇒ apt 包��CMake 行为�PCL/Eigen 版本一致,这里报的错到机器人上一样会报 | +| **排错�本低** | 机器人上改代�� `scp`/`git push` + �编,一轮�几分钟;本机 `--symlink-install` 改完�� launch �� | + +**一��**:开�机是「编译 + 逻辑验��的地方,机器人是「跑 + 标定�的地方。 + +--- + +## 2. 什么能拷,什么�能拷 + +因为两边都是 **x86_64 + Ubuntu 22.04 + Humble**,二进制本身是兼容的 —— 所以结论比 ARM 的情况�微宽�一点: + +| 内容 | 建议 | 原因 | +|---|---|---| +| `src/` | ✅ **必拷** | ��/�置,唯一真正的交付物 | +| `docs/`�`scripts/` | ✅ | 纯文本 | +| `build/` | � �拷 | 中间产物,�编�有�义 | +| `install/` | ⚠� **有�件�拷**,默认�建议�编 | �下 | +| `/usr/local/lib/liblivox_lidar_sdk*.so` | � | 虽然�架构,但**目标机根本没装**,必须在那�机编一次 | + +`install/` 想直接拷,必须**�时**满足三�: + +1. 机器人上的用户�与家目录和开�机相�(都是 `/home/kevin`); +2. 工作区路径一字�差(都是 `~/RC2027_BR_code/minco_ws`); +3. 两边�赖版本一致(�一批 apt 包)。 + +任何一��满足,`source install/setup.bash` 就会指��存在的路径 —— 而这些路径是 +**写死在文件内容里**的(`install/setup.bash`�`*.pc`�`local_setup.bash`),�是软链接改一改就行。 + +而且我们用的是 `--symlink-install`,`install/` 里大�文件是**指� `src/` 的�对符�链接**, +拷过去�么断链,�么指回开�机。 + +> **建议**:机器上�编。M6 上 SCAN 那 8 个包大约 **5 分钟**,全� 20–30 分钟, +> 比“拷过去�现路径�对��回��编�快。 + +--- + +## 3. 这�开�机现在缺什么(已实测) + +系统�赖**基本�了**,�差 3 个: + +| 缺的 | �需�它 | 安装方� | +|---|---|---| +| `ros-humble-pcl-ros` | `Point-LIO`�`icp_relocalization`�`msg_convert` | apt | +| `ros-humble-backward-ros` | `minco_planner`(`find_package(... REQUIRED)`) | apt | +| `Livox-SDK2` | `livox_ros_driver2`(`find_library(... REQUIRED)`) | ��编到 `/usr/local` | + +**已�确认存在**(�用��装):`pcl_conversions`�`nav2_core`�`nav2_costmap_2d`�`nav2_util`� +`tf2_eigen`�`eigen3_cmake_module`�`pluginlib`�`rclcpp_components`�`rosidl_default_generators`� +`yaml_cpp_vendor`�`cv_bridge`�`message_filters`�`Eigen3`�`PCL 1.12`�`OpenCV 4`�`glog`。 + +**�用装 `qpOASES`**:已� vendored 在 `minco_controller/third_party/qpOASES`, +`CMakeLists.txt` 会优先用自带的��库编译。 + +### 一�命令�定 + +```bash +cd ~/RC2027_BR_code/minco_ws +bash scripts/setup_deps.sh # 装� apt + Livox-SDK2 +bash scripts/setup_deps.sh --check # �看缺什么,�动系统 +``` + +> 需� `sudo` 和外网。会先校验 `Ubuntu 22.04` 与 `/opt/ros/humble`,�满足直接退出。 + +--- + +## 4. 开�机上编译 + +```bash +source /opt/ros/humble/setup.bash +cd ~/RC2027_BR_code/minco_ws + +# 4.1 先编消�包(C++ 包都�赖它们) +colcon build --symlink-install -DPython3_EXECUTABLE=/usr/bin/python3 \ + --packages-select ros_interfaces scan_planner_msgs + +# 4.2 �编全部 +colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release \ + -DPython3_EXECUTABLE=/usr/bin/python3 +``` + +**`-DPython3_EXECUTABLE=/usr/bin/python3` 这一�别�**:ROS 的代�生�器 +(`rosidl_adapter`)��系统 python3.10 里的 `empy`。如果你的 `PATH` 上有 conda / pyenv / +其他 `python3`(本项目开�机上的 WorkBuddy 自带 3.13 就在最��),CMake 会挑错解释器, +报 `ModuleNotFoundError: No module named 'em'` —— 这个报错看��缺包,其实是解释器选错。 + +**为什么分两步**:一次性编全部时,colcon 虽然会按�赖拓扑排�,但消�包刚生�时 +`rosidl` 的 CMake �置�尔会晚一�,报 `Could not find ...__rosidl_typesupport_c`。 +分两步能排除这个干扰,第一次建工作区时建议照�。 + +编完的验收: + +```bash +source install/setup.bash +ros2 pkg list | grep -E "scan_planner|plan_env|point_lio|livox_ros_driver2|body_odom|step_blocker" +# 6 个包都在 +``` + +### �想� SCAN 那�链路时 + +`navigation/` 那套(MINCO + Nav2,16 万行)编译最慢��赖最多(`backward_ros` + nav2 + qpOASES)。 +先跑通 SCAN 的�,�以�编 8 个包: + +```bash +colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release \ + -DPython3_EXECUTABLE=/usr/bin/python3 \ + --packages-up-to scan_planner step_blocker body_odom +``` + +### 已�实测的结果(24 核 x86_64) + +| 项 | 结果 | +|---|---| +| SCAN 链路 8 个包 | ✅ **2 分 08 秒** 全部通过(�有 warning,无 error) | +| 编译产物 | `install/` 7.2 MB�`build/` 41 MB | +| `ros2 launch step_blocker ... --show-args` | ✅ 正常解� | +| `step_blocker` / `body_odom` 节点 | ✅ 能起�能建 publisher/subscriber | +| 完整 19 个包 | ⛔ 需�先补 `pcl_ros` + `backward_ros` + `Livox-SDK2` | + +> 2026-10-19 实测。当时顺手把 `step_blocker`�`body_odom` 从 `ament_python` 改�了 +> `ament_cmake`(原因�上�「��表),所以现在是 **16 个 C++ + 2 个 Python(走 ament_cmake) +> + 1 个 `ament_python`(底盘桥,注册正常)**。 + +--- + + +## 5. 到机器人上��什么 + +顺��能乱,**�一步都�过验收�往下**。 + +### 5.1 装系统(M6 出厂是 Windows 11) + +Humble �认 **Ubuntu 22.04**,别的版本都装�上 apt 包。 + +1. � Ubuntu **22.04.5** �动 U 盘(Rufus / balenaEtcher); +2. M6 开机按 `F7`(GMKtec 常�的�动��键,进�去就 `Del` 进 BIOS 找 Boot Menu); +3. BIOS 里**关掉 Secure Boot**,�则第三方驱动(Livox / �些网�)会被拦; +4. 建议**整盘装 Ubuntu**(�系统还�处� Windows 快速�动�时间�步,比赛中没必�); +5. 装完确认: + +```bash +uname -m # 期望 x86_64 +lsb_release -d # 期望 Ubuntu 22.04.x LTS +uname -r # 期望 6.8.x(22.04.5 的 HWE 内核) +``` + +> **内核别太�**:6600H 是 Zen3+�7640HS 是 Zen4,需� 6.x 内核; +> 22.04.5 自带 6.8 HWE,正好。若装的是 22.04.0 �镜�(5.15 内核), +> 先 `sudo apt install --install-recommends linux-generic-hwe-22.04` �继续。 + +然�装 ROS: + +```bash +sudo apt install -y ros-humble-desktop +``` + +### 5.2 �网�怎么分工(M6 的关键优势) + +M6 有两个 2.5G 网�,**别桥接,�干�的**: + +| 网� | 接什么 | IP | +|---|---|---| +| `enp1s0`(举例) | **MID360 雷达**,直连,��交�机 | �� `192.168.1.47/24` | +| `enp2s0`(举例) | 路由器 / 笔记本 SSH / 传文件 | DHCP,或���网段 | + +```bash +ip -br a # 先看清哪个�是哪个(�拔网线对比) +sudo nmcli con add type ethernet ifname enp1s0 con-name lidar \ + ipv4.method manual ipv4.addresses 192.168.1.47/24 +sudo nmcli con up lidar +ping 192.168.1.196 # 雷达出厂 IP,通则网线/供电没问题 +``` + +⚠� **网���能和开�机��**(`enp1s0` / `enp2s0` / `eno1`),别照抄。 +而且两个�顺�在�系统��能�过�,所以**一定先 `ip -br a` 确认**�写死�置。 + +`MID360_config.json` 里的 `host_net_info.*_ip` 必须等于**接雷达那个�**的 IP(这里是 `192.168.1.47`), +�是�一个�的。 + +### 5.3 怎么把代�传过去(三�路,按推�排�) + +| 方� | 适�什么时候 | 速度 | 缺点 | +|---|---|---|---| +| **① GitHub(已有仓库)** � | 想留版本历��多人�作�以�改动能追踪 | 14 MB,几�秒 | 需�凭�;**PCD 地图传�了**(已被 `.gitignore`) | +| ② 局域网 `rsync` | �想�文件��想污染仓库;�一�网线/路由器 | �兆网 ~100 MB/s,177 MB 约 2 秒 | 没有版本历� | +| ③ U 盘 / `tar` | 场地没网�两边连�到一起 | 看 U 盘 | 手工,易� | + +#### ① GitHub(仓库已就绪) + +仓库:`https://github.com/Keviniscoding666/RC2027_BR_code.git`(`main` 分支) + +**开�机上**: + +```bash +cd ~/RC2027_BR_code +git add minco_ws +git commit -m "feat(minco_ws): MID360 + SCAN 无图导航,��阶�堵与车体里程计" +git push origin main # 会让你输入用户� + PAT(�是登录密�) +``` + +> 实测 `git add minco_ws` 会收 **828 个文件�14.2 MB**; +> `build/ install/ log/`�`*.pcd`�`*.bag` 都已被 `minco_ws/.gitignore` 排除,**�会误传 177 MB**。 + +**M6 上**: + +```bash +cd ~ +git clone https://github.com/Keviniscoding666/RC2027_BR_code.git +# 已有仓库则:cd RC2027_BR_code && git pull +``` + +> GitHub 现在**�接�账�密�**,push 时� `Personal Access Token`(Settings → Developer settings → +> Personal access tokens → Fine-grained,勾 `repo` 读写)。第一次输完�以用 +> `git config --global credential.helper store` 记�(明文存在 `~/.git-credentials`,自己�衡)。 + +#### ⚠� 地图 PCD �**�独**传(GitHub 上没有) + +`minco_ws/.gitignore` 明确排除了 `*.pcd`,因为 5 个文件共 **155 MB**�且�场地就�: + +``` +src/perception/icp_relocalization/pcd/cloudlab_processed{,_red,_blue}.pcd ~92 MB +src/navigation/navi2_bringup/maps/pcd/{2026rmuc,111,2026rmul}.pcd ~63 MB +``` + +�跑 SCAN(无图)时**根本�需�这些**,�以�管;�用 MINCO/PCT 的全局规划�传: + +```bash +# �传 PCD(-z 压缩,PCD 是文本,压得动) +rsync -avz --include='*/' --include='*.pcd' --exclude='*' \ + minco_ws/src/ @:~/RC2027_BR_code/minco_ws/src/ +``` + +#### ② 局域网 rsync(�想用 git 时) + +```bash +bash scripts/deploy_to_robot.sh @ # ��步 +bash scripts/deploy_to_robot.sh @ --build # �步 + 远程编译 +``` + +等价的手写版: + +```bash +cd ~/RC2027_BR_code +rsync -av --exclude build/ --exclude install/ --exclude log/ \ + minco_ws/ @:~/RC2027_BR_code/minco_ws/ +``` + +#### 传完在 M6 上装�赖 + +```bash +cd ~/RC2027_BR_code/minco_ws +bash scripts/setup_deps.sh +bash scripts/setup_deps.sh --check # 应该全绿 +``` + +### 5.4 编译(6 核 12 线程) + +```bash +source /opt/ros/humble/setup.bash +cd ~/RC2027_BR_code/minco_ws + +colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release \ + -DPython3_EXECUTABLE=/usr/bin/python3 \ + --parallel-workers 6 +``` + +| 机器 | 并行度 | 预计耗时 | +|---|---|---| +| 开�机 24 核 / 16 G | 默认 | 全� 8–12 min(SCAN �集实测 2 min 08 s) | +| **M6 6 核 / 16 G** | `6` | 全� **20–30 min**,SCAN �集约 **5 min** | +| M6 6 核 / 32 G | `8`(超线程也用上) | 全� 15–25 min | + +16 GB 内存够用,**�需�加 swap**;真�到 `Killed` �把 `--parallel-workers` �到 4。 + +### 5.5 改「跟机器绑定�的�置 + +这几项**必须在机器人上��**,�能沿用开�机的值: + +| 文件 | 改什么 | +|---|---| +| `livox_ros_driver2/config/MID360_config.json` | `host_net_info.*_ip` = 机器人网� IP;`lidar_configs[0].ip` = 雷达 IP | +| `techx_r2_chassis_control/config/chassis_serial.yaml` | `port`(`/dev/ttyUSB0` 还是 `/dev/ttyACM0`) | +| `body_odom/config/body_odom.yaml` | 雷达→车体中心外�(跟**车**绑定,�是跟电脑) | +| `step_blocker/config/step_blocker.yaml` | �阶矩形(跟**场地**绑定) | +| `plan_manage/config/planner_vehicle.yaml` | 车体�径�车高��速(跟**车**绑定) | + +> 如果开�机就在车上(雷达已接本机),那 5.5 里的值在开�机标完�以直接�步过去; +> 如果开�机是��机�车上�有一套硬件,这 5 项到车上必须�新标。 + +### 5.6 串���(��一次) + +```bash +sudo usermod -aG dialout $USER # �新登录生效 +``` + +--- + +## 6. 把「已�修好�的�置带回去 + +开�机上调通的�数,回传到机器人: + +```bash +# 在开�机上(��步�置,�动代�) +rsync -av --include='*/' --include='*.yaml' --include='*.json' --exclude='*' \ + src/ @:~/RC2027_BR_code/minco_ws/src/ +``` + +⚠� 但 `body_odom` / `step_blocker` / `planner_vehicle` 这三份是**机器相关**的, +�步�确认机器人上的硬件和场地跟开�机一致,�则会把错误的标定覆盖过去。 + +--- + +## 7. 移�检查清� + +到机器人上�项打勾,全过�谈「�目标自动驾驶�: + +- [ ] `uname -m` = `x86_64`(M6 应为 x86_64) +- [ ] `lsb_release -d` = Ubuntu 22.04,`/opt/ros/humble` 存在 +- [ ] 内核 ≥ 6.x(`uname -r`) +- [ ] �网�分工确认:`ip -br a` 里接雷达那个�是 `192.168.1.47` +- [ ] `bash scripts/setup_deps.sh --check` 无 � +- [ ] ��步了 `src/`+`docs/`+`scripts/`,没有 `build/` `install/` `log/` +- [ ] `colcon build` �功,无 `Failed` / `Aborted` +- [ ] `source install/setup.bash` � `ros2 pkg list` 能看到 `scan_planner` +- [ ] 雷达 `ping` 通,`ros2 topic hz /livox/lidar` ≈ 10 Hz +- [ ] `ros2 topic hz /aft_mapped_to_init` 有输出 +- [ ] `ros2 topic hz /body_odom` 与上��频 +- [ ] `ros2 topic hz /cloud_registered_for_scan` 有输出(= step_blocker 通了) +- [ ] 串���生效(`ls -l /dev/ttyUSB0` 属组是 `dialout`) +- [ ] 架空�目标,`/cmd_vel` 有�零输出 +- [ ] �地低速试跑(�速��) + +--- + +## 8. 常�� + +| 现象 | 原因 | 处� | +|---|---|---| +| `find_library(... livox_lidar_sdk_shared ... REQUIRED)` 失败 | Livox-SDK2 没装 | `setup_deps.sh`;装完 `sudo ldconfig` | +| `Could not find backward_ros` | 缺 `ros-humble-backward-ros` | apt;�里没有就��编 `pal-robotics/backward_ros` | +| `Could not find pcl_ros` | 缺 `ros-humble-pcl-ros` | apt | +| `ModuleNotFoundError: No module named 'em'` | CMake 挑了�系统 `python3`(conda/pyenv/自带 3.13),里�没有 `empy` | 加 `-DPython3_EXECUTABLE=/usr/bin/python3` | +| `ros2 pkg`/`ros2 launch` 报 `package not found`,但包明明编过了 | `install//share//hook/` 里�有 `pythonpath.*`�缺 `ament_prefix_path.*`,�缀没进 `AMENT_PREFIX_PATH`(`--merge-install` 也救�了) | 检查那个 `hook/` 目录;缺钩�就把该包改� `ament_cmake` 安装脚本(本项目的 `step_blocker`/`body_odom` 已这么改) | +| `fatal error: error writing to /tmp/ccXXXX.s: 设备上没有空间` | 容器/精简系统里 `/tmp` 是� tmpfs | `TMPDIR=/path/on/disk colcon build ...` | +| 编译被 `Killed`(OOM) | 内存�够或并行度太高 | � `--parallel-workers`(M6 上一般�会,16 G 够) | +| `install/setup.bash` 报路径�存在 | 拷了 `install/` | 删掉�编 | +| `ros2: command not found` | 没 `source /opt/ros/humble/setup.bash` | 加到 `~/.bashrc` | +| 雷达 ping �通 | 网� IP / `MID360_config.json` 的 host IP �对 | 两边都改;确认是**接雷达那个�**的 IP | +| �系统�两个网�顺��了 | 网�� `enpXsY` 由 PCI 枚举决定 | `ip -br a` �新确认,改 nmcli �置与 `host_net_info` | +| 雷达间歇丢包 / 帧率掉 | 两个网�被桥接,或雷达�走了交�机 | �� `brctl`/`nmcli` 桥接,雷达直连一个� | +| M6 装完没 Wi-Fi/�牙 | RZ616 需�较新内核 | 用 22.04.5(6.8 内核);�镜�先装 `linux-generic-hwe-22.04` | + +--- + +## 9. 一��总结 + +- **开�机**(本机 24 核):装 3 个�赖 → 编一� → 把编译错误�CMake 错误全排掉。**这一步必须�**。 +- **机器人**(GMK M6,x86_64 6 核):拷 `src/` → 跑�一个 `setup_deps.sh` → �编(全� 20–30 min) + → �标外�/�阶。**�赖和错误�会�犯,因为系统�架构��行版。** +- 能�能��编?M6 和开�机都是 x86_64,**�论上**��用户��家目录�工作区路径三者完全一致, + 拷 `install/` 能跑。但 `--symlink-install` 下 `install/` 全是�对符�链接, + 一旦�一致就 `package not found` 一片 —— 而 M6 �编�� 20–30 分钟,�值得赌。 +- 唯一**必须**在 M6 上��的是 `/usr/local` 里的 **Livox-SDK2**(`setup_deps.sh` 会处�)。 diff --git a/minco_ws/docs/QUICKSTART.md b/minco_ws/docs/QUICKSTART.md new file mode 100644 index 0000000..a9e74be --- /dev/null +++ b/minco_ws/docs/QUICKSTART.md @@ -0,0 +1,308 @@ +# 从零到「�目标点自主导航�—— 上机�程 + +> 适用:`minco_ws` + SCAN(无图)+ 轮�全�底盘 + MID360。 +> 本文按**实际�作顺�**写,�一步都有验收判�;判��过��往下走。 + +## 0. 先回答「现在能直接跑�� + +**代�层�是通的,但�能"装完雷达就�目标"**,还差 4 件事: + +| # | 缺什么 | 在哪� | +|---|---|---| +| 1 | �赖没装�没编译 | §3 | +| 2 | 雷达 IP 没� | §2 | +| 3 | **雷达→车体中心外�没填**(雷达�在中心时必填) | §4 | +| 4 | �阶区域没标(�影�"�走斜�") | §7 | + +�外:SCAN 这�链路(8 个包)已在开�机上编译通过(2 分 08 秒); +� Point-LIO / Nav2 的完整 19 个包还需� `pcl_ros`�`backward_ros`�`Livox-SDK2`,� `DEPLOY_ROBOT.md` §3。 + +--- + +## 1. 雷达安装上车 + +### 1.1 �� + +MID360 的�标系:**x ���y �左�z �上**。 + +- 让雷达的 x 轴与车体正�方一致(±2° 内); +- 尽�**水平**安装(roll/pitch 越接近 0 越好)。Point-LIO 能容��倾角,但倾角会直接�� + `body_pose` 的俯仰,影���上的高度估计; +- 雷达**��挡�轮�/车体的视野**:`blind: 0.35 m` 会剔除以车体中心为�心�35 cm 内的点, + 车体比这更大时�把 `blind` 调大(� §4.3)。 + +### 1.2 记录三个尺寸(��填外��用) + +在车上�,��米,**记到 1 cm 精度**: + +| �什么 | 怎么� | 记作 | +|---|---|---| +| 雷达光心到车体旋转中心的���离 | 两者分别垂直投影到地�,�投影点沿车头方�的�离 | `dx`(雷达在中心�方为正) | +| 左��移 | �上,�横� | `dy`(雷达在中心左侧为正) | +| 高度差 | 雷达光心离地高度 − 车体旋转中心离地高度 | `dz`(雷达更高为正) | + +### 1.3 接线 + +- 网线:雷达 → 上�机(建议直连,���过交�机,��组播/带宽问题); +- 供电:按雷达规格(12 V),确认电�足够; +- 上�机网�:**�兆**,且��开 Wi-Fi 桥接。 + +--- + +## 2. 网络�置(雷达能被 ping 通) + +出厂雷达 IP 通常是 `192.168.1.1xx`。本工程�置里写的是 `192.168.1.196`。 + +### 2.1 上�机网� + +```bash +ip a # 找到接雷达的那�网�,例如 enp3s0 +sudo ip addr add 192.168.1.47/24 dev enp3s0 +sudo ip link set enp3s0 up +ping 192.168.1.196 # 能通�继续 +``` + +> `192.168.1.47` 是 `MID360_config.json` 里 `host_net_info` 的默认值,�以改, +> 但�与网�地�一致。 + +### 2.2 改雷达 IP(如果与 196 ��) + +`src/perception/livox_ros_driver2/config/MID360_config.json` + +```json +"host_net_info": { + "cmd_data_ip": "192.168.1.47", � 上�机网� IP + ... +}, +"lidar_configs": [ + { "ip": "192.168.1.196", ... } � 雷达实际 IP +] +``` + +改完**��驱动**。 + +**验收**:`ping` 通;起驱动� `ros2 topic hz /livox/lidar` 有 ~10 Hz。 + +--- + +## 3. �赖与编译 + +```bash +# 一�命令装�(apt + Livox-SDK2 ��编译) +bash scripts/setup_deps.sh +bash scripts/setup_deps.sh --check # �看缺什么 + +# 手动装的�,这两个是必须的: +sudo apt install -y ros-humble-pcl-ros ros-humble-backward-ros +# Livox-SDK2 按 https://github.com/Livox-SDK/Livox-SDK2 编译安装到 /usr/local + +cd ~/RC2027_BR_code/minco_ws +source /opt/ros/humble/setup.bash + +# 强制用系统 python(PATH 上若有 conda / 其他 python3 会报 No module named 'em') +colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release \ + -DPython3_EXECUTABLE=/usr/bin/python3 \ + --packages-up-to scan_planner step_blocker body_odom +source install/setup.bash +``` + +**验收**:退出� 0,且下� 8 个包都在: + +```bash +ros2 pkg list | grep -E "scan_planner|plan_env|path_searching|bspline_opt|traj_utils|step_blocker|body_odom" +``` + +> 实测(24 核):这 8 个包全� **2 分 08 秒** 通过。 +> 完整 19 个包还�装 `backward_ros`/`Livox-SDK2`,� `DEPLOY_ROBOT.md`。 + +--- + +## 4. 外�:雷达�在车体中心时怎么填 + +### 4.1 为什么需� + +SCAN 有两个�姿输入,用途��: + +| 输入 | 用途 | 应该是� | +|---|---|---| +| `sensor_pose` | 射线起点(点云去畸�/��更新) | **雷达** | +| `body_pose` | 轨迹起点�到点判定��圆柱碰撞中心 | **车体中心** | + +Point-LIO 输出的 `/aft_mapped_to_init` 是**雷达**�姿。所以工程里加了 `body_odom` 节点: + +``` +/aft_mapped_to_init ──► body_odom ──► /body_odom (车体中心) + │ + └──────────────────────────────► sensor_pose(雷达) +``` + +### 4.2 填哪几个数 + +`src/scan/body_odom/config/body_odom.yaml` + +```yaml +body_odom: + ros__parameters: + offset_x: 0.0 + offset_y: 0.0 + offset_z: 0.0 + offset_yaw: 0.0 +``` + +�义:**车体中心在雷达�标系下的�标**(x ��y 左�z 上)。 + +用 §1.2 �到的 `dx/dy/dz` �算: + +``` +offset_x = -dx (雷达在中心�方 dx ⇒ 中心在雷达�方 dx) +offset_y = -dy (雷达在中心左侧 dy ⇒ 中心在雷达�侧 dy) +offset_z = -dz + z_ref +``` + +`z_ref` 是**碰撞�考高度**,建议� `0.2 ~ 0.3 m`(离地)。因为 SCAN 用 `body_pose.z` +去查碰撞体素,z 太高会�掉矮障�。 + +**例**:雷达装在车体中心正�方 0.30 m�高 0.50 m,车体碰撞�考高度� 0.25 m: + +``` +offset_x = -0.30 +offset_y = 0.00 +offset_z = -0.50 + 0.25 = -0.25 +``` + +此时 `/body_odom` 的 z ≈ 0.25,轨迹贴�"车体中部"走。 + +### 4.3 相关�数 + +| 文件 | �数 | 作用 | +|---|---|---| +| `body_odom.yaml` | `offset_x/y/z/yaw` | 雷达→车体中心 | +| `planner_vehicle.yaml` | `grid_map.double_cylinder_radius` | 车体�径(两个圆) | +| �上 | `grid_map.double_cylinder_offset` | 两圆心沿车头方���多少 | +| �上 | `grid_map.body_height` | 车高 | +| �上 | `grid_map.obstacles_inflation_z_up/down` | 障�上下膨胀 | +| `mid360.yaml` | `blind` / `blind_center` | 剔除车体自身点云;车体大于 35 cm 时调大 `blind` | + +**验收**:�止时 `ros2 topic echo /body_odom --once` 的 xy 与 `/aft_mapped_to_init` 相差 +正好是 `offset` 旋转�的结果;推车走 1 m,`/body_odom` 的�移应与实际一致。 + +--- + +## 5. 车体几何与速度 + +`planner_vehicle.yaml`: + +```yaml +grid_map.double_cylinder_radius: 0.30 # 车体�径 +grid_map.double_cylinder_offset: 0.20 # ��圆心�移 +grid_map.body_height: 0.50 +manager.max_vel: 0.80 +manager.max_acc: 0.60 +``` + +`controllers_vehicle.yaml`: + +```yaml +max_vx: 0.80 +max_vy: 0.40 +max_vyaw: 1.20 +``` + +**先��大**:第一次上机建议全部��(`max_vel: 0.4`�`max_vx: 0.4`),确认行为正常�放开。 + +--- + +## 6. 分级验�(�步都有判�) + +### 6.1 �测雷达 + LIO + +```bash +ros2 launch scan_planner vehicle_bringup.launch.py \ + launch_chassis:=false launch_scan:=false launch_blocker:=false +``` + +判�: + +```bash +ros2 topic hz /livox/lidar # ~10 Hz +ros2 topic hz /aft_mapped_to_init # 明显高于 10 Hz +ros2 topic hz /cloud_registered # 正常输出 +ros2 run tf2_ros tf2_echo camera_init body # 推车时�姿连续�化 +``` + +### 6.2 起 SCAN(��接底盘) + +```bash +ros2 launch scan_planner vehicle_bringup.launch.py launch_chassis:=false +``` + +RViz2:Fixed Frame `camera_init`,加 `/cloud_registered_for_scan`�`/grid_map/occupancy_inflate`。 + +判�:能看到体素地图;`/cmd_vel` 在没�目标时应该是 0 或没有。 + +### 6.3 �目标(空载验�) + +```bash +ros2 topic pub --once /move_base_simple/goal geometry_msgs/msg/PoseStamped \ + "{header: {frame_id: camera_init}, pose: {position: {x: 2.0, y: 0.0}}}" +ros2 topic echo /cmd_vel +``` + +判�:出现�零 `linear.x`;`ros2 topic hz /cmd_vel` 约 100 Hz(控制器频率)。 + +> 这一步轮�会转,**必须先架空**。 + +--- + +## 7. 标�阶区域(�走斜�) + +� `SCAN_VEHICLE.md` §7。简述: + +1. RViz 里 Fixed Frame `camera_init`,显示 `/cloud_registered`; +2. 用 **Publish Point** 点�阶投影的两个对角,`ros2 topic echo /clicked_point` 读 x/y; +3. 填 `step_blocker/config/step_blocker.yaml` 的 `regions`; +4. �� launch ��(`--symlink-install` 下 install 里的 yaml 是符�链接,直通 `src/`,**�用�编译**); +5. 看 `/cloud_registered_for_scan` 里出现那堵墙。 + +--- + +## 8. 接底盘(第一次动轮�) + +```bash +# 1) 架空 +ros2 launch scan_planner vehicle_bringup.launch.py +# 2) �目标,确认轮�转�与 /cmd_vel 符�一致 +# 3) �地,速度��,人在�边�时断电 +``` + +`chassis_serial.yaml` 的 `port` �指对(`/dev/ttyUSB0` 或 udev 别�)。 + +**验收**:`/cmd_vel` 的 `linear.x` 为正时车��;`angular.z` 为正时逆时针。 + +--- + +## 9. 排错速查 + +| 现象 | 原因 | +|---|---| +| `/livox/lidar` 没数� | 雷达 IP / 网� / `ping` �通 | +| `/aft_mapped_to_init` �动 | 点云没进 LIO;看 `ros2 topic hz /livox/lidar` | +| SCAN �动�无 `/cmd_vel` | `cloud` 没数�(检查 `cloud_topic` 是�指� `/cloud_registered_for_scan`);或 `body_pose` 没数�(`body_odom` 没起) | +| 车�在离目标几�厘米处 | `body_odom` 的 `offset_x/y` 没填或符�错 | +| 车头/车尾蹭障� | `double_cylinder_radius/offset` ��,或 `offset_x` 没补� | +| 到了目标附近��横跳 | `finish_dist` 太� / `kp_pos` 太大;先把 `max_vel` �下� | +| 上�上到一�退回 | �太陡或点云把��判�障�;看 `/grid_map/occupancy_inflate` 是�把��填满 | +| 明明有斜��绕远 | `step_blocker` 的矩形把斜�也圈进去了 | + +--- + +## 10. 最��行清�(TL;DR) + +1. 装雷达,� `dx/dy/dz`; +2. �网� + `MID360_config.json`,`ping` 通; +3. 装�赖,`colcon build`; +4. 填 `body_odom.yaml` 的 `offset_x/y/z`; +5. 填 `planner_vehicle.yaml` 的车体几何 + `controllers_vehicle.yaml` 的速度(先��); +6. 起 `vehicle_bringup.launch.py launch_chassis:=false`,�目标看 `/cmd_vel`; +7. 标 `step_blocker` 的�阶矩形; +8. 接底盘,架空 → �地。 diff --git a/minco_ws/docs/README.md b/minco_ws/docs/README.md new file mode 100644 index 0000000..3fd01b3 --- /dev/null +++ b/minco_ws/docs/README.md @@ -0,0 +1,225 @@ +# minco_ws —— MINCO + ROG-Map 导航工作区(移�自 BIT `navi_minco_bit`) + +> 本工作区从 `~/references/navi_minco_bit` 移�而�,**��留导航/感知链路**, +> 去掉了比赛决策(`bt_manager`)��判系统串�(`communication`)�仿真�模�。 +> 底盘桥�自本仓库的 `sru_ws/src/techx_r2_chassis_control`。 +> +> **第一次上机**:先读 **[`QUICKSTART.md`](QUICKSTART.md)**(从雷达安装�网络�编译� +> 外�,到�目标点,�步带验收判�)。 + +## 两套导航方案(互斥,�能�时�动) + +| | **SCAN(无图,推�先试)** | **MINCO / Nav2(有图)** | +|---|---|---| +| 文档 | **[`SCAN_VEHICLE.md`](SCAN_VEHICLE.md)** | 本文件 | +| �动 | `ros2 launch scan_planner vehicle_bringup.launch.py` | `ros2 launch navi2 minco_ws_bringup.launch.py map:=...` | +| 先验地图 | **�需�** | 需� `.pgm + .yaml` | +| 上斜� | ✅ 3D 体素 + 3D B 样� | ⚠� 2D costmap 易被��点云堵死 | +| 包�置 | `src/scan/` | `src/perception`�`src/navigation`�`src/interfaces` | + +两者都往 `/cmd_vel` �,�时开会互相抢�题。 + + +## 1. �留了哪些包 + +| 包 | 作用 | +|---|---| +| `perception/livox_ros_driver2` | MID360 驱动(点云 + IMU) | +| `perception/Point-LIO` | LiDAR-IMU 里程计,输出 `/aft_mapped_to_init` 与 TF | +| `perception/rog_map` | ROG-Map(局部��/ESDF,动�障�衰�) | +| `perception/msg_convert` | 点云�剪/转�(�选) | +| `perception/icp_relocalization` | 先验 PCD 地图�定�(�选) | +| `perception/dbscan_cluster` | 动�障��类(�选) | +| `navigation/minco_planner` | Nav2 **全局规划�件**(�是独立节点) | +| `navigation/minco_controller` | Nav2 **控制�件**(MPC,� `/cmd_vel_mpc`) | +| `navigation/navi2_bringup` | Nav2 launch��数�地图�rviz �置 | +| `interfaces/ros_interfaces` | 自定义消�(`MpcPositionCommand` 等) | +| `chassis/techx_r2_chassis_control` | `/cmd_vel` → STM32 串�桥(10 字节帧 + CRC16) | + +**去掉了**:`decision/bt_manager`(比赛行为树)�`navigation/communication`(�判系统串�)� +`simulation`(git submodule)�`dual_lidar_calibration`(�雷达�需�)�`utils/*`(离线工具)。 + +## 2. 数�� + +``` +MID360 ──► livox_ros_driver2 ──► /livox/lidar, /livox/imu + └─► Point-LIO ──► /aft_mapped_to_init + └─► TF: camera_init → body / base_link + +Nav2: + map_server + AMCL ──► map → odom + planner_server ──► minco_planner(全局路径) + controller_server ──► minco_controller(MPC)──► cmd_vel_nav + velocity_smoother ──► /cmd_vel + └─► chassis_serial_node ──► 串� 10 字节 ──► STM32 +``` + +> 注�:`controller_server` 的输出是 **`cmd_vel_nav`**(� +> `navigation/navi2_bringup/launch/navigation_launch.py:128`), +> 最�由 `velocity_smoother` remap � **`/cmd_vel`**(�文件 `:179`)。 +> 所以底盘桥订阅 `/cmd_vel` ��,**�需�** `bt_manager` 转�。 + +## 3. 外部�赖(�在本仓库,需�自己装) + +| �赖 | 说明 | +|---|---| +| `ros-humble-navigation2`�`ros-humble-nav2-bringup` | **必需**,MINCO 是 Nav2 �件 | +| `spatio_temporal_voxel_layer` | **必需**,`sentry1.yaml` 的 `stvl_layer` 用它。apt 通常没有,需��编译 | +| `ros-humble-backward-ros` | `minco_planner` 的 `find_package(backward_ros)` �求 | +| `pcl_conversions`�`yaml_cpp_vendor`�`eigen3_cmake_module` | apt �装 | +| Livox-SDK2 | `livox_ros_driver2` 编译需�(>2.0) | + +## 4. 构建(**我没有执行,请你�跑**) + +```bash +cd ~/RC2027_BR_code/minco_ws +source /opt/ros/humble/setup.bash + +# 建议按�赖顺�(原仓库 build.bash 也是串行先编这些) +for p in ros_interfaces livox_ros_driver2 rog_map point_lio \ + dbscan_cluster minco_planner minco_controller; do + colcon build --symlink-install --packages-select $p \ + --cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=1 +done +colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release +``` + +## 5. �动 + +```bash +source /opt/ros/humble/setup.bash +source ~/RC2027_BR_code/minco_ws/install/setup.bash + +# 全套(雷达 + LIO + Nav2 + 底盘桥) +ros2 launch navi2 minco_ws_bringup.launch.py \ + map:=$HOME/RC2027_BR_code/minco_ws/src/navigation/navi2_bringup/maps/<你的图>.yaml + +# �测 LIO(�� Nav2/底盘) +ros2 launch navi2 minco_ws_bringup.launch.py launch_nav:=false launch_chassis:=false + +# 用 RViz 给�始�姿:2D Pose Estimate,或�布 /initialpose +``` + +�动顺�由 `minco_ws_bringup.launch.py` 内部��:先起 `livox_pointlio_container`, +延迟 6 s �起 Nav2(`planner_server` � `LoadComposableNodes` 进那个容器)。 +容器没起�就起 Nav2,会看到 `Failed to load node ... into container`。 + +## 6. ⚠� 必须按你们机器人改的�数 + +### 6.1 雷达网络(最先改) + +`src/perception/livox_ros_driver2/config/MID360_config.json` + +```json +"host_net_info": { + "cmd_data_ip": "192.168.1.47", � 上�机网� IP,改�你自己的 + ... +} +"lidar_configs": [ + { "ip": "192.168.1.196", ... } � 雷达 IP(出厂标签上有) +] +``` + +查看网�:`ip a`,选与雷达�网段的那个�。改完**��驱动**。 + +### 6.2 雷达→车体中心�移(**最��的外�,代�里硬编�**) + +`src/perception/Point-LIO/src/laserMapping.cpp:665` + +```cpp +tf2::Vector3 offset_vec(0.0, 0.20, 0.0); // �形哨 +``` + +�义:`base_link`(Nav2 的 `robot_base_frame`)在**雷达�标系**下的�置。 +当�是 `x=0, y=+0.20, z=0`(原比赛车“�形哨�的�移)。 + +**怎么改**:�出雷达光心到车体旋转中心的三维�移,按雷达�标系填进去 +(MID360 的 x ���y �左�z �上,需与实车��一致)。 + +�外两处���数: + +- `src/perception/Point-LIO/config/mid360.yaml` 的 `blind_center: [0.0, 0.20, 0.0]` + —— 雷达中心盲区�移,应与上�的�移一致; +- �文件 `blind: 0.35` —— 盲区�径(米),车体�挡大时调大。 + +> ⚠� 这段代�还把 `base_link` 的 **rotation 强制写���四元数** +> (`laserMapping.cpp:683-686`),� `base_link` 永远��车转。 +> 原比赛车是全�底盘�� odom �姿�,所以能接�;如果你们的规划/�障�赖 +> `base_link` 的��,需�改�用 `odomAftMapped` 的四元数。 + +### 6.3 雷达-IMU 外�(**�用改**) + +`src/perception/Point-LIO/config/mid360.yaml` + +```yaml +extrinsic_T: [ -0.011, -0.02329, 0.04412 ] +extrinsic_R: [ 1,0,0, 0,1,0, 0,0,1 ] +``` + +这是 **MID360 内部 LiDAR→IMU 的出厂标定**,�雷达�需�改。 + +### 6.4 雷达型�/点云格�(一般�用改) + +`config/single_MID360_component.yaml`:`xfer_format: 1`(Livox 自定义格�)� +`publish_freq: 20.0`�`frame_id: livox_frame`�`multi_topic: 0`。 +`mid360.yaml` 里 `lidar_type: 1`�`scan_line: 4`�`timestamp_unit: 3`。 + +### 6.5 底盘串�桥 + +`src/chassis/techx_r2_chassis_control/config/chassis_serial.yaml` + +| �数 | 现值 | 说明 | +|---|---|---| +| `port` | `/dev/ttyUSB0` | 按实际设备改,建议� udev 别� | +| `baudrate` | `115200` | 与 STM32 一致 | +| `max_vx_m_s` / `max_vy_m_s` | `0.5` | 会被**�默截断**,� ≥ 上层速度 | +| `max_wz_rad_s` | `0.5` | �上 | +| `cmd_vel_timeout_sec` | `0.2` | Nav2 输出 10–100 Hz,0.2 s 够用(�� sru_nav �有 1.5 Hz) | +| `velocity_rate_hz` | `30.0` | 固定 30 Hz �帧,与 `/cmd_vel` 到达无关 | + +�议:`AA 55 | vx int16 | vy int16 | wz int16 (×1000) | CRC16-MODBUS`,�端,10 字节。 +**必须与 STM32 固件完全一致**,改�议�两边�时改。 + +### 6.6 Nav2 / 机器人几何与�速 + +`src/navigation/navi2_bringup/params/sentry1.yaml` + +| �置 | �数 | 现值 | 怎么定 | +|---|---|---|---| +| `local_costmap` / `global_costmap` | `robot_radius` | `0.20` | 按车体最大外接�径 | +| `global_costmap.inflation_layer` | `inflation_radius` | `0.80` | 一般 2–3 �车�径 | +| `stvl_layer.mid360` | `min/max_obstacle_height` | `0.1 / 0.8` | 按车体高度与需��障的高度带 | +| `stvl_layer.mid360` | `vertical_fov_offset` | `0.3927` | MID360 固定(-7°~52°),�雷达�改 | +| `minco_optimizer` | `max_velocity` | `3.0` | 你们底盘实际最高速 | +| `velocity_smoother` | `max_velocity` | `[3.5, 3.5, 5.0]` | `[vx, vy, wz]` 上�,**必须 ≤ 底盘能力** | +| `general_goal_checker` | `xy_goal_tolerance` | `0.3` | 到达判定�径 | +| `controller_server` | `controller_frequency` | `100.0` | MPC 频率,算力�够��到 50 | +| `FollowPath` | `Q` / `R` | `[3,3,2]` / `[1.5,1.5,1.0]` | MPC ��,先别动 | + +### 6.7 地图与�始�姿 + +- **地图**:`navigation2.launch.py` 的 `map` �数(默认是比赛场地的 + `maps/first_floor/first_floor.yaml`,**必须��你们场地的图**)。 + 地图需 `map_server` 格�:`.pgm` + `.yaml`(`resolution`�`origin`)。 +- **�始�姿**:RViz 的 `2D Pose Estimate`,或� `/initialpose`; + 固定场地也�以用 `icp_relocalization` + 先验 PCD(`start.bash` 里�起)。 +- `maps/2026/*.pcd`�`icp_relocalization` 里的 PCD 都是**比赛场地**的,直接删/替�。 + +### 6.8 TF 树(自查用) + +``` +map ──(AMCL/ICP)──► odom? / camera_init ──(Point-LIO)──► body + └──► base_link � � 6.2 的�移 +``` + +`ros2 run tf2_ros tf2_echo camera_init base_link` 应能读到 6.2 里�的�移; +`ros2 run tf2_ros tf2_echo map base_link` 在给过�始�姿�应有值。 + +## 7. 已知缺� / 我未验�的部分 + +1. **没有构建**(原仓库 `AGENTS.md` 明确�止未授�构建),所以编译错误未暴露。 +2. `spatio_temporal_voxel_layer` �在仓库里,未安装则 `global_costmap` 起��。 +3. 比赛地图与 PCD 未替�,直接跑会加载到错误场地。 +4. `icp_relocalization` 未接入总 launch(原仓库也是�独起),需�时自己加。 +5. 原仓库的 `bt_manager` 被去掉�,**没有“到点�继续决策�的逻辑**; + 现在��应 Nav2 的 `NavigateToPose` action / `goal_pose`。 diff --git a/minco_ws/docs/SCAN_VEHICLE.md b/minco_ws/docs/SCAN_VEHICLE.md new file mode 100644 index 0000000..63608fd --- /dev/null +++ b/minco_ws/docs/SCAN_VEHICLE.md @@ -0,0 +1,240 @@ +# SCAN 无图方案(轮�底盘)—— 与 minco/Nav2 方案并存 + +> 为什么加在 `minco_ws` 而�是新建 `scan_ws`: +> 感知链路(`livox_ros_driver2` + `Point-LIO`)和底盘桥(`techx_r2_chassis_control`) +> 两套方案完全共用,新建工作区�会多一份 170 MB 的��包。 +> SCAN 本身�有 6 个包�约 670 KB,直接放进 `src/scan/` ��。 + +## 1. 新增的包 + +| 包 | 作用 | +|---|---| +| `scan_planner_msgs` | B 样�等消� | +| `plan_env` | 3D 滑动体素地图(`grid_map`) | +| `path_searching` | A* �端 | +| `bspline_opt` | B 样�优化 | +| `traj_utils` | 轨迹工具 | +| `plan_manage` | FSM + 控制器(`scan_planner_node`�`closed_loop_controller`) | + +去掉了原仓库的 `simulator/*`(Go2 模型�mock 地图)和 PCT(tomogram 全局规划)。 +`plan_manage` 里��留 `go2_kinematic_sim` / `go2_gait_publisher` 两个�执行文件, +它们��赖标准 ROS 消����赖 Go2 模型,**编译无害��会�动**。 + +## 2. 两套导航栈**互斥**,�能�时�动 + +| | 方案 A:SCAN(无图) | 方案 B:MINCO/Nav2(有图) | +|---|---|---| +| �动 | `vehicle_bringup.launch.py` | `navi2/minco_ws_bringup.launch.py` | +| 先验地图 | **�需�** | 需� `.pgm + .yaml` | +| 上斜� | ✅ 3D 体素 + 3D B 样� | ⚠� 2D costmap 容易被��点云堵死 | +| 输出 | `/cmd_vel` | `/cmd_vel` | + +**两者都� `/cmd_vel` �布**,�时�动会互相打架(两个 publisher 抢�一个�题, +底盘会收到交替的速度)。切�时先 Ctrl-C 干净�起�一套。 + +## 3. �动 + +```bash +source /opt/ros/humble/setup.bash +source ~/RC2027_BR_code/minco_ws/install/setup.bash + +# 整机:MID360 + Point-LIO + SCAN + 底盘桥 +ros2 launch scan_planner vehicle_bringup.launch.py + +# �架:�接底盘 +ros2 launch scan_planner vehicle_bringup.launch.py launch_chassis:=false + +# �调 SCAN(雷达/LIO 已在跑) +ros2 launch scan_planner run_vehicle.launch.py max_vel:=0.5 +``` + +�目标(RViz 的 **2D Goal Pose** 默认� `/goal_pose`,SCAN 订阅的是 +`/move_base_simple/goal`,RViz 里选 "2D Goal Pose" 工具�按钮��;或用命令行): + +```bash +ros2 topic pub --once /move_base_simple/goal geometry_msgs/msg/PoseStamped \ + "{header: {frame_id: camera_init}, pose: {position: {x: 3.0, y: 0.0}}}" +``` + +## 4. �题 + +| 方� | �题 | 说明 | +|---|---|---| +| 入 | `/cloud_registered` | Point-LIO 世界系�采样点云 | +| 入 | `/aft_mapped_to_init` | Point-LIO 里程计(�时作 `body_pose` 与 `sensor_pose`) | +| 入 | `/move_base_simple/goal` | 目标点 `PoseStamped` | +| 出 | `/cmd_vel` | `Twist`(vx / vy / wz)→ 底盘桥 | + +`/cloud_registered` 已在世界系,所以�置里是: + +```yaml +grid_map.cloud_is_world: true +grid_map.need_extrinsic: false +``` + +## 5. 外�:分两层,�有一层需�你填 + +### 5.1 雷达内部外� —— **�用改** + +`grid_map.cpp:68-76` 的 `lidar_extrinsic_`(`-0.011, -0.02329, 0.04412`)是 +**MID360 内部 LiDAR→IMU 的出厂值**,�是车体安装�姿。因为用世界系点云 + +`need_extrinsic: false`,这个矩阵��与计算。 + +### 5.2 雷达→车体中心 —— **雷达�在中心时必须填** + +SCAN 的两个�姿输入用途��: + +| 输入 | 用途 | 应该是� | +|---|---|---| +| `sensor_pose` | 射线起点 | 雷达 | +| `body_pose` | 轨迹起点�到点判定��圆柱碰撞中心 | **车体中心** | + +Point-LIO 输出的是雷达�姿,所以工程里加了 `body_odom` 节点��算: + +``` +/aft_mapped_to_init ──► body_odom ──► /body_odom ──► body_pose + └──────────────────────────────────────────► sensor_pose +``` + +填 `src/scan/body_odom/config/body_odom.yaml`: + +```yaml +body_odom: + ros__parameters: + offset_x: -0.30 # 车体中心在雷达系下的 x(雷达在� 0.30 ⇒ -0.30) + offset_y: 0.00 + offset_z: -0.25 # -雷达高度 + 碰撞�考高度(0.2~0.3) + offset_yaw: 0.0 +``` + +**�填会怎样**:车会�在离目标一个�移�的�置;�圆柱碰撞中心��雷达, +车头/车尾�能蹭到障�。 + +具体�法与符�规则� **[`QUICKSTART.md`](QUICKSTART.md) §4**。 + +## 6. 轮�车必须改的�数 + +`src/scan/plan_manage/config/planner_vehicle.yaml` + +| �数 | 现值 | �义 | +|---|---|---| +| `grid_map.double_cylinder_radius` | `0.30` | �圆柱碰撞�径(车体�径) | +| `grid_map.double_cylinder_offset` | `0.20` | 两圆心沿车体 x 的���移 | +| `grid_map.body_height` | `0.50` | 车高,影�障� z �膨胀 | +| `grid_map.obstacles_inflation_z_up/down` | `0.15 / 0.05` | 障�上下膨胀 | +| `manager.max_vel` / `max_acc` | `0.80 / 0.60` | 规划速度/加速度 | +| `optimization.max_vel` / `max_acc` | `0.80 / 0.60` | 优化约� | +| `grid_map.sliding_map_size_x/y/z` | `10 / 10 / 5` | 滑动窗�,越大越耗 CPU | + +`config/controllers_vehicle.yaml` + +| �数 | 现值 | �义 | +|---|---|---| +| `max_vx` / `max_vy` / `max_vyaw` | `0.80 / 0.40 / 1.20` | **�得超过底盘能力** | +| `heading_error_threshold` | `0.60` | ��误差超过它就原地转 | +| `finish_dist` | `0.15` | 到点判定�径 | + +## 7. �走斜���走�阶(`step_blocker`) + +场地�时有�阶和斜�通��一平�时,SCAN 本身**分�清两者**:它的碰撞判定是�点 +(`plan_env/include/plan_env/grid_map.h:371`),�查轨迹点所在的那个体素, +`body_height` 也��与碰撞。�阶立�上方是 free,A* 就会从上方"跳"上去。 + +`step_blocker` 在点云进入 SCAN **之�**,把�阶所在的矩形区域填�一堵从地�到 +`wall_height` 的实心点阵墙: + +``` +/cloud_registered ──► step_blocker ──► /cloud_registered_for_scan ──► SCAN + ▲ + config/step_blocker.yaml 里的 regions(世界系矩形) +``` + +### 7.1 标定�阶区域(一次��) + +��:**�次�动的起点一致**(你们已确认),所以 Point-LIO 的世界系 `camera_init` +原点��现,矩形�标�有�义。 + +```bash +# 1) 起驱动 + LIO(先�接底盘) +ros2 launch scan_planner vehicle_bringup.launch.py \ + launch_chassis:=false launch_scan:=false + +# 2) RViz2:Fixed Frame 选 camera_init,Add -> PointCloud2 -> /cloud_registered + +# 3) 用工具� "Publish Point" 点�阶投影的�两个对角】,读�标: +ros2 topic echo /clicked_point +# �个点给出 x/y/z,记下两组 x/y +``` + +把四个数填进 `src/scan/step_blocker/config/step_blocker.yaml`: + +```yaml +step_blocker: + ros__parameters: + regions: "1.00,2.40,-0.80,0.60" # xmin,xmax,ymin,ymax + wall_height: 2.0 # �高于车体(0.5 m)+ 规划余� + cell_size: 0.10 # 点阵间�,0.1 m 足够 +``` + +> 用 `--symlink-install` 构建时,`install/` 里的这份 yaml 是指回 `src/` 的符�链接, +> **改完�� launch 就生效,�用�新 `colcon build`**。 + +- 区域�**盖��阶的整个投影**,四周外扩 10–20 cm,��边缘�过去; +- **��把斜�圈进去**,�则斜�也会被堵; +- 多段楼梯/多个入�用分�分隔:`"1,2.4,-0.8,0.6; 5,6.2,0.0,1.4"`。 + +### 7.2 验� + +```bash +ros2 topic echo /cloud_registered_for_scan --once --no-arr | head -10 +# 或者在 RViz 里�时显示 /cloud_registered_for_scan,应能看到那堵墙 +``` + +然�正常起: + +```bash +ros2 launch scan_planner vehicle_bringup.launch.py +``` + +A* �能从斜�走。 + +### 7.3 如果�想用�堵 + +```bash +ros2 launch scan_planner vehicle_bringup.launch.py \ + launch_blocker:=false cloud_topic:=/cloud_registered +``` + +⚠� 两个�数�**一起**传:关掉 `step_blocker` �,`cloud_topic` 的默认值 +`/cloud_registered_for_scan` 就没人�布了,SCAN 会一直等�到点云。 + +### 7.4 局� + +- 这是**几何�堵**,�是语义�解:�阶区域�人工标定,�场地��标; +- 若世界系原点漂移(起点�一致�LIO �定�失败),墙会跟�漂 → 建议固定起点, + 或用 `icp_relocalization` ��全局�姿; +- 墙是"点阵",`cell_size` 太大(> 0.2 m)�能在 `resolution: 0.05` 的栅格里留�, + �� 0.10 m ��。 + +## 8. ⚠� 轮�车的两个硬�制 + +1. **�阶�能上**。SCAN 的 3D 体素�判断“��上方是� free�,�阶和斜�在它眼里 + 都是�通行的。四足能跨,轮�会��。 + → 场地有�阶时:绕开,或把�阶区域在点云里标�障�,或调大 + `obstacles_inflation_z_down` 让�阶“长高��墙。 +2. **纯局部会陷入局部��**。`planning_horizon: 3.5 m`�窗� `10×10 m`, + �到 U 型墙�长走廊会�回打转。 + → 需�长�离全局引导时,改用原仓库的 `navi_mode=3` + PCT(需�一次性 PCD/tomogram, + �以现场用 MID360 录一圈生�,�算“预先导入地图�)。 + +## 9. �赖(比 Nav2 方案少) + +- `Eigen3`�`PCL`(`plan_env` 用)�`tf2`�`tf2_geometry_msgs` +- **�需�** `nav2`�**�需�** `spatio_temporal_voxel_layer` +- 雷达/LIO 侧�是:Livox-SDK2�`livox_ros_driver2`�`point_lio` + +## 10. 与 `sru_ws` 的关系 + +底盘桥直接�用了 `sru_ws/src/techx_r2_chassis_control` 的�一份代�, +�议(10 字节 + CRC16-MODBUS,30 Hz)��;`cmd_vel_timeout_sec: 0.2` +在这里够用,因为 SCAN 的控制频率是 100 Hz,�� sru_nav �有 1.5 Hz。 diff --git a/minco_ws/scripts/deploy_to_robot.sh b/minco_ws/scripts/deploy_to_robot.sh new file mode 100755 index 0000000..ba62532 --- /dev/null +++ b/minco_ws/scripts/deploy_to_robot.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash +# 把工作区�步到机器人�电脑(GMK M6),�选地在那边直接编译。 +# +# bash scripts/deploy_to_robot.sh @ # ��步 +# bash scripts/deploy_to_robot.sh @ --build # �步并远程编译 +# bash scripts/deploy_to_robot.sh @ --dry-run # �看会传什么 +# +# �传 src/ docs/ scripts/,**永远�传** build/ install/ log/。 +# 目标机默认路径 ~/RC2027_BR_code/minco_ws(�用环境�� REMOTE_WS 覆盖)。 +# +# �置:两边都装好 rsync(sudo apt install rsync);已�置 SSH �密更好。 + +set -euo pipefail + +DEST="${1:-}" +if [ -z "$DEST" ] || [ "$DEST" = "-h" ] || [ "$DEST" = "--help" ]; then + sed -n '2,12p' "$0" + exit 0 +fi +shift + +DO_BUILD=0 +DRY="" +for a in "$@"; do + case "$a" in + --build) DO_BUILD=1 ;; + --dry-run) DRY="--dry-run" ;; + *) echo "未知�数: $a" >&2; exit 2 ;; + esac +done + +SRC_WS="$(cd "$(dirname "$0")/.." && pwd)" +REMOTE_WS="${REMOTE_WS:-RC2027_BR_code/minco_ws}" # 相对家目录 + +echo "== �步 ==" +echo " � : $SRC_WS" +echo " 目标: $DEST:~/$REMOTE_WS" +[ -n "$DRY" ] && echo " (dry-run,�会真的写)" + +# 排除项: +# build/ install/ log/ —— 构建产物,路径写死且全是符�链接 +# __pycache__ *.pyc —— 无�义且会造�“改了没生效�的错觉 +# .git —— �需�,传过去�而大 +rsync -az --info=stats2 $DRY \ + --exclude 'build/' \ + --exclude 'install/' \ + --exclude 'log/' \ + --exclude '__pycache__/' \ + --exclude '*.pyc' \ + --exclude '.git/' \ + "$SRC_WS/" "$DEST:~/$REMOTE_WS/" + +if [ "$DO_BUILD" -eq 0 ] || [ -n "$DRY" ]; then + cat </dev/null 2>&1; then + echo " OK $p" + else + echo " FAIL $p" + fi +done +REMOTE + +echo +echo "编译完�。�地�记得先跑 docs/DEPLOY_ROBOT.md 的检查清�(网�/串�/标定)。" diff --git a/minco_ws/scripts/setup_deps.sh b/minco_ws/scripts/setup_deps.sh new file mode 100755 index 0000000..b940e98 --- /dev/null +++ b/minco_ws/scripts/setup_deps.sh @@ -0,0 +1,175 @@ +#!/usr/bin/env bash +# 在�任何一�】Ubuntu 22.04 + ROS 2 Humble 机器上装 minco_ws 的系统�赖。 +# +# 开�机(x86_64)跑一次,机器人�电脑(aarch64)�跑一次。 +# ���以拷,�赖�能拷。 +# +# 用法: +# bash scripts/setup_deps.sh # 装 apt + Livox-SDK2 +# bash scripts/setup_deps.sh --skip-sdk # �装 apt(SDK 已装过) +# bash scripts/setup_deps.sh --check # �体检,什么都�装 +# +# 需� sudo ��与外网。 + +set -euo pipefail + +SKIP_SDK=0 +CHECK_ONLY=0 +for a in "$@"; do + case "$a" in + --skip-sdk) SKIP_SDK=1 ;; + --check) CHECK_ONLY=1 ;; + -h|--help) sed -n '2,16p' "$0"; exit 0 ;; + *) echo "未知�数: $a" >&2; exit 2 ;; + esac +done + +say() { printf '\n\033[1m== %s ==\033[0m\n' "$*"; } +ok() { printf ' \033[32m✅\033[0m %s\n' "$*"; } +bad() { printf ' \033[31m�\033[0m %s\n' "$*"; } + +# ---------------------------------------------------------------- 环境体检 +say "环境" +ARCH=$(uname -m) +UBU=$(. /etc/os-release && echo "$VERSION_ID") +printf ' 架构 : %s\n' "$ARCH" +printf ' 系统 : Ubuntu %s\n' "$UBU" +printf ' 内核 : %s\n' "$(uname -r)" +printf ' CPU 核数 : %s\n' "$(nproc)" +printf ' 内存 : %s\n' "$(awk '/^MemTotal:/{printf "%.1f G", $2/1048576}' /proc/meminfo)" + +if [ "$UBU" != "22.04" ]; then + echo + bad "本工程�求 Ubuntu 22.04(Humble 的对应版本),当�是 $UBU" + echo " Jetson 注�:JetPack 5 = Ubuntu 20.04,装�了 Humble 二进制包," + echo " 必须� JetPack 6,或从��编 ROS 2(�建议)。" + exit 1 +fi + +if [ ! -d /opt/ros/humble ]; then + bad "找�到 /opt/ros/humble,先装 ROS 2 Humble �跑本脚本" + exit 1 +fi +ok "ROS 2 Humble 已安装" + +# ---------------------------------------------------------------- apt �赖 +# 说明: +# - qpOASES��用装】,已在 minco_controller/third_party 里 vendored +# - glog / OpenCV / Eigen / PCL 本体:ROS Humble desktop 或系统包�� +APT_PKGS=( + build-essential + cmake + git + libeigen3-dev + libpcl-dev + libyaml-cpp-dev + libgoogle-glog-dev + ros-humble-pcl-conversions + ros-humble-pcl-ros + ros-humble-backward-ros + ros-humble-tf2-eigen + ros-humble-eigen3-cmake-module + ros-humble-nav2-core + ros-humble-nav2-costmap-2d + ros-humble-nav2-util + ros-humble-pluginlib + ros-humble-rclcpp-components + ros-humble-rosidl-default-generators + ros-humble-cv-bridge + ros-humble-message-filters + ros-humble-yaml-cpp-vendor +) + +# shellcheck disable=SC1091 +# ROS 的 setup.bash 会引用未定义��,与本脚本的 set -u 冲�,临时放开 +set +u +source /opt/ros/humble/setup.bash +set -u + +say "apt �赖检查" + +# dpkg 数�库在容器/精简系统里�能��读(连 bash 都显示未安装),先探一下: +if dpkg -s bash >/dev/null 2>&1; then DPKG_OK=1; else DPKG_OK=0; fi +[ "$DPKG_OK" -eq 0 ] && echo " (dpkg 数�库��读,改用文件/命令探测)" + +# dpkg ��用时的兜底探测 +probe() { + case "$1" in + build-essential) command -v g++ >/dev/null && command -v make >/dev/null ;; + cmake) command -v cmake >/dev/null ;; + git) command -v git >/dev/null ;; + libeigen3-dev) [ -e /usr/include/eigen3/Eigen/Core ] ;; + libpcl-dev) ls /usr/include/pcl-* >/dev/null 2>&1 ;; + libyaml-cpp-dev) ls /usr/include/yaml-cpp >/dev/null 2>&1 ;; + libgoogle-glog-dev) [ -e /usr/include/glog/logging.h ] ;; + *) return 1 ;; + esac +} + +# ros-humble-pcl-ros -> pcl_ros,用 ros2 pkg 判断最�� +ros_pkg_name() { local n=${1#ros-humble-}; echo "${n//-/_}"; } + +MISSING=() +for p in "${APT_PKGS[@]}"; do + case "$p" in + ros-humble-*) + if ros2 pkg prefix "$(ros_pkg_name "$p")" >/dev/null 2>&1; then + ok "$p" + else + bad "$p (缺)"; MISSING+=("$p") + fi + ;; + *) + if { [ "$DPKG_OK" -eq 1 ] && dpkg -s "$p" >/dev/null 2>&1; } || probe "$p"; then + ok "$p" + else + bad "$p (缺)"; MISSING+=("$p") + fi + ;; + esac +done + +if [ ${#MISSING[@]} -gt 0 ] && [ "$CHECK_ONLY" -eq 0 ]; then + say "安装 ${#MISSING[@]} 个缺失的 apt 包" + sudo apt-get update + sudo apt-get install -y "${MISSING[@]}" +elif [ ${#MISSING[@]} -gt 0 ]; then + echo + echo " 待装:sudo apt-get install -y ${MISSING[*]}" +fi + +# ---------------------------------------------------------------- Livox SDK2 +say "Livox-SDK2(激光雷达驱动�赖,装到 /usr/local,dpkg 查�到)" +SDK_LIB=$(ls /usr/local/lib/liblivox_lidar_sdk_shared.so 2>/dev/null || true) + +if [ -n "$SDK_LIB" ]; then + ok "已安装:$SDK_LIB" +elif [ "$CHECK_ONLY" -eq 1 ]; then + bad "未安装(livox_ros_driver2 会编译失败)" +elif [ "$SKIP_SDK" -eq 1 ]; then + bad "未安装,但指定了 --skip-sdk" +else + echo " 从��编译安装 ..." + SDK_SRC="${HOME}/src/Livox-SDK2" + if [ ! -d "$SDK_SRC" ]; then + mkdir -p "$(dirname "$SDK_SRC")" + git clone --depth 1 https://github.com/Livox-SDK/Livox-SDK2.git "$SDK_SRC" + fi + cmake -S "$SDK_SRC" -B "$SDK_SRC/build" -DCMAKE_BUILD_TYPE=Release + cmake --build "$SDK_SRC/build" -j"$(nproc)" + sudo cmake --install "$SDK_SRC/build" + sudo ldconfig + ok "已装到 /usr/local/lib" +fi + +# ---------------------------------------------------------------- 结论 +say "结论" +if [ ${#MISSING[@]} -eq 0 ] && { [ -n "$SDK_LIB" ] || [ "$SKIP_SDK" -eq 0 ]; }; then + echo " �赖�了。下一步:" + echo " source /opt/ros/humble/setup.bash" + echo " cd $(cd "$(dirname "$0")/.." && pwd)" + echo " colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release" +else + echo " 还有缺项,�上�的 �。" + exit 1 +fi diff --git a/minco_ws/src/chassis/techx_r2_chassis_control/config/chassis_serial.yaml b/minco_ws/src/chassis/techx_r2_chassis_control/config/chassis_serial.yaml new file mode 100644 index 0000000..3c80cdf --- /dev/null +++ b/minco_ws/src/chassis/techx_r2_chassis_control/config/chassis_serial.yaml @@ -0,0 +1,63 @@ +# ============================================================================= +# chassis_serial_node — �行�数(R2 底盘串�桥) +# +# 本文件是本节点所有�调项的**唯一真�**。launch/chassis_serial.launch.py 里 port 的 +# launch �数默认值就是从这里�读的,因此 launch 文件��能�与它冲�。ROS 2 中 +# parameters 列表按顺�应用��者胜,所以 launch 文件��能覆盖 port,且�在你显� +# 传 port:=... 时��生。 +# +# install 出�的是**拷�**(setup.py 用拷�方�安装 config/*.yaml),所以改 src/ 下的 +# 本文件必须�新编译�生效。想改完�用���建,就把它直接指给节点: +# ros2 launch techx_r2_chassis_control chassis_serial.launch.py \ +# params_file:=$HOME/sru_ws/src/techx_r2_chassis_control/config/chassis_serial.yaml +# ============================================================================= + +chassis_serial_node: + ros__parameters: + + # 串�设备。两�命�风格**�能选一�**,并与你的 udev 规则��一致 + # —— 本包�自带 .rules 文件: + # /dev/ttyUSB0 内核原始�;与枚举顺�有关,��或�入其他 USB 串�设备� + # �能改� + # /dev/r2_chassis 绑定到适�器�列�的 udev 稳定别�(需你自建规则) + # 请在真机上核实:这两个路径在裸开�机上都�存在,且节点打�开设备时会直接抛错。 + port: /dev/ttyUSB0 + + baudrate: 115200 + + # 这个值会传给 serial.Serial(),但节点**从�回读**任何帧 + # (� protocol.py:�� 上�机 -> STM32 ��),所以它对行为完全无影�。 + serial_timeout_sec: 0.02 + + # 下行�帧率。**固定定时器**:�隔 1/velocity_rate_hz 秒就写一帧,与 /cmd_vel 到达 + # 快慢无关,因此数值没�时也在���样的字节。带宽�是瓶颈 —— �帧 10 B,按此速率 + # �� 115200 8N1 的约 2.6%。 + velocity_rate_hz: 30.0 + + # /cmd_vel �默超过这么久,就进入 stale 分支(�下方 send_zero_on_timeout)。 + # 注�:上游策略� /cmd_vel 的实际速率�有约 1.4-1.7 Hz(周期约 0.66 s,� Odin + # 深度��制),**比本超时更长**。�� send_zero_on_timeout: true,就�味�� + # 0.66 s 里约有 0.46 s 在�零速帧 —— 轮�会走走��。请在真机上核实;若确实如此, + # 应把它放宽到 >= 1.0。 + cmd_vel_timeout_sec: 0.2 + + # true = stale 期间�续�零速帧把链路撑�(�动瞬间也算 stale,因为 + # _last_cmd_time �值为 0.0)。 + # false = stale 期间完全��,�动阶段�样��。 + # 两��值下,下�机都**必须**实现自己的超时:本节点写失败的那一帧,与 STM32 + # 从未收到的那一帧,是无法区分的。 + send_zero_on_timeout: true + + # 输出�幅,作用在 /cmd_vel �分�**乘 1000 转线上格�之�**。 + # 现值已低于上游策略能给出的值,因而几乎�一步都在生效: + # 纯策略�摇�回中 : |vx| <= 0.6, |wz| <= 0.6 + # 策略 + 摇�推到底 : |vx| <= 2.7, |wz| <= 2.2 + # 截断是**�默**的 —— 策略节点收�到任何�馈,无从察觉。 + # 这是策略选择而��议�制:线上格�本身能表达 ±32.767(int16 × 1000)。 + max_vx_m_s: 0.5 + max_vy_m_s: 0.5 + max_wz_rad_s: 0.5 + + # true = 30 Hz �帧打一行 INFO,�完整�六进制负载。 + # 按默认速率会�常�;�在调试�议时打开。 + log_velocity_frames: true diff --git a/minco_ws/src/chassis/techx_r2_chassis_control/docs/R2底盘串��议_v2.pdf b/minco_ws/src/chassis/techx_r2_chassis_control/docs/R2底盘串��议_v2.pdf new file mode 100644 index 0000000..a83875c Binary files /dev/null and b/minco_ws/src/chassis/techx_r2_chassis_control/docs/R2底盘串��议_v2.pdf differ diff --git a/minco_ws/src/chassis/techx_r2_chassis_control/docs/build_protocol_pdf.py b/minco_ws/src/chassis/techx_r2_chassis_control/docs/build_protocol_pdf.py new file mode 100644 index 0000000..fab0a5b --- /dev/null +++ b/minco_ws/src/chassis/techx_r2_chassis_control/docs/build_protocol_pdf.py @@ -0,0 +1,559 @@ +# -*- coding: utf-8 -*- +"""生�本包的串��议 PDF 说明(下�机接收模�对接用)。 + +用法: + source $WS/venv/bin/activate + python src/techx_r2_chassis_control/docs/build_protocol_pdf.py + +�赖:reportlab(已在 $WS/venv 内)+ 系统中文字体 arphic/uming.ttc。 +示例帧与 CRC 全部由 ../techx_r2_chassis_control/protocol.py 现算,��与代�一致。 + +注�(踩过的�): + 1. 正文里的����用 U+2212(−),UMing 没有该字形,会渲染�空白框;用 ASCII 连字符。 + 2. 代��必须� HTML 转义,�则代�里的 " None: + pdfmetrics.registerFont(TTFont(CJK, CJK_FONT_PATH, subfontIndex=CJK_SUBFONT_INDEX)) + pdfmetrics.registerFontFamily(CJK, normal=CJK, bold=CJK, italic=CJK, boldItalic=CJK) + + +# ---------------------------------------------------------------- styles +def build_styles() -> dict: + s = {} + s["title"] = ParagraphStyle( + "title", fontName=CJK, fontSize=20, leading=27, textColor=ACCENT, spaceAfter=4, alignment=TA_LEFT + ) + s["subtitle"] = ParagraphStyle( + "subtitle", fontName=CJK, fontSize=10.5, leading=16, textColor=MUTED, spaceAfter=2 + ) + s["h1"] = ParagraphStyle( + "h1", fontName=CJK, fontSize=13.5, leading=19, textColor=ACCENT, spaceBefore=13, spaceAfter=5 + ) + s["h2"] = ParagraphStyle( + "h2", fontName=CJK, fontSize=11.5, leading=17, textColor=INK, spaceBefore=9, spaceAfter=3 + ) + s["body"] = ParagraphStyle( + "body", fontName=CJK, fontSize=9.8, leading=15.6, textColor=INK, spaceAfter=4 + ) + s["bullet"] = ParagraphStyle( + "bullet", parent=s["body"], leftIndent=11, bulletIndent=2, spaceAfter=1.5 + ) + s["code"] = ParagraphStyle( + "code", fontName=MONO, fontSize=8.1, leading=11.6, textColor=INK + ) + s["cell"] = ParagraphStyle( + "cell", fontName=CJK, fontSize=8.8, leading=12.6, textColor=INK + ) + s["cellh"] = ParagraphStyle( + "cellh", fontName=CJK, fontSize=8.8, leading=12.6, textColor=colors.white + ) + s["cellc"] = ParagraphStyle( + "cellc", fontName=MONO, fontSize=8.6, leading=12.6, textColor=INK + ) + s["byteidx"] = ParagraphStyle( + "byteidx", fontName=CJK, fontSize=7.6, leading=10, textColor=MUTED, alignment=TA_CENTER + ) + s["bytename"] = ParagraphStyle( + "bytename", fontName=CJK, fontSize=9, leading=12, textColor=colors.white, alignment=TA_CENTER + ) + s["footnote"] = ParagraphStyle( + "footnote", fontName=CJK, fontSize=8.4, leading=13, textColor=MUTED, spaceAfter=3 + ) + return s + + +STYLES = build_styles() + + +def esc_code(text: str) -> str: + """代��转义:先转义 HTML 实体,��留空格与�行。""" + text = text.replace("&", "&").replace("<", "<").replace(">", ">") + return text.replace("\n", "
").replace(" ", " ") + + +def code_block(text: str, width: float): + inner = Paragraph(esc_code(text), STYLES["code"]) + return Table([[inner]], colWidths=[width], + style=TableStyle([ + ("BACKGROUND", (0, 0), (-1, -1), CODE_BG), + ("BOX", (0, 0), (-1, -1), 0.5, RULE), + ("LEFTPADDING", (0, 0), (-1, -1), 4.5 * mm), + ("RIGHTPADDING", (0, 0), (-1, -1), 4.5 * mm), + ("TOPPADDING", (0, 0), (-1, -1), 3.2 * mm), + ("BOTTOMPADDING", (0, 0), (-1, -1), 3.2 * mm), + ])) + + +def note(text: str, width: float, kind: str = "warn"): + bg, line = (WARN_BG, WARN_LINE) if kind == "warn" else (OK_BG, OK_LINE) + return Table([[Paragraph(text, STYLES["cell"])]], colWidths=[width], + style=TableStyle([ + ("BACKGROUND", (0, 0), (-1, -1), bg), + ("LINEBEFORE", (0, 0), (0, -1), 2.2, line), + ("LEFTPADDING", (0, 0), (-1, -1), 4 * mm), + ("RIGHTPADDING", (0, 0), (-1, -1), 4 * mm), + ("TOPPADDING", (0, 0), (-1, -1), 3 * mm), + ("BOTTOMPADDING", (0, 0), (-1, -1), 3 * mm), + ])) + + +def data_table(rows, col_widths, code_cols=(), align_center=()): + body = [] + for r_i, row in enumerate(rows): + out = [] + for c_i, cell in enumerate(row): + if isinstance(cell, str): + st = STYLES["cellh"] if r_i == 0 else (STYLES["cellc"] if c_i in code_cols else STYLES["cell"]) + out.append(Paragraph(cell, st)) + else: + out.append(cell) + body.append(out) + t = Table(body, colWidths=col_widths, repeatRows=1) + t.setStyle(TableStyle([ + ("BACKGROUND", (0, 0), (-1, 0), CELL_HDR), + ("ROWBACKGROUNDS", (0, 1), (-1, -1), [colors.white, CELL_ALT]), + ("GRID", (0, 0), (-1, -1), 0.4, RULE), + ("VALIGN", (0, 0), (-1, -1), "MIDDLE"), + ("LEFTPADDING", (0, 0), (-1, -1), 2.6 * mm), + ("RIGHTPADDING", (0, 0), (-1, -1), 2.6 * mm), + ("TOPPADDING", (0, 0), (-1, -1), 2.0 * mm), + ("BOTTOMPADDING", (0, 0), (-1, -1), 2.0 * mm), + *[("ALIGN", (c, 1), (c, -1), "CENTER") for c in align_center], + ])) + return t + + +# ---------------------------------------------------------------- examples +def frames(): + ex = [ + ("é�™æ­¢ï¼ˆå�œè½¦ï¼‰", 0.0, 0.0, 0.0), + ("å‰�è¿›", 0.25, 0.0, 0.0), + ("å�Žé€€", -0.20, 0.0, 0.0), + ("左横移", 0.0, 0.15, 0.0), + ("原地å�³è½¬", 0.0, 0.0, -0.30), + ("æ–œå�‘ + 转å�‘", 0.10, 0.05, 0.20), + ("æž�é™�值(å‰�进满速)", 2.5, 0.0, 0.0), + ("æž�é™�值(旋转满速)", 0.0, 0.0, 1.5), + ] + out = [] + for name, vx, vy, wz in ex: + raw = P.pack_velocity_frame(vx * P.VX_SCALE, vy * P.VY_SCALE, wz * P.OMEGA_SCALE) + out.append((name, vx, vy, wz, raw)) + return out + + +def main() -> None: + register_fonts() + + doc = BaseDocTemplate( + OUT_PDF, + pagesize=A4, + leftMargin=17 * mm, + rightMargin=17 * mm, + topMargin=16 * mm, + bottomMargin=16 * mm, + title="R2 底盘串å�£é€šä¿¡å��è®® v2", + author="techx_r2_chassis_control", + subject="下ä½�机(STM32)接收模å�—实现说明", + ) + W = doc.width + + def on_page(canv, d): + canv.saveState() + canv.setStrokeColor(RULE) + canv.setLineWidth(0.5) + y = A4[1] - 12 * mm + canv.line(doc.leftMargin, y, A4[0] - doc.rightMargin, y) + canv.setFont(CJK, 7.8) + canv.setFillColor(MUTED) + canv.drawString(doc.leftMargin, y + 2.6 * mm, "R2 底盘串å�£é€šä¿¡å��è®® v2 · 下ä½�机接收模å�—实现说明") + canv.drawRightString(A4[0] - doc.rightMargin, y + 2.6 * mm, "第 %d 页" % d.page) + canv.line(doc.leftMargin, 12 * mm, A4[0] - doc.rightMargin, 12 * mm) + canv.restoreState() + + doc.addPageTemplates([PageTemplate( + id="main", + frames=[Frame(doc.leftMargin, doc.bottomMargin, W, doc.height, id="f")], + onPage=on_page)]) + + F = [] + add = F.append + + def h1(t): + add(Paragraph(t, STYLES["h1"])) + + def h2(t): + add(Paragraph(t, STYLES["h2"])) + + def para(t): + add(Paragraph(t, STYLES["body"])) + + def bullets(items, numbered=False): + for i, t in enumerate(items): + add(Paragraph(t, STYLES["bullet"], bulletText=("%d." % (i + 1)) if numbered else "·")) + + # ------------------------------------------------------------ å°�é�¢ + add(Paragraph("R2 底盘串å�£é€šä¿¡å��è®® v2", STYLES["title"])) + add(Paragraph("下ä½�机(STM32)接收模å�—实现说明 —— 上ä½�机到 下ä½�机 å�•å�‘速度指令", STYLES["subtitle"])) + add(HRFlowable(width="100%", thickness=1.4, color=ACCENT, spaceBefore=5, spaceAfter=7)) + + add(data_table([ + ["项目", "内容"], + ["å��议版本", "v2(定长 10 字节,å�ªå�‘速度指令)"], + ["上ä½�机实现", "ROS 2 包 techx_r2_chassis_control,节点 chassis_serial_node"], + ["通信方å�‘", "上ä½�机 → 下ä½�机,å�•å�‘。下ä½�机无需回包,å��è®®ä¸�å�«ä»»ä½•上行帧"], + ["文档用途", "供下ä½�机开å�‘者实现接收 / 校验 / è§£æž�模å�—;帧示例与 CRC 由上ä½�机代ç �现算,å�¯ç›´æŽ¥ä½œæµ‹è¯•å�‘é‡�"], + ], [24 * mm, W - 24 * mm])) + + add(Spacer(1, 6)) + add(note( + "一å�¥è¯�总结:上ä½�机æ¯� 33 ms å�‘一帧 10 字节数æ�®ï¼Œå¸§å†…就是 vxã€�vyã€�omega 三个 int16 å°�端数值加一个 CRC16。" + "下ä½�机è¦�å�šçš„事å�ªæœ‰ä¸‰ä»¶â€”—按 10 字节切帧ã€�校验 CRCã€�把三个数å�–出æ�¥é©±åŠ¨ç”µæœºï¼›" + "å�¦å¤–建议加一æ�¡ã€Œè¶…时未收到å�ˆæ³•帧就å�œè½¦ã€�的兜底逻辑。", W, kind="ok")) + add(Spacer(1, 3)) + + # ------------------------------------------------------------ 1 + h1("1. 概述") + para("上ä½�机è¿�行 ROS 2 导航 / é�¥æŽ§æ ˆï¼ŒæŠŠæœ€ç»ˆé€Ÿåº¦æŒ‡ä»¤å�‘布在 /cmd_vel" + "(geometry_msgs/Twist)è¯�题上。本节点订阅该è¯�题,å�–出线速度 xã€�线速度 yã€�角速度 z 三个分é‡�," + "æ�¢ç®—æˆ�æ•´æ•°å�ŽæŒ‰æœ¬å��议打包,ç»�串å�£å†™å…¥ä¸‹ä½�机。整æ�¡é“¾è·¯æ˜¯å�•å�‘的:上ä½�机å�ªå�‘,从ä¸�读串å�£ï¼Œ" + "å› æ­¤å��议里没有应答ã€�没有åº�å�·ã€�没有回读状æ€�。" % MONO) + para("下ä½�机侧è¦�实现的收帧逻辑,本质是一个「固定长度 + 帧头 + CRCã€�的字节æµ�è§£æž�器。需è¦�注æ„�的是:" + "帧头 AA 55 会å�¶ç„¶å‡ºçŽ°åœ¨æ•°æ�®åŒºé‡Œï¼ˆé€Ÿåº¦å€¼æ�°å¥½ä¸º 0x55AA 或 0xAA55 时)," + "所以ä¸�能é� æ�œç´¢å¸§å¤´æ�¥åˆ‡å¸§â€”—必须以「10 字节固定帧 + CRC 校验通过ã€�作为唯一的帧确认æ�¡ä»¶ã€‚" + "这一点在第 6 节展开。" % MONO) + + # ------------------------------------------------------------ 2 + h1("2. 物ç�†å±‚å�‚æ•°") + add(data_table([ + ["å�‚æ•°", "å�–值", "说明"], + ["波特率", "115200 bps", "å�¯é€šè¿‡ä¸Šä½�机å�‚æ•° baudrate 修改,下ä½�机需ä¿�æŒ�一致"], + ["æ•°æ�®ä½� / 校验 / å�œæ­¢ä½�", "8 / None / 1", "å�³ 8N1,无奇å�¶æ ¡éªŒ"], + ["æµ�控", "æ— ", "软件与硬件æµ�控都ä¸�使用"], + ["电平", "按硬件设计", "上ä½�机侧通过 USB-TTL 适é…�器转为串å�£è®¾å¤‡èŠ‚ç‚¹ï¼ˆé»˜è®¤ /dev/r2_chassis)"], + ["帧率", "默认 30 Hz", "å�³çº¦ 33 ms 一帧;上ä½�机å�‚æ•° velocity_rate_hz å�¯è°ƒ"], + ["链路方å�‘", "上ä½�机 → 下ä½�机", "下ä½�机å�‘回的任何字节上ä½�机都ä¸�会读å�–,请勿ä¾�赖上行通é�“"], + ], [38 * mm, 32 * mm, W - 70 * mm])) + + # ------------------------------------------------------------ 3 + h1("3. 帧结构(定长 10 字节)") + para("所有多字节数值å�‡ä¸ºå°�端(little-endian,低字节在å‰�)。") + add(data_table([ + ["å��ç§»", "长度", "字段", "类型", "å�•ä½�", "说明"], + ["0", "2", "header", "uint8[2]", "—", "固定 0xAA 0x55"], + ["2", "2", "vx", "int16 LE", "mm/s", "机体å��标系å‰�å�Žæ–¹å�‘,å‰�进为正"], + ["4", "2", "vy", "int16 LE", "mm/s", "机体å��标系左å�³æ–¹å�‘,左移为正"], + ["6", "2", "omega", "int16 LE", "mrad/s", "绕 Z 轴角速度,逆时针(左转)为正"], + ["8", "2", "crc16", "uint16 LE", "—", "CRC16-MODBUS,覆盖 byte0 ~ byte7"], + ], [14 * mm, 14 * mm, 20 * mm, 21 * mm, 17 * mm, W - 86 * mm], code_cols=(2,), align_center=(0, 1, 4))) + + add(Spacer(1, 4)) + cells = [("byte 0-1", "AA 55"), ("byte 2-3", "vx"), ("byte 4-5", "vy"), + ("byte 6-7", "omega"), ("byte 8-9", "crc16")] + widths = [22 * mm, 25 * mm, 25 * mm, 30 * mm, 30 * mm] + scale = (W - 8 * mm) / sum(widths) + widths = [w * scale for w in widths] + bd = Table([[Paragraph(c[0], STYLES["byteidx"]) for c in cells], + [Paragraph(c[1], STYLES["bytename"]) for c in cells]], colWidths=widths) + bd.setStyle(TableStyle([ + ("VALIGN", (0, 0), (-1, -1), "MIDDLE"), + ("TOPPADDING", (0, 0), (-1, 0), 1.2 * mm), + ("BOTTOMPADDING", (0, 0), (-1, 0), 0.8 * mm), + ("TOPPADDING", (0, 1), (-1, 1), 0.8 * mm), + ("BOTTOMPADDING", (0, 1), (-1, 1), 1.6 * mm), + ("LEFTPADDING", (0, 0), (-1, -1), 1.6 * mm), + ("RIGHTPADDING", (0, 0), (-1, -1), 1.6 * mm), + ("BACKGROUND", (0, 1), (0, 1), colors.HexColor("#5F5E5A")), + ("BACKGROUND", (1, 1), (3, 1), colors.HexColor("#185FA5")), + ("BACKGROUND", (4, 1), (4, 1), colors.HexColor("#993C1D")), + ("BOX", (0, 1), (0, 1), 0.6, colors.white), + ("BOX", (1, 1), (3, 1), 0.6, colors.white), + ("BOX", (4, 1), (4, 1), 0.6, colors.white), + ])) + add(KeepTogether([bd, Spacer(1, 3), + Paragraph("图 1 帧字节布局(ç�°è‰² = 帧头,è“�色 = 速度数æ�®åŒºï¼Œæ©™è‰² = 校验)", + STYLES["footnote"])])) + + # ------------------------------------------------------------ 4 + h1("4. 字段语义与数值æ�¢ç®—") + para("三个字段都是 int16(-32768 ~ 32767),å�•ä½�分别为 mm/sã€�mm/sã€�mrad/s,å�³ã€Œç±³æ¯�ç§’ × 1000ã€�" + "和「弧度æ¯�ç§’ × 1000ã€�,全部é�  1000 这一个比例常数æ�¢ç®—,下ä½�机侧å��算则是除以 1000。" + "符å�·çº¦å®šä¸Ž geometry_msgs/Twist 一致。") + add(data_table([ + ["字段", "上ä½�机æ�¢ç®—(→ 下å�‘值)", "下ä½�机å��ç®—", "实际上é™�", "int16 满é‡�程"], + ["vx", "mm/s = round(vx_m_s × 1000)", "vx_m_s = vx / 1000.0", "±2500", "±32767"], + ["vy", "mm/s = round(vy_m_s × 1000)", "vy_m_s = vy / 1000.0", "±2500", "±32767"], + ["omega", "mrad/s = round(wz_rad_s × 1000)", "wz_rad_s = omega / 1000.0", "±1500", "±32767"], + ], [13 * mm, 66 * mm, 52 * mm, 18 * mm, 27 * mm], code_cols=(1, 2), align_center=(3, 4))) + add(Spacer(1, 3)) + add(Paragraph("实际上é™�指上ä½�机下å�‘å‰�çš„é™�幅:vx/vy 为 ±2500(±2.5 m/s),omega 为 ±1500(±1.5 rad/s)," + "下ä½�机收到的数值ä¸�会超出该范围;ä»�建议下ä½�机å�šä¸€æ¬¡èŒƒå›´é’³åˆ¶ä½œä¸ºé˜²å¾¡æ€§å¤„ç�†ã€‚", + STYLES["footnote"])) + + # ------------------------------------------------------------ 5 + h1("5. CRC16-MODBUS 校验") + para("校验算法为标准 CRC16-MODBUS:多项å¼� 0x8005(å��å°„å½¢å¼� 0xA001),åˆ�值 0xFFFF," + "输入输出都ä¸�å�šå�–å��,也没有最终异或。计算范围是 byte0 ~ byte7(帧头 + æ•°æ�®ï¼‰ï¼Œ" + "算出的 16 ä½�结果以å°�端写入 byte8ã€�byte9(低字节在å‰�)。") + h2("5.1 接收端校验è¦�点") + bullets([ + "先按å°�端把 byte8ã€�byte9 拼æˆ�期望值:expect = byte8 | (byte9 << 8)" % MONO, + "å†�对å‰� 8 字节算 CRC,与 expect 比较,ä¸�相等å�³ä¸¢å¸§", + "多项å¼�ã€�åˆ�值ã€�ä½�åº�三者任一ä¸�å�Œéƒ½ä¼šå’Œä¸Šä½�机对ä¸�上,请直接使用下é�¢çš„å�‚考实现", + ]) + add(KeepTogether([ + Paragraph("5.2 C å�‚考实现(å�¯ç›´æŽ¥æŠ„è¿› STM32)", STYLES["h2"]), + code_block( + "/* CRC16-MODBUS: poly=0xA001, init=0xFFFF, no reflect in/out, no final xor */\n" + "uint16_t crc16_modbus(const uint8_t *buf, uint16_t len)\n" + "{\n" + " uint16_t crc = 0xFFFF;\n" + " for (uint16_t i = 0; i < len; i++) {\n" + " crc ^= (uint16_t)buf[i];\n" + " for (int b = 0; b < 8; b++) {\n" + " if (crc & 0x0001) crc = (crc >> 1) ^ 0xA001;\n" + " else crc = (crc >> 1);\n" + " crc &= 0xFFFF;\n" + " }\n" + " }\n" + " return crc;\n" + "}\n" + "\n" + "/* usage: after a full 10-byte frame f[] has arrived */\n" + "uint16_t expect = (uint16_t)f[8] | ((uint16_t)f[9] << 8);\n" + "if (crc16_modbus(f, 8) != expect) { /* drop this frame */ }", + W)])) + + # ------------------------------------------------------------ 6 + h1("6. 接收端实现建议") + add(note( + "关键å�‘:帧头ä¸�å�¯ä½œä¸ºåˆ‡å¸§ä¾�æ�®ã€‚æ•°æ�®åŒºé‡Œçš„ vx / vy / omega 是任æ„� int16," + "完全å�¯èƒ½ç­‰äºŽ 0x55AA 或 0xAA55,从而在字节æµ�里造出一个å�‡çš„ AA 55。" + "正确å�šæ³•æ˜¯å›ºå®š 10 字节切帧 + CRC 判定:å�ªæœ‰ 10 字节对é½�且 CRC 通过的帧æ‰�采信。" + "è‹¥ CRC 失败,ä¸�è¦�整帧丢弃å�Žä»Žä¸‹ä¸€å¸§å¼€å§‹ï¼Œè€Œåº”é€�个字节滑动é‡�å�Œæ­¥ï¼ˆä¸¢ 1 字节å†�试)," + "这样å�¶å�‘干扰å�Žæœ€å¤šä¸¢ä¸€å¸§å°±èƒ½é‡�新对é½�。" % MONO, W)) + + h2("6.1 推è��收帧æµ�程") + bullets([ + "串å�£ç”¨ DMA + 空闲中断(IDLE)收数æ�®ï¼Œæˆ–中断驱动填环形缓冲,按 10 字节一帧å�–出;", + "检查字节 0ã€�1 是å�¦ä¸º 0xAA 0x55。ä¸�是则丢弃 1 字节,回到上一步;", + "对å‰� 8 字节算 CRC16,与 byte8 / byte9(å°�端拼接)比对。失败则丢弃 1 字节并é‡�新对é½�ï¼›", + "校验通过:按å°�端解æž� vxã€�vyã€�omega,并刷新「最å�Žä¸€æ¬¡æœ‰æ•ˆå¸§åˆ°è¾¾æ—¶é—´ã€�ï¼›", + "把三个值写入电机控制环节(å�¯æŒ‰éœ€å†�å�šæ­»åŒºä¸Žæ–œçŽ‡é™�制);", + "å�¦è®¾ä¸€ä¸ªå®šæ—¶å™¨ï¼šè‹¥è·�上次有效帧超过 300 ~ 500 ms,则强制 vx = vy = omega = 0 并置故障标志。", + ], numbered=True) + + add(Spacer(1, 4)) + add(KeepTogether([code_block( + "/* 10-byte fixed frame + CRC resync */\n" + "static uint8_t buf[10];\n" + "static uint16_t len = 0;\n" + "static uint32_t last_ok_ms = 0;\n" + "\n" + "void on_rx_byte(uint8_t b)\n" + "{\n" + " buf[len++] = b;\n" + " if (len < 10) return;\n" + "\n" + " if (buf[0] == 0xAA && buf[1] == 0x55\n" + " && crc16_modbus(buf, 8) == ((uint16_t)buf[8] | ((uint16_t)buf[9] << 8))) {\n" + " int16_t vx = (int16_t)((uint16_t)buf[2] | ((uint16_t)buf[3] << 8));\n" + " int16_t vy = (int16_t)((uint16_t)buf[4] | ((uint16_t)buf[5] << 8));\n" + " int16_t omega = (int16_t)((uint16_t)buf[6] | ((uint16_t)buf[7] << 8));\n" + " apply_velocity(vx, vy, omega); /* units: mm/s, mm/s, mrad/s */\n" + " last_ok_ms = now_ms();\n" + " len = 0; /* whole frame consumed */\n" + " } else {\n" + " memmove(buf, buf + 1, 9); /* shift by 1 byte and retry */\n" + " len = 9;\n" + " }\n" + "}\n" + "\n" + "/* watchdog: call from a 100 Hz ~ 1 kHz task */\n" + "void safety_tick(void)\n" + "{\n" + " if (now_ms() - last_ok_ms > 400) apply_velocity(0, 0, 0);\n" + "}", + W)])) + + h2("6.2 è¶…æ—¶å�œè½¦çº¦å®š") + para("上ä½�机的行为:å�ªè¦� 200 ms 内没有收到新的 /cmd_vel,它就æŒ�ç»­å�‘é€�全零帧(vx = vy = omega = 0)," + "而ä¸�是å�œå�‘。也就是说链路正常è¿�行时下ä½�机一定会æŒ�续收到帧——「收ä¸�到帧ã€�本身就æ„�味ç�€å¼‚常" + "(上ä½�机崩溃ã€�串å�£æ–­å¼€ã€�线缆æ�¾åŠ¨ï¼‰ã€‚æ‰€ä»¥ä¸‹ä½�机必须自带超时å�œè½¦ï¼Œä¸�能å�ªä¾�赖上ä½�机å�‘零帧。") + para("上ä½�机零速帧的固定字节为 %s,å�¯ç”¨å®ƒä½œä¸ºã€Œå�œè½¦å¸§ã€�的识别基准。" + % (MONO, P.frame_to_hex(P.pack_velocity_frame(0, 0, 0)))) + + # ------------------------------------------------------------ 7 + add(PageBreak()) + h1("7. 示例帧(å�¯ç›´æŽ¥ä½œå�•元测试å�‘é‡�)") + para("下表全部由上ä½�机代ç � protocol.py 现算生æˆ�,与实际下å�‘的字节完全一致。" + "建议下ä½�机把这些帧ç�Œè¿›è§£æž�函数å�šå›žå½’测试。" % MONO) + rows = [["场景", "vx (m/s)", "vy (m/s)", "omega (rad/s)", "payload byte2~byte7", "完整 10 字节帧"]] + for name, vx, vy, wz, raw in frames(): + rows.append([name, "%+.2f" % vx, "%+.2f" % vy, "%+.3f" % wz, + P.frame_to_hex(raw[2:8]), P.frame_to_hex(raw)]) + add(data_table(rows, [31 * mm, 15 * mm, 15 * mm, 20 * mm, 40 * mm, W - 121 * mm], + code_cols=(1, 2, 3, 4, 5), align_center=(1, 2, 3))) + + add(Spacer(1, 7)) + h2("7.1 é€�字节解释示例:å‰�è¿› 0.25 m/s") + raw = P.pack_velocity_frame(0.25 * P.VX_SCALE, 0, 0) + bytes_hex = ["%02X" % b for b in raw] + meaning = [ + "帧头高字节,固定 0xAA", + "帧头低字节,固定 0x55", + "vx 低字节:250 mm/s = 0x00FA", + "vx 高字节", + "vy 低字节:0 mm/s", + "vy 高字节", + "omega 低字节:0 mrad/s", + "omega 高字节", + "CRC16 低字节", + "CRC16 高字节", + ] + rows = [["字节ä½�ç½®", "值", "å�«ä¹‰"]] + [["byte %d" % i, bytes_hex[i], meaning[i]] for i in range(10)] + add(data_table(rows, [24 * mm, 16 * mm, W - 40 * mm], code_cols=(1,), align_center=(1,))) + add(Spacer(1, 3)) + add(Paragraph("整帧:%sï¼›CRC16-MODBUS 计算结果为 " + "0x%04X(å°�端写入å�³ %s %s)。" + % (MONO, P.frame_to_hex(raw), MONO, + P.crc16_modbus(bytes(b"\xAA\x55" + raw[2:8])), bytes_hex[8], bytes_hex[9]), + STYLES["footnote"])) + + # ------------------------------------------------------------ 8 + h1("8. 上ä½�机侧行为(对接需知)") + add(data_table([ + ["å�‚数(ROS 2 å�‚æ•°å��)", "默认值", "对下ä½�机的影å“�"], + ["velocity_rate_hz", "30.0", "å�‘包频率,决定下ä½�机收到帧的节å¥�"], + ["cmd_vel_timeout_sec", "0.2", "超过该时长无新指令å�³å�‘零速帧"], + ["send_zero_on_timeout", "true", "ç½® false 则超时å�Žç›´æŽ¥å�œå�‘(此时下ä½�机的超时兜底更关键)"], + ["max_vx_m_s / max_vy_m_s", "2.5 / 2.5", "下å�‘å‰�çš„é™�幅,vx / vy ä¸�会超过 ±2500"], + ["max_wz_rad_s", "1.5", "下å�‘å‰�的角速度é™�幅,omega ä¸�会超过 ±1500"], + ["baudrate", "115200", "必须与下ä½�机一致"], + ["port", "/dev/...", "上ä½�机侧串å�£è®¾å¤‡å��(默认 /dev/r2_chassis),与下ä½�机无关"], + ], [46 * mm, 26 * mm, W - 72 * mm], code_cols=(0,), align_center=(1,))) + + h2("8.1 上电与é‡�å�¯è¡Œä¸º") + bullets([ + "上ä½�机节点å�¯åЍå�Žç«‹åˆ»æŒ‰å¸§çއå�‘帧,在收到第一æ�¡ /cmd_vel 之å‰�å�‘的都是零速帧;", + "没有任何æ�¡æ‰‹ã€�心跳或使能æµ�程。下ä½�机éš�时上电都能从下一帧开始正常接收;", + "下ä½�机é‡�å�¯ä¸�需è¦�通知上ä½�机,å�ªè¦�按 10 字节切帧å�³å�¯é‡�æ–°å�Œæ­¥ï¼›", + "上ä½�机ä¸�会因为下ä½�机ä¸�回包而报错——它根本ä¸�读串å�£ã€‚", + ]) + + # ------------------------------------------------------------ 9 + h1("9. 下ä½�机自检清å�•") + add(data_table([ + ["#", "检查项", "通过标准"], + ["1", "串å�£å�‚æ•°", "115200 8N1,无æµ�控"], + ["2", "收帧切分", "以 10 字节为å�•ä½�处ç�†ï¼Œä¸�用æ�œå¸§å¤´åˆ‡å¸§"], + ["3", "CRC 实现", "对 byte0~7 ç®— 0xA001 / 0xFFFF,结果与 byte8ã€�byte9(å°�端)一致"], + ["4", "字节åº�", "vx / vy / omega 按å°�端拼 int16,负数能正确解æž�(如 0xFF9C = -100)"], + ["5", "é‡�å�Œæ­¥", "ç�Œå…¥å�«å�‡å¸§å¤´æˆ–å�� CRC çš„è„�字节æµ�å�Žï¼Œèƒ½åœ¨ 1 ~ 2 帧内æ�¢å¤�对é½�"], + ["6", "è¶…æ—¶å�œè½¦", "å�œå�‘æ•°æ�® 300 ~ 500 ms å�Žç”µæœºé€Ÿåº¦å½’零并置标志"], + ["7", "示例帧回归", "第 7 节所有示例帧的解æž�结果与表中数值一致"], + ["8", "零速帧", "收到全零帧å�Žç”µæœºç¡®å®žå�œæ­¢ï¼ˆè€Œä¸�是仅写入å�˜é‡�)"], + ], [9 * mm, 30 * mm, W - 39 * mm], align_center=(0,))) + + add(Spacer(1, 6)) + add(note("负数字节åº�自检用例:int16 -100 = 0xFF9C,å°�端下å�‘为 9C FF" + "(低字节 9C 在å‰�,高字节 FF 在å�Žï¼‰ã€‚若解æž�出 +155 之类的怪值," + "说明字节åº�或符å�·æ‰©å±•写错了。" % MONO, W, kind="ok")) + + # ------------------------------------------------------------ 附录 + add(PageBreak()) + h1("附录 A 上ä½�机å�‘é€�侧实现(Python,节选自 protocol.py)") + add(code_block( + "FRAME_LEN = 10\n" + "HEADER = b\"\\xAA\\x55\"\n" + "VX_SCALE = VY_SCALE = OMEGA_SCALE = 1000.0 # m/s->mm/s, rad/s->mrad/s\n" + "\n" + "def pack_velocity_frame(vx_mm_s, vy_mm_s, omega_mrad_s):\n" + " payload = bytearray(HEADER)\n" + " payload.extend(struct.pack(\"docs/build_protocol_pdf.py 自动生æˆ�ï¼›å��议若有改动," + "é‡�æ–°è¿�行该脚本å�³å�¯å¾—到与新版固件一致的新版 PDF。å��è®®æ�ƒå¨�定义è§� " + "techx_r2_chassis_control/protocol.py 文件头注释。" + % (MONO, MONO), STYLES["footnote"])) + + doc.build(F) + print("written:", OUT_PDF, os.path.getsize(OUT_PDF), "bytes") + + +if __name__ == "__main__": + main() diff --git a/minco_ws/src/chassis/techx_r2_chassis_control/docs/å��è®®è�½åœ°æ ¸æŸ¥æŠ¥å‘Š_2026-10-03.md b/minco_ws/src/chassis/techx_r2_chassis_control/docs/å��è®®è�½åœ°æ ¸æŸ¥æŠ¥å‘Š_2026-10-03.md new file mode 100644 index 0000000..fdc4d0f --- /dev/null +++ b/minco_ws/src/chassis/techx_r2_chassis_control/docs/å��è®®è�½åœ°æ ¸æŸ¥æŠ¥å‘Š_2026-10-03.md @@ -0,0 +1,242 @@ +# R2 底盘å��è®® · 上ä½�机侧核查与自检手册 + +- 日期:2026-10-03 +- 范围:**ä»… `src/techx_r2_chassis_control`(ROS 2 上ä½�机包)**,ä¸�涉å�Šä¸‹ä½�机固件 +- æ�ƒå¨�实现:`techx_r2_chassis_control/protocol.py` +- 接å�£å¥‘约文档:`docs/R2底盘串å�£å��è®®_v2.pdf` + +--- + +## 0. 一å�¥è¯� + +上ä½�机这一侧**实现是正确的**:帧格å¼�ã€�CRCã€�字节åº�ã€�é‡�纲都已用交å�‰éªŒè¯�跑通(§7 验è¯�记录)。 +真正需è¦�你「掌æ�¡ã€�çš„ä¸�是写它,而是**能回答下é�¢ 6 个问题**——它们全都指å�‘「å��议契约ã€�和「失效路径ã€�,而这两样代ç �里没有。 + +--- + +## Q1 · 为什么是å°�端 ` bytes: + return struct.pack("h", -100) # b'\xff\x9c' â†� 大端:高字节在å‰� +``` + +`-0.1 m/s` × 1000 = `-100 mm/s` = `0xFF9C`,å°�端上线就是 `9C FF`。 +上ä½�机产出 `AA 55 9C FF 00 ...`(è§� §7)。**è®°ä½�这个 `9C FF`——它是判断字节åº�写错的最快特å¾�。** + +**为什么这件事必须你æ�¥å®š**:字节åº�是两边å�„自手工拼装的约定,ä¸�是代ç �内部的自洽性。编译器ä¸�会帮你检查,测试也ä¸�会自动å�‘现——å�ªæœ‰å��议文档能定它。 + +--- + +## Q2 · CRC 覆盖哪几个字节?校验失败时è°�负责? + +### CRC å�‚数(`protocol.py:58-69`) + +| å�‚æ•° | 值 | +|---|---| +| 多项å¼� | `0xA001`(MODBUS å��å°„å½¢å¼�) | +| åˆ�值 | `0xFFFF` | +| 输入/输出ä½�å��转 | æ—  | +| 最终异或 | æ—  | +| **覆盖范围** | **`byte0..byte7`(帧头 + 三个 int16),ä¸�å�« CRC 自身** | +| CRC 字段摆放 | `byte8` 低字节ã€�`byte9` 高字节 | + +代ç �里的实现与文档一致: + +```python +payload.extend(struct.pack("32 m/s 的输入,物ç�†ä¸Šä¸�å�¯èƒ½ã€‚ +3. **é™�å¹…å�Žä¸�回写**(`chassis_serial_node.py:72-81`): + +```python +def _on_cmd_vel(self, msg: Twist) -> None: + self._latest_vx_m_s = self._clamp(msg.linear.x, ...) # å�ªå­˜å†…部å�˜é‡� +``` + + `msg` 本身没被修改,也没有任何å��馈è¯�题。**下游节点ä¸�知é�“指令被截断了**——`/cmd_vel` 上写ç�€ 3.0 m/s,实际å�‘出去的是 2.5 m/s,`ros2 topic echo /cmd_vel` 看ä¸�出æ�¥ã€‚ + → 排查「车走ä¸�到预期速度ã€�时,这是一个会骗人的地方。诊断方法:把 `log_velocity_frames` 打开,对比日志里的 `TX vx=...` 与 `/cmd_vel` 的原值。 + +**结论**:`int16` çš„ 1 mm/s å�°é˜¶**ä¸�是抖动的å�¯èƒ½åŽŸå› **。真正需è¦�你判断的是: + +- **下游(下ä½�机舵轮解算)的死区有多大?** 如果它的死区折算æˆ�线速度比 1 mm/s 粗(这类代ç �的死区常设 0.1 rad/s é‡�级),那么**主导精度的是那个死区,ä¸�是å��è®®é‡�化**。 +- **节æ‹�是å�¦å¯¹é½�?** 上ä½�机 30 Hz 定频å�‘é€�,下ä½�机以什么频率消费?两个ä¸�å�Œé¢‘率之间如果没有缓冲,会造æˆ�速度指令被éš�机å�–样,**è¿™æ‰�是低速顿挫的典型æˆ�å› **,而且它属于**契约层**——需è¦�在å��议文档里规定下ä½�机的消费节æ‹�(或规定「æ¯�当收到å�ˆæ³•帧立å�³æ›´æ–°ç›®æ ‡å€¼ã€�)。 + +é‡�化ã€�死区ã€�采样节æ‹�,这三者的关系是排查慢速抖动的固定顺åº�:**先比粗细,å†�比频率。** + +--- + +## Q6 · 架空状æ€�下怎么è¯�明「下ä½�机收到的是å�Œä¸€æ�¡å¸§ã€�? + +上ä½�机侧现有æ�¡ä»¶ï¼š**串å�£å�•å�‘,无 ACK,没有回读**。`test_cmd_vel_pub.py` å�ªå�‘ `/cmd_vel`,ä¸�验è¯�任何东西。 + +分三步补,从便宜到贵: + +### 第 1 步(现在就能å�šï¼Œä¸�需è¦�硬件)——固化自检å�‘é‡� + +把 §7 çš„ 5 æ�¡å¸§äº¤ç»™ä¸‹ä½�机å�šå�•元测试。**这是唯一能跨过「上ä½�机怎么打包ã€�与「下ä½�机怎么解包ã€�边界ã€�且ä¸�需è¦�任何硬件的验è¯�手段。** + +| 输入 (m/s, m/s, rad/s) | 线上 10 字节 | 期望解出 | +|---|---|---| +| `(+0.000, +0.000, +0.000)` | `AA 55 00 00 00 00 00 00 CF 09` | `(0, 0, 0)` | +| `(+0.100, +0.000, +0.000)` | `AA 55 64 00 00 00 00 00 C7 2D` | `(+0.1, 0, 0)` | +| `(-0.100, +0.000, +0.000)` | `AA 55 9C FF 00 00 00 00 C6 81` | `(-0.1, 0, 0)` | +| `(+0.000, +0.100, +0.000)` | `AA 55 00 00 64 00 00 00 D0 39` | `(0, +0.1, 0)` | +| `(+0.000, +0.000, +0.100)` | `AA 55 00 00 00 00 64 00 E5 C9` | `(0, 0, +0.1)` | + +> 价值:**任一侧改代ç �,跑这张表就知é�“有没有破å��议。** 它把「å�£å¤´çº¦å®šã€�å�˜æˆ�了「å�¯æ‰§è¡Œæ–­è¨€ã€�。建议直接放进å��议文档附录。 + +### 第 2 步(架空抬轮)——上ä½�机侧å�‘é€�留痕 + +ç»™ `chassis_serial_node` 加一个**å�ªè¯»**诊断:把æ¯�帧的 `frame_to_hex()` 和时间戳记进环形缓冲,å�‘布到 `~/tx_trace`(`std_msgs/String`),默认关闭。 +- 纯观测,ä¸�改å�‘é€�逻辑ã€�ä¸�改安全默认值。 +- 用 `ros2 topic echo` 就能é€�帧核对「打算å�‘什么ã€�和「实际写了什么字节ã€�。 +- 注æ„�è¿™å�ªèƒ½è¯�明**上ä½�机å�‘出了什么**,è¯�明ä¸�了下ä½�机收到了。 + +### 第 3 步(唯一能è¯�明「下ä½�机真的执行了ã€�的办法)——è¦�求下ä½�机回读 + +请下ä½�机增加一æ�¡**上行帧**(建议用 `55 AA` 起头,与下行 `AA 55` 对称,é�¿å…�误判),内容为「当å‰�执行的 vx/vy/ω + 本地时间戳ã€�,10 Hz å�³å�¯ã€‚上ä½�机订阅å�Žä¸Žå·²å�‘é€�命令å�𿗶间坹é½�比对。 + +- 这一步会把「å�•å�‘无回读ã€�的架构改掉,属于**架构决策,需è¦�ä½ æ‹�æ�¿**,ä¸�是改个å�‚数。 +- 收益:直接得到「指令延迟ã€�「CRC 失败率ã€�「失è�”次数ã€�三个å�¯é‡�化验收指标,也是 §Q3 é‚£æ�¡å®‰å…¨è¾¹ç•Œå”¯ä¸€çš„验è¯�æ–¹å¼�。 + +--- + +## 附 A · 上ä½�机包体检清å�•(本包实测) + +| # | ä½�ç½® | 现象 | 性质 | +|---|---|---|---| +| 1 | `chassis_serial_node.py:32` | `serial_timeout_sec: 0.02` 声明并传给了 `serial.Serial`,但节点从ä¸� `read()` ⇒ **é›¶å½±å“�的死å�‚æ•°** | 无害,但说明å�‚数未é€�个确认 | +| 2 | `config/chassis_serial.yaml:12` | `log_velocity_frames: true` ⇒ 30 Hz æ¯�帧打一行 hex 日志。**默认值是å�¦å�ˆé€‚è¦�人工判断** | 需决策 | +| 3 | `chassis_serial_node.py:62` | `1.0 / max(1.0, rate_hz)` ⇒ `velocity_rate_hz` ä¼  0 æ—¶**é�™é»˜é™�级æˆ� 1 Hz**,ä¸�报错也ä¸�告警 | é�™é»˜é™�级 | +| 4 | `chassis_serial_node.py:57,85` | `_last_cmd_time = 0.0` åˆ�值 ⇒ å�¯åŠ¨çž¬é—´å�³åˆ¤ stale。é…� `send_zero_on_timeout: true` 时会先å�‘零速帧(正确);若设为 `false`,节点å�¯åЍå�Ž**完全ä¸�å�‘帧**,下ä½�机必须自己有兜底 | 跨设备安全边界 | +| 5 | `chassis_serial_node.py:72-81` | é™�幅结果ä¸�回写 `msg`ã€�æ— å��馈è¯�题 ⇒ 下游无法感知截断 | å�¯è§‚测性缺å�£ | +| 6 | `yaml:3` vs `launch/chassis_serial.launch.py:14,24` | yaml 写 `port: /dev/ttyUSB0`,launch çš„ `port_arg` 默认 `/dev/r2_chassis` 且作为**å�Žç½®å�‚数覆盖** ⇒ **yaml 里的 port 永远ä¸�生效**。两处必须统一 | **真实缺陷** | +| 7 | `chassis_serial_node.py:98` | `self._serial.write(frame)` 未检查返回值是å�¦ == `FRAME_LEN` | 建议加固 | +| 8 | `chassis_serial_node.py:76` | 用 `time.monotonic()` 计时(正确å�šæ³•ï¼‰ï¼›æ³¨æ„�ä¸�è¦�改æˆ� `time.time()`——墙钟会因 NTP è·³å�˜å¯¼è‡´è¯¯åˆ¤ | 已正确 | + +**第 6 æ�¡æ˜¯è¿™é‡Œå”¯ä¸€éœ€è¦�改代ç �çš„**:`launch` 里的 `port` 覆盖会让 yaml é…�置失效。两ç§�修法(需你确认): +- 删掉 `launch` çš„ `port_arg` 默认覆盖,å�ªä¿�ç•™ `DeclareLaunchArgument('port', default_value='')` 并在为空时ä¸�传该å�‚æ•°ï¼› +- 或把 yaml 与 launch 的默认值统一为å�Œä¸€ä¸ªè®¾å¤‡è·¯å¾„(并é…� udev 规则固定设备å��)。 + +--- + +## 附 B · 自己验è¯�å��议一致性的方法(ä¸�需è¦�硬件) + +ä¸�è¦�「读一é��觉得对ã€�就结æ�Ÿã€‚用**独立实现 + éš�机交å�‰éªŒè¯�**: + +1. 按 `docs/R2底盘串å�£å��è®®_v2.pdf` 的文字æ��述,**ä¸�看 `protocol.py`**,å�¦å¤–写一份最å°�实现; +2. 用 5000 组éš�机 8 字节 payload 对比两份实现的 `crc16_modbus()`ï¼› +3. 用 3000 组éš�机 `(vx, vy, ω)`(å�«è¶…é™�值)跑「打包 → 解包ã€�闭环,比对是å�¦ç­‰äºŽã€Œé™�å¹…+å››èˆ�五入ã€�å�Žçš„æœŸæœ›å€¼ã€‚ + +本次核查按此方法执行,结果è§� §7。 + +--- + +## 7. 验è¯�记录(2026-10-03 实测) + +| 项目 | 方法 | 结果 | +|---|---|---| +| CRC16-MODBUS 一致性 | 5000 组éš�机 8 字节 payload,对照独立实现 | **ä¸�一致 0 组** | +| 端到端 pack → parse 闭环 | 3000 组éš�机 `(vx, vy, ω)`(å�« ±3.5 / ±2.0 è¶…é™�) | **失败 0 组** | +| 负值字节åº� | `-0.1 m/s` → 是å�¦äº§å‡º `9C FF` | **通过** | +| å�Œé‡�é™�幅一致性 | 上ä½�机 ±2.5 / ±2.5 / ±1.5 与å��议文档一致 | **通过** | +| 溢出风险 | `int16` 满é‡�程 ±32.767 m/s vs é™�å¹… ±2.5 m/s | **ä¸�å�¯èƒ½æº¢å‡º** | + +**å�¯ç›´æŽ¥ç²˜è´´çš„æ–­è¨€**: + +```python +from techx_r2_chassis_control.protocol import pack_velocity_frame, frame_to_hex +assert frame_to_hex(pack_velocity_frame(0, 0, 0)) == "AA 55 00 00 00 00 00 00 CF 09" +assert frame_to_hex(pack_velocity_frame(100, 0, 0)) == "AA 55 64 00 00 00 00 00 C7 2D" +assert frame_to_hex(pack_velocity_frame(-100, 0, 0)) == "AA 55 9C FF 00 00 00 00 C6 81" +assert frame_to_hex(pack_velocity_frame(0, 100, 0)) == "AA 55 00 00 64 00 00 00 D0 39" +assert frame_to_hex(pack_velocity_frame(0, 0, 100)) == "AA 55 00 00 00 00 64 00 E5 C9" +``` diff --git a/minco_ws/src/chassis/techx_r2_chassis_control/launch/chassis_serial.launch.py b/minco_ws/src/chassis/techx_r2_chassis_control/launch/chassis_serial.launch.py new file mode 100644 index 0000000..a228f91 --- /dev/null +++ b/minco_ws/src/chassis/techx_r2_chassis_control/launch/chassis_serial.launch.py @@ -0,0 +1,93 @@ +"""å�¯åЍ R2 底盘串å�£æ¡¥ï¼ˆ/cmd_vel -> STM32 速度帧)。 + +本节点所有å�¯è°ƒé¡¹çš„唯一真æº�是 config/chassis_serial.yaml。这里é¢�外把 port 暴露æˆ� launch +å�‚数,因为å�°æž¶è°ƒè¯•时常需è¦�临时æ�¢ä¸ªè®¾å¤‡ï¼›å®ƒçš„默认值**从 yaml å��读**,两者因此ä¸�å�¯èƒ½ä¸�一致。 + +é‡�è¦� —— 为什么过去改 yaml 对 port 完全无效: +ROS 2 里 parameters 是一个**列表**,按顺åº�应用ã€�**å�Žè€…胜**。本文件旧版写的是:: + + parameters=[LaunchConfiguration('config'), {'port': LaunchConfiguration('port')}] + +而 port çš„ launch 默认值被硬编ç �æˆ� /dev/r2_chassis。于是第二段字典永远压过å�‚数文件, +config/chassis_serial.yaml 里写的 port å�˜æˆ�死信 —— 无论怎么改 yaml 都改ä¸�动它。 +这与 sru_nav_ros2/launch/sru_nav.launch.py 中记录的失败模å¼�å�Œæº�(当年 +odom_twist_in_base_frame 一直是 false,而 yaml 写的是 true),修法也相å�Œï¼šé»˜è®¤å€¼ä»Žæ–‡ä»¶è¯»ã€‚ + +关于 install æ‹·è´�:setup.py 是用**æ‹·è´�**æ–¹å¼�安装 config/*.yaml 的,所以 +install/.../share/techx_r2_chassis_control/config/ 下是å�¦ä¸€ä¸ªæ–‡ä»¶ï¼›æ”¹ src/ 里的 yaml +å¿…é¡»é‡�新编译æ‰�生效。用 params_file:= 直接指å�‘æº�ç �æ ‘å�¯ä»¥å…�é‡�建(该å�‚数就是为此存在), +长期方案是 colcon build --symlink-install。 + +典型用法:: + + ros2 launch techx_r2_chassis_control chassis_serial.launch.py + + # å�°æž¶æµ‹è¯•临时æ�¢è®¾å¤‡ + ros2 launch techx_r2_chassis_control chassis_serial.launch.py port:=/dev/ttyUSB0 + + # 改完å�³ç”¨ï¼Œä¸�å¿…é‡�新编译 + ros2 launch techx_r2_chassis_control chassis_serial.launch.py \\ + params_file:=$HOME/sru_ws/src/techx_r2_chassis_control/config/chassis_serial.yaml + +警告 —— 节点在构造函数里就打开串å�£ï¼Œä¸”下ä½�机没有独立的失è�”兜底: +任何能触达 /cmd_vel 的测试都必须先让轮å­�离地。 +""" + +import os +import yaml + +from ament_index_python.packages import get_package_share_directory +from launch import LaunchDescription +from launch.actions import DeclareLaunchArgument +from launch.substitutions import LaunchConfiguration +from launch_ros.actions import Node + + +def _yaml_default(params_file, name, fallback): + """读å�–å�‚数文件里 name 的写法值。 + + 有æ„�**ä¸�å�š** .lower()。sru_nav_ros2/launch/sru_nav.launch.py 里的å�Œå��助手末尾带 + .lower(),那是为读布尔值写的;照抄到这里会把设备路径 /dev/ttyUSB0 å�˜æˆ� /dev/ttyusb0。 + + 文件读ä¸�出æ�¥æ—¶å›žè�½åˆ° fallback,这样 yaml å��了也ä»�能å�¯åŠ¨ï¼Œè®©èŠ‚ç‚¹è‡ªå·±æŠ¥æ›´æ¸…æ¥šçš„é”™ï¼Œ + 而ä¸�是死在 launch 系统里。 + """ + try: + with open(params_file, 'r') as f: + params = yaml.safe_load(f)['chassis_serial_node']['ros__parameters'] + return str(params[name]) + except Exception: + return fallback + + +def generate_launch_description(): + pkg_share = get_package_share_directory('techx_r2_chassis_control') + default_params_file = os.path.join(pkg_share, 'config', 'chassis_serial.yaml') + + declared_arguments = [ + DeclareLaunchArgument( + 'params_file', default_value=default_params_file, + description='节点å�‚数文件(默认å�–包 share 目录下的 config/chassis_serial.yaml)。' + '安装出æ�¥çš„æ˜¯æ‹·è´�而é�žç¬¦å�·é“¾æŽ¥ —— 把它指å�‘ src/ 下那份å�³å�¯æ”¹å®Œå�³ç”¨ã€�' + '无需é‡�新编译。'), + DeclareLaunchArgument( + 'port', default_value=_yaml_default(default_params_file, 'port', '/dev/ttyUSB0'), + description='串å�£è®¾å¤‡ã€‚默认值从 config/chassis_serial.yaml å��读,该文件å�³å”¯ä¸€çœŸæº�ï¼›' + '临时覆盖一次用 port:=...。'), + ] + + chassis_node = Node( + package='techx_r2_chassis_control', + executable='chassis_serial_node', + name='chassis_serial_node', + output='screen', + # 顺åº�有æ„�义:第 0 项是å�‚数文件,第 1 项是命令行覆盖。å�Žè€…胜 —— 这是故æ„�çš„ + # (port:=... å°±é� å®ƒç”Ÿæ•ˆï¼‰ï¼Œè€Œå®ƒä¹‹æ‰€ä»¥å®‰å…¨ï¼Œå�ªå› ä¸ºä¸Šé�¢ port 的默认值正是从 + # å�Œä¸€ä¸ªæ–‡ä»¶è¯»å‡ºæ�¥çš„。 + parameters=[ + LaunchConfiguration('params_file'), + {'port': LaunchConfiguration('port')}, + ], + ) + + return LaunchDescription(declared_arguments + [chassis_node]) diff --git a/minco_ws/src/chassis/techx_r2_chassis_control/package.xml b/minco_ws/src/chassis/techx_r2_chassis_control/package.xml new file mode 100644 index 0000000..e204111 --- /dev/null +++ b/minco_ws/src/chassis/techx_r2_chassis_control/package.xml @@ -0,0 +1,19 @@ + + + techx_r2_chassis_control + 0.2.0 + Python serial bridge: /cmd_vel -> R2 chassis STM32 velocity frames. + techx + MIT + + ament_python + rclpy + geometry_msgs + + ament_lint_auto + ament_lint_common + + + ament_python + + diff --git a/minco_ws/src/chassis/techx_r2_chassis_control/resource/techx_r2_chassis_control b/minco_ws/src/chassis/techx_r2_chassis_control/resource/techx_r2_chassis_control new file mode 100644 index 0000000..e69de29 diff --git a/minco_ws/src/chassis/techx_r2_chassis_control/setup.cfg b/minco_ws/src/chassis/techx_r2_chassis_control/setup.cfg new file mode 100644 index 0000000..49fa6f7 --- /dev/null +++ b/minco_ws/src/chassis/techx_r2_chassis_control/setup.cfg @@ -0,0 +1,4 @@ +[develop] +script_dir=$base/lib/techx_r2_chassis_control +[install] +install_scripts=$base/lib/techx_r2_chassis_control diff --git a/minco_ws/src/chassis/techx_r2_chassis_control/setup.py b/minco_ws/src/chassis/techx_r2_chassis_control/setup.py new file mode 100644 index 0000000..84e37f2 --- /dev/null +++ b/minco_ws/src/chassis/techx_r2_chassis_control/setup.py @@ -0,0 +1,30 @@ +from setuptools import setup +from glob import glob +import os + +package_name = 'techx_r2_chassis_control' + +setup( + name=package_name, + version='0.2.0', + packages=[package_name], + data_files=[ + ('share/ament_index/resource_index/packages', ['resource/' + package_name]), + ('share/' + package_name, ['package.xml']), + (os.path.join('share', package_name, 'launch'), glob('launch/*.launch.py')), + (os.path.join('share', package_name, 'config'), glob('config/*.yaml')), + ], + install_requires=['setuptools', 'pyserial'], + zip_safe=True, + maintainer='techx', + maintainer_email='todo@example.com', + description='Python serial bridge: /cmd_vel -> R2 chassis STM32 velocity frames.', + license='MIT', + tests_require=['pytest'], + entry_points={ + 'console_scripts': [ + 'chassis_serial_node = techx_r2_chassis_control.chassis_serial_node:main', + 'test_cmd_vel_pub = techx_r2_chassis_control.test_cmd_vel_pub:main', + ], + }, +) diff --git a/minco_ws/src/chassis/techx_r2_chassis_control/techx_r2_chassis_control/__init__.py b/minco_ws/src/chassis/techx_r2_chassis_control/techx_r2_chassis_control/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/minco_ws/src/chassis/techx_r2_chassis_control/techx_r2_chassis_control/chassis_serial_node.py b/minco_ws/src/chassis/techx_r2_chassis_control/techx_r2_chassis_control/chassis_serial_node.py new file mode 100644 index 0000000..5d159e2 --- /dev/null +++ b/minco_ws/src/chassis/techx_r2_chassis_control/techx_r2_chassis_control/chassis_serial_node.py @@ -0,0 +1,121 @@ +from __future__ import annotations + +import threading +import time + +import rclpy +from rclpy.node import Node +from geometry_msgs.msg import Twist + +try: + import serial +except ImportError as exc: # pragma: no cover - runtime dependency on robot + serial = None + +from .protocol import ( + OMEGA_SCALE, + VX_SCALE, + VY_SCALE, + frame_to_hex, + pack_velocity_frame, +) + + +class ChassisSerialNode(Node): + """Bridge /cmd_vel -> STM32 serial velocity frames.""" + + def __init__(self) -> None: + super().__init__("chassis_serial_node") + + self.declare_parameter("port", "/dev/ttyUSB0") + self.declare_parameter("baudrate", 115200) + self.declare_parameter("serial_timeout_sec", 0.02) + self.declare_parameter("velocity_rate_hz", 30.0) + self.declare_parameter("cmd_vel_timeout_sec", 0.2) + self.declare_parameter("send_zero_on_timeout", True) + self.declare_parameter("max_vx_m_s", 2.5) + self.declare_parameter("max_vy_m_s", 2.5) + self.declare_parameter("max_wz_rad_s", 1.5) + self.declare_parameter("log_velocity_frames", False) + + if serial is None: + raise RuntimeError("pyserial is not installed. Install with: sudo apt install python3-serial") + + self._port = self.get_parameter("port").value + self._baudrate = int(self.get_parameter("baudrate").value) + self._serial = serial.Serial( + self._port, + self._baudrate, + timeout=float(self.get_parameter("serial_timeout_sec").value), + ) + self.get_logger().info(f"Opened chassis serial port {self._port} @ {self._baudrate}") + + self._write_lock = threading.Lock() + self._latest_vx_m_s = 0.0 + self._latest_vy_m_s = 0.0 + self._latest_wz_rad_s = 0.0 + self._last_cmd_time = 0.0 + + self.create_subscription(Twist, "/cmd_vel", self._on_cmd_vel, 10) + + rate_hz = float(self.get_parameter("velocity_rate_hz").value) + self.create_timer(1.0 / max(1.0, rate_hz), self._velocity_timer_cb) + + def destroy_node(self) -> bool: + try: + if self._serial is not None and self._serial.is_open: + self._serial.close() + except Exception: + pass + return super().destroy_node() + + def _on_cmd_vel(self, msg: Twist) -> None: + self._latest_vx_m_s = self._clamp(msg.linear.x, float(self.get_parameter("max_vx_m_s").value)) + self._latest_vy_m_s = self._clamp(msg.linear.y, float(self.get_parameter("max_vy_m_s").value)) + self._latest_wz_rad_s = self._clamp(msg.angular.z, float(self.get_parameter("max_wz_rad_s").value)) + self._last_cmd_time = time.monotonic() + + @staticmethod + def _clamp(value: float, limit: float) -> float: + limit = abs(float(limit)) + return max(-limit, min(limit, float(value))) + + def _velocity_timer_cb(self) -> None: + timeout_sec = float(self.get_parameter("cmd_vel_timeout_sec").value) + stale = self._last_cmd_time <= 0.0 or (time.monotonic() - self._last_cmd_time) > timeout_sec + + if stale: + if not bool(self.get_parameter("send_zero_on_timeout").value): + return + vx = vy = wz = 0.0 + else: + vx = self._latest_vx_m_s + vy = self._latest_vy_m_s + wz = self._latest_wz_rad_s + + frame = pack_velocity_frame(vx * VX_SCALE, vy * VY_SCALE, wz * OMEGA_SCALE) + with self._write_lock: + self._serial.write(frame) + self._serial.flush() + + if bool(self.get_parameter("log_velocity_frames").value): + self.get_logger().info( + f"TX vx={vx * VX_SCALE:.0f}mm/s vy={vy * VY_SCALE:.0f}mm/s " + f"omega={wz * OMEGA_SCALE:.0f}mrad/s | {frame_to_hex(frame)}" + ) + + +def main(args=None) -> None: + rclpy.init(args=args) + node = ChassisSerialNode() + try: + rclpy.spin(node) + except KeyboardInterrupt: + pass + finally: + node.destroy_node() + rclpy.shutdown() + + +if __name__ == "__main__": + main() diff --git a/minco_ws/src/chassis/techx_r2_chassis_control/techx_r2_chassis_control/protocol.py b/minco_ws/src/chassis/techx_r2_chassis_control/techx_r2_chassis_control/protocol.py new file mode 100644 index 0000000..32a826b --- /dev/null +++ b/minco_ws/src/chassis/techx_r2_chassis_control/techx_r2_chassis_control/protocol.py @@ -0,0 +1,117 @@ +"""R2 chassis serial protocol, v2 (velocity only). + +Frame layout, fixed 10 bytes, little endian: + + Byte0-1 0xAA 0x55 header + Byte2-3 vx int16, mm/s + Byte4-5 vy int16, mm/s + Byte6-7 omega int16, mrad/s + Byte8-9 CRC16-MODBUS over byte0..byte7 + +Host -> STM32 only. The host never reads frames back, so there is no receive +command set. + +Sign convention follows geometry_msgs/Twist: + vx = linear.x (m/s, forward positive) + vy = linear.y (m/s, left positive) + omega = angular.z (rad/s, counter-clockwise positive) +""" + +from __future__ import annotations + +from dataclasses import dataclass +import struct + +FRAME_LEN = 10 +HEADER = b"\xAA\x55" + +VX_SCALE = 1000.0 # m/s -> mm/s +VY_SCALE = 1000.0 # m/s -> mm/s +OMEGA_SCALE = 1000.0 # rad/s -> mrad/s + + +class ProtocolError(ValueError): + """Raised when a serial frame is malformed.""" + + +@dataclass(frozen=True) +class VelocityCommand: + """Parsed chassis velocity frame.""" + + vx_mm_s: int + vy_mm_s: int + omega_mrad_s: int + + @property + def vx_m_s(self) -> float: + return self.vx_mm_s / VX_SCALE + + @property + def vy_m_s(self) -> float: + return self.vy_mm_s / VY_SCALE + + @property + def omega_rad_s(self) -> float: + return self.omega_mrad_s / OMEGA_SCALE + + +def crc16_modbus(data: bytes) -> int: + """Compute CRC16-MODBUS, polynomial 0xA001, init 0xFFFF.""" + crc = 0xFFFF + for byte in data: + crc ^= byte + for _ in range(8): + if crc & 0x0001: + crc = (crc >> 1) ^ 0xA001 + else: + crc >>= 1 + crc &= 0xFFFF + return crc + + +def clamp_i16(value: float | int) -> int: + return max(-32768, min(32767, int(round(value)))) + + +def i16_to_le(value: int) -> bytes: + return struct.pack(" int: + return struct.unpack_from(" int: + return struct.unpack_from(" bytes: + """Build a 10-byte velocity frame for the STM32.""" + payload = bytearray(HEADER) + payload.extend(i16_to_le(vx_mm_s)) + payload.extend(i16_to_le(vy_mm_s)) + payload.extend(i16_to_le(omega_mrad_s)) + payload.extend(struct.pack(" VelocityCommand: + """Parse a velocity frame. Used by tooling and lower-machine-side tests.""" + raw = bytes(raw) + if len(raw) != FRAME_LEN: + raise ProtocolError(f"frame length must be {FRAME_LEN}, got {len(raw)}") + if raw[0:2] != HEADER: + raise ProtocolError("invalid frame header") + expected_crc = le_to_u16(raw, 8) + actual_crc = crc16_modbus(raw[:8]) + if expected_crc != actual_crc: + raise ProtocolError(f"crc mismatch expected=0x{expected_crc:04X}, actual=0x{actual_crc:04X}") + return VelocityCommand( + vx_mm_s=le_to_i16(raw, 2), + vy_mm_s=le_to_i16(raw, 4), + omega_mrad_s=le_to_i16(raw, 6), + ) + + +def frame_to_hex(frame: bytes | bytearray) -> str: + return " ".join(f"{b:02X}" for b in bytes(frame)) diff --git a/minco_ws/src/chassis/techx_r2_chassis_control/techx_r2_chassis_control/test_cmd_vel_pub.py b/minco_ws/src/chassis/techx_r2_chassis_control/techx_r2_chassis_control/test_cmd_vel_pub.py new file mode 100644 index 0000000..cdbb025 --- /dev/null +++ b/minco_ws/src/chassis/techx_r2_chassis_control/techx_r2_chassis_control/test_cmd_vel_pub.py @@ -0,0 +1,55 @@ +from __future__ import annotations + +import argparse +import time + +import rclpy +from rclpy.node import Node +from geometry_msgs.msg import Twist + + +class CmdVelPublisher(Node): + def __init__(self, vx: float, vy: float, omega: float, rate_hz: float, duration_sec: float) -> None: + super().__init__("test_cmd_vel_pub") + self._publisher = self.create_publisher(Twist, "/cmd_vel", 10) + self._vx = vx + self._vy = vy + self._omega = omega + self._duration_sec = duration_sec + self._start_time = time.monotonic() + self._timer = self.create_timer(1.0 / max(1.0, rate_hz), self._timer_cb) + + def _timer_cb(self) -> None: + elapsed = time.monotonic() - self._start_time + if elapsed > self._duration_sec: + self.get_logger().info("Finished publishing /cmd_vel") + rclpy.shutdown() + return + msg = Twist() + msg.linear.x = self._vx + msg.linear.y = self._vy + msg.angular.z = self._omega + self._publisher.publish(msg) + self.get_logger().info(f"Publish /cmd_vel vx={self._vx:.3f} vy={self._vy:.3f} omega={self._omega:.3f}") + + +def build_arg_parser() -> argparse.ArgumentParser: + parser = argparse.ArgumentParser(description="Publish test /cmd_vel") + parser.add_argument("--vx", type=float, default=0.1, help="linear.x in m/s") + parser.add_argument("--vy", type=float, default=0.0, help="linear.y in m/s") + parser.add_argument("--omega", type=float, default=0.0, help="angular.z in rad/s") + parser.add_argument("--rate-hz", type=float, default=10.0) + parser.add_argument("--duration-sec", type=float, default=3.0) + return parser + + +def main(args=None) -> None: + parser = build_arg_parser() + parsed_args, ros_args = parser.parse_known_args(args) + rclpy.init(args=ros_args) + node = CmdVelPublisher(parsed_args.vx, parsed_args.vy, parsed_args.omega, parsed_args.rate_hz, parsed_args.duration_sec) + rclpy.spin(node) + + +if __name__ == "__main__": + main() diff --git a/minco_ws/src/interfaces/ros_interfaces/CMakeLists.txt b/minco_ws/src/interfaces/ros_interfaces/CMakeLists.txt new file mode 100644 index 0000000..56bb38b --- /dev/null +++ b/minco_ws/src/interfaces/ros_interfaces/CMakeLists.txt @@ -0,0 +1,53 @@ +cmake_minimum_required(VERSION 3.8) +project(ros_interfaces) + +if(CMAKE_COMPILER_ID MATCHES "Clang|GNU") + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_EXTENSIONS OFF) # ç¦�用编译器扩展 + add_compile_options(-Wall -Wextra -Wpedantic) + set(CMAKE_BUILD_TYPE "Release") + add_compile_options(-Werror) +endif() + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# Find required packages +find_package(ament_cmake REQUIRED) +find_package(std_msgs REQUIRED) +find_package(nav_msgs REQUIRED) +find_package(geometry_msgs REQUIRED) +find_package(sensor_msgs REQUIRED) +find_package(rosidl_default_generators REQUIRED) + +# Declare ROS2 message, service, and action files +set(msg_files + "msg/cluster/DynamicObstacle.msg" + "msg/cluster/DynamicObstacleArray.msg" + "msg/minco_traj/PositionCommand.msg" + "msg/minco_traj/MpcPositionCommand.msg" + "msg/Behavior.msg" + "msg/EnemyRobotStatus.msg" + "msg/RadarInfo.msg" + "msg/AllyRobotStatus.msg" + "msg/TeamInformation.msg" + "msg/GameInfo.msg" + "msg/SentryInfoOffline.msg" + "msg/SentryInfoOnline.msg" +) + +# set(srv_files + +# ) + +# Generate interfaces +rosidl_generate_interfaces(${PROJECT_NAME} + ${msg_files} + ${srv_files} + DEPENDENCIES std_msgs geometry_msgs nav_msgs sensor_msgs +) + +# Export dependencies +ament_export_dependencies(rosidl_default_runtime) + +ament_package() \ No newline at end of file diff --git a/minco_ws/src/interfaces/ros_interfaces/msg/AllyRobotStatus.msg b/minco_ws/src/interfaces/ros_interfaces/msg/AllyRobotStatus.msg new file mode 100644 index 0000000..e68352e --- /dev/null +++ b/minco_ws/src/interfaces/ros_interfaces/msg/AllyRobotStatus.msg @@ -0,0 +1,11 @@ +# 机器人装甲æ�¿ID常é‡�定义 +uint8 HERO = 1 # 英雄机器人 +uint8 ENGINEER = 2 # 工程机器人 +uint8 INFANTRY_3 = 3 # 3å�·æ­¥å…µæœºå™¨äºº +uint8 INFANTRY_4 = 4 # 4å�·æ­¥å…µæœºå™¨äºº +uint8 robot_id # 机器人ID +# 机器人的基本状æ€�ä¿¡æ�¯ +uint16 robot_hp # 剩余血é‡� + +# 机器人ä½�置信æ�¯ +geometry_msgs/Pose position # ä½�ç½®å��æ ‡ \ No newline at end of file diff --git a/minco_ws/src/interfaces/ros_interfaces/msg/Behavior.msg b/minco_ws/src/interfaces/ros_interfaces/msg/Behavior.msg new file mode 100644 index 0000000..5513973 --- /dev/null +++ b/minco_ws/src/interfaces/ros_interfaces/msg/Behavior.msg @@ -0,0 +1,48 @@ +uint8 desired_stance +uint8 STANCE_ATTACK=1 +uint8 STANCE_DEFEND=2 +uint8 STANCE_MOVE=3 +uint8 STANCE_ENHANCED_ATTACK = 4 +uint8 STANCE_ENHANCED_DEFEND = 5 +uint8 STANCE_ENHANCED_MOVE = 6 + +uint8 control_mode +uint8 CONTROL_AUTO=0 +uint8 CONTROL_MANUAL=1 + +bool use_gyro_mode +float32 gyro_vel + +uint8 desire_lifter_pos +uint8 LIFTER_TOP=0 +uint8 LIFTER_BOTTOM=1 +uint8 LIFTER_MIDDLE=2 + +uint16 ammo_purchase_request + +uint8 revive_request +uint8 remote_revive_request +uint8 remote_ammo_request +uint8 remote_health_request + +bool use_limited_scan +float32 scan_yaw_min +float32 scan_yaw_max + +uint8 pitch_mode +uint8 PITCH_TOP=0 +uint8 PITCH_BOTTOM=1 + +bool not_aim_enemy +bool use_capacitor + +bool tunnel_escape_active +float32 tunnel_escape_vx +float32 tunnel_escape_vy +float32 tunnel_escape_wz + +bool tunnel_prepare_active +bool tunnel_ready + +bool tunnel_align_active +float32 tunnel_align_angle_deg diff --git a/minco_ws/src/interfaces/ros_interfaces/msg/EnemyRobotStatus.msg b/minco_ws/src/interfaces/ros_interfaces/msg/EnemyRobotStatus.msg new file mode 100644 index 0000000..677fa45 --- /dev/null +++ b/minco_ws/src/interfaces/ros_interfaces/msg/EnemyRobotStatus.msg @@ -0,0 +1,13 @@ +# 机器人装甲æ�¿ID常é‡�定义 +uint8 HERO = 1 # 英雄机器人 +uint8 ENGINEER = 2 # 工程机器人 +uint8 INFANTRY_3 = 3 # 3å�·æ­¥å…µæœºå™¨äºº +uint8 INFANTRY_4 = 4 # 4å�·æ­¥å…µæœºå™¨äºº + +# 机器人的基本状æ€�ä¿¡æ�¯ +uint8 robot_id # 机器人ID,è“�æ–¹=红方+100 +uint16 robot_hp # 机器人血é‡� +uint16 allowed_projectile # å…�许å�‘射的弹丸数é‡�,å�•ä½�å�‘ + +# 机器人ä½�置信æ�¯ +geometry_msgs/Pose position # ä½�ç½®å��æ ‡ \ No newline at end of file diff --git a/minco_ws/src/interfaces/ros_interfaces/msg/GameInfo.msg b/minco_ws/src/interfaces/ros_interfaces/msg/GameInfo.msg new file mode 100644 index 0000000..a8a74ec --- /dev/null +++ b/minco_ws/src/interfaces/ros_interfaces/msg/GameInfo.msg @@ -0,0 +1,11 @@ +std_msgs/Header header + +uint16 game_time_remaining # 比赛剩余时间,å�•ä½�s +uint16 coin_remaining # 己方剩余金å¸�æ•°é‡� +uint32 event_code # 场地事件代ç �,未解ç �,需接收å�Žæ ¹æ�®å��议解ç � +uint8 game_status # 0:未开始比赛 1:准备阶段 2:15sè£�判系统自检 3:5s倒计时 4:比赛中 5:比赛结算中 +float32 manual_point_x # 手动指定的目标点xå��标,å�•ä½�m,å��标系minimap +float32 manual_point_y # 手动指定的目标点yå��标,å�•ä½�m,å��标系minimap +uint8 manual_key # 手动指定的目标点快æ�· +uint16 enemy_outpost_hp # 敌方å‰�哨站血é‡� +uint16 enemy_base_hp # 敌方基地血é‡� diff --git a/minco_ws/src/interfaces/ros_interfaces/msg/RadarInfo.msg b/minco_ws/src/interfaces/ros_interfaces/msg/RadarInfo.msg new file mode 100644 index 0000000..eeb24e6 --- /dev/null +++ b/minco_ws/src/interfaces/ros_interfaces/msg/RadarInfo.msg @@ -0,0 +1,6 @@ +std_msgs/Header header + +ros_interfaces/EnemyRobotStatus[6] enemies # 雷达检测到的机器人信æ�¯åˆ—表,最多6个机器人 +uint16 enemy_coin_left # 敌方剩余金å¸�æ•°é‡� +uint16 enemy_coin_accumulated # 敌方累计获得金å¸�æ•°é‡� +bool is_enemy_outpost_sensed # 敌方å‰�哨站是å�¦è¢«é›·è¾¾è¯†åˆ«åˆ° \ No newline at end of file diff --git a/minco_ws/src/interfaces/ros_interfaces/msg/SentryInfoOffline.msg b/minco_ws/src/interfaces/ros_interfaces/msg/SentryInfoOffline.msg new file mode 100644 index 0000000..e742656 --- /dev/null +++ b/minco_ws/src/interfaces/ros_interfaces/msg/SentryInfoOffline.msg @@ -0,0 +1,12 @@ +std_msgs/Header header + +bool is_get # 视觉是å�¦çž„准到敌人 +geometry_msgs/Point armor_pos # 瞄准到的装甲æ�¿ä½�置,具体å��标系询问视觉 +uint8 armor_num # ä¸�å�šçº¢è“�方区分 +float32 yaw_camerainit_to_gimbal # camera_init到gimbalçš„yaw轴角度 逆时针为正 +uint8 lifter_current_pos # 0 -- kTop 1 -- kBottom 2 -- kMiddle +bool is_transformable # 是å�¦èƒ½å¤Ÿè¿›è¡Œå�˜å½¢ï¼ˆä¸�æ­¢å�˜å½¢ä¸­ä¸�能å�˜å½¢ï¼Œå�‡é™�å�¡ä½�å�Žä¹Ÿæ— æ³•进行å�˜å½¢ï¼‰ +float32 transform_state # å�˜å½¢çжæ€�,0-1,0%为未å�˜å½¢ï¼Œ100%为完全å�˜å½¢ï¼Œè¿‡æ¸¡çжæ€�æ ¹æ�®å®žé™…情况å�˜åŒ– +uint8 capacitor_capacity # 电容容é‡�百分比 + +bool tunnel_yaw_aligned # 底盘航å�‘是å�¦å®Œæˆ�对é½� diff --git a/minco_ws/src/interfaces/ros_interfaces/msg/SentryInfoOnline.msg b/minco_ws/src/interfaces/ros_interfaces/msg/SentryInfoOnline.msg new file mode 100644 index 0000000..0bc8baa --- /dev/null +++ b/minco_ws/src/interfaces/ros_interfaces/msg/SentryInfoOnline.msg @@ -0,0 +1,13 @@ +std_msgs/Header header + +uint16 self_health # 机器人血é‡� +uint16 bullets_remaining # 剩余å�‘å¼¹é‡� +uint16 cooling_value # 机器人æ¯�秒冷å�´å€¼ +uint16 heat_limit # 机器人热é‡�上é™� +uint16 current_heat # 机器人当å‰�热é‡� +geometry_msgs/Point sentry_pos # 哨兵ä½�ç½® +float32 speed_monitor_angle # 测速模å�—æœ�å�‘,å�•ä½�为度,正北为0度 +uint32 sentry_info_1 # 哨兵信æ�¯1,未解ç �,需接收å�Žæ ¹æ�®å��议解ç � +uint16 sentry_info_2 # 哨兵信æ�¯2,未解ç �,需接收å�Žæ ¹æ�®å��议解ç � +uint64 sentry_info_3 # 哨兵信æ�¯3,未解ç �,需接收å�Žæ ¹æ�®å��议解ç � +uint8 energy_ratio # 底盘能é‡�比例 \ No newline at end of file diff --git a/minco_ws/src/interfaces/ros_interfaces/msg/TeamInformation.msg b/minco_ws/src/interfaces/ros_interfaces/msg/TeamInformation.msg new file mode 100644 index 0000000..48b4449 --- /dev/null +++ b/minco_ws/src/interfaces/ros_interfaces/msg/TeamInformation.msg @@ -0,0 +1,5 @@ +std_msgs/Header header # 时间戳和å��标系 + +AllyRobotStatus[4] allies # å››å��队å�‹æœºå™¨äººçжæ€� +uint16 outpost_hp # å‰�哨站血é‡� +uint16 base_hp # 基地血é‡� \ No newline at end of file diff --git a/minco_ws/src/interfaces/ros_interfaces/msg/cluster/DynamicObstacle.msg b/minco_ws/src/interfaces/ros_interfaces/msg/cluster/DynamicObstacle.msg new file mode 100644 index 0000000..81cddee --- /dev/null +++ b/minco_ws/src/interfaces/ros_interfaces/msg/cluster/DynamicObstacle.msg @@ -0,0 +1,6 @@ +int32 id +geometry_msgs/Point centroid +geometry_msgs/Vector3 size +geometry_msgs/Quaternion orientation +geometry_msgs/Vector3 velocity +float32 speed diff --git a/minco_ws/src/interfaces/ros_interfaces/msg/cluster/DynamicObstacleArray.msg b/minco_ws/src/interfaces/ros_interfaces/msg/cluster/DynamicObstacleArray.msg new file mode 100644 index 0000000..acc5002 --- /dev/null +++ b/minco_ws/src/interfaces/ros_interfaces/msg/cluster/DynamicObstacleArray.msg @@ -0,0 +1,2 @@ +std_msgs/Header header +DynamicObstacle[] obstacles diff --git a/minco_ws/src/interfaces/ros_interfaces/msg/minco_traj/MpcPositionCommand.msg b/minco_ws/src/interfaces/ros_interfaces/msg/minco_traj/MpcPositionCommand.msg new file mode 100644 index 0000000..b0d7ff9 --- /dev/null +++ b/minco_ws/src/interfaces/ros_interfaces/msg/minco_traj/MpcPositionCommand.msg @@ -0,0 +1,6 @@ +std_msgs/Header header +ros_interfaces/PositionCommand[] cmds +uint32 mpc_horizon +uint8 command_flag +uint8 NORMAL_COMMAND = 1 +uint8 BLOCK_COMMAND = 137 diff --git a/minco_ws/src/interfaces/ros_interfaces/msg/minco_traj/PositionCommand.msg b/minco_ws/src/interfaces/ros_interfaces/msg/minco_traj/PositionCommand.msg new file mode 100644 index 0000000..4ed81d6 --- /dev/null +++ b/minco_ws/src/interfaces/ros_interfaces/msg/minco_traj/PositionCommand.msg @@ -0,0 +1,15 @@ +std_msgs/Header header +geometry_msgs/Point position +geometry_msgs/Vector3 velocity +geometry_msgs/Vector3 acceleration +geometry_msgs/Vector3 jerk +geometry_msgs/Vector3 angular_velocity +float64 yaw +float64 yaw_dot +float64 vel_norm +float64 acc_norm + + +float64[3] kx +float64[3] kv +uint32 trajectory_id diff --git a/minco_ws/src/interfaces/ros_interfaces/package.xml b/minco_ws/src/interfaces/ros_interfaces/package.xml new file mode 100644 index 0000000..c627317 --- /dev/null +++ b/minco_ws/src/interfaces/ros_interfaces/package.xml @@ -0,0 +1,33 @@ + + + + ros_interfaces + 2.0.0 + + The ros_interfaces package provides all the messages for RoboMaster AI Robot driver + + YuChen + RoboMaster + GPL 3.0 + https://github.com/RoboMaster/RoboRTS-Base + https://github.com/RoboMaster/RoboRTS-Base/issues + + ament_cmake + rosidl_default_generators + + std_msgs + geometry_msgs + rosidl_default_generators + + nav_msgs + sensor_msgs + + rosidl_default_runtime + rosidl_interface_packages + + + + + ament_cmake + + \ No newline at end of file diff --git a/minco_ws/src/navigation/minco_controller/CMakeLists.txt b/minco_ws/src/navigation/minco_controller/CMakeLists.txt new file mode 100755 index 0000000..b86edef --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/CMakeLists.txt @@ -0,0 +1,58 @@ +cmake_minimum_required(VERSION 3.10) +project(minco_controller) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_BUILD_TYPE Release) + +find_package(ament_cmake_auto REQUIRED) +ament_auto_find_build_dependencies() + +find_package(Eigen3 REQUIRED) + +option(MINCO_DEBUG "Enable Minco debug printing" OFF) + +find_package(qpOASES QUIET) +if(NOT qpOASES_FOUND) + find_path(QPOASES_INCLUDE_DIR qpOASES.hpp PATH_SUFFIXES qpOASES qpoases) + find_library(QPOASES_LIBRARY qpOASES) +endif() + +ament_auto_add_library(${PROJECT_NAME} SHARED + src/mpc_solver.cpp + src/minco_mpc_controller.cpp + src/performance/mpc_performance_monitor.cpp +) + +target_include_directories(${PROJECT_NAME} + PUBLIC + $ + $ +) + +target_link_libraries(${PROJECT_NAME} + Eigen3::Eigen +) + +if(MINCO_DEBUG) + target_compile_definitions(${PROJECT_NAME} PRIVATE MINCO_DEBUG) +endif() + +set(_QPOASES_LINKED FALSE) + +set(_QPOASES_VENDOR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/qpOASES) +if(EXISTS "${_QPOASES_VENDOR_DIR}/include/qpOASES.hpp" AND EXISTS "${_QPOASES_VENDOR_DIR}/src") + file(GLOB _QPOASES_VENDOR_SRC "${_QPOASES_VENDOR_DIR}/src/*.cpp") + add_library(qpOASES_vendor STATIC ${_QPOASES_VENDOR_SRC}) + set_target_properties(qpOASES_vendor PROPERTIES POSITION_INDEPENDENT_CODE ON) + target_include_directories(qpOASES_vendor PUBLIC "${_QPOASES_VENDOR_DIR}/include") + target_compile_definitions(qpOASES_vendor PRIVATE __NO_COPYRIGHT__ LINUX) + + target_link_libraries(${PROJECT_NAME} qpOASES_vendor) + set(_QPOASES_LINKED TRUE) +endif() + +pluginlib_export_plugin_description_file(nav2_core minco_controller.xml) + +ament_auto_package(USE_SCOPED_HEADER_INSTALL_DIR) diff --git a/minco_ws/src/navigation/minco_controller/README.md b/minco_ws/src/navigation/minco_controller/README.md new file mode 100755 index 0000000..5f4f4e7 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/README.md @@ -0,0 +1,168 @@ +# 🎮 MincoMpcController + +> é�¢å�‘å…¨å�‘哨兵底盘的 Nav2 Controller æ�’件:以 MINCO 轨迹为å�‚考,使用å‡�è�šå¼� QP MPC 在 SE(2) 状æ€�空间输出全局å��标系速度指令。 + +[返回项目主页](../../../README.md) · [MINCO Planner](../minco_planner/README.md) + +## ✨ 模å�—定ä½� + +`minco_controller::MincoMpcController` 实现 `nav2_core::Controller`,订阅规划器生æˆ�çš„ `/opt_path` 与 Point-LIO 里程计,在 Nav2 Controller Server 的控制周期内求解 MPC。当å‰�主é…�置控制频率为 **100 Hz**。 + +主è¦�特性: + +- 状æ€� `x = [px, py, yaw]`,控制 `u = [vx, vy, wz]`。 +- qpOASES 求解å‡�è�šå�Žçš„æœ‰çº¦æ�ŸäºŒæ¬¡è§„划。 +- å�•调推进å�‚考索引,å‡�少高速è¿�动时å�‚考点回跳。 +- 速度ã€�角速度å�Šç›¸é‚»æŽ§åˆ¶é‡�差分约æ�Ÿã€‚ +- 控制时延ã€�雷达到底盘å�‚考点æ�†è‡‚å�Šè½¦ä½“ roll è¡¥å�¿ã€‚ +- 支æŒ�固定角速度å°�陀螺模å¼�与 yaw 优化轨迹。 +- å�‘布预测轨迹,æ��供求解耗时与频率统计。 + +## 🧠 模å�—æµ�程图 + +```mermaid +flowchart LR + T["/opt_path"] --> R[å�‚考åº�列构造] + O["/aft_mapped_to_init"] --> S[ä½�姿与全局速度æ��å�–] + S --> L[æ�†è‡‚ / roll / æ—¶å»¶è¡¥å�¿] + R --> Q[å‡�è�šå¼� QP] + L --> Q + Q --> C[速度与加速度约æ�Ÿ] + C --> U["/cmd_vel_mpc"] + Q --> V["/mpc_predict_path"] +``` + +### æµ�程概述 + +控制器以 `/opt_path` 中的 P/V/A/J 与 yaw å�‚考构造有é™�时域åº�列,å�Œæ—¶ä»Ž latest-state odom æ��å�–当å‰� SE(2) 状æ€�。完æˆ�æ�†è‡‚ã€�固定 roll 和控制时延补å�¿å�Žï¼Œå°†è·Ÿè¸ªé—®é¢˜å‡�è�šä¸ºå�ªåŒ…å�«æŽ§åˆ¶é‡�çš„ QPï¼›qpOASES 求解å�Žåº”用速度死区ã€�目标å�œè½¦å’Œ speed limit,最å�Žé€šè¿‡ `/cmd_vel_mpc` 输出世界å��标系速度。 + +## 🧪 技术方å�‘ + +- 状æ€�为 `[x, y, yaw]`,控制为 `[vx, vy, wz]`,通过固定 `dt` 的离散模型预测有é™�时域状æ€�。 +- 代价由状æ€�跟踪误差 `Q` 和控制å�‚考误差 `R` æž„æˆ�;速度ã€�角速度和相邻控制é‡�差分由 QP 上下界约æ�Ÿã€‚ +- å�‚考索引å�•è°ƒå‰�进,并结å�ˆ `control_delay_compensation` å‰�ç§»å�‚考,å‡�少高速è¿�动时跟踪旧å�‚考。 +- Planner 输出的速度/加速度等å‰�馈会进入 MPC å�‚考构造;上游热å�¯åŠ¨å’Œè½¨è¿¹è¾¹ç•ŒçŠ¶æ€�会直接影å“�控制器收到的å�‚考速度。 + +## âš¡ 性能方å�‘ + +- 将状æ€�消元å�Žæ±‚è§£å‡�è�š QP,é™�制 100 Hz 控制周期内的决策å�˜é‡�规模。 +- odom 订阅使用 `KeepLast(1) + best_effort + volatile`,å�ªæ¶ˆè´¹æœ€æ–°çжæ€�,é�¿å…�高频定ä½�消æ�¯æŽ’队。 +- `/opt_path` 使用 `SystemDefaultsQoS`;控制与预测å�¯è§†åŒ– publisher 深度为 1,é�¿å…�历å�²æŽ§åˆ¶ç»“果积压。 +- `MpcPerformanceMonitor` 在开关å�¯ç”¨æ—¶è®°å½•求解耗时ã€�完整周期耗时ã€�控制频率ã€�命令/å�‚考速度和 odom 回调延迟;关闭时ä¸�写 CSV。 + +## ðŸŒ� å��标系与输出约定 + +控制器从 odom 四元数æ��å�– yaw,将雷达å�‚考点速度转æ�¢å¹¶è¡¥å�¿åˆ°åº•盘控制å�‚考点。输出的 `vx/vy` ä¿�æŒ�为**全局å��标系速度分é‡�**,用于当å‰�下ä½�机通信约定;ä¸�è¦�默认把它当作 `base_link` 局部速度。 + +æ�†è‡‚速度关系å�¯æ¦‚括为: + +```text +v_base = v_lidar + ω × r +``` + +其中 `r` 的符å�·å�–决于é…�置中“雷达å�‚考点相对底盘å�‚考点â€�的定义。修改安装ä½�ç½®å�Žï¼ŒPlanner 与 Controller å¿…é¡»å�Œæ­¥æ ¡æ ¸ã€‚ + +## 📡 ROS 接å�£ + +| æ–¹å�‘ | Topic | 类型 | 说明 | +|---|---|---|---| +| 输入 | `/opt_path` | `ros_interfaces/msg/MpcPositionCommand` | MINCO ä½�ç½®ã€�速度ã€�æœ�å�‘å�‚考 | +| 输入 | `/aft_mapped_to_init` | `nav_msgs/msg/Odometry` | 当å‰�ä½�å§¿ã€�速度与角速度 | +| 输出 | `/cmd_vel_mpc` | `geometry_msgs/msg/Twist` | æ��供给 communication / 底盘链路的控制é‡� | +| 输出 | `/mpc_predict_path` | `nav_msgs/msg/Path` | MPC 预测轨迹å�¯è§†åŒ– | + +Nav2 标准接å�£ `setPlan()`ã€�`computeVelocityCommands()` å’Œ `setSpeedLimit()` ä»�ç”±æ�’件实现;项目主链路的高阶轨迹信æ�¯æ�¥è‡ª `/opt_path`。 + +## âš™ï¸� 关键å�‚æ•° + +é…�ç½®ä½�于 `src/navigation/navi2_bringup/params/sentry1.yaml` çš„ `controller_server.ros__parameters.FollowPath`。 + +| å�‚æ•° | 当å‰�典型值 | 说明 | +|---|---:|---| +| `controller_frequency` | `100.0` | Controller Server 调用频率 | +| `dt` | `0.05` | MPC 预测离散步长,ä¸�ç­‰å�ŒäºŽæŽ§åˆ¶å‘¨æœŸ | +| `lookahead_time` | `0.5` | å�‚考轨迹å‰�视时间 | +| `control_delay_compensation` | `0.05` | 控制链路时延预测 | +| `Q` | `[3, 3, 2]` | xã€�yã€�yaw 跟踪æ�ƒé‡� | +| `R` | `[1.5, 1.5, 1]` | vxã€�vyã€�wz 输入æ�ƒé‡� | +| `vx/vy_min/max` | `±3.0` | 全局平移速度约æ�Ÿ | +| `omega_min/max` | `±5.0` | 角速度约æ�Ÿ | +| `use_acc_constraints` | `true` | å�¯ç”¨ç›¸é‚»æŽ§åˆ¶é‡�差分约æ�Ÿ | +| `ax/ay_min/max` | `±2.0` | 平移加速度约æ�Ÿ | +| `alpha_min/max` | `±5.0` | 角加速度约æ�Ÿ | +| `use_small_gyro_mode` | `false` | 固定角速度å°�陀螺模å¼� | +| `fixed_wz` | `4.18` | å°�陀螺目标角速度 | + +### ðŸ“� æ�†è‡‚与姿æ€�è¡¥å�¿ + +```yaml +lidar_offset_x: 0.0 +lidar_offset_y: -0.20 +lidar_roll_offset: 0.1745 +``` + +- `lidar_offset_x/y`:里程计å�‚考点与底盘控制å�‚考点的平é�¢å��移。 +- `lidar_roll_offset`:安装姿æ€�导致的固定横滚补å�¿ã€‚ +- 三者å�‡æ˜¯å®žä½“标定é‡�,ä¸�应仅凭轨迹观感éš�æ„�调整。 +- 修改å�Žåº”低速验è¯�原地旋转ã€�纯 x/y 平移和组å�ˆè¿�动,确认补å�¿æ–¹å�‘正确。 + +## 🚀 å�¯åŠ¨ä¸Žæ£€æŸ¥ + +控制器éš� Nav2 完整å�¯åŠ¨ï¼š + +```bash +ros2 launch navi2 navigation2.launch.py +``` + +è¿�行时检查: + +```bash +ros2 topic hz /opt_path +ros2 topic hz /aft_mapped_to_init +ros2 topic hz /cmd_vel_mpc +ros2 topic echo /cmd_vel_mpc --once +``` + +在 RViz 中å� åŠ  `/opt_path_vis` 与 `/mpc_predict_path`,å�¯å¿«é€Ÿåˆ¤æ–­è¯¯å·®æ�¥è‡ªå�‚考轨迹还是控制器预测。 + +## 📈 性能观测 + +`performance.enable` 为总开关,`print_enable`ã€�`detailed_csv_enable` å’Œ `odom_sub_debug_enable` 分别控制终端摘è¦�ã€�é€�周期 CSV å’Œ odom 订阅窗å�£ç»Ÿè®¡ã€‚当å‰�比赛 YAML 中总开关与 `print_enable` 为开å�¯ï¼Œè¯¦ç»† CSV 与 odom 窗å�£ç»Ÿè®¡å…³é—­ï¼›ç”±äºŽå‘¨æœŸæ ·æœ¬å�ªåœ¨ detailed CSV å¼€å�¯æ—¶é‡‡é›†ï¼Œé»˜è®¤ä¸�会记录é€�周期求解 CSV。详细性能 CSV 默认路径: + +```text +/tmp/mpc_perf_detailed.csv +``` + +字段包å�« `success`ã€�`solve_time_ms`ã€�`cycle_time_ms`ã€�`controller_hz`ã€�`cmd_vx/vy/wz` å’Œ `ref_vx/vy/wz`,并å�¯é™„带 `run_id/scenario/variant`。`csv_flush_every_n` 用于é™�低刷盘频率。 + +é‡�点关注控制回调实际频率ã€�QP 求解 P95/P99ã€�失败次数,以å�Šå‘½ä»¤é€Ÿåº¦ä¸Žå�‚考速度的稳æ€�差。100 Hz 控制è¦�求 CSVã€�终端日志和å�¯è§†åŒ–ä¸�能阻塞主回调。 + +## âš ï¸� 已知问题与改进方å�‘ + +- 当å‰�电控速度跟éš�存在稳æ€�误差,上游 Planner 因而强制ä¿�留热å�¯åŠ¨é€Ÿåº¦/加速度å‰�馈。该补å�¿ä¼šæ��高å�‚考速度,但ä¸�能替代底盘速度闭环标定;应è�”å�ˆå¯¹æ¯” `ref_v*`ã€�`cmd_v*` 与底盘å��馈。 +- 模型是速度层 SE(2) è¿�动学模型,未显å¼�æ��述轮胎侧滑ã€�电机/底盘执行延迟å�˜åŒ–和速度闭环动æ€�;高加速度ã€�å�¡é�¢æˆ–碰撞扰动下模型误差会增大。 +- `/opt_path` 与 odom 使用ä¸�å�Œ QoS 语义:轨迹为系统默认 QoS,odom 为 best-effort latest-state。诊断“无控制输出â€�时必须分别检查两æ�¡è®¢é˜…是å�¦åŒ¹é…�。 +- 预测轨迹用于诊断,ä¸�代表底盘真实执行路径;实际闭环效果需结å�ˆ odomã€�communication CSV 和下ä½�机å��馈判断。 + +## 🛠ï¸� 常è§�问题 + +| 现象 | 优先检查 | +|---|---| +| `/cmd_vel_mpc` 无输出 | Nav2 lifecycleã€�是å�¦æ”¶åˆ° `/opt_path` 与 odom | +| 速度方å�‘与车体直觉ä¸�一致 | 输出为全局速度;核对下ä½�机å��标约定 | +| 原地旋转伴éš�平移 | æ�†è‡‚å��移符å�·ã€�雷达安装ä½�置和角速度å�•ä½� | +| 高频振è�¡ | `Q/R` 比例ã€�æ—¶å»¶è¡¥å�¿ã€�å�‚考密度ã€�加速度约æ�Ÿ | +| 跟踪明显滞å�Ž | odom/轨迹时间戳ã€�控制延迟ã€�å‰�视时间和下ä½�机延迟 | +| QP ä¸�å�¯è¡Œ | åˆ�始状æ€�å��å·®ã€�速度/加速度边界和å�‚考çª�å�˜ | +| å°�陀螺退出异常 | 上层模å¼�切æ�¢æ˜¯å�¦æ�¢å¤�å�‚数与固定角速度é…�ç½® | + +## 🗂ï¸� 关键æº�ç � + +- `src/minco_mpc_controller.cpp`:æ�’件生命周期ã€�å�‚考构造ã€�è¡¥å�¿ã€�QP 与输出。 +- `include/minco_controller/minco_mpc_controller.hpp`:状æ€�ã€�å�‚数与接å�£å®šä¹‰ã€‚ +- `minco_controller.xml`:pluginlib 注册信æ�¯ã€‚ +- `src/navigation/navi2_bringup/params/sentry1.yaml`:比赛主å�‚数。 + +## 📚 延伸阅读 + +轨迹如何生æˆ�è§� [MincoPlanner 文档](../minco_planner/README.md),系统å�¯åŠ¨å’Œé€šä¿¡é“¾è·¯è§�[项目主 README](../../../README.md)。 diff --git a/minco_ws/src/navigation/minco_controller/include/color_text.hpp b/minco_ws/src/navigation/minco_controller/include/color_text.hpp new file mode 100644 index 0000000..fdf329b --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/include/color_text.hpp @@ -0,0 +1,31 @@ +// +// Created by yunfan on 11/8/24. +// + +#ifndef SUPER_COLOR_TEXT_HPP +#define SUPER_COLOR_TEXT_HPP + +#include +namespace color_text { +static const std::string RESET = "\033[0m"; +static const std::string BLACK = "\033[30m"; /* Black */ +static const std::string RED = "\033[31m"; /* Red */ +static const std::string GREEN = "\033[32m"; /* Green */ +static const std::string YELLOW = "\033[33m"; /* Yellow */ +static const std::string BLUE = "\033[34m"; /* Blue */ +static const std::string MAGENTA = "\033[35m"; /* Magenta */ +static const std::string CYAN = "\033[36m"; /* Cyan */ +static const std::string WHITE = "\033[37m"; /* White */ +static const std::string REDPURPLE = "\033[95m"; /* Red Purple */ +static const std::string BOLDBLACK = "\033[1m\033[30m"; /* Bold Black */ +static const std::string BOLDRED = "\033[1m\033[31m"; /* Bold Red */ +static const std::string BOLDGREEN = "\033[1m\033[32m"; /* Bold Green */ +static const std::string BOLDYELLOW = "\033[1m\033[33m"; /* Bold Yellow */ +static const std::string BOLDBLUE = "\033[1m\033[34m"; /* Bold Blue */ +static const std::string BOLDMAGENTA = "\033[1m\033[35m"; /* Bold Magenta */ +static const std::string BOLDCYAN = "\033[1m\033[36m"; /* Bold Cyan */ +static const std::string BOLDWHITE = "\033[1m\033[37m"; /* Bold White */ +static const std::string BOLDREDPURPLE = "\033[1m\033[95m"; /* Bold Red Purple */ +} // namespace color_text + +#endif // SUPER_COLOR_TEXT_HPP diff --git a/minco_ws/src/navigation/minco_controller/include/log.hpp b/minco_ws/src/navigation/minco_controller/include/log.hpp new file mode 100644 index 0000000..66249c3 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/include/log.hpp @@ -0,0 +1,77 @@ +#pragma once +#include "color_text.hpp" +#include +#include +#include +#include +#include +#include +#include +#include + +namespace custom_log { +inline std::string now_string() +{ + using namespace std::chrono; + const auto now = system_clock::now(); + const auto now_t = system_clock::to_time_t(now); + std::tm tm_buf{}; +#if defined(_WIN32) + localtime_s(&tm_buf, &now_t); +#else + localtime_r(&now_t, &tm_buf); +#endif + const auto ms = duration_cast(now.time_since_epoch()) % 1000; + std::ostringstream ts; + ts << std::setfill('0') << std::setw(2) << tm_buf.tm_hour << ':' << std::setw(2) << tm_buf.tm_min << ':' + << std::setw(2) << tm_buf.tm_sec << '.' << std::setw(3) << ms.count(); + return ts.str(); +} +template struct named_value +{ + std::string_view name; + const T * ptr; +}; + +template constexpr named_value nv(std::string_view name, const T & v) +{ + return {name, &v}; +} + +void log_info_line(std::string_view text); + +template inline void log_info(std::string prefix, const NVs &... nvs) +{ + std::ostringstream oss; + oss << std::boolalpha; + ((oss << prefix << nvs.name << " = " << *(nvs.ptr) << ::color_text::RESET << '\n'), ...); + log_info_line(oss.str()); +} + +// 带分割线与列对é½�çš„å�—状调试输出 +template inline void log_block(std::string prefix, const NVs &... nvs) +{ + // 计算最大键å��宽度 + std::size_t maxw = 0; + (void)std::initializer_list{(maxw = std::max(maxw, nvs.name.size()), 0)...}; + + // 构造分割线(至少 50 列) + const std::size_t bar_len = std::max(50, maxw + 10); + std::string bar(bar_len, '-'); + + std::ostringstream oss; + oss << std::boolalpha; + // 时间戳 + 顶部分割线 + oss << prefix << '[' << now_string() << "] " << bar << ::color_text::RESET << '\n'; + // 对é½�çš„ name : value + ((oss << prefix << std::left << std::setw(static_cast(maxw)) << nvs.name << " : " << *(nvs.ptr) + << ::color_text::RESET << '\n'), + ...); + // 底部分割线 + oss << prefix << bar << ::color_text::RESET << '\n'; + + log_info_line(oss.str()); +} +} // namespace custom_log + +#define NV(var) ::custom_log::nv(#var, (var)) \ No newline at end of file diff --git a/minco_ws/src/navigation/minco_controller/include/minco_controller/minco_mpc_controller.hpp b/minco_ws/src/navigation/minco_controller/include/minco_controller/minco_mpc_controller.hpp new file mode 100644 index 0000000..1b0194c --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/include/minco_controller/minco_mpc_controller.hpp @@ -0,0 +1,178 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include "nav2_core/controller.hpp" + +#include "geometry_msgs/msg/pose_stamped.hpp" +#include "geometry_msgs/msg/twist.hpp" +#include "geometry_msgs/msg/twist_stamped.hpp" +#include "nav_msgs/msg/odometry.hpp" +#include "nav_msgs/msg/path.hpp" + +#include "rclcpp/rclcpp.hpp" +#include "rclcpp_lifecycle/lifecycle_node.hpp" +#include "tf2_ros/buffer.h" + +#include "ros_interfaces/msg/mpc_position_command.hpp" + +#include "log.hpp" +#include "minco_controller/mpc_solver.hpp" +#include "minco_controller/performance/mpc_performance_monitor.hpp" + +namespace minco_controller { + +class MincoMpcController : public nav2_core::Controller +{ +public: + // === Constructor & Lifecycle === + MincoMpcController() = default; + ~MincoMpcController() override; + + void configure(const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent, + std::string name, + std::shared_ptr tf, + std::shared_ptr costmap_ros) override; + + void cleanup() override; + void activate() override; + void deactivate() override; + + // === Core Planning Interfaces === + geometry_msgs::msg::TwistStamped computeVelocityCommands(const geometry_msgs::msg::PoseStamped & pose, + const geometry_msgs::msg::Twist & velocity, + nav2_core::GoalChecker * goal_checker) override; + + void applyGravityCompensation(const nav_msgs::msg::Odometry::SharedPtr & odom, double & vx, double & vy); + + void setPlan(const nav_msgs::msg::Path & path) override; + + void setSpeedLimit(const double & speed_limit, const bool & percentage) override; + +private: + // === Callbacks === + void onOptPath(const ros_interfaces::msg::MpcPositionCommand::SharedPtr msg); + void onOdom(const nav_msgs::msg::Odometry::SharedPtr msg); + + // === Utility & Helper Functions === + void configureMpcPerfLogging(const rclcpp_lifecycle::LifecycleNode::SharedPtr & node); + + // --- Reference and Path Processing --- + // Find the nearest point on cached trajectory and build horizon reference sequence. + bool buildReferenceFromOptPath(const State & curr, std::vector & out_ref) const; + + bool transformPathToOdom(const ros_interfaces::msg::MpcPositionCommand::SharedPtr & opt, + std::vector & out_cmds) const; + + // --- Motion and Frame Utilities --- + void compensateLeverArm(double v_lidar_x, + double v_lidar_y, + double omega_z, + double yaw, + double & vx_global, + double & vy_global, + double & omega_global) const; + + void extractGlobalVelocityAndYaw(const nav_msgs::msg::Odometry::SharedPtr & odom, + double & vx_global, + double & vy_global, + double & omega_global, + double & yaw_global) const; + + // --- Interpolation Utilities --- + static double normalizeYaw(double yaw); + inline static double interpolateYaw(double yaw1, double yaw2, double alpha) + { + double diff = std::atan2(std::sin(yaw2 - yaw1), std::cos(yaw2 - yaw1)); + return yaw1 + diff * alpha; + } + + inline static double interpolate(double v1, double v2, double alpha) { return v1 + (v2 - v1) * alpha; } + + inline static Eigen::Vector2d interpolate( + const Eigen::Vector2d & v1, const Eigen::Vector2d & v2, double alpha) + { + return v1 + (v2 - v1) * alpha; + } + + // --- Visualization --- + void publishVisualization(const std::vector & pred_path, const State & curr_state); + + // === ROS 2 Interfaces (Publishers, Subscribers, Timers) === + rclcpp::Subscription::SharedPtr opt_path_sub_; + rclcpp::Subscription::SharedPtr odom_sub_; + rclcpp::Publisher::SharedPtr mpc_predict_path_pub_; + rclcpp::Publisher::SharedPtr mpc_real_path_pub_; + rclcpp::Publisher::SharedPtr cmd_vel_mpc_pub_; + + // === TF & Costmap & Frames === + rclcpp_lifecycle::LifecycleNode::WeakPtr node_; + rclcpp::Logger logger_{rclcpp::get_logger("MincoMpcController")}; + std::string name_; + + std::shared_ptr tf_; + std::shared_ptr costmap_ros_; + + std::string global_frame_; + std::string base_frame_; + std::string odom_frame_; + std::string map_frame_; + + // === State Variables & Caches === + // --- Visualization Cache --- + std::vector real_path_history_; + rclcpp::Time last_real_path_pub_time_; + + // --- Runtime Data Cache --- + mutable std::mutex data_mtx_; + ros_interfaces::msg::MpcPositionCommand::SharedPtr latest_opt_path_; + nav_msgs::msg::Odometry::SharedPtr latest_odom_; + + // --- Reference Tracking State --- + // Track reference index over time when trajectory is not updated to avoid jumping back to start. + mutable double tracked_ref_idx_{0.0}; + mutable rclcpp::Time tracked_ref_time_; + mutable uint32_t tracked_opt_traj_id_{0}; + mutable bool has_tracked_ref_{false}; + + // --- Nav2 Plan Cache --- + nav_msgs::msg::Path global_plan_; + mutable std::mutex plan_mtx_; + + // === Core Modules (Pointers to FSM, Optimizers, etc.) === + MPCConfig mpc_config_; + std::unique_ptr solver_; + + // === Configurations & Parameters === + // Dynamic speed limit from Nav2 setSpeedLimit(). + double speed_limit_{0.0}; + bool speed_limit_percentage_{false}; + + // Other controller parameters. + double fixed_wz_{0.0}; + double deadzone_speed_threshold_{0.02}; + double control_delay_compensation_{0.25}; + double lidar_offset_x_{0.0}; + double lidar_offset_y_{0.0}; + double lidar_roll_offset_ = 0.0; + bool use_small_gyro_mode_{true}; + MpcPerformanceMonitor mpc_perf_monitor_; + long long last_mpc_perf_stamp_ns_{0}; + + // Low-pass filter for MPC output to prevent stick-slip oscillation on slopes. + mutable Eigen::Vector3d prev_u_global_{0.0, 0.0, 0.0}; + double vel_smooth_alpha_{0.3}; + + // P0: Integral action for unmodeled disturbances (gravity on slopes, slip). + // Leaky integrators of along-track and cross-track position errors. + mutable Eigen::Vector2d integral_err_{0.0, 0.0}; + double k_i_along_{1.5}; // integral gain: along-track (boost on slopes) + double k_i_cross_{3.0}; // integral gain: cross-track (precision on curves) + double integral_decay_{0.98}; +}; + +} // namespace minco_controller diff --git a/minco_ws/src/navigation/minco_controller/include/minco_controller/mpc_solver.hpp b/minco_ws/src/navigation/minco_controller/include/minco_controller/mpc_solver.hpp new file mode 100644 index 0000000..08439da --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/include/minco_controller/mpc_solver.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include + +#include + +#include "minco_controller/mpc_types.hpp" + +namespace minco_controller { + +// 纯 C++ MPC 求解器:ä¸�ä¾�èµ– ROS,仅ä¾�èµ– Eigen 与 qpOASES。 +class MpcSolver +{ +public: + explicit MpcSolver(const MPCConfig & config); + + void setConfig(const MPCConfig & config); + + // @brief 求解一次 MPC。 + // @param curr 当å‰�状æ€� (map) + // @param ref_traj å�‚考轨迹 (horizon 个点,若ä¸�足由æ�’件层补é½�) + // @param out_u 输出控制 (map) + // @param out_pred (å�¯é€‰) 输出预测轨迹 + // @return 是å�¦æ±‚è§£æˆ�功 + bool solve(const State & curr, + const std::vector & ref_traj, + Control & out_u, + std::vector * out_pred = nullptr); + + Eigen::Vector3d getLastControl() const { return last_u_global_; } + +private: + // 构建离散线性模型:x_{k+1} = A x_k + B_k u_k + // 状æ€�为 [x,y,yaw],控制å�˜é‡� u_k 为 map/global ç³» [vx, vy, omega] + void buildStepModel(double yaw_ref, Eigen::Matrix3d & A, Eigen::Matrix & B) const; + + // 组装 MPC çš„ condensed QP:0.5*U^T H U + g^T U + // 其中 U å †å� äº† horizon 个控制é‡� [vx, vy, omega] (map/global) + bool buildCondensedQP(const State & curr, + const std::vector & ref_traj, + Eigen::MatrixXd & H, + Eigen::VectorXd & g, + Eigen::VectorXd & lb, + Eigen::VectorXd & ub, + Eigen::MatrixXd & A_con, + Eigen::VectorXd & lbA, + Eigen::VectorXd & ubA); + +private: + MPCConfig config_; + + // 用于加速度约æ�Ÿçš„上一时刻 global 控制é‡� + Eigen::Vector3d last_u_global_{0.0, 0.0, 0.0}; + bool has_last_u_{false}; +}; + +} // namespace minco_controller diff --git a/minco_ws/src/navigation/minco_controller/include/minco_controller/mpc_types.hpp b/minco_ws/src/navigation/minco_controller/include/minco_controller/mpc_types.hpp new file mode 100644 index 0000000..0a5656f --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/include/minco_controller/mpc_types.hpp @@ -0,0 +1,79 @@ +#pragma once + +#include + +#include + +namespace minco_controller { + +// 状æ€�:全局系 (map) 下的ä½�å§¿ +struct State +{ + double x{0.0}; + double y{0.0}; + double yaw{0.0}; + double vx{0.0}; + double vy{0.0}; + double omega{0.0}; +}; + +// 控制é‡�:速度命令 (vx, vy, omega) +// 约定:对外输出为全局系 (map) 下速度;æ�’件层å†�转æ�¢åˆ° base_link。 +struct Control +{ + double vx{0.0}; + double vy{0.0}; + double omega{0.0}; +}; + +// å�‚考点:æ�¥è‡ª Minco 轨迹的高精度å‰�馈信æ�¯ +struct ReferencePoint +{ + Eigen::Vector2d pos{0.0, 0.0}; // mapç³»ä½�ç½® + Eigen::Vector2d vel{0.0, 0.0}; // map系速度(å‰�馈) + double yaw{0.0}; // å�‚考航å�‘ + double yaw_rate{0.0}; // å�‚考角速度(å‰�馈) +}; + +// MPC é…�ç½® +struct MPCConfig +{ + // 采样周期与预测步长 + double dt{0.05}; + double planner_freq{20.0}; + double lookahead_time{0.5}; + + int horizon{10}; + + // 代价æ�ƒé‡�:Q(状æ€�误差) / R(控制误差) + // 状æ€�采用 [x, y, yaw],控制采用 [vx, vy, omega] + // Q_along/cross are rotated to align with the reference heading at each horizon step. + Eigen::Vector3d Q{5.0, 5.0, 2.0}; + double q_along{3.0}; // weight along heading (lower → timing flexibility) + double q_cross{12.0}; // weight cross-track (higher → precision) + Eigen::Vector3d R{1.0, 1.0, 0.5}; + + // 速度约æ�Ÿï¼ˆä½œç”¨åœ¨ map/global 速度å�˜é‡�上) + double vx_min{-1.0}; + double vx_max{1.0}; + double vy_min{-1.0}; + double vy_max{1.0}; + double omega_min{-2.0}; + double omega_max{2.0}; + + // 加速度约æ�Ÿï¼ˆå�¯é€‰ï¼‰ + bool use_acc_constraints{false}; + double ax_min{-2.0}; + double ax_max{2.0}; + double ay_min{-2.0}; + double ay_max{2.0}; + double alpha_min{-4.0}; + double alpha_max{4.0}; + + // qpOASES 求解器å�‚æ•° + int max_working_set_recalculations{200}; + int max_iterations{200}; + double eps_regularization{1e-9}; +}; + +} // namespace minco_controller diff --git a/minco_ws/src/navigation/minco_controller/include/minco_controller/performance/mpc_performance_monitor.hpp b/minco_ws/src/navigation/minco_controller/include/minco_controller/performance/mpc_performance_monitor.hpp new file mode 100644 index 0000000..9682943 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/include/minco_controller/performance/mpc_performance_monitor.hpp @@ -0,0 +1,98 @@ +#pragma once + +#include +#include +#include +#include + +#include "builtin_interfaces/msg/time.hpp" +#include "rclcpp/rclcpp.hpp" + +namespace minco_controller { + +struct MpcPerformanceConfig +{ + bool enable{true}; + bool print_enable{true}; + bool detailed_csv_enable{false}; + bool odom_sub_debug_enable{true}; + + std::string detailed_csv_path{"/tmp/mpc_perf_detailed.csv"}; + + std::string run_id; + std::string scenario; + std::string variant; + + double print_period_sec{1.0}; + int csv_flush_every_n{30}; +}; + +struct MpcPerfSample +{ + double stamp_ros{0.0}; + long long stamp_steady_ns{0}; + bool success{false}; + double solve_time_ms{std::numeric_limits::quiet_NaN()}; + double cycle_time_ms{std::numeric_limits::quiet_NaN()}; + double controller_hz{std::numeric_limits::quiet_NaN()}; + double cmd_vx{0.0}; + double cmd_vy{0.0}; + double cmd_wz{0.0}; + double ref_vx{std::numeric_limits::quiet_NaN()}; + double ref_vy{std::numeric_limits::quiet_NaN()}; + double ref_wz{std::numeric_limits::quiet_NaN()}; +}; + +struct OdomSubWindowStats +{ + std::chrono::steady_clock::time_point window_start{}; + + uint64_t callback_count{0}; + double delay_sum_ms{0.0}; + double delay_min_ms{std::numeric_limits::infinity()}; + double delay_max_ms{0.0}; + uint64_t delay_count{0}; +}; + +class MpcPerformanceMonitor +{ +public: + MpcPerformanceMonitor() = default; + ~MpcPerformanceMonitor(); + + void configure(const MpcPerformanceConfig & config, rclcpp::Logger logger); + void close(); + + bool enabled() const; + bool detailedCsvEnabled() const; + bool printEnabled() const; + + void recordMpcSample(const MpcPerfSample & sample); + + void recordOdomCallback( + const rclcpp::Time & now, + const builtin_interfaces::msg::Time & stamp); + + static long long steadyNowNs(); + +private: + void writeDetailedHeader(); + void writeDetailedRow(const MpcPerfSample & sample); + + void maybePrintOdomStats(); + void resetOdomWindow(std::chrono::steady_clock::time_point now); + + void flushIfNeeded(); + + static std::string num(double value); + static std::string boolean(bool value); + static std::string sanitize(std::string value); + + MpcPerformanceConfig config_{}; + rclcpp::Logger logger_{rclcpp::get_logger("MpcPerformanceMonitor")}; + std::ofstream detailed_csv_; + int detailed_csv_rows_{0}; + OdomSubWindowStats odom_stats_{}; +}; + +} // namespace minco_controller diff --git a/minco_ws/src/navigation/minco_controller/minco_controller.xml b/minco_ws/src/navigation/minco_controller/minco_controller.xml new file mode 100755 index 0000000..436337b --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/minco_controller.xml @@ -0,0 +1,9 @@ + + + + + 基于 qpOASES çš„ Minco MPC 控制器 + + + + diff --git a/minco_ws/src/navigation/minco_controller/package.xml b/minco_ws/src/navigation/minco_controller/package.xml new file mode 100755 index 0000000..c05b534 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/package.xml @@ -0,0 +1,32 @@ + + + + minco_controller + 0.0.1 + Nav2 Controller plugin: Minco MPC controller based on qpOASES + TODO + Apache-2.0 + + ament_cmake + + nav2_common + nav2_core + nav2_util + nav2_costmap_2d + rclcpp + rclcpp_lifecycle + geometry_msgs + nav_msgs + pluginlib + tf2 + tf2_ros + tf2_geometry_msgs + ros_interfaces + + eigen3_cmake_module + + + ament_cmake + + + diff --git a/minco_ws/src/navigation/minco_controller/src/minco_mpc_controller.cpp b/minco_ws/src/navigation/minco_controller/src/minco_mpc_controller.cpp new file mode 100644 index 0000000..2b3ab7b --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/src/minco_mpc_controller.cpp @@ -0,0 +1,996 @@ +#include "minco_controller/minco_mpc_controller.hpp" +#include "color_text.hpp" +#include "log.hpp" +#include + +#include +#include +#include +#include +#include + +#include + +#ifdef MINCO_DEBUG +#include +#include +#endif + +#include "nav2_util/node_utils.hpp" + +#include "tf2/LinearMath/Matrix3x3.h" +#include "tf2/utils.h" +#include "tf2_geometry_msgs/tf2_geometry_msgs.hpp" + +#include "pluginlib/class_list_macros.hpp" + +namespace custom_log { +void log_info_line(std::string_view text) +{ + std::cout << text; +} +} // namespace custom_log + +namespace minco_controller { + +MincoMpcController::~MincoMpcController() +{ + mpc_perf_monitor_.close(); +} + +double MincoMpcController::normalizeYaw(double yaw) +{ + return std::atan2(std::sin(yaw), std::cos(yaw)); +} + +void MincoMpcController::configureMpcPerfLogging( + const rclcpp_lifecycle::LifecycleNode::SharedPtr & node) +{ + const std::string default_mpc_csv_path = "/tmp/mpc_perf_detailed.csv"; + + nav2_util::declare_parameter_if_not_declared( + node, name_ + ".performance.enable", rclcpp::ParameterValue(true)); + nav2_util::declare_parameter_if_not_declared( + node, name_ + ".performance.print_enable", rclcpp::ParameterValue(true)); + nav2_util::declare_parameter_if_not_declared( + node, name_ + ".performance.detailed_csv_enable", rclcpp::ParameterValue(false)); + nav2_util::declare_parameter_if_not_declared( + node, name_ + ".performance.odom_sub_debug_enable", rclcpp::ParameterValue(true)); + nav2_util::declare_parameter_if_not_declared( + node, name_ + ".performance.print_period_sec", rclcpp::ParameterValue(1.0)); + nav2_util::declare_parameter_if_not_declared( + node, name_ + ".performance.csv_flush_every_n", rclcpp::ParameterValue(30)); + nav2_util::declare_parameter_if_not_declared( + node, name_ + ".performance.mpc_csv_path", rclcpp::ParameterValue(default_mpc_csv_path)); + nav2_util::declare_parameter_if_not_declared( + node, name_ + ".performance.run_id", rclcpp::ParameterValue("")); + nav2_util::declare_parameter_if_not_declared( + node, name_ + ".performance.scenario", rclcpp::ParameterValue("")); + nav2_util::declare_parameter_if_not_declared( + node, name_ + ".performance.variant", rclcpp::ParameterValue("")); + + bool performance_enable = true; + bool print_enable = true; + bool detailed_csv_enable = false; + bool odom_sub_debug_enable = true; + double print_period_sec = 1.0; + int csv_flush_every_n = 30; + std::string mpc_csv_path = default_mpc_csv_path; + std::string run_id; + std::string scenario; + std::string variant; + node->get_parameter(name_ + ".performance.enable", performance_enable); + node->get_parameter(name_ + ".performance.print_enable", print_enable); + node->get_parameter(name_ + ".performance.detailed_csv_enable", detailed_csv_enable); + node->get_parameter(name_ + ".performance.odom_sub_debug_enable", odom_sub_debug_enable); + node->get_parameter(name_ + ".performance.print_period_sec", print_period_sec); + node->get_parameter(name_ + ".performance.csv_flush_every_n", csv_flush_every_n); + node->get_parameter(name_ + ".performance.mpc_csv_path", mpc_csv_path); + node->get_parameter(name_ + ".performance.run_id", run_id); + node->get_parameter(name_ + ".performance.scenario", scenario); + node->get_parameter(name_ + ".performance.variant", variant); + + MpcPerformanceConfig perf_cfg; + perf_cfg.enable = performance_enable; + perf_cfg.print_enable = print_enable; + perf_cfg.detailed_csv_enable = detailed_csv_enable; + perf_cfg.odom_sub_debug_enable = odom_sub_debug_enable; + perf_cfg.detailed_csv_path = mpc_csv_path; + perf_cfg.run_id = run_id; + perf_cfg.scenario = scenario; + perf_cfg.variant = variant; + perf_cfg.print_period_sec = print_period_sec; + perf_cfg.csv_flush_every_n = csv_flush_every_n; + + mpc_perf_monitor_.configure(perf_cfg, logger_); +} + +void MincoMpcController::configure(const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent, + std::string name, + std::shared_ptr tf, + std::shared_ptr costmap_ros) +{ + node_ = parent; + name_ = name; + tf_ = tf; + costmap_ros_ = costmap_ros; + + auto node = parent.lock(); + logger_ = node->get_logger(); + + global_frame_ = costmap_ros_->getGlobalFrameID(); + base_frame_ = costmap_ros_->getBaseFrameID(); + configureMpcPerfLogging(node); + + // 声明/读å�–å�‚æ•° + nav2_util::declare_parameter_if_not_declared(node, name + ".dt", rclcpp::ParameterValue(0.05)); + nav2_util::declare_parameter_if_not_declared(node, name + ".horizon", rclcpp::ParameterValue(10)); + + nav2_util::declare_parameter_if_not_declared( + node, name + ".Q", rclcpp::ParameterValue(std::vector{5.0, 5.0, 2.0})); + nav2_util::declare_parameter_if_not_declared( + node, name + ".R", rclcpp::ParameterValue(std::vector{1.0, 1.0, 0.5})); + + nav2_util::declare_parameter_if_not_declared(node, name + ".vx_min", rclcpp::ParameterValue(-1.0)); + nav2_util::declare_parameter_if_not_declared(node, name + ".vx_max", rclcpp::ParameterValue(1.0)); + nav2_util::declare_parameter_if_not_declared(node, name + ".vy_min", rclcpp::ParameterValue(-1.0)); + nav2_util::declare_parameter_if_not_declared(node, name + ".vy_max", rclcpp::ParameterValue(1.0)); + nav2_util::declare_parameter_if_not_declared(node, name + ".omega_min", rclcpp::ParameterValue(-2.0)); + nav2_util::declare_parameter_if_not_declared(node, name + ".omega_max", rclcpp::ParameterValue(2.0)); + nav2_util::declare_parameter_if_not_declared(node, name + ".fixed_wz", rclcpp::ParameterValue(0.0)); + nav2_util::declare_parameter_if_not_declared( + node, name + ".deadzone_speed_threshold", rclcpp::ParameterValue(0.02)); + nav2_util::declare_parameter_if_not_declared( + node, name + ".control_delay_compensation", rclcpp::ParameterValue(0.25)); + nav2_util::declare_parameter_if_not_declared( + node, name + ".use_small_gyro_mode", rclcpp::ParameterValue(true)); + + nav2_util::declare_parameter_if_not_declared( + node, name + ".use_acc_constraints", rclcpp::ParameterValue(false)); + nav2_util::declare_parameter_if_not_declared(node, name + ".ax_min", rclcpp::ParameterValue(-2.0)); + nav2_util::declare_parameter_if_not_declared(node, name + ".ax_max", rclcpp::ParameterValue(2.0)); + nav2_util::declare_parameter_if_not_declared(node, name + ".ay_min", rclcpp::ParameterValue(-2.0)); + nav2_util::declare_parameter_if_not_declared(node, name + ".ay_max", rclcpp::ParameterValue(2.0)); + nav2_util::declare_parameter_if_not_declared(node, name + ".alpha_min", rclcpp::ParameterValue(-4.0)); + nav2_util::declare_parameter_if_not_declared(node, name + ".alpha_max", rclcpp::ParameterValue(4.0)); + + nav2_util::declare_parameter_if_not_declared( + node, name + ".odom_frame", rclcpp::ParameterValue("camera_init")); + nav2_util::declare_parameter_if_not_declared(node, name + ".map_frame", rclcpp::ParameterValue("map")); + nav2_util::declare_parameter_if_not_declared(node, name + ".lidar_offset_x", rclcpp::ParameterValue(0.0)); + nav2_util::declare_parameter_if_not_declared(node, name + ".lidar_offset_y", rclcpp::ParameterValue(0.0)); + nav2_util::declare_parameter_if_not_declared( + node, name + ".lidar_roll_offset", rclcpp::ParameterValue(0.0)); + + double dt = 0.05; + double lookahead_time = 0.5; + node->get_parameter(name + ".dt", dt); + node->get_parameter(name + ".lookahead_time", lookahead_time); + + std::vector Qv; + std::vector Rv; + node->get_parameter(name + ".Q", Qv); + node->get_parameter(name + ".R", Rv); + + mpc_config_.dt = dt; + mpc_config_.lookahead_time = lookahead_time; + mpc_config_.horizon = static_cast(std::ceil(lookahead_time / dt)); + if (Qv.size() == 3) { + mpc_config_.Q = Eigen::Vector3d(Qv[0], Qv[1], Qv[2]); + } + if (Rv.size() == 3) { + mpc_config_.R = Eigen::Vector3d(Rv[0], Rv[1], Rv[2]); + } + + node->get_parameter(name + ".vx_min", mpc_config_.vx_min); + node->get_parameter(name + ".vx_max", mpc_config_.vx_max); + node->get_parameter(name + ".vy_min", mpc_config_.vy_min); + node->get_parameter(name + ".vy_max", mpc_config_.vy_max); + node->get_parameter(name + ".omega_min", mpc_config_.omega_min); + node->get_parameter(name + ".omega_max", mpc_config_.omega_max); + node->get_parameter(name + ".fixed_wz", fixed_wz_); + node->get_parameter(name + ".deadzone_speed_threshold", deadzone_speed_threshold_); + node->get_parameter(name + ".control_delay_compensation", control_delay_compensation_); + node->get_parameter(name + ".use_small_gyro_mode", use_small_gyro_mode_); + + node->get_parameter(name + ".use_acc_constraints", mpc_config_.use_acc_constraints); + node->get_parameter(name + ".ax_min", mpc_config_.ax_min); + node->get_parameter(name + ".ax_max", mpc_config_.ax_max); + node->get_parameter(name + ".ay_min", mpc_config_.ay_min); + node->get_parameter(name + ".ay_max", mpc_config_.ay_max); + node->get_parameter(name + ".alpha_min", mpc_config_.alpha_min); + node->get_parameter(name + ".alpha_max", mpc_config_.alpha_max); + + node->get_parameter(name + ".odom_frame", odom_frame_); + node->get_parameter(name + ".map_frame", map_frame_); + node->get_parameter(name + ".lidar_offset_x", lidar_offset_x_); + node->get_parameter(name + ".lidar_offset_y", lidar_offset_y_); + node->get_parameter(name + ".lidar_roll_offset", lidar_roll_offset_); + + solver_ = std::make_unique(mpc_config_); + + // 订阅优化轨迹:/opt_path + opt_path_sub_ = node->create_subscription("/opt_path", + rclcpp::SystemDefaultsQoS(), + std::bind(&MincoMpcController::onOptPath, this, std::placeholders::_1)); + + // 订阅里程计:用于延迟补å�¿å’Œmpc输入状æ€� + auto odom_qos = rclcpp::QoS(rclcpp::KeepLast(1)).best_effort().durability_volatile(); + odom_sub_ = node->create_subscription("/aft_mapped_to_init", + odom_qos, + std::bind(&MincoMpcController::onOdom, this, std::placeholders::_1)); + + mpc_predict_path_pub_ = node->create_publisher("/mpc_predict_path", 1); + mpc_real_path_pub_ = node->create_publisher("/mpc_real_path", 1); + cmd_vel_mpc_pub_ = node->create_publisher("/cmd_vel_mpc", 1); + real_path_history_.clear(); + last_real_path_pub_time_ = node->now(); + + RCLCPP_INFO(logger_, + "%s: MincoMpcController configured (dt=%.3f, lookahead_time=%.3f, deadzone=%.3f, delay_comp=%.3f, " + "small_gyro=%s, fixed_wz=%.3f, lidar_offset_x=%.3f, lidar_offset_y=%.3f, lidar_roll_offset=%.3f)", + name_.c_str(), + dt, + lookahead_time, + deadzone_speed_threshold_, + control_delay_compensation_, + use_small_gyro_mode_ ? "true" : "false", + fixed_wz_, + lidar_offset_x_, + lidar_offset_y_, + lidar_roll_offset_); +} + +void MincoMpcController::compensateLeverArm(double v_lidar_x, + double v_lidar_y, + double omega_z, + double yaw, + double & vx_global, + double & vy_global, + double & omega_global) const +{ + const double v_body_x = v_lidar_x + omega_z * lidar_offset_y_; + const double v_body_y = v_lidar_y - omega_z * lidar_offset_x_; + + const double cos_yaw = std::cos(yaw); + const double sin_yaw = std::sin(yaw); + vx_global = v_body_x * cos_yaw - v_body_y * sin_yaw; + vy_global = v_body_x * sin_yaw + v_body_y * cos_yaw; + omega_global = omega_z; + // std::cout << "Raw velocities: vx_lidar=" << v_lidar_x << ", vy_lidar=" << v_lidar_y + // << ", omega_z=" << omega_z << ", yaw=" << yaw << std::endl; + // std::cout << "Compensated velocities: vx_global=" << vx_global << ", vy_global=" << vy_global + // << ", omega_global=" << omega_global << std::endl; +} + +void MincoMpcController::extractGlobalVelocityAndYaw(const nav_msgs::msg::Odometry::SharedPtr & odom, + double & vx_global, + double & vy_global, + double & omega_global, + double & yaw_global) const +{ + // 1. æ��å�– 3D 体轴速度 (IMU 物ç�†ä¸­å¿ƒçš„局部速度) + Eigen::Vector3d v_body_imu( + odom->twist.twist.linear.x, odom->twist.twist.linear.y, odom->twist.twist.linear.z); + + // 2. æ��å�–å…¨é‡� 3D å§¿æ€�四元数 + Eigen::Quaterniond q(odom->pose.pose.orientation.w, + odom->pose.pose.orientation.x, + odom->pose.pose.orientation.y, + odom->pose.pose.orientation.z); + + // 3. 3D 旋转:将倾斜机体系下的速度无æ�Ÿæ˜ å°„回与地é�¢å¹³è¡Œçš„全局系 + Eigen::Vector3d v_imu_global = q * v_body_imu; + + // 4. æ��å�–角速度与 Yaw è§’ + omega_global = odom->twist.twist.angular.z; + yaw_global = tf2::getYaw(odom->pose.pose.orientation); + + // 5. 计算全局æ�†è‡‚è¡¥å�¿ (将底盘水平安装å��置旋转到全局系) + double offset_global_x = std::cos(yaw_global) * lidar_offset_x_ - std::sin(yaw_global) * lidar_offset_y_; + double offset_global_y = std::sin(yaw_global) * lidar_offset_x_ + std::cos(yaw_global) * lidar_offset_y_; + // 6. 计算底盘旋转中心的全局速度 + vx_global = v_imu_global.x() + omega_global * offset_global_y; + vy_global = v_imu_global.y() - omega_global * offset_global_x; +} + +void MincoMpcController::cleanup() +{ + mpc_perf_monitor_.close(); + opt_path_sub_.reset(); + odom_sub_.reset(); + mpc_predict_path_pub_.reset(); + mpc_real_path_pub_.reset(); + cmd_vel_mpc_pub_.reset(); + solver_.reset(); + + std::lock_guard lk(data_mtx_); + latest_opt_path_.reset(); + latest_odom_.reset(); +} + +void MincoMpcController::activate() +{ +} + +void MincoMpcController::deactivate() +{ +} + +void MincoMpcController::setPlan(const nav_msgs::msg::Path & path) +{ + std::lock_guard lk(plan_mtx_); + global_plan_ = path; +} + +void MincoMpcController::setSpeedLimit(const double & speed_limit, const bool & percentage) +{ + speed_limit_ = speed_limit; + speed_limit_percentage_ = percentage; +} + +void MincoMpcController::onOptPath(const ros_interfaces::msg::MpcPositionCommand::SharedPtr msg) +{ + std::lock_guard lk(data_mtx_); + + const uint32_t new_traj_id = (msg && !msg->cmds.empty()) ? msg->cmds.front().trajectory_id : 0u; + const uint32_t old_traj_id = (latest_opt_path_ && !latest_opt_path_->cmds.empty()) + ? latest_opt_path_->cmds.front().trajectory_id + : 0u; + + // 仅在轨迹 ID 切æ�¢æ—¶é‡�置跟踪状æ€�ï¼›å�Œä¸€è½¨è¿¹é‡�å¤�å�‘布(更新时间戳)ä¸�é‡�ç½® + if (new_traj_id != old_traj_id) { + has_tracked_ref_ = false; + } + + latest_opt_path_ = msg; +} + +void MincoMpcController::onOdom(const nav_msgs::msg::Odometry::SharedPtr msg) +{ + auto node = node_.lock(); + if (node && msg) { + mpc_perf_monitor_.recordOdomCallback(node->now(), msg->header.stamp); + } + + std::lock_guard lk(data_mtx_); + latest_odom_ = msg; +} + +bool MincoMpcController::transformPathToOdom(const ros_interfaces::msg::MpcPositionCommand::SharedPtr & opt, + std::vector & out_cmds) const +{ + std::string source_frame = opt->header.frame_id; + if (source_frame.empty()) { + source_frame = map_frame_; + auto node_ptr = node_.lock(); + if (node_ptr) { + RCLCPP_WARN_THROTTLE(logger_, + *node_ptr->get_clock(), + 10000, + "Received opt_path with empty frame_id, defaulting to '%s'", + source_frame.c_str()); + } + } + + // 从costmap获å�–全局å��标系,优先使用global_frame_,如果未设置则退回到odom_frame_ + std::string target_frame = global_frame_; + if (target_frame.empty()) { + target_frame = odom_frame_; + } + + if (source_frame == target_frame) { + out_cmds = opt->cmds; + return true; + } + + // 如果å��标系ä¸�å�Œï¼Œå°�试进行转æ�¢ + try { + geometry_msgs::msg::TransformStamped transform = + tf_->lookupTransform(target_frame, source_frame, tf2::TimePointZero); + + out_cmds = opt->cmds; + for (auto & cmd : out_cmds) { + // Transform position + geometry_msgs::msg::PointStamped p_in, p_out; + p_in.header.frame_id = source_frame; + p_in.point = cmd.position; + tf2::doTransform(p_in, p_out, transform); + cmd.position = p_out.point; + + // Transform velocity (vector) + geometry_msgs::msg::Vector3Stamped v_in, v_out; + v_in.header.frame_id = source_frame; + v_in.vector = cmd.velocity; + tf2::doTransform(v_in, v_out, transform); + cmd.velocity = v_out.vector; + + // Transform acceleration (vector) + geometry_msgs::msg::Vector3Stamped a_in, a_out; + a_in.header.frame_id = source_frame; + a_in.vector = cmd.acceleration; + tf2::doTransform(a_in, a_out, transform); + cmd.acceleration = a_out.vector; + + // Transform jerk (vector) + geometry_msgs::msg::Vector3Stamped j_in, j_out; + j_in.header.frame_id = source_frame; + j_in.vector = cmd.jerk; + tf2::doTransform(j_in, j_out, transform); + cmd.jerk = j_out.vector; + + // Transform yaw + double yaw_diff = tf2::getYaw(transform.transform.rotation); + cmd.yaw = normalizeYaw(cmd.yaw + yaw_diff); + } + + } catch (tf2::TransformException & ex) { + return false; + } + return true; +} + +bool MincoMpcController::buildReferenceFromOptPath( + const State & curr, std::vector & out_ref) const +{ + auto node = node_.lock(); + if (!node) { + return false; + } + const rclcpp::Time now = node->now(); + + // 获å�–最新的优化轨迹和里程计数æ�®ï¼Œä»¥å�Šå½“å‰�跟踪状æ€�(索引ã€�时间戳ã€�轨迹ID) + ros_interfaces::msg::MpcPositionCommand::SharedPtr opt; + double tracked_ref_idx = 0.0; + rclcpp::Time tracked_ref_time; + uint32_t tracked_opt_traj_id = 0u; + bool has_tracked_ref = false; + { + std::lock_guard lk(data_mtx_); + opt = latest_opt_path_; + tracked_ref_idx = tracked_ref_idx_; + tracked_ref_time = tracked_ref_time_; + tracked_opt_traj_id = tracked_opt_traj_id_; + has_tracked_ref = has_tracked_ref_; + } + + if (!opt || opt->cmds.empty()) { + return false; + } + + // å��标系转æ�¢å¤„ç�† + std::vector cmds; + if (!transformPathToOdom(opt, cmds)) { + return false; + } + + const size_t n_cmds = cmds.size(); + const double planner_dt = 1.0 / mpc_config_.planner_freq; + if (planner_dt <= 1.0e-6) { + return false; + } + + // 最近点æ�œç´¢ï¼ˆåŸºäºŽæœ€å°�欧å¼�è·�离),并计算更精确的最近点投影索引 + size_t best_idx = 0; + double best_d2 = std::numeric_limits::infinity(); + for (size_t i = 0; i < n_cmds; ++i) { + const double dx = cmds[i].position.x - curr.x; + const double dy = cmds[i].position.y - curr.y; + const double d2 = dx * dx + dy * dy; + if (d2 < best_d2) { + best_d2 = d2; + best_idx = i; + } + } + + double nearest_idx_float = static_cast(best_idx); + + if (best_idx < n_cmds - 1) { + const auto & p_curr = cmds[best_idx]; + const auto & p_next = cmds[best_idx + 1]; + + Eigen::Vector2d a_vec(p_next.position.x - p_curr.position.x, p_next.position.y - p_curr.position.y); + Eigen::Vector2d b_vec(curr.x - p_curr.position.x, curr.y - p_curr.position.y); + + double len_sq = a_vec.squaredNorm(); + if (len_sq > 1e-6) { + double projection = a_vec.dot(b_vec) / len_sq; + if (projection > -0.5 && projection < 1.0) { + nearest_idx_float += projection; + } + } + } + + nearest_idx_float = std::max(0.0, nearest_idx_float); + + const uint32_t current_traj_id = (!opt->cmds.empty()) ? opt->cmds.front().trajectory_id : 0u; + + // 轨迹未更新时,按时间æŒ�ç»­å�‘å‰�推进å�‚考索引,且ä¸�å…�许回退 + // const bool same_opt_traj = has_tracked_ref && tracked_opt_traj_id == current_traj_id; + + // double progress_idx_float = nearest_idx_float; + // if (same_opt_traj) { + // double dt_pass = (now - tracked_ref_time).seconds(); + // dt_pass = std::max(0.0, dt_pass); + // progress_idx_float = tracked_ref_idx + dt_pass / planner_dt; + // } + // double current_idx_float = std::max(nearest_idx_float, progress_idx_float); + + // // å�Œä¸€æ�¡è½¨è¿¹è‹¥è¶…过阈值ä»�未更新,判定规划器å�¡æ­» + // const double traj_stamp_sec = + // static_cast(opt->header.stamp.sec) + static_cast(opt->header.stamp.nanosec) * 1.0e-9; + // const double absolute_age = now.seconds() - traj_stamp_sec; + // if (same_opt_traj && absolute_age > 0.5) { + // return false; + // } + + double current_idx_float = nearest_idx_float; + current_idx_float = std::min(current_idx_float, static_cast(n_cmds - 1)); + + { + std::lock_guard lk(data_mtx_); + tracked_ref_idx_ = current_idx_float; + tracked_ref_time_ = now; + tracked_opt_traj_id_ = current_traj_id; + has_tracked_ref_ = true; + } + + double current_traj_time = current_idx_float * planner_dt; + + // 让 MPC 始终去追踪未æ�¥ä¸€æ®µæ—¶é—´çš„å�‚考点,用于控制延迟补å�¿ + double control_delay = control_delay_compensation_; + + current_traj_time += control_delay; + + const int N = mpc_config_.horizon; + const double mpc_dt = mpc_config_.dt; + out_ref.clear(); + out_ref.reserve(static_cast(N)); + + for (int k = 0; k < N; ++k) { + double target_time = current_traj_time + k * mpc_dt; + double target_idx_float = target_time / planner_dt; + + if (target_idx_float < 0.0) + target_idx_float = 0.0; + if (target_idx_float > static_cast(n_cmds - 1)) { + target_idx_float = static_cast(n_cmds - 1); + } + + size_t target_idx = static_cast(std::floor(target_idx_float)); + size_t next_idx = target_idx + 1; + double alpha = target_idx_float - static_cast(target_idx); + + ReferencePoint rp; + if (next_idx < n_cmds) { + // 二次å‰�馈æ�’值(泰勒展开),使用 P/V/A/J 进行æ�’值,补å�¿æŽ§åˆ¶å»¶è¿Ÿå¸¦æ�¥çš„误差。 + const double dt = std::max(0.0, std::min(planner_dt, alpha * planner_dt)); + const double dt2 = dt * dt; + const double dt3 = dt2 * dt; + + const Eigen::Vector2d p_i(cmds[target_idx].position.x, cmds[target_idx].position.y); + const Eigen::Vector2d v_i(cmds[target_idx].velocity.x, cmds[target_idx].velocity.y); + const Eigen::Vector2d a_i(cmds[target_idx].acceleration.x, cmds[target_idx].acceleration.y); + const Eigen::Vector2d j_i(cmds[target_idx].jerk.x, cmds[target_idx].jerk.y); + + rp.pos = p_i + v_i * dt + 0.5 * a_i * dt2 + (1.0 / 6.0) * j_i * dt3; + rp.vel = v_i + a_i * dt + 0.5 * j_i * dt2; + + // 线性角度æ�’值 + rp.yaw = interpolateYaw(cmds[target_idx].yaw, cmds[next_idx].yaw, alpha); + rp.yaw_rate = interpolate(cmds[target_idx].yaw_dot, cmds[next_idx].yaw_dot, alpha); + } else { + const auto & p_end = cmds.back(); + rp.pos = Eigen::Vector2d(p_end.position.x, p_end.position.y); + rp.vel = Eigen::Vector2d(0.0, 0.0); + rp.yaw = p_end.yaw; + rp.yaw_rate = 0.0; + } + out_ref.push_back(rp); + } + + // 对å�‚考åº�列的 yaw 进行连续性处ç�† + if (!out_ref.empty()) { + double diff = out_ref[0].yaw - curr.yaw; + // å°† diff é™�制在 [-PI, PI] + diff = std::atan2(std::sin(diff), std::cos(diff)); + out_ref[0].yaw = curr.yaw + diff; + + for (size_t i = 1; i < out_ref.size(); ++i) { + double d_yaw = out_ref[i].yaw - out_ref[i - 1].yaw; + d_yaw = std::atan2(std::sin(d_yaw), std::cos(d_yaw)); + out_ref[i].yaw = out_ref[i - 1].yaw + d_yaw; + } + } + return true; +} + +void MincoMpcController::applyGravityCompensation( + const nav_msgs::msg::Odometry::SharedPtr & odom, double & vx, double & vy) +{ + if (!odom) { + return; + } + + tf2::Quaternion q; + tf2::fromMsg(odom->pose.pose.orientation, q); + + double roll = 0.0; + double pitch = 0.0; + double yaw = 0.0; + tf2::Matrix3x3(q).getRPY(roll, pitch, yaw); + // std::cout << "Original roll: " << roll << ", pitch: " << pitch << ", yaw: " << yaw << std::endl; + const double true_roll = roll - lidar_roll_offset_; + constexpr double angle_threshold = 0.05; + constexpr double k_gravity_x = 1.0; + constexpr double k_gravity_y = 20.0; + + double body_comp_x = 0.0; + double body_comp_y = 0.0; + if (std::abs(pitch) > angle_threshold) { + body_comp_x = k_gravity_x * std::sin(-pitch); + } + if (std::abs(true_roll) > angle_threshold) { + body_comp_y = k_gravity_y * std::sin(std::abs(true_roll)); + } + + if (body_comp_x == 0.0 && body_comp_y == 0.0) { + return; + } + + const double global_comp_x = body_comp_x * std::cos(yaw) - body_comp_y * std::sin(yaw); + const double global_comp_y = body_comp_x * std::sin(yaw) + body_comp_y * std::cos(yaw); + + vx += global_comp_x; + vy += global_comp_y; + + vx = std::clamp(vx, mpc_config_.vx_min, mpc_config_.vx_max); + vy = std::clamp(vy, mpc_config_.vy_min, mpc_config_.vy_max); +} + +geometry_msgs::msg::TwistStamped MincoMpcController::computeVelocityCommands( + const geometry_msgs::msg::PoseStamped & pose, + const geometry_msgs::msg::Twist & velocity, + nav2_core::GoalChecker * goal_checker) +{ + const bool record_perf = mpc_perf_monitor_.detailedCsvEnabled(); + const auto cycle_start = record_perf ? std::chrono::steady_clock::now() : std::chrono::steady_clock::time_point{}; + auto node = node_.lock(); + + const rclcpp::Time now = node->now(); + std::optional perf; + if (record_perf) { + perf.emplace(); + perf->stamp_ros = now.seconds(); + perf->stamp_steady_ns = MpcPerformanceMonitor::steadyNowNs(); + } + auto finish = [&](geometry_msgs::msg::TwistStamped out_cmd, bool success, const std::string &) { + if (perf) { + perf->success = success; + perf->cycle_time_ms = + std::chrono::duration(std::chrono::steady_clock::now() - cycle_start).count(); + if (last_mpc_perf_stamp_ns_ > 0 && perf->stamp_steady_ns > last_mpc_perf_stamp_ns_) { + const double dt_sec = static_cast(perf->stamp_steady_ns - last_mpc_perf_stamp_ns_) * 1.0e-9; + if (dt_sec > 1.0e-9) { + perf->controller_hz = 1.0 / dt_sec; + } + } + last_mpc_perf_stamp_ns_ = perf->stamp_steady_ns; + perf->cmd_vx = out_cmd.twist.linear.x; + perf->cmd_vy = out_cmd.twist.linear.y; + perf->cmd_wz = out_cmd.twist.angular.z; + mpc_perf_monitor_.recordMpcSample(*perf); + } + return out_cmd; + }; + + nav_msgs::msg::Odometry::SharedPtr latest_odom; + { + std::lock_guard lk(data_mtx_); + latest_odom = latest_odom_; + } + + // 1) 构造当å‰�状æ€�(基于 pose + 最新里程计速度,用于延迟补å�¿ï¼‰ + State curr; + curr.x = pose.pose.position.x; + curr.y = pose.pose.position.y; + curr.yaw = normalizeYaw(tf2::getYaw(pose.pose.orientation)); + if (latest_odom) { + double vx = latest_odom->twist.twist.linear.x; + double vy = latest_odom->twist.twist.linear.y; + double omega = latest_odom->twist.twist.angular.z; + double yaw = normalizeYaw(tf2::getYaw(latest_odom->pose.pose.orientation)); + // extractGlobalVelocityAndYaw(latest_odom, vx, vy, omega, yaw); + compensateLeverArm(vx, vy, omega, yaw, curr.vx, curr.vy, curr.omega); + + // curr.yaw = normalizeYaw(yaw); + // curr.vx = vx; + // curr.vy = vy; + // curr.omega = omega; + + const double noise_threshold = 0.03; + if (std::abs(curr.vx) < noise_threshold) { + curr.vx = 0.0; + } + if (std::abs(curr.vy) < noise_threshold) { + curr.vy = 0.0; + } + if (std::abs(curr.omega) < noise_threshold) { + curr.omega = 0.0; + } + } else { + curr.vx = 0.0; + curr.vy = 0.0; + curr.omega = 0.0; + } + + geometry_msgs::msg::TwistStamped cmd; + cmd.header.stamp = now; + cmd.header.frame_id = global_frame_; + + // Sync Nav2 success semantics: if GoalChecker says reached, output zero command immediately. + if (goal_checker != nullptr) { + geometry_msgs::msg::PoseStamped goal_pose; + bool has_goal_pose = false; + { + std::lock_guard lk(plan_mtx_); + if (!global_plan_.poses.empty()) { + goal_pose = global_plan_.poses.back(); + has_goal_pose = true; + } + } + + if (has_goal_pose && goal_checker->isGoalReached(pose.pose, goal_pose.pose, velocity)) { + std::lock_guard lk(data_mtx_); + has_tracked_ref_ = false; + latest_opt_path_.reset(); + cmd.twist.linear.x = 0.0; + cmd.twist.linear.y = 0.0; + cmd.twist.angular.z = 0.0; + return finish(cmd, true, "NONE"); + } + } + + if (control_delay_compensation_ > 1e-3) { + curr.x += curr.vx * control_delay_compensation_; + curr.y += curr.vy * control_delay_compensation_; + curr.yaw += curr.omega * control_delay_compensation_; + curr.yaw = normalizeYaw(curr.yaw); + } + + // 2) 构造å�‚考åº�列:优先 /opt_path + std::vector ref; + bool ok_ref = buildReferenceFromOptPath(curr, ref); + + if (!ok_ref || !solver_) { + // æ— å�‚考则输出 0 + cmd.twist.linear.x = 0.0; + cmd.twist.linear.y = 0.0; + cmd.twist.angular.z = 0.0; + return finish(cmd, false, ok_ref ? "SOLVER_UNAVAILABLE" : "NO_REFERENCE"); + } + if (perf && !ref.empty()) { + perf->ref_vx = ref.front().vel.x(); + perf->ref_vy = ref.front().vel.y(); + perf->ref_wz = ref.front().yaw_rate; + } + + // 3) 调用 MPC 求解(输出 global_frame_ 系速度,此处为 camera_init) + Control u_global; + std::vector pred_states; + const auto solve_start = record_perf ? std::chrono::steady_clock::now() : std::chrono::steady_clock::time_point{}; +#ifdef MINCO_DEBUG + auto t_start = std::chrono::high_resolution_clock::now(); +#endif + bool success = solver_->solve(curr, ref, u_global, &pred_states); + if (perf) { + perf->solve_time_ms = + std::chrono::duration(std::chrono::steady_clock::now() - solve_start).count(); + } + + publishVisualization(pred_states, curr); + +#ifdef MINCO_DEBUG + auto t_end = std::chrono::high_resolution_clock::now(); + if (success && !ref.empty()) { + double dt_ms = std::chrono::duration(t_end - t_start).count(); + + double plan_vx = u_global.vx; + double plan_vy = u_global.vy; + double ref_vx = ref[0].vel.x(); + double ref_vy = ref[0].vel.y(); + double v_err_x = plan_vx - ref_vx; + double v_err_y = plan_vy - ref_vy; + + double curr_x = curr.x; + double curr_y = curr.y; + double ref_x = ref[0].pos.x(); + double ref_y = ref[0].pos.y(); + double p_err_x = curr_x - ref_x; + double p_err_y = curr_y - ref_y; + + custom_log::log_block(std::string("\033[34m[MincoMpc] "), + NV(plan_vx), + NV(plan_vy), + NV(ref_vx), + NV(ref_vy), + NV(v_err_x), + NV(v_err_y), + NV(curr_x), + NV(curr_y), + NV(ref_x), + NV(ref_y), + NV(p_err_x), + NV(p_err_y), + NV(dt_ms)); + } +#endif + + if (!success) { + std::cout << color_text::RED << "[MincoMpc] Solver Failed!" << color_text::RESET << std::endl; + // Debug info for failure + if (!ref.empty()) { + std::cout << "[MincoMpc] Ref Size: " << ref.size() << std::endl; + std::cout << "[MincoMpc] Curr: " << curr.x << ", " << curr.y << ", " << curr.yaw << std::endl; + std::cout << "[MincoMpc] Ref[0]: " << ref[0].pos.x() << ", " << ref[0].pos.y() << ", " << ref[0].yaw + << std::endl; + } + + cmd.twist.linear.x = 0.0; + cmd.twist.linear.y = 0.0; + cmd.twist.angular.z = 0.0; + return finish(cmd, false, "QP_FAILED"); + } + + // 5) 直接下å�‘全局å��标系速度 + double vx_mpc = u_global.vx; + double vy_mpc = u_global.vy; + double wz = fixed_wz_; + + // å°�陀螺模å¼�:当å�¯ç”¨æ—¶ï¼Œå§‹ç»ˆè¾“出固定的旋转速度,而ä¸�使用 MPC 输出的角速度。 + if (!use_small_gyro_mode_) { + wz = std::min(mpc_config_.omega_max, std::max(mpc_config_.omega_min, u_global.omega)); + } + + double output_delay = 0.025; + double phase_delay = curr.omega * output_delay; + double cos_phase = std::cos(phase_delay); + double sin_phase = std::sin(phase_delay); + double vx = cos_phase * vx_mpc + sin_phase * vy_mpc; + double vy = -sin_phase * vx_mpc + cos_phase * vy_mpc; + // 5) 处ç�† Nav2 setSpeedLimit + if (speed_limit_ > 1e-6) { + const double v_norm = std::hypot(vx, vy); + if (v_norm > 1e-6) { + double scale = 1.0; + if (speed_limit_percentage_) { + scale = std::clamp(speed_limit_ / 100.0, 0.0, 1.0); + } else { + scale = std::min(1.0, speed_limit_ / v_norm); + } + vx *= scale; + vy *= scale; + } + } + + // 6) 死区截断 + const double deadzone = deadzone_speed_threshold_; + if (std::hypot(vx, vy) < deadzone) { + vx = 0.0; + vy = 0.0; + } + constexpr double goal_pos_threshold = 0.3; + bool stop_mpc_cmd = false; + geometry_msgs::msg::PoseStamped goal_pose_stamped; + { + std::lock_guard lk(plan_mtx_); + if (!global_plan_.poses.empty()) { + goal_pose_stamped = global_plan_.poses.back(); + } + } + if (!goal_pose_stamped.header.frame_id.empty()) { + geometry_msgs::msg::PoseStamped goal_pose_in_odom = goal_pose_stamped; + if (goal_pose_in_odom.header.frame_id != odom_frame_) { + try { + goal_pose_in_odom = tf_->transform(goal_pose_in_odom, odom_frame_); + } catch (const tf2::TransformException &) { + goal_pose_in_odom.header.frame_id.clear(); + } + } + if (!goal_pose_in_odom.header.frame_id.empty()) { + const double dx = pose.pose.position.x - goal_pose_in_odom.pose.position.x; + const double dy = pose.pose.position.y - goal_pose_in_odom.pose.position.y; + const double dist = std::hypot(dx, dy); + stop_mpc_cmd = (dist <= goal_pos_threshold); + } + } + if (cmd_vel_mpc_pub_) { + geometry_msgs::msg::Twist raw_cmd; + raw_cmd.linear.x = stop_mpc_cmd ? 0.0 : vx; + raw_cmd.linear.y = stop_mpc_cmd ? 0.0 : vy; + raw_cmd.angular.z = stop_mpc_cmd ? 0.0 : wz; + cmd_vel_mpc_pub_->publish(raw_cmd); + } + // applyGravityCompensation(latest_odom, vx, vy); + cmd.twist.linear.x = vx; + cmd.twist.linear.y = vy; + cmd.twist.angular.z = wz; + return finish(cmd, true, "NONE"); +} + +void MincoMpcController::publishVisualization( + const std::vector & pred_path, const State & curr_state) +{ + auto node = node_.lock(); + if (!node) + return; + + rclcpp::Time now = node->now(); + + // 1. å�‘布预测路径 + if (mpc_predict_path_pub_ && mpc_predict_path_pub_->get_subscription_count() > 0 && !pred_path.empty()) { + nav_msgs::msg::Path path_msg; + path_msg.header.stamp = now; + path_msg.header.frame_id = global_frame_; + + for (const auto & s : pred_path) { + geometry_msgs::msg::PoseStamped ps; + ps.header = path_msg.header; + ps.pose.position.x = s.x; + ps.pose.position.y = s.y; + ps.pose.position.z = 0.0; + + tf2::Quaternion q; + q.setRPY(0, 0, s.yaw); + ps.pose.orientation = tf2::toMsg(q); + path_msg.poses.push_back(ps); + } + mpc_predict_path_pub_->publish(path_msg); + } + + // 2. å�‘布实际路径 + geometry_msgs::msg::PoseStamped ps; + ps.header.stamp = now; + ps.header.frame_id = global_frame_; + ps.pose.position.x = curr_state.x; + ps.pose.position.y = curr_state.y; + ps.pose.position.z = 0.0; + tf2::Quaternion q; + q.setRPY(0, 0, curr_state.yaw); + ps.pose.orientation = tf2::toMsg(q); + + if (real_path_history_.empty()) { + real_path_history_.push_back(ps); + } else { + const auto & last = real_path_history_.back(); + double dist = + std::hypot(last.pose.position.x - ps.pose.position.x, last.pose.position.y - ps.pose.position.y); + // 简å�•çš„è·�离过滤,é�¿å…�原地ä¸�动时数æ�®å †ç§¯ + if (dist > 0.02) { + real_path_history_.push_back(ps); + } + } + + // ä¿�æŒ�历å�²é•¿åº¦ + if (real_path_history_.size() > 5000) { + size_t remove_count = real_path_history_.size() - 5000; + real_path_history_.erase(real_path_history_.begin(), real_path_history_.begin() + remove_count); + } + + if (mpc_real_path_pub_ && mpc_real_path_pub_->get_subscription_count() > 0) { + // é™�频å�‘布:1.0 Hz + if ((now - last_real_path_pub_time_).seconds() > 1.0) { + nav_msgs::msg::Path path_msg; + path_msg.header.stamp = now; + path_msg.header.frame_id = global_frame_; + // 如果历å�²å¤ªé•¿ï¼Œå�¯ä»¥å�ªå�‘布最近的一部分,或者对历å�²è¿›è¡Œä¸‹é‡‡æ ·ï¼ˆæœ¬ä¾‹ç›´æŽ¥å�‘布全部,但频率低) + path_msg.poses = real_path_history_; + mpc_real_path_pub_->publish(path_msg); + last_real_path_pub_time_ = now; + } + } +} + +} // namespace minco_controller + +PLUGINLIB_EXPORT_CLASS(minco_controller::MincoMpcController, nav2_core::Controller) diff --git a/minco_ws/src/navigation/minco_controller/src/mpc_solver.cpp b/minco_ws/src/navigation/minco_controller/src/mpc_solver.cpp new file mode 100644 index 0000000..a397b8d --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/src/mpc_solver.cpp @@ -0,0 +1,357 @@ +#include "minco_controller/mpc_solver.hpp" + +#include +#include +#include +#include +#include + +#include "color_text.hpp" +#include + +namespace minco_controller { + +MpcSolver::MpcSolver(const MPCConfig & config) : config_(config) +{ +} + +void MpcSolver::setConfig(const MPCConfig & config) +{ + config_ = config; +} + +void MpcSolver::buildStepModel( + double /*yaw_ref*/, Eigen::Matrix3d & A, Eigen::Matrix & B) const +{ + A.setIdentity(); + + B.setZero(); + // 纯全局å��标系控制,解耦 X, Y, Yaw + B(0, 0) = config_.dt; + B(1, 1) = config_.dt; + B(2, 2) = config_.dt; +} + +bool MpcSolver::buildCondensedQP(const State & curr, + const std::vector & ref_traj, + Eigen::MatrixXd & H, + Eigen::VectorXd & g, + Eigen::VectorXd & lb, + Eigen::VectorXd & ub, + Eigen::MatrixXd & A_con, + Eigen::VectorXd & lbA, + Eigen::VectorXd & ubA) +{ + const int N = config_.horizon; + if (N <= 0) { + return false; + } + if (static_cast(ref_traj.size()) < N) { + return false; + } + + // 构建堆å� æ¨¡åž‹ X = A_hat x0 + B_hat U + // 其中nx,nu 分别为å�•步状æ€�与控制é‡�维度,nX,nU 为堆å� å�Žç»´åº¦ + const int nx = 3; + const int nu = 3; + const int nU = nu * N; + const int nX = nx * N; + + // å †å� çжæ€�:X = [x1..xN, y1..yN, yaw1..yawN] + // X = [x1,y1,yaw1, x2,y2,yaw2, ..., xN,yN,yawN]^T + // X = A_hat * x0 + B_hat * U + Eigen::MatrixXd A_hat = Eigen::MatrixXd::Zero(nX, nx); + Eigen::MatrixXd B_hat = Eigen::MatrixXd::Zero(nX, nU); + + Eigen::Matrix3d A = Eigen::Matrix3d::Identity(); + + for (int i = 0; i < N; ++i) { + Eigen::Matrix Bi; + buildStepModel(ref_traj[i].yaw, A, Bi); + + // A_hat block: A^{i+1} + Eigen::Matrix3d A_power = Eigen::Matrix3d::Identity(); + for (int p = 0; p < i + 1; ++p) { + A_power = A * A_power; + } + A_hat.block<3, 3>(i * nx, 0) = A_power; + + // B_hat: å½±å“� x_{i+1} 的所有 u_0..u_i + for (int j = 0; j <= i; ++j) { + // 由于 A=I,这里ä»�按通用形å¼�写:A^{i-j} * B_j + Eigen::Matrix3d A_ij = Eigen::Matrix3d::Identity(); + for (int p = 0; p < i - j; ++p) { + A_ij = A * A_ij; + } + + Eigen::Matrix Bj; + buildStepModel(ref_traj[j].yaw, A, Bj); + + B_hat.block<3, 3>(i * nx, j * nu) = A_ij * Bj; + } + } + + // å�‚考状æ€�å †å�  X_ref + Eigen::VectorXd X_ref = Eigen::VectorXd::Zero(nX); + for (int i = 0; i < N; ++i) { + X_ref(i * nx + 0) = ref_traj[i].pos.x(); + X_ref(i * nx + 1) = ref_traj[i].pos.y(); + X_ref(i * nx + 2) = ref_traj[i].yaw; + } + + // å�‚考控制堆å�  U_ref (直接使用全局速度) + Eigen::VectorXd U_ref = Eigen::VectorXd::Zero(nU); + for (int i = 0; i < N; ++i) { + U_ref(i * nu + 0) = ref_traj[i].vel.x(); + U_ref(i * nu + 1) = ref_traj[i].vel.y(); + U_ref(i * nu + 2) = ref_traj[i].yaw_rate; + } + + // Q_bar / R_bar (对角å�—) + // P1: Rotate Q at each horizon step to decompose tracking penalty + // into along-track (heading direction) and cross-track (perpendicular). + // Higher cross-track weight enforces precision on curves/narrow passages. + Eigen::MatrixXd Q_bar = Eigen::MatrixXd::Zero(nX, nX); + Eigen::MatrixXd R_bar = Eigen::MatrixXd::Zero(nU, nU); + for (int i = 0; i < N; ++i) { + const double yaw_ref = ref_traj[i].yaw; + const double c = std::cos(yaw_ref); + const double s = std::sin(yaw_ref); + // Q_xy = R^T * diag(q_along, q_cross) * R (R is 2D rotation by yaw_ref) + // R = [c, -s; s, c], so: + // Q_xy = [c*q_along*c + s*q_cross*s, c*q_along*(-s) + s*q_cross*c; + // (-s)*q_along*c + c*q_cross*s, (-s)*q_along*(-s) + c*q_cross*c] + const double qa = config_.q_along; + const double qc = config_.q_cross; + Q_bar(i * nx + 0, i * nx + 0) = qa * c * c + qc * s * s; + Q_bar(i * nx + 0, i * nx + 1) = (qc - qa) * c * s; + Q_bar(i * nx + 1, i * nx + 0) = (qc - qa) * c * s; + Q_bar(i * nx + 1, i * nx + 1) = qa * s * s + qc * c * c; + Q_bar(i * nx + 2, i * nx + 2) = config_.Q.z(); // yaw weight unchanged + + R_bar.block<3, 3>(i * nu, i * nu) = config_.R.asDiagonal(); + } + + // d = A_hat * x0 - X_ref + Eigen::Vector3d x0(curr.x, curr.y, curr.yaw); + const Eigen::VectorXd d = A_hat * x0 - X_ref; + + // H = 2*(B^T Q B + R) + H = 2.0 * (B_hat.transpose() * Q_bar * B_hat + R_bar); + + // 数值正则(é�¿å…� Hessian 奇异) + H += config_.eps_regularization * Eigen::MatrixXd::Identity(nU, nU); + + // g = 2*(B^T Q d - R U_ref) + g = 2.0 * (B_hat.transpose() * Q_bar * d - R_bar * U_ref); + + // å�˜é‡�边界(速度约æ�Ÿï¼Œmap/global 系) + // Use -1e12 instead of -inf: qpOASES defines INFTY=1e20 internally. + // IEEE -inf causes NaN in active-set arithmetic. + lb = Eigen::VectorXd::Constant(nU, -1.0e12); + ub = Eigen::VectorXd::Constant(nU, 1.0e12); + for (int i = 0; i < N; ++i) { + lb(i * nu + 0) = config_.vx_min; + ub(i * nu + 0) = config_.vx_max; + lb(i * nu + 1) = config_.vy_min; + ub(i * nu + 1) = config_.vy_max; + lb(i * nu + 2) = config_.omega_min; + ub(i * nu + 2) = config_.omega_max; + } + + // 加速度约æ�Ÿï¼ˆå�¯é€‰ï¼‰ï¼ša_min <= (v_k - v_{k-1})/dt <= a_max + if (!config_.use_acc_constraints) { + A_con.resize(0, 0); + lbA.resize(0); + ubA.resize(0); + return true; + } + + const int nC = 3 * N; // 对æ¯�个 k 对æ¯�个轴å�„一个差分约æ�Ÿï¼šv_k - v_{k-1} + A_con = Eigen::MatrixXd::Zero(nC, nU); + lbA = Eigen::VectorXd::Zero(nC); + ubA = Eigen::VectorXd::Zero(nC); + + const double last_vx = last_u_global_.x(); + const double last_vy = last_u_global_.y(); + const double last_w = last_u_global_.z(); + + // 约æ�Ÿå½¢å¼�:lbA <= A_con * U <= ubA + // 这里 A_con * U 直接表示 (v_k - v_{k-1}),å†�用 bounds é™�制到 [a_min*dt, a_max*dt] + for (int k = 0; k < N; ++k) { + for (int axis = 0; axis < 3; ++axis) { + const int row = k * 3 + axis; + const int col_curr = k * 3 + axis; + A_con(row, col_curr) = 1.0; + + if (k == 0) { + // v0 - v(-1) + // v(-1) 使用当å‰�时刻真实全局速度作为已知常数,转移到 bounds: + // a_min*dt <= v0 - v_curr_global <= a_max*dt + const double last = (axis == 0 ? last_vx : (axis == 1 ? last_vy : last_w)); + lbA(row) = + (axis == 0 ? config_.ax_min : (axis == 1 ? config_.ay_min : config_.alpha_min)) * config_.dt + + last; + ubA(row) = + (axis == 0 ? config_.ax_max : (axis == 1 ? config_.ay_max : config_.alpha_max)) * config_.dt + + last; + } else { + const int col_prev = (k - 1) * 3 + axis; + A_con(row, col_prev) = -1.0; + lbA(row) = + (axis == 0 ? config_.ax_min : (axis == 1 ? config_.ay_min : config_.alpha_min)) * config_.dt; + ubA(row) = + (axis == 0 ? config_.ax_max : (axis == 1 ? config_.ay_max : config_.alpha_max)) * config_.dt; + } + } + } + + return true; +} + +bool MpcSolver::solve(const State & curr, + const std::vector & ref_traj, + Control & out_u, + std::vector * out_pred) +{ + const int N = config_.horizon; + if (N <= 0) { + return false; + } + if (static_cast(ref_traj.size()) < N) { + return false; + } + + Eigen::MatrixXd H; + Eigen::VectorXd g; + Eigen::VectorXd lb; + Eigen::VectorXd ub; + Eigen::MatrixXd A_con; + Eigen::VectorXd lbA; + Eigen::VectorXd ubA; + + if (!buildCondensedQP(curr, ref_traj, H, g, lb, ub, A_con, lbA, ubA)) { + return false; + } + + const int nV = static_cast(g.size()); + const int nC = static_cast(lbA.size()); + + std::vector H_qp(static_cast(nV) * static_cast(nV), 0.0); + for (int i = 0; i < nV; ++i) { + for (int j = 0; j < nV; ++j) { + H_qp[static_cast(i) * static_cast(nV) + static_cast(j)] = + static_cast(H(i, j)); + } + } + + std::vector g_qp(static_cast(nV), 0.0); + std::vector lb_qp(static_cast(nV), 0.0); + std::vector ub_qp(static_cast(nV), 0.0); + for (int i = 0; i < nV; ++i) { + g_qp[static_cast(i)] = static_cast(g(i)); + lb_qp[static_cast(i)] = static_cast(lb(i)); + ub_qp[static_cast(i)] = static_cast(ub(i)); + } + + std::vector A_qp; + std::vector lbA_qp; + std::vector ubA_qp; + + const qpOASES::real_t * A_ptr = nullptr; + const qpOASES::real_t * lbA_ptr = nullptr; + const qpOASES::real_t * ubA_ptr = nullptr; + + if (nC > 0) { + A_qp.assign(static_cast(nC) * static_cast(nV), 0.0); + for (int i = 0; i < nC; ++i) { + for (int j = 0; j < nV; ++j) { + A_qp[static_cast(i) * static_cast(nV) + static_cast(j)] = + static_cast(A_con(i, j)); + } + } + + lbA_qp.assign(static_cast(nC), 0.0); + ubA_qp.assign(static_cast(nC), 0.0); + for (int i = 0; i < nC; ++i) { + lbA_qp[static_cast(i)] = static_cast(lbA(i)); + ubA_qp[static_cast(i)] = static_cast(ubA(i)); + } + + A_ptr = A_qp.data(); + lbA_ptr = lbA_qp.data(); + ubA_ptr = ubA_qp.data(); + } + + qpOASES::QProblem qp(nV, nC); + qpOASES::Options options; + options.setToMPC(); + options.printLevel = qpOASES::PL_NONE; + qp.setOptions(options); + + qpOASES::int_t nWSR = static_cast(config_.max_working_set_recalculations); + const qpOASES::returnValue ret = + qp.init(H_qp.data(), g_qp.data(), A_ptr, lb_qp.data(), ub_qp.data(), lbA_ptr, ubA_ptr, nWSR); + + if (ret != qpOASES::SUCCESSFUL_RETURN) { + if (ret == qpOASES::RET_MAX_NWSR_REACHED) { + std::cout << color_text::RED << "[MpcSolver] qpOASES Max NWSR Reached!" << color_text::RESET + << std::endl; + } else if (ret == qpOASES::RET_INIT_FAILED_INFEASIBILITY) { + std::cout << color_text::RED << "[MpcSolver] qpOASES Infeasible!" << color_text::RESET << std::endl; + } else { + std::cout << color_text::RED << "[MpcSolver] qpOASES Error Code: " << static_cast(ret) + << color_text::RESET << std::endl; + } + return false; + } + + std::vector xOpt(static_cast(nV), 0.0); + qp.getPrimalSolution(xOpt.data()); + + // 如果需è¦�输出预测轨迹 + if (out_pred) { + out_pred->clear(); + out_pred->reserve(N + 1); + out_pred->push_back(curr); + + State s = curr; + Eigen::Matrix3d A; // Identity inside buildStepModel + Eigen::Matrix B; + + for (int i = 0; i < N; ++i) { + const double ux = static_cast(xOpt[static_cast(3 * i + 0)]); + const double uy = static_cast(xOpt[static_cast(3 * i + 1)]); + const double uw = static_cast(xOpt[static_cast(3 * i + 2)]); + + // 使用 QP 构建时的线性化点 (reference yaw) 进行推演 + buildStepModel(ref_traj[i].yaw, A, B); + + double dx = B(0, 0) * ux + B(0, 1) * uy + B(0, 2) * uw; + double dy = B(1, 0) * ux + B(1, 1) * uy + B(1, 2) * uw; + double dyaw = B(2, 0) * ux + B(2, 1) * uy + B(2, 2) * uw; + + s.x += dx; + s.y += dy; + s.yaw += dyaw; + out_pred->push_back(s); + } + } + + // å�–第一个控制é‡� u0 (global) + const Eigen::Vector3d u0_global( + static_cast(xOpt[0]), static_cast(xOpt[1]), static_cast(xOpt[2])); + + // 记录上一帧全局速度,用于平滑加速度 + last_u_global_ = u0_global; + has_last_u_ = true; + + // 直接输出全局速度 + out_u.vx = u0_global.x(); + out_u.vy = u0_global.y(); + out_u.omega = u0_global.z(); + + return true; +} + +} // namespace minco_controller diff --git a/minco_ws/src/navigation/minco_controller/src/performance/mpc_performance_monitor.cpp b/minco_ws/src/navigation/minco_controller/src/performance/mpc_performance_monitor.cpp new file mode 100644 index 0000000..dbd3fa2 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/src/performance/mpc_performance_monitor.cpp @@ -0,0 +1,203 @@ +#include "minco_controller/performance/mpc_performance_monitor.hpp" + +#include +#include +#include +#include +#include + +namespace minco_controller { + +MpcPerformanceMonitor::~MpcPerformanceMonitor() +{ + close(); +} + +void MpcPerformanceMonitor::configure(const MpcPerformanceConfig & config, rclcpp::Logger logger) +{ + close(); + config_ = config; + logger_ = logger; + detailed_csv_rows_ = 0; + resetOdomWindow(std::chrono::steady_clock::now()); + + if (!enabled() || !detailedCsvEnabled()) { + return; + } + + detailed_csv_.open(config_.detailed_csv_path, std::ios::out | std::ios::trunc); + if (!detailed_csv_.is_open()) { + RCLCPP_ERROR(logger_, "[MincoMpc] Failed to open MPC perf CSV: %s", config_.detailed_csv_path.c_str()); + config_.detailed_csv_enable = false; + return; + } + + writeDetailedHeader(); +} + +void MpcPerformanceMonitor::close() +{ + if (detailed_csv_.is_open()) { + detailed_csv_.flush(); + detailed_csv_.close(); + } +} + +bool MpcPerformanceMonitor::enabled() const +{ + return config_.enable; +} + +bool MpcPerformanceMonitor::detailedCsvEnabled() const +{ + return config_.enable && config_.detailed_csv_enable; +} + +bool MpcPerformanceMonitor::printEnabled() const +{ + return config_.enable && config_.print_enable; +} + +void MpcPerformanceMonitor::recordMpcSample(const MpcPerfSample & sample) +{ + if (!detailedCsvEnabled() || !detailed_csv_.is_open()) { + return; + } + + writeDetailedRow(sample); + flushIfNeeded(); +} + +void MpcPerformanceMonitor::recordOdomCallback( + const rclcpp::Time & now, + const builtin_interfaces::msg::Time & stamp) +{ + if (!enabled() || !config_.odom_sub_debug_enable) { + return; + } + + if (odom_stats_.window_start == std::chrono::steady_clock::time_point{}) { + resetOdomWindow(std::chrono::steady_clock::now()); + } + + ++odom_stats_.callback_count; + + const rclcpp::Time stamp_time(stamp); + const double delay_ms = (now - stamp_time).seconds() * 1000.0; + if (std::isfinite(delay_ms)) { + odom_stats_.delay_sum_ms += delay_ms; + odom_stats_.delay_min_ms = std::min(odom_stats_.delay_min_ms, delay_ms); + odom_stats_.delay_max_ms = std::max(odom_stats_.delay_max_ms, delay_ms); + ++odom_stats_.delay_count; + } + + maybePrintOdomStats(); +} + +long long MpcPerformanceMonitor::steadyNowNs() +{ + return std::chrono::duration_cast( + std::chrono::steady_clock::now().time_since_epoch()).count(); +} + +void MpcPerformanceMonitor::writeDetailedHeader() +{ + if (!detailed_csv_.is_open()) { + return; + } + + detailed_csv_ + << "run_id,scenario,variant,stamp_ros,stamp_steady_ns,success,solve_time_ms,cycle_time_ms," + "controller_hz,cmd_vx,cmd_vy,cmd_wz,ref_vx,ref_vy,ref_wz\n"; +} + +void MpcPerformanceMonitor::writeDetailedRow(const MpcPerfSample & sample) +{ + detailed_csv_ << sanitize(config_.run_id) << ',' << sanitize(config_.scenario) << ',' + << sanitize(config_.variant) << ',' << num(sample.stamp_ros) << ',' + << sample.stamp_steady_ns << ',' << boolean(sample.success) << ',' + << num(sample.solve_time_ms) << ',' << num(sample.cycle_time_ms) << ',' + << num(sample.controller_hz) << ',' << num(sample.cmd_vx) << ',' + << num(sample.cmd_vy) << ',' << num(sample.cmd_wz) << ',' << num(sample.ref_vx) << ',' + << num(sample.ref_vy) << ',' << num(sample.ref_wz) << '\n'; +} + +void MpcPerformanceMonitor::maybePrintOdomStats() +{ + if (!printEnabled()) { + return; + } + + const auto now = std::chrono::steady_clock::now(); + const double window_sec = std::chrono::duration(now - odom_stats_.window_start).count(); + const double print_period_sec = std::max(config_.print_period_sec, 1.0e-6); + if (window_sec < print_period_sec) { + return; + } + + const double callback_hz = window_sec > 1.0e-9 + ? static_cast(odom_stats_.callback_count) / window_sec + : 0.0; + const double avg_delay_ms = odom_stats_.delay_count > 0 + ? odom_stats_.delay_sum_ms / static_cast(odom_stats_.delay_count) + : std::numeric_limits::quiet_NaN(); + const double min_delay_ms = odom_stats_.delay_count > 0 + ? odom_stats_.delay_min_ms + : std::numeric_limits::quiet_NaN(); + const double max_delay_ms = odom_stats_.delay_count > 0 + ? odom_stats_.delay_max_ms + : std::numeric_limits::quiet_NaN(); + + RCLCPP_INFO( + logger_, + "[MincoMpc][OdomSub] callback_hz=%.3f delay_ms avg=%.3f min=%.3f max=%.3f count=%lu", + callback_hz, + avg_delay_ms, + min_delay_ms, + max_delay_ms, + static_cast(odom_stats_.callback_count)); + + resetOdomWindow(now); +} + +void MpcPerformanceMonitor::resetOdomWindow(std::chrono::steady_clock::time_point now) +{ + odom_stats_.window_start = now; + odom_stats_.callback_count = 0; + odom_stats_.delay_sum_ms = 0.0; + odom_stats_.delay_min_ms = std::numeric_limits::infinity(); + odom_stats_.delay_max_ms = 0.0; + odom_stats_.delay_count = 0; +} + +void MpcPerformanceMonitor::flushIfNeeded() +{ + const int flush_every_n = std::max(config_.csv_flush_every_n, 1); + if (++detailed_csv_rows_ % flush_every_n == 0) { + detailed_csv_.flush(); + } +} + +std::string MpcPerformanceMonitor::num(double value) +{ + if (!std::isfinite(value)) { + return "NaN"; + } + + std::ostringstream ss; + ss << std::fixed << std::setprecision(6) << value; + return ss.str(); +} + +std::string MpcPerformanceMonitor::boolean(bool value) +{ + return value ? "1" : "0"; +} + +std::string MpcPerformanceMonitor::sanitize(std::string value) +{ + std::replace(value.begin(), value.end(), ',', '_'); + return value; +} + +} // namespace minco_controller diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/.coin-or/projDesc.xml b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/.coin-or/projDesc.xml new file mode 100755 index 0000000..9d3f420 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/.coin-or/projDesc.xml @@ -0,0 +1,60 @@ + + + + + qpOASES + + qpOASES is an open-source C++ implementation of the recently + proposed online active set strategy for solving quadratic + programming (QP) problems. It has several theoretical features + that make it particularly suited for model predictive control + (MPC) applications. Further numerical modifications have made + qpOASES a reliable QP solver, even when tackling semi-definite, + ill-posed or degenerated QP problems. Moreover, several + interfaces to third-party software make qpOASES easy-to-use + even for users without knowledge of C/C++. + + An open-source C++ implementation of the recently proposed online active set strategy. + Joachim Ferreau + https://github.com/coin-or/qpOASES + ​GNU Lesser General Public License (LGPL), v2.1 + http://www.gnu.org/licenses/lgpl-2.1.html + + + + BLAS + http://www.netlib.org/blas + Optional + + + LAPACK + http://www.netlib.org/lapack + Optional + + + C++ + + Active + 3 + + + + Linux + g++ + + + Microsoft Windows + CYGWIN/g++ + + + + Optimization deterministic nonlinear + + + + http://www.qpOASES.org/go/manual + https://github.com/coin-or/qpOASES + + http://list.coin-or.org/mailman/listinfo/qpOASES + + diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/AUTHORS b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/AUTHORS new file mode 100755 index 0000000..e9ad01c --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/AUTHORS @@ -0,0 +1,94 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +MAIN AUTHORS +============ + +qpOASES's core functionality and software design have been developed by the +following main developers (in alphabetical order): + + Hans Joachim Ferreau + Christian Kirches + Andreas Potschka + + + +FURTHER AUTHORS +=============== + +Moreover, the following developers have contributed code to qpOASES's +third-party interfaces or provided additional functionality +(in alphabetical order): + + Alexander Buchner + Holger Diedam + Dennis Janka + Manuel Kudruss + Andreas Waechter + Sebastian F. Walter + + + +CONTRIBUTORS +============ + +Finally, the following people have not contributed to the source code, +but have helped making qpOASES even more useful by testing, reporting +bugs or proposing algorithmic improvements (in alphabetical order): + + Eckhard Arnold + Joris Gillis + Boris Houska + D. Kwame Minde Kufoalor + Aude Perrin + Silvio Traversaro + Milan Vukov + Thomas Wiese + Leonard Wirsching + + + +SCIENTIFIC MENTORS +================== + +We also would like to thank two persons who had a major share in making +qpOASES a success. Not by writing even a single line of code, but by +establishing the idea of using a homotopy-based approach for high-speed +QP solutions and by excellent scientific guidance during the development +process: + + Hans Georg Bock + Moritz Diehl + + + +All users are invited to further improve qpOASES by providing comments, +code enhancements, bug reports, additional documentation or whatever you +feel is missing. + + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/AUTHORS.txt b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/AUTHORS.txt new file mode 100755 index 0000000..012529d --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/AUTHORS.txt @@ -0,0 +1,94 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +MAIN AUTHORS +============ + +qpOASES's core functionality and software design have been developed by the +following main developers (in alphabetical order): + + Hans Joachim Ferreau + Christian Kirches + Andreas Potschka + + + +FURTHER AUTHORS +=============== + +Moreover, the following developers have contributed code to qpOASES's +third-party interfaces or provided additional functionality +(in alphabetical order): + + Alexander Buchner + Holger Diedam + Dennis Janka + Manuel Kudruss + Andreas Waechter + Sebastian F. Walter + + + +CONTRIBUTORS +============ + +Finally, the following people have not contributed to the source code, +but have helped making qpOASES even more useful by testing, reporting +bugs or proposing algorithmic improvements (in alphabetical order): + + Eckhard Arnold + Joris Gillis + Boris Houska + D. Kwame Minde Kufoalor + Aude Perrin + Silvio Traversaro + Milan Vukov + Thomas Wiese + Leonard Wirsching + + + +SCIENTIFIC MENTORS +================== + +We also would like to thank two persons who had a major share in making +qpOASES a success. Not by writing even a single line of code, but by +establishing the idea of using a homotopy-based approach for high-speed +QP solutions and by excellent scientific guidance during the development +process: + + Hans Georg Bock + Moritz Diehl + + + +All users are invited to further improve qpOASES by providing comments, +code enhancements, bug reports, additional documentation or whatever you +feel is missing. + + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/CMakeLists.txt b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/CMakeLists.txt new file mode 100755 index 0000000..4ec78e3 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/CMakeLists.txt @@ -0,0 +1,200 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: CMakeLists.txt +## Author: Hans Joachim Ferreau (thanks to Milan Vukov) +## Version: 3.2 +## Date: 2007-2017 +## + +cmake_minimum_required(VERSION 3.18) + +PROJECT(qpOASES CXX) +SET(PACKAGE_NAME "qpOASES") +SET(PACKAGE_VERSION "3.2.2") +SET(PACKAGE_SO_VERSION "3.2") +SET(PACKAGE_DESCRIPTION "An implementation of the online active set strategy") +SET(PACKAGE_AUTHOR "Hans Joachim Ferreau, Andreas Potschka, Christian Kirches et al.") +SET(PACKAGE_MAINTAINER "Hans Joachim Ferreau, Andreas Potschka, Christian Kirches et al.") +SET(PACKAGE_URL "https://projects.coin-or.org/qpOASES") + +SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) +SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/libs) + +IF(NOT CMAKE_INSTALL_LIBDIR) + SET(CMAKE_INSTALL_LIBDIR lib) +ENDIF(NOT CMAKE_INSTALL_LIBDIR) + +IF(NOT CMAKE_INSTALL_BINDIR) + SET(CMAKE_INSTALL_BINDIR ${CMAKE_INSTALL_LIBDIR}) +ENDIF(NOT CMAKE_INSTALL_BINDIR) + +IF(NOT CMAKE_INSTALL_INCLUDEDIR) + SET(CMAKE_INSTALL_INCLUDEDIR include) +ENDIF(NOT CMAKE_INSTALL_INCLUDEDIR) + + +IF( NOT CMAKE_VERBOSE_MAKEFILE ) + SET( CMAKE_VERBOSE_MAKEFILE OFF ) +ENDIF( NOT CMAKE_VERBOSE_MAKEFILE ) + +IF( NOT CMAKE_BUILD_TYPE ) + SET(CMAKE_BUILD_TYPE Release CACHE STRING + "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." + FORCE + ) +ENDIF( NOT CMAKE_BUILD_TYPE ) + +option(BUILD_SHARED_LIBS "If ON, build shared library instead of static" OFF) +option(QPOASES_BUILD_EXAMPLES "Build examples." ON) +option(QPOASES_AVOID_LA_NAMING_CONFLICTS "If ON, avoid to re-defined symbols that conflict with Blas/Lapack provided functions." OFF) + +IF(BUILD_SHARED_LIBS AND WIN32) + MESSAGE(FATAL_ERROR "Compiling qpOASES as a shared library in Windows is not supported.") +ENDIF() + +############################################################ +#################### compiler flags ######################## +############################################################ +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__NO_COPYRIGHT__") +IF(QPOASES_AVOID_LA_NAMING_CONFLICTS) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__AVOID_LA_NAMING_CONFLICTS__") +ENDIF() + +IF ( UNIX ) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wfloat-equal -Wshadow -DLINUX") + SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -O3 -finline-functions") +ELSEIF( WINDOWS ) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nologo -EHsc -DWIN32") +ENDIF() + +SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D__DEBUG__") + +############################################################ +######################## rpath ############################# +############################################################ +# use, i.e. don't skip the full RPATH for the build tree +set(CMAKE_SKIP_BUILD_RPATH FALSE) + +# when building, don't use the install RPATH already +# (but later on when installing) +set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) + +set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib/casadi") + +# add the automatically determined parts of the RPATH +# which point to directories outside the build tree to the install RPATH +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + +# the RPATH to be used when installing, but only if it's not a system directory +list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) +if("${isSystemDir}" STREQUAL "-1") + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib/casadi") +endif("${isSystemDir}" STREQUAL "-1") + + + +############################################################ +#################### build and install ##################### +############################################################ +INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include) +# compile qpOASES libraries +FILE(GLOB SRC src/*.cpp) + +# library +ADD_LIBRARY(qpOASES ${SRC}) +INSTALL(TARGETS qpOASES + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) +SET_TARGET_PROPERTIES( + qpOASES + PROPERTIES + SOVERSION ${PACKAGE_SO_VERSION} + ) + +# headers +INSTALL(FILES include/qpOASES.hpp + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +INSTALL(DIRECTORY include/qpOASES + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING PATTERN "*.hpp" + PATTERN "*.ipp" + PATTERN ".svn" EXCLUDE) + +############################################################ +######################### Package Config ################### +############################################################ + +include(CMakePackageConfigHelpers) +set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) +set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}) +configure_package_config_file(qpOASESConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/qpOASESConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/qpOASES + PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR + NO_CHECK_REQUIRED_COMPONENTS_MACRO) + +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/qpOASESConfigVersion.cmake + VERSION ${PACKAGE_VERSION} + COMPATIBILITY SameMajorVersion) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qpOASESConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/qpOASESConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/qpOASES + COMPONENT qpOASES) + +############################################################ +######################### examples ######################### +############################################################ + +if (QPOASES_BUILD_EXAMPLES) + # compile qpOASES examples + SET(EXAMPLE_NAMES + example1 + example1a + example1b + example2 + example3 + example3b + example4 + example5 + exampleLP + qrecipe + qrecipeSchur + ) + + FOREACH(ELEMENT ${EXAMPLE_NAMES}) + ADD_EXECUTABLE(${ELEMENT} examples/${ELEMENT}.cpp) + TARGET_LINK_LIBRARIES(${ELEMENT} qpOASES) + ENDFOREACH(ELEMENT ${EXAMPLE_NAMES}) +endif(QPOASES_BUILD_EXAMPLES) + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/INSTALL b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/INSTALL new file mode 100755 index 0000000..e4c3d73 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/INSTALL @@ -0,0 +1,79 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +INSTALLATION UNDER LINUX +======================== + +0. Obtain qpOASES from COIN-OR: + +Download a zipped archive containg the latest stable release and unpack it +into . Alternatively, you check out the latest stable branch, +e.g. by running + +svn co https://projects.coin-or.org/svn/qpOASES/stable/3.2 + +from your shell. + + +1. Compilation of the qpOASES library libqpOASES.a (or .so) and test examples: + +cd +make + +The library libqpOASES.a (or .so) provides the complete functionality of the +qpOASES software package. It can be used by, e.g., linking it against a main +function from the examples folder. The make also compiles a couple of test +examples; executables are stored within the directory /bin. + + +2. Running a simple test example: + +Among others, an executable called example1 should have been created; run +it in order to test your installation: + +cd /bin +./example1 + +If it terminates after successfully solving two QP problems, qpOASES has been +successfully installed! + + +3. Optional, create source code documentation (using doxygen): + +cd /doc +doxygen doxygen.config + +Afterwards, you can open the file /doc/html/index.html with +your favorite browser in order to view qpOASES's source code documentation. + + +NOTE: More detailed installation instructions, including information on how + to run unit tests can be found in the qpOASES User's Manual located + at /doc/manual.pdf! + + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/INSTALL.txt b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/INSTALL.txt new file mode 100755 index 0000000..1515425 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/INSTALL.txt @@ -0,0 +1,79 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +INSTALLATION UNDER LINUX +======================== + +0. Obtain qpOASES from COIN-OR: + +Download a zipped archive containg the latest stable release and unpack it +into . Alternatively, you check out the latest stable branch, +e.g. by running + +svn co https://projects.coin-or.org/svn/qpOASES/stable/3.2 + +from your shell. + + +1. Compilation of the qpOASES library libqpOASES.a (or .so) and test examples: + +cd +make + +The library libqpOASES.a (or .so) provides the complete functionality of the +qpOASES software package. It can be used by, e.g., linking it against a main +function from the examples folder. The make also compiles a couple of test +examples; executables are stored within the directory /bin. + + +2. Running a simple test example: + +Among others, an executable called example1 should have been created; run +it in order to test your installation: + +cd /bin +./example1 + +If it terminates after successfully solving two QP problems, qpOASES has been +successfully installed! + + +3. Optional, create source code documentation (using doxygen): + +cd /doc +doxygen doxygen.config + +Afterwards, you can open the file /doc/html/index.html with +your favorite browser in order to view qpOASES's source code documentation. + + +NOTE: More detailed installation instructions, including information on how + to run unit tests can be found in the qpOASES User's Manual located + at /doc/manual.pdf! + + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/LICENSE b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/LICENSE new file mode 100755 index 0000000..9ef3d70 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/LICENSE @@ -0,0 +1,503 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/LICENSE.txt b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/LICENSE.txt new file mode 100755 index 0000000..2d59e84 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/LICENSE.txt @@ -0,0 +1,503 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/Makefile b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/Makefile new file mode 100755 index 0000000..62097aa --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/Makefile @@ -0,0 +1,118 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: Makefile +## Author: Hans Joachim Ferreau +## Version: 3.2 +## Date: 2007-2017 +## + +include make.mk + +## +## targets +## + + +ifeq ($(DEF_SOLVER), SOLVER_MUMPS) +EXTERNAL = mumps +else +EXTERNAL = +endif + +all: $(EXTERNAL) bin src examples +#src_aw testing + +ifeq ($(DEF_SOLVER), SOLVER_MUMPS) +mumps: + @echo $(QPOASESROOT) + @cd external/ThirdParty-Mumps; \ + if [ -d "MUMPS" ]; then \ + echo "Found MUMPS source code."; \ + else get.Mumps; ./configure --prefix=$(PWD)/external/mumps_installation; fi; \ + make && make install +endif + +src: $(EXTERNAL) + @cd $@; ${MAKE} -s + +bin: + mkdir bin + +#src_aw: +# @cd $@; ${MAKE} -s + +examples: src + @cd $@; ${MAKE} -s + +doc: + @cd $@; ${MAKE} -s + +testing: src + @cd testing/cpp; ${MAKE} -s + +test: testing + @cd testing/cpp; ${MAKE} -s runTests + +debugging: + @cd $@; ${MAKE} -s + +clean: +ifeq ($(DEF_SOLVER), SOLVER_MUMPS) + @echo Cleaning up \(mumps\) + @cd external/ThirdParty-Mumps && ${MAKE} -s clean + @cd external && ${RM} -rf mumps_installation +endif + @cd src && ${MAKE} -s clean + @cd examples && ${MAKE} -s clean + @cd bin && ${RM} -f *.* *{EXE} + @cd testing/cpp && ${MAKE} -s clean + +# && cd src_aw && ${MAKE} -s clean && cd .. \ +# && cd debugging && ${MAKE} -s clean && cd .. \ + + +clobber: clean + +scilab: + @echo Compiling Scilab interface... + @cd ./interfaces/scilab/; ${MAKE} -s + +python: all + cd ./interfaces/python/ && python setup.py build_ext --inplace + +pythoninstall: all + cd ./interfaces/python/ && python setup.py install + +c_wrapper: + @echo Compiling C interface... + @cd ./interfaces/c/; ${MAKE} -s + +.PHONY : all src examples doc testing debugging clean clobber scilab python phythoninstall c_wrapper + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/README b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/README new file mode 100755 index 0000000..cafbbc2 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/README @@ -0,0 +1,84 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +INTRODUCTION +============ + +qpOASES is an open-source C++ implementation of the recently proposed +online active set strategy, which was inspired by important observations +from the field of parametric quadratic programming (QP). It has several +theoretical features that make it particularly suited for model predictive +control (MPC) applications. Further numerical modifications have made +qpOASES a reliable QP solver, even when tackling semi-definite, ill-posed or +degenerated QP problems. Moreover, several interfaces to third-party software +like ​Matlab or ​Simulink are provided that make qpOASES easy-to-use even for +users without knowledge of C/C++. + + + +GETTING STARTED +=============== + +1. For installation, usage and additional information on this software package + see the qpOASES User's Manual located at doc/manual.pdf or check its + source code documentation! + + +2. The file LICENSE.txt contains a copy of the GNU Lesser General Public + License (v2.1). Please read it carefully before using qpOASES! + + +3. The whole software package can be obtained from + + http://www.qpOASES.org/ or + https://github.com/coin-or/qpOASES/ + + On this webpage you will also find further support such as a list of + questions posed by other users. + + + +CONTACT THE AUTHORS +=================== + +If you have got questions, remarks or comments on qpOASES, it is strongly +encouraged to report them by creating a new ticket at the qpOASES webpage. +In case you do not want to disclose your feedback to the public, you may +send an e-mail to + + support@qpOASES.org + +Finally, you may contact one of the main authors directly: + + Hans Joachim Ferreau, joachim.ferreau@ch.abb.com + Andreas Potschka, potschka@iwr.uni-heidelberg.de + Christian Kirches, christian.kirches@iwr.uni-heidelberg.de + +Also bug reports, source code enhancements or success stories are most welcome! + + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/doc/DoxygenLayout.xml b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/doc/DoxygenLayout.xml new file mode 100755 index 0000000..927d94d --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/doc/DoxygenLayout.xml @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/doc/Makefile b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/doc/Makefile new file mode 100755 index 0000000..462a5aa --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/doc/Makefile @@ -0,0 +1,66 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: Makefile +## Author: Hans Joachim Ferreau +## Version: 3.2 +## Date: 2007-2017 +## + + + +## +## settings +## + +MAKEPDF = pdflatex +LATEX = latex + + +## +## targets +## + +all: doc + + +.PHONY: doc +doc: + @ echo "Creating doxygen documentation " + @ doxygen doxygen.config + + +.PHONY: clean +clean: + @ ${RM} -rf ./html + + +.PHONY: clobber +clobber: clean + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/doc/doxygen.config b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/doc/doxygen.config new file mode 100755 index 0000000..34a0347 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/doc/doxygen.config @@ -0,0 +1,310 @@ +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +DOXYFILE_ENCODING = UTF-8 +PROJECT_NAME = qpOASES +PROJECT_NUMBER = 3.2.2 +PROJECT_BRIEF = "An Implementation of the Online Active Set Strategy" +PROJECT_LOGO = +OUTPUT_DIRECTORY = +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = NO +ABBREVIATE_BRIEF = +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = YES +FULL_PATH_NAMES = YES +STRIP_FROM_PATH = .. +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +QT_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 4 +ALIASES = +TCL_SUBST = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +OPTIMIZE_FOR_FORTRAN = NO +OPTIMIZE_OUTPUT_VHDL = NO +EXTENSION_MAPPING = +MARKDOWN_SUPPORT = YES +AUTOLINK_SUPPORT = YES +BUILTIN_STL_SUPPORT = NO +CPP_CLI_SUPPORT = NO +SIP_SUPPORT = NO +IDL_PROPERTY_SUPPORT = YES +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +INLINE_GROUPED_CLASSES = NO +INLINE_SIMPLE_STRUCTS = NO +TYPEDEF_HIDES_STRUCT = NO +SYMBOL_CACHE_SIZE = 0 +LOOKUP_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = NO +EXTRACT_PRIVATE = YES +EXTRACT_PACKAGE = NO +EXTRACT_STATIC = NO +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +EXTRACT_ANON_NSPACES = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +FORCE_LOCAL_INCLUDES = NO +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_MEMBERS_CTORS_1ST = NO +SORT_GROUP_NAMES = NO +SORT_BY_SCOPE_NAME = NO +STRICT_PROTO_MATCHING = NO +GENERATE_TODOLIST = NO +GENERATE_TESTLIST = NO +GENERATE_BUGLIST = NO +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_FILES = YES +SHOW_NAMESPACES = YES +FILE_VERSION_FILTER = +LAYOUT_FILE = DoxygenLayout.xml +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = ./mainpage.dox \ +../src \ +../include/qpOASES \ +../include/qpOASES/extras \ +../examples +INPUT_ENCODING = UTF-8 +FILE_PATTERNS = *.cpp \ +*.ipp \ +*.hpp \ +*.c +RECURSIVE = YES +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXCLUDE_SYMBOLS = +EXAMPLE_PATH = ../examples +EXAMPLE_PATTERNS = +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +FILTER_SOURCE_PATTERNS = + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = NO +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = YES +REFERENCES_RELATION = YES +REFERENCES_LINK_SOURCE = YES +USE_HTAGS = NO +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_EXTRA_STYLESHEET = +HTML_EXTRA_FILES = +HTML_COLORSTYLE_HUE = 220 +HTML_COLORSTYLE_SAT = 100 +HTML_COLORSTYLE_GAMMA = 80 +HTML_TIMESTAMP = YES +HTML_DYNAMIC_SECTIONS = NO +HTML_INDEX_NUM_ENTRIES = 100 +GENERATE_DOCSET = NO +DOCSET_FEEDNAME = "Doxygen generated docs" +DOCSET_BUNDLE_ID = org.doxygen.Project +DOCSET_PUBLISHER_ID = org.doxygen.Publisher +DOCSET_PUBLISHER_NAME = Publisher +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +CHM_INDEX_ENCODING = +BINARY_TOC = NO +TOC_EXPAND = NO +GENERATE_QHP = NO +QCH_FILE = +QHP_NAMESPACE = org.doxygen.Project +QHP_VIRTUAL_FOLDER = doc +QHP_CUST_FILTER_NAME = +QHP_CUST_FILTER_ATTRS = +QHP_SECT_FILTER_ATTRS = +QHG_LOCATION = +GENERATE_ECLIPSEHELP = NO +ECLIPSE_DOC_ID = org.doxygen.Project +DISABLE_INDEX = NO +GENERATE_TREEVIEW = NO +ENUM_VALUES_PER_LINE = 4 +TREEVIEW_WIDTH = 250 +EXT_LINKS_IN_WINDOW = NO +FORMULA_FONTSIZE = 10 +FORMULA_TRANSPARENT = YES +USE_MATHJAX = NO +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest +MATHJAX_EXTENSIONS = +SEARCHENGINE = NO +SERVER_BASED_SEARCH = NO + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +LATEX_FOOTER = +PDF_HYPERLINKS = YES +USE_PDFLATEX = NO +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +LATEX_SOURCE_CODE = NO +LATEX_BIB_STYLE = plain + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = RTF +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = MAN +MAN_EXTENSION = .3 +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = NO +XML_OUTPUT = XML +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +MSCGEN_PATH = +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +DOT_NUM_THREADS = 0 +DOT_FONTNAME = Helvetica +DOT_FONTSIZE = 10 +DOT_FONTPATH = +CLASS_GRAPH = YES +COLLABORATION_GRAPH = NO +GROUP_GRAPHS = YES +UML_LOOK = NO +UML_LIMIT_NUM_FIELDS = 10 +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +CALLER_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +INTERACTIVE_SVG = NO +DOT_PATH = +DOTFILE_DIRS = +MSCFILE_DIRS = +DOT_GRAPH_MAX_NODES = 50 +MAX_DOT_GRAPH_DEPTH = 0 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/doc/mainpage.dox b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/doc/mainpage.dox new file mode 100755 index 0000000..50d39dd --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/doc/mainpage.dox @@ -0,0 +1,135 @@ +/** + * \mainpage Main Page + * + *

 

+ * + * \section sec_copyright Copyright + * + * qpOASES -- An Implementation of the Online Active Set Strategy. \n + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + *

 

+ * + * + * \section sec_developers Authors and Contributors + * + * qpOASES's core functionality and software design have been developed by + * the following main developers (in alphabetical order): + *
    + *
  • Hans Joachim Ferreau + *
  • Christian Kirches + *
  • Andreas Potschka + *
+ * + * Moreover, the following developers have contributed code to qpOASES's + * third-party interfaces or provided additional functionality + * (in alphabetical order): + *
    + *
  • Alexander Buchner + *
  • Holger Diedam + *
  • Dennis Janka + *
  • Manuel Kudruss + *
  • Andreas Waechter + *
  • Sebastian F. Walter + *
+ * + * Finally, the following people have not contributed to the source code, + * but have helped making qpOASES even more useful by testing, reporting + * bugs or proposing algorithmic improvements (in alphabetical order): + *
    + *
  • Eckhard Arnold + *
  • Joris Gillis + *
  • Boris Houska + *
  • D. Kwame Minde Kufoalor + *
  • Aude Perrin + *
  • Milan Vukov + *
  • Thomas Wiese + *
  • Leonard Wirsching + *
+ * + * We also would like to thank two persons who had a major share in making + * qpOASES a success. Not by writing even a single line of code, but by + * establishing the idea of using a homotopy-based approach for high-speed + * QP solutions and by excellent scientific guidance during the development + * process: + *
    + *
  • Hans Georg Bock + *
  • Moritz Diehl + *
+ * + * All users are invited to further improve qpOASES by providing comments, code enhancements, + * bug reports, additional documentation or whatever you feel is missing. The preferred way + * of doing so is to create a new ticket + * at the qpOASES webpage. In case you do not want to disclose your feedback to the public, + * you may send an e-mail to support@qpOASES.org + * or contact one of the main developers directly. + *

 

+ * + * + * \section sec_citing Citing qpOASES + * + * If you use qpOASES within your scientific work, we strongly encourage you to cite at least + * one of the following publications: + * + *
    + *
  • Reference to the software: + * \code + * @ARTICLE{Ferreau2014, + * author = {H.J. Ferreau and C. Kirches and A. Potschka and H.G. Bock and M. Diehl}, + * title = {{qpOASES}: A parametric active-set algorithm for quadratic programming}, + * journal = {Mathematical Programming Computation}, + * year = {2014}, + * volume = {6}, + * number = {4}, + * pages = {327--363}, + * keywords = {qpOASES, parametric quadratic programming, active set method, model predictive control} + * } + * \endcode + * + *
  • Reference to the online active set strategy: + * \code + * @ARTICLE{Ferreau2008, + * author = {H.J. Ferreau and H.G. Bock and M. Diehl}, + * title = {An online active set strategy to overcome the limitations of explicit MPC}, + * journal = {International Journal of Robust and Nonlinear Control}, + * year = {2008}, + * volume = {18}, + * number = {8}, + * pages = {816--830}, + * keywords = {model predictive control, parametric quadratic programming, online active set strategy} + * } + * \endcode + * + *
  • Reference to the webpage: + * \code + * @MISC{qpOASES2017, + * author = {H.J. Ferreau and A. Potschka and C. Kirches}, + * title = {{qpOASES} webpage}, + * howpublished = {http://www.qpOASES.org/}, + * year = {2007--2017}, + * keywords = {qpOASES, model predictive control, parametric quadratic programming, online active set strategy} + * } + * \endcode + *
+ *

 

+ * + * \section sec_moreinfo More Information + * + * More information can be found on http://www.qpOASES.org/ + * and in the qpOASES User's Manual. + *

 

+ */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/doc/manual.pdf b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/doc/manual.pdf new file mode 100755 index 0000000..2bb7587 Binary files /dev/null and b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/doc/manual.pdf differ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/Makefile b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/Makefile new file mode 100755 index 0000000..cfcbba8 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/Makefile @@ -0,0 +1,107 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: examples/Makefile +## Author: Hans Joachim Ferreau +## Version: 3.2 +## Date: 2007-2017 +## + +include ../make.mk + +## +## flags +## + +IFLAGS = -I. \ + -I${IDIR} + +QPOASES_EXES = \ + ${BINDIR}/example1${EXE} \ + ${BINDIR}/example1a${EXE} \ + ${BINDIR}/example1b${EXE} \ + ${BINDIR}/example2${EXE} \ + ${BINDIR}/example3${EXE} \ + ${BINDIR}/example3b${EXE} \ + ${BINDIR}/example4${EXE} \ + ${BINDIR}/example5${EXE} \ + ${BINDIR}/exampleLP${EXE} \ + ${BINDIR}/qrecipe${EXE} \ + ${BINDIR}/qrecipeSchur${EXE} + + +## +## targets +## + +all: ${QPOASES_EXES} + +${BINDIR}/%${EXE}: %.${OBJEXT} ${LINK_DEPENDS} + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${CPPFLAGS} $< ${QPOASES_LINK} ${LINK_LIBRARIES} + +${BINDIR}/example4${EXE}: example4.${OBJEXT} example4CP.cpp ${LINK_DEPENDS} + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${CPPFLAGS} $< ${QPOASES_LINK} ${LINK_LIBRARIES} + +${BINDIR}/qrecipe${EXE}: qrecipe.${OBJEXT} qrecipe_data.hpp ${LINK_DEPENDS} + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${CPPFLAGS} $< ${QPOASES_LINK} ${LINK_LIBRARIES} + +${BINDIR}/qrecipeSchur${EXE}: qrecipeSchur.${OBJEXT} qrecipe_data.hpp ${LINK_DEPENDS} + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${CPPFLAGS} $< ${QPOASES_LINK} ${LINK_LIBRARIES} + + +clean: + @${ECHO} "Cleaning up (examples)" + @${RM} -f *.${OBJEXT} ${QPOASES_EXES} + +clobber: clean + + +${LINK_DEPENDS}: + @cd ..; ${MAKE} -s src + +example4.${OBJEXT}: example4.cpp example4CP.cpp + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} -c ${IFLAGS} ${CPPFLAGS} $< + +qrecipe.${OBJEXT}: qrecipe.cpp qrecipe_data.hpp + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${IFLAGS} ${CPPFLAGS} -c $< + +qrecipeSchur.${OBJEXT}: qrecipeSchur.cpp qrecipe_data.hpp + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${IFLAGS} ${CPPFLAGS} -c $< + +%.${OBJEXT}: %.cpp + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} -c ${IFLAGS} ${CPPFLAGS} $< + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example1.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example1.cpp new file mode 100644 index 0000000..931520e --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example1.cpp @@ -0,0 +1,104 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file examples/example1.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + * + * Very simple example for testing qpOASES using the QProblem class. + */ + +#include + +/** Example for qpOASES main function using the QProblem class. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* Setup data of first QP. */ + real_t H[2 * 2] = {1.0, 0.0, 0.0, 0.5}; + real_t A[1 * 2] = {1.0, 1.0}; + real_t g[2] = {1.5, 1.0}; + real_t lb[2] = {0.5, -2.0}; + real_t ub[2] = {5.0, 2.0}; + real_t lbA[1] = {-1.0}; + real_t ubA[1] = {2.0}; + + /* Setup data of second QP. */ + real_t g_new[2] = {1.0, 1.5}; + real_t lb_new[2] = {0.0, -1.0}; + real_t ub_new[2] = {5.0, -0.5}; + real_t lbA_new[1] = {-2.0}; + real_t ubA_new[1] = {1.0}; + + /* Setting up QProblem object. */ + QProblem example(2, 1); + + Options options; + example.setOptions(options); + + /* Solve first QP. */ + int_t nWSR = 10; + example.init(H, g, A, lb, ub, lbA, ubA, nWSR); + + /* Get and print solution of first QP. */ + real_t xOpt[2]; + real_t yOpt[2 + 1]; + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + printf("\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", + xOpt[0], + xOpt[1], + yOpt[0], + yOpt[1], + yOpt[2], + example.getObjVal()); + + /* Solve second QP. */ + nWSR = 10; + example.hotstart(g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR); + + /* Get and print solution of second QP. */ + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + printf("\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", + xOpt[0], + xOpt[1], + yOpt[0], + yOpt[1], + yOpt[2], + example.getObjVal()); + + example.printOptions(); + /*example.printProperties();*/ + + /*getGlobalMessageHandler()->listAllMessages();*/ + + return 0; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example1a.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example1a.cpp new file mode 100644 index 0000000..f24afee --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example1a.cpp @@ -0,0 +1,79 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file examples/example1a.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + * + * Very simple example for testing qpOASES using the SQProblem class. + */ + +#include + +/** Example for qpOASES main function using the SQProblem class. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* Setup data of first QP. */ + real_t H[2 * 2] = {1.0, 0.0, 0.0, 0.5}; + real_t A[1 * 2] = {1.0, 1.0}; + real_t g[2] = {1.5, 1.0}; + real_t lb[2] = {0.5, -2.0}; + real_t ub[2] = {5.0, 2.0}; + real_t lbA[1] = {-1.0}; + real_t ubA[1] = {2.0}; + + /* Setup data of second QP. */ + real_t H_new[2 * 2] = {1.0, 0.5, 0.5, 0.5}; + real_t A_new[1 * 2] = {1.0, 5.0}; + real_t g_new[2] = {1.0, 1.5}; + real_t lb_new[2] = {0.0, -1.0}; + real_t ub_new[2] = {5.0, -0.5}; + real_t lbA_new[1] = {-2.0}; + real_t ubA_new[1] = {1.0}; + + /* Setting up SQProblem object. */ + SQProblem example(2, 1); + + /* Solve first QP. */ + int_t nWSR = 10; + example.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + + /* Solve second QP. */ + nWSR = 10; + example.hotstart(H_new, g_new, A_new, lb_new, ub_new, lbA_new, ubA_new, nWSR, 0); + + /* Get and print solution of second QP. */ + real_t xOpt[2]; + example.getPrimalSolution(xOpt); + printf("\nxOpt = [ %e, %e ]; objVal = %e\n\n", xOpt[0], xOpt[1], example.getObjVal()); + + return 0; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example1b.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example1b.cpp new file mode 100644 index 0000000..8e76d27 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example1b.cpp @@ -0,0 +1,84 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file examples/example1b.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + * + * Very simple example for testing qpOASES using the QProblemB class. + */ + +#include + +/** Example for qpOASES main function using the QProblemB class. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* Setup data of first QP. */ + real_t H[2 * 2] = {1.0, 0.0, 0.0, 0.5}; + real_t g[2] = {1.5, 1.0}; + real_t lb[2] = {0.5, -2.0}; + real_t ub[2] = {5.0, 2.0}; + + /* Setup data of second QP. */ + real_t g_new[2] = {1.0, 1.5}; + real_t lb_new[2] = {0.0, -1.0}; + real_t ub_new[2] = {5.0, -0.5}; + + /* Setting up QProblemB object. */ + QProblemB example(2); + + Options options; + // options.enableFlippingBounds = BT_FALSE; + options.initialStatusBounds = ST_INACTIVE; + options.numRefinementSteps = 1; + options.enableCholeskyRefactorisation = 1; + example.setOptions(options); + + /* Solve first QP. */ + int_t nWSR = 10; + example.init(H, g, lb, ub, nWSR, 0); + + /* Get and print solution of first QP. */ + real_t xOpt[2]; + example.getPrimalSolution(xOpt); + printf("\nxOpt = [ %e, %e ]; objVal = %e\n\n", xOpt[0], xOpt[1], example.getObjVal()); + + /* Solve second QP. */ + nWSR = 10; + example.hotstart(g_new, lb_new, ub_new, nWSR, 0); + // printf( "\nnWSR = %d\n\n", nWSR ); + + /* Get and print solution of second QP. */ + example.getPrimalSolution(xOpt); + printf("\nxOpt = [ %e, %e ]; objVal = %e\n\n", xOpt[0], xOpt[1], example.getObjVal()); + + return 0; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example2.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example2.cpp new file mode 100644 index 0000000..f803f00 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example2.cpp @@ -0,0 +1,115 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file examples/example2.cpp + * \author Hans Joachim Ferreau (thanks to Boris Houska) + * \version 3.2 + * \date 2008-2017 + * + * Very simple example for testing qpOASES in combination + * with the SolutionAnalysis class. + */ + +#include + +/** Example for qpOASES main function using the SolutionAnalysis class. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* Setup data of first QP. */ + real_t H[2 * 2] = {1.0, 0.0, 0.0, 0.5}; + real_t A[1 * 2] = {1.0, 1.0}; + real_t g[2] = {1.5, 1.0}; + real_t lb[2] = {0.5, -2.0}; + real_t ub[2] = {5.0, 2.0}; + real_t lbA[1] = {-1.0}; + real_t ubA[1] = {2.0}; + + /* Setup data of second QP. */ + real_t H_new[2 * 2] = {1.0, 0.5, 0.5, 0.5}; + real_t A_new[1 * 2] = {1.0, 5.0}; + real_t g_new[2] = {1.0, 1.5}; + real_t lb_new[2] = {0.0, -1.0}; + real_t ub_new[2] = {5.0, -0.5}; + real_t lbA_new[1] = {-2.0}; + real_t ubA_new[1] = {1.0}; + + /* Setting up SQProblem object and solution analyser. */ + SQProblem example(2, 1); + SolutionAnalysis analyser; + + /* Solve first QP ... */ + int_t nWSR = 10; + example.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + + /* ... and analyse it. */ + real_t maxKktViolation = analyser.getKktViolation(&example); + printf("maxKktViolation: %e\n", maxKktViolation); + + /* Solve second QP ... */ + nWSR = 10; + example.hotstart(H_new, g_new, A_new, lb_new, ub_new, lbA_new, ubA_new, nWSR, 0); + + /* ... and analyse it. */ + maxKktViolation = analyser.getKktViolation(&example); + printf("maxKktViolation: %e\n", maxKktViolation); + + // ------------ VARIANCE-COVARIANCE EVALUATION -------------------- + + real_t * Var = new real_t[5 * 5]; + real_t * Primal_Dual_Var = new real_t[5 * 5]; + + int_t run1, run2; + for (run1 = 0; run1 < 5 * 5; run1++) + Var[run1] = 0.0; + + Var[0] = 1.0; + Var[6] = 1.0; + + // ( 1 0 0 0 0 ) + // ( 0 1 0 0 0 ) + // Var = ( 0 0 0 0 0 ) + // ( 0 0 0 0 0 ) + // ( 0 0 0 0 0 ) + + analyser.getVarianceCovariance(&example, Var, Primal_Dual_Var); + + printf("\nPrimal_Dual_VAR = \n"); + for (run1 = 0; run1 < 5; run1++) { + for (run2 = 0; run2 < 5; run2++) { + printf(" %10f", Primal_Dual_Var[run1 * 5 + run2]); + } + printf("\n"); + } + + delete[] Primal_Dual_Var; + delete[] Var; + + return 0; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example3.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example3.cpp new file mode 100644 index 0000000..15a89c0 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example3.cpp @@ -0,0 +1,82 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file examples/example3.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2008-2017 + * + * Example demonstrating usage of qpOASES for solving a QP sequence of the + * Online QP Benchmark Collection. In order to run it, you have to download + * "Example 02" from from http://www.qpOASES.org/onlineQP/ and store it into + * the directory bin/chain80w/. + */ + +#include + +/** Example for qpOASES main function using the OQP interface. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* 1) Define benchmark arguments. */ + BooleanType isSparse = BT_FALSE; + Options options; + options.setToMPC(); + options.printLevel = PL_NONE; + + int_t nWSR = 600; + real_t maxCPUtime = 10.0; /* seconds */ + real_t maxStationarity, maxFeasibility, maxComplementarity; + + /* 2) Run benchmark. */ + if (runOqpBenchmark("./chain80w/", + isSparse, + options, + nWSR, + maxCPUtime, + maxStationarity, + maxFeasibility, + maxComplementarity) != SUCCESSFUL_RETURN) { + myPrintf("In order to run this example, you need to download example no. 02\nfrom the Online QP " + "Benchmark Collection website first!\n"); + return -1; + } + + /* 3) Print results. */ + printf("\n\n"); + printf("OQP Benchmark Results:\n"); + printf("======================\n\n"); + printf("maximum violation stationarity: %.3e\n", maxStationarity); + printf("maximum violation feasibility: %.3e\n", maxFeasibility); + printf("maximum violation complementarity: %.3e\n", maxComplementarity); + printf("\n"); + printf("maximum CPU time: %.3f milliseconds\n\n", 1000.0 * maxCPUtime); + + return 0; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example3b.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example3b.cpp new file mode 100644 index 0000000..799a101 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example3b.cpp @@ -0,0 +1,82 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file examples/example3b.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2008-2017 + * + * Example demonstrating usage of qpOASES for solving a QP sequence of the + * Online QP Benchmark Collection. In order to run it, you have to download + * "Example 02" from http://www.qpOASES.org/onlineQP/ and store it into + * the directory bin/chain80/. + */ + +#include + +/** Example for qpOASES main function using the OQP interface. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* 1) Define benchmark arguments. */ + BooleanType isSparse = BT_FALSE; + Options options; + options.setToMPC(); + options.printLevel = PL_NONE; + + int_t nWSR = 300; + real_t maxCPUtime = 10.0; /* seconds */ + real_t maxStationarity, maxFeasibility, maxComplementarity; + + /* 2) Run benchmark. */ + if (runOqpBenchmark("./chain80/", + isSparse, + options, + nWSR, + maxCPUtime, + maxStationarity, + maxFeasibility, + maxComplementarity) != SUCCESSFUL_RETURN) { + myPrintf("In order to run this example, you need to download example no. 02\nfrom the Online QP " + "Benchmark Collection website first!\n"); + return -1; + } + + /* 3) Print results. */ + printf("\n\n"); + printf("OQP Benchmark Results:\n"); + printf("======================\n\n"); + printf("maximum violation stationarity: %.3e\n", maxStationarity); + printf("maximum violation feasibility: %.3e\n", maxFeasibility); + printf("maximum violation complementarity: %.3e\n", maxComplementarity); + printf("\n"); + printf("maximum CPU time: %.3f milliseconds\n\n", 1000.0 * maxCPUtime); + + return 0; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example4.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example4.cpp new file mode 100644 index 0000000..2a9106b --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example4.cpp @@ -0,0 +1,161 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file examples/example4.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2009-2017 + * + * Very simple example for testing qpOASES (using the possibility to specify + * user-defined constraint product function). + */ + +#include + +#include "example4CP.cpp" +#include + +/** Example for qpOASES main function using the possibility to specify + * user-defined constraint product function. */ +int main() +{ + USING_NAMESPACE_QPOASES + + int_t i, j; + + /* Setup data of first QP... */ + real_t H[7 * 7]; + real_t A[50 * 7]; + real_t g[7]; + real_t lbA[50]; + + /* ( 1.0 0.5 | ) + * ( 0.5 2.0 | ) + * ( --------+------------------- ) + * H = ( | 1e-6 ) + * ( | 1e-6 ) + * ( | ... ) + * ( | 1e-6 ) */ + for (i = 0; i < 7 * 7; ++i) + H[i] = 0.0; + for (i = 2; i < 7; ++i) + H[i * 7 + i] = 1.0e-6; + H[0] = 1.0; + H[1] = 0.5; + H[7] = 0.5; + H[8] = 2.0; + + /* ( x.x x.x | 1.0 ) + * ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) + * ( x.x x.x | 1.0 ) + * A = ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) + * ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) + * ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) */ + for (i = 0; i < 50 * 7; ++i) + A[i] = 0.0; + for (i = 0; i < 50; ++i) { + for (j = 0; j < 2; ++j) + A[i * 7 + j] = (real_t)rand() / (real_t)RAND_MAX; + + A[i * 7 + (i / 10) + 2] = 1.0; + } + + /* ( -1.0 ) + * ( -0.5 ) + * ( ---- ) + * g = ( ) + * ( ) + * ( ) + * ( ) */ + for (i = 0; i < 7; ++i) + g[i] = 0.0; + g[0] = -1.0; + g[1] = -0.5; + + for (i = 0; i < 50; ++i) + lbA[i] = 1.0; + + /* ... and setting up user-defined constraint product function. */ + MyConstraintProduct myCP(7, 50, A); + + /* Setting up QProblem object and set construct product function. */ + QProblem exampleCP(7, 50); + exampleCP.setPrintLevel(PL_NONE); + + exampleCP.setConstraintProduct(&myCP); + + /* Solve first QP. */ + real_t cputime = 1.0; + int_t nWSR = 100; + exampleCP.init(H, g, A, 0, 0, lbA, 0, nWSR, &cputime); + + /* Solve second QP using a modified gradient. */ + g[0] = -2.0; + g[1] = 0.5; + + cputime = 1.0; + nWSR = 100; + exampleCP.hotstart(g, 0, 0, lbA, 0, nWSR, &cputime); + + /* Get and print solution of second QP. */ + real_t xOpt[7]; + exampleCP.getPrimalSolution(xOpt); + printf("\nxOpt = [ %e, %e, %e ... ]; objVal = %e\n", xOpt[0], xOpt[1], xOpt[2], exampleCP.getObjVal()); + printf("CPU time: %.3f microseconds\n\n", cputime * 1.0e6); + + /* Do the same without specifying constraint product. */ + QProblem example(7, 50); + example.setPrintLevel(PL_NONE); + + /* Solve first QP. */ + g[0] = -1.0; + g[1] = -0.5; + + cputime = 1.0; + nWSR = 100; + example.init(H, g, A, 0, 0, lbA, 0, nWSR, &cputime); + + /* Solve second QP using a modified gradient. */ + g[0] = -2.0; + g[1] = 0.5; + + cputime = 1.0; + nWSR = 100; + example.hotstart(g, 0, 0, lbA, 0, nWSR, &cputime); + + /* Get and print solution of second QP. */ + example.getPrimalSolution(xOpt); + printf("\nxOpt = [ %e, %e, %e ... ]; objVal = %e\n", xOpt[0], xOpt[1], xOpt[2], example.getObjVal()); + printf("CPU time: %.3f microseconds\n\n", cputime * 1.0e6); + + return 0; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example4CP.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example4CP.cpp new file mode 100644 index 0000000..1c72da3 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example4CP.cpp @@ -0,0 +1,98 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file examples/example4CP.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2009-2017 + * + * Sample implementation of the ConstraintProduct class tailored for Example4. + */ + +BEGIN_NAMESPACE_QPOASES + +/** + * \brief Example illustrating the use of the \a ConstraintProduct class. + * + * Example illustrating the use of the \a ConstraintProduct class. + * + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + */ +class MyConstraintProduct : public ConstraintProduct +{ +public: + /** Default constructor. */ + MyConstraintProduct(){}; + + /** Constructor. */ + MyConstraintProduct(int_t _nV, int_t _nC, real_t * _A) + { + nV = _nV; + nC = _nC; + A = _A; + }; + + /** Copy constructor (flat copy). */ + MyConstraintProduct(const MyConstraintProduct & rhs) + { + nV = rhs.nV; + nC = rhs.nC; + A = rhs.A; + }; + + /** Destructor. */ + virtual ~MyConstraintProduct(){}; + + /** Assignment operator (flat copy). */ + MyConstraintProduct & operator=(const MyConstraintProduct & rhs) + { + if (this != &rhs) { + nV = rhs.nV; + nC = rhs.nC; + A = rhs.A; + } + return *this; + }; + + virtual int_t operator()(int_t constrIndex, const real_t * const x, real_t * const constrValue) const + { + int_t i; + + constrValue[0] = 1.0 * x[(constrIndex / 10) + 2]; + + for (i = 0; i < 2; ++i) + constrValue[0] += A[constrIndex * nV + i] * x[i]; + + return 0; + }; + +protected: + int_t nV; /**< Number of variables. */ + int_t nC; /**< Number of constraints. */ + real_t * A; /**< Pointer to full constraint matrix (typically not needed!). */ +}; + +END_NAMESPACE_QPOASES diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example5.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example5.cpp new file mode 100644 index 0000000..5747a4d --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/example5.cpp @@ -0,0 +1,190 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file examples/example5.cpp + * \author Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2011-2017 + * + * Very simple example for testing qpOASES (using the possibility to + * compute the local linear feedback law) + */ + +#include + +#include "example4CP.cpp" +#include + +/** Example for qpOASES main function using the possibility to specify + * user-defined constraint product function. */ +int main() +{ + USING_NAMESPACE_QPOASES + + int_t i, j, jj; + real_t d = 0.0; + + /* Setup data of first QP... */ + real_t H[7 * 7]; + real_t A[50 * 7]; + real_t g[7]; + real_t lbA[50]; + + /* ( 1.0 0.5 | ) + * ( 0.5 2.0 | ) + * ( --------+------------------- ) + * H = ( | 1e-6 ) + * ( | 1e-6 ) + * ( | ... ) + * ( | 1e-6 ) */ + for (i = 0; i < 7 * 7; ++i) + H[i] = 0.0; + for (i = 2; i < 7; ++i) + H[i * 7 + i] = 1.0e-6; + H[0] = 1.0; + H[1] = 0.5; + H[7] = 0.5; + H[8] = 2.0; + + /* ( x.x x.x | 1.0 ) + * ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) + * ( x.x x.x | 1.0 ) + * A = ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) + * ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) + * ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) */ + for (i = 0; i < 50 * 7; ++i) + A[i] = 0.0; + for (i = 0; i < 50; ++i) { + for (j = 0; j < 2; ++j) + A[i * 7 + j] = (real_t)rand() / (real_t)RAND_MAX; + + A[i * 7 + (i / 10) + 2] = 1.0; + } + + /* ( -1.0 ) + * ( -0.5 ) + * ( ---- ) + * g = ( ) + * ( ) + * ( ) + * ( ) */ + for (i = 0; i < 7; ++i) + g[i] = 0.0; + g[0] = -1.0; + g[1] = -0.5; + + for (i = 0; i < 50; ++i) + lbA[i] = 1.0; + + /* ... and setting up user-defined constraint product function. */ + MyConstraintProduct myCP(7, 50, A); + + /* Setting up QProblem object and set construct product function. */ + QProblem example(7, 50); + example.setConstraintProduct(&myCP); + + /* Solve first QP. */ + real_t cputime = 1.0; + int_t nWSR = 100; + example.init(H, g, A, 0, 0, lbA, 0, nWSR, &cputime); + + /* Get and print solution of QP. */ + real_t xOpt[7], yOpt[7 + 50]; + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + + /* Compute local linear feedback law */ + const int_t n_rhs = 7 + 7 + 50; + real_t g_in[7 * n_rhs]; + real_t b_in[7 * n_rhs]; + real_t bA_in[50 * n_rhs]; + real_t x_out[7 * n_rhs]; + real_t y_out[(7 + 50) * n_rhs]; + + int_t ii; + memset(g_in, 0, sizeof(g_in)); + memset(b_in, 0, sizeof(b_in)); + memset(bA_in, 0, sizeof(bA_in)); + + for (ii = 0; ii < 7; ++ii) + g_in[ii * 7 + ii] = 1.0; + for (ii = 0; ii < 7; ++ii) + b_in[(ii + 7) * 7 + ii] = 1.0; + for (ii = 0; ii < 50; ++ii) + bA_in[(ii + 14) * 50 + ii] = 1.0; + + example.solveCurrentEQP(n_rhs, g_in, b_in, b_in, bA_in, bA_in, x_out, y_out); + + /* Verify validity of local feedback law by perturbation and hot starts */ + real_t perturb = 1.0e-6; + real_t nrm = 0.0; + for (ii = 0; ii < n_rhs; ++ii) { + for (jj = 0; jj < 7; ++jj) + g_in[ii * 7 + jj] = g[jj] + g_in[ii * 7 + jj] * perturb; + for (jj = 0; jj < 50; ++jj) + bA_in[ii * 50 + jj] = lbA[jj] + bA_in[ii * 50 + jj] * perturb; + + nWSR = 100; + example.hotstart(&g_in[ii * 7], 0, 0, &bA_in[ii * 50], 0, nWSR, 0); + + real_t xPer[7], yPer[7 + 50]; + example.getPrimalSolution(xPer); + example.getDualSolution(yPer); + + for (jj = 0; jj < 7; ++jj) { + d = getAbs(x_out[ii * 7 + jj] * perturb - (xPer[jj] - xOpt[jj])); + if (nrm < d) + nrm = d; + } + for (jj = 0; jj < 7 + 50; ++jj) { + d = getAbs(y_out[ii * (7 + 50) + jj] * perturb - (yPer[jj] - yOpt[jj])); + if (nrm < d) + nrm = d; + } + } + printf("Maximum perturbation over all directions: %e\n", nrm); + + /* // print feedback matrix + for (ii = 0; ii < n_rhs; ++ii) + { + printf ("x: "); + for (jj = 0; jj < 7; ++jj ) + printf ("%8.2e ", x_out[ii*7+jj]); + printf (" y: "); + for (jj = 0; jj < 7+50; ++jj ) + printf ("%8.2e ", y_out[ii*(7+50)+jj]); + printf("\n"); + } +*/ + + return 0; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/exampleLP.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/exampleLP.cpp new file mode 100644 index 0000000..c93bd63 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/exampleLP.cpp @@ -0,0 +1,80 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file examples/exampleLP.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2008-2017 + * + * Very simple example for solving a LP sequence using qpOASES. + */ + +#include + +/** Example for qpOASES main function solving LPs. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* Setup data of first LP. */ + real_t A[1 * 2] = {1.0, 1.0}; + real_t g[2] = {1.5, 1.0}; + real_t lb[2] = {0.5, -2.0}; + real_t ub[2] = {5.0, 2.0}; + real_t lbA[1] = {-1.0}; + real_t ubA[1] = {2.0}; + + /* Setup data of second LP. */ + real_t g_new[2] = {1.0, 1.5}; + real_t lb_new[2] = {0.0, -1.0}; + real_t ub_new[2] = {5.0, -0.5}; + real_t lbA_new[1] = {-2.0}; + real_t ubA_new[1] = {1.0}; + + /* Setting up QProblem object with zero Hessian matrix. */ + QProblem example(2, 1, HST_ZERO); + + Options options; + // options.setToMPC(); + example.setOptions(options); + + /* Solve first LP. */ + int_t nWSR = 10; + example.init(0, g, A, lb, ub, lbA, ubA, nWSR, 0); + + /* Solve second LP. */ + nWSR = 10; + example.hotstart(g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR, 0); + + /* Get and print solution of second LP. */ + real_t xOpt[2]; + example.getPrimalSolution(xOpt); + printf("\nxOpt = [ %e, %e ]; objVal = %e\n\n", xOpt[0], xOpt[1], example.getObjVal()); + + return 0; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/generate_sparse_qp/main.py b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/generate_sparse_qp/main.py new file mode 100755 index 0000000..729eb83 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/generate_sparse_qp/main.py @@ -0,0 +1,58 @@ +import numpy as np +import scipy as sp +from scipy.sparse import csc_matrix, coo_matrix, csr_matrix, lil_matrix, random +from jinja2 import Environment +from jinja2.loaders import FileSystemLoader +import os + +seed = 42 +density = 0.1 +gamma = 0.01 + +out_file_name = 'qp_data.hpp' +in_file_name = 'qp_data.in.hpp' + +NV = 100 +NC = 10 + +H = csc_matrix((NV, NV)) +A = csc_matrix((NV, NV)) + +myinf = 1e10 + +for i in range(NV): + H[i,i] = 1.0 + +# H = H + gamma*random(NV, NV, density=density, format='csc', random_state=seed) +# H = H.T*H + +for i in range(NC): + A[i,i] = 1.0 + +H_ri = H.indices +H_cp = H.indptr +H_val = H.data +H_nnz = H.nnz + +A_ri = A.indices +A_cp = A.indptr +A_val = A.data +A_nnz = A.nnz + +g = np.ones((NV,1)) + +lb = -myinf*np.ones((NV, 1)) +ub = myinf*np.ones((NV, 1)) + +lbA = -np.ones((NC, 1)) +ubA = np.ones((NC, 1)) + +print('rendering templated C++ code...') +env = Environment(loader=FileSystemLoader(os.path.dirname(os.path.abspath(__file__)))) +tmpl = env.get_template(in_file_name) + +code = tmpl.render(NV = NV, NC = NC, H_cp = H_cp, H_ri = H_ri, H_val = H_val, H_nnz = H_nnz, \ + A_cp = A_cp, A_ri = A_ri, A_val = A_val, A_nnz = A_nnz, g = g, lb = lb, ub = ub, lbA = lbA, ubA = ubA) + +with open(out_file_name, "w+") as f: + f.write(code.replace('inf', 'Inf')) diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/generate_sparse_qp/qp_data.in.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/generate_sparse_qp/qp_data.in.hpp new file mode 100644 index 0000000..607e2e2 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/generate_sparse_qp/qp_data.in.hpp @@ -0,0 +1,116 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \author Andrea Zanelli + * \version 3.2 + * \date 2022 + * + * QP data generated by a Python script for testing purposes. + */ + +USING_NAMESPACE_QPOASES + +#define NV \ +{ \ +{ \ +NV \ +} \ +} +#define NC \ +{ \ +{ \ +NC \ +} \ +} + +const real_t Inf = INFTY; + +sparse_int_t H_ri[] = { + {% for d in H_ri %} + {{ d }}, + {%- endfor %} +}; + +sparse_int_t H_cp[] = { + {% for d in H_cp %} + {{ d }}, + {%- endfor %} +}; + +real_t H_val[] = { + {% for d in H_val %} + {{ d }}, + {%- endfor %} +}; + +sparse_int_t A_ri[] = { + {% for d in A_ri %} + {{ d }}, + {%- endfor %} +}; + +sparse_int_t A_cp[] = { + {% for d in A_cp %} + {{ d }}, + {%- endfor %} +}; + +real_t A_val[] = { + {% for d in A_val %} + {{ d }}, + {%- endfor %} +}; + +real_t g[] = { + {% for d in g %} + {{ d[0] }}, + {%- endfor %} +}; + +real_t lb[] = { + {% for d in lb %} + {{ d[0] }}, + {%- endfor %} +}; + +real_t ub[] = { + {% for d in ub %} + {{ d[0] }}, + {%- endfor %} +}; + +real_t lbA[] = { + {% for d in lbA %} + {{ d[0] }}, + {%- endfor %} +}; + +real_t ubA[] = { + {% for d in ubA %} + {{ d[0] }}, + {%- endfor %} + }; + +long H_nnz = {{H_nnz}}; +long A_nnz = {{A_nnz}}; diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/generate_sparse_qp/simple_qp_data.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/generate_sparse_qp/simple_qp_data.hpp new file mode 100644 index 0000000..e511f10 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/generate_sparse_qp/simple_qp_data.hpp @@ -0,0 +1,14374 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \author Andrea Zanelli + * \version 3.2 + * \date 2022 + * + * QP data generated by a Python script for testing purposes. + */ + +USING_NAMESPACE_QPOASES + +#define NV 100 +#define NC 10 + +const real_t Inf = INFTY; + +sparse_int_t H_ri[] = { + + 96, + 24, + 78, + 71, + 52, + 50, + 27, + 95, + 88, + 70, + 65, + 21, + 90, + 69, + 39, + 13, + 4, + 83, + 76, + 36, + 56, + 89, + 60, + 22, + 7, + 97, + 79, + 47, + 46, + 32, + 17, + 86, + 35, + 20, + 73, + 53, + 41, + 30, + 28, + 25, + 23, + 11, + 6, + 92, + 82, + 74, + 58, + 45, + 44, + 33, + 26, + 98, + 93, + 77, + 68, + 64, + 29, + 16, + 14, + 12, + 8, + 87, + 84, + 81, + 72, + 66, + 59, + 57, + 55, + 54, + 40, + 37, + 18, + 3, + 1, + 94, + 91, + 85, + 80, + 75, + 63, + 62, + 61, + 51, + 49, + 34, + 31, + 5, + 0, + 42, + 38, + 27, + 96, + 89, + 74, + 71, + 51, + 44, + 23, + 82, + 62, + 47, + 46, + 32, + 17, + 99, + 88, + 50, + 19, + 98, + 93, + 77, + 68, + 64, + 14, + 12, + 8, + 79, + 75, + 21, + 11, + 7, + 94, + 69, + 56, + 53, + 52, + 30, + 29, + 16, + 6, + 87, + 84, + 81, + 66, + 59, + 57, + 55, + 54, + 49, + 40, + 37, + 18, + 3, + 0, + 97, + 90, + 85, + 80, + 78, + 76, + 73, + 72, + 65, + 60, + 48, + 35, + 31, + 15, + 1, + 87, + 77, + 16, + 66, + 50, + 10, + 36, + 95, + 85, + 80, + 74, + 84, + 82, + 40, + 37, + 3, + 99, + 97, + 89, + 83, + 67, + 34, + 7, + 90, + 86, + 63, + 61, + 49, + 19, + 5, + 81, + 59, + 55, + 54, + 53, + 79, + 65, + 9, + 70, + 69, + 51, + 47, + 32, + 22, + 18, + 75, + 56, + 48, + 94, + 60, + 31, + 30, + 25, + 21, + 20, + 11, + 92, + 91, + 68, + 62, + 58, + 57, + 52, + 45, + 43, + 42, + 41, + 28, + 26, + 17, + 2, + 53, + 67, + 2, + 9, + 77, + 63, + 61, + 50, + 88, + 71, + 36, + 93, + 82, + 56, + 35, + 98, + 97, + 92, + 58, + 33, + 7, + 99, + 90, + 68, + 48, + 46, + 41, + 31, + 17, + 89, + 52, + 43, + 39, + 21, + 6, + 86, + 85, + 76, + 69, + 28, + 20, + 14, + 5, + 75, + 70, + 65, + 62, + 42, + 25, + 16, + 96, + 95, + 91, + 80, + 74, + 73, + 30, + 26, + 22, + 15, + 13, + 94, + 79, + 78, + 11, + 83, + 60, + 47, + 45, + 34, + 32, + 23, + 4, + 87, + 84, + 81, + 72, + 66, + 59, + 57, + 55, + 54, + 49, + 40, + 37, + 18, + 3, + 1, + 0, + 81, + 31, + 97, + 86, + 73, + 51, + 91, + 89, + 61, + 58, + 7, + 98, + 87, + 74, + 57, + 38, + 78, + 68, + 66, + 52, + 50, + 35, + 33, + 27, + 8, + 95, + 88, + 55, + 49, + 12, + 11, + 6, + 90, + 84, + 82, + 69, + 41, + 39, + 30, + 22, + 13, + 0, + 75, + 70, + 65, + 62, + 25, + 16, + 15, + 71, + 64, + 59, + 42, + 29, + 21, + 10, + 5, + 83, + 72, + 60, + 47, + 45, + 37, + 34, + 32, + 23, + 4, + 3, + 92, + 74, + 39, + 24, + 66, + 65, + 48, + 41, + 11, + 36, + 25, + 78, + 50, + 7, + 77, + 44, + 73, + 88, + 47, + 15, + 6, + 84, + 54, + 40, + 37, + 90, + 19, + 2, + 96, + 87, + 68, + 67, + 43, + 79, + 70, + 32, + 30, + 22, + 17, + 9, + 86, + 76, + 69, + 57, + 28, + 20, + 18, + 16, + 14, + 3, + 83, + 71, + 64, + 59, + 42, + 29, + 23, + 21, + 10, + 4, + 82, + 72, + 60, + 58, + 56, + 55, + 52, + 33, + 94, + 91, + 85, + 80, + 75, + 63, + 62, + 61, + 51, + 49, + 34, + 31, + 5, + 0, + 97, + 86, + 82, + 98, + 34, + 26, + 79, + 68, + 59, + 17, + 15, + 10, + 5, + 96, + 83, + 71, + 95, + 88, + 84, + 70, + 65, + 49, + 13, + 4, + 85, + 81, + 38, + 33, + 27, + 58, + 24, + 12, + 91, + 80, + 73, + 51, + 44, + 41, + 31, + 28, + 25, + 23, + 0, + 89, + 78, + 66, + 60, + 55, + 54, + 47, + 45, + 43, + 39, + 21, + 11, + 3, + 94, + 87, + 69, + 56, + 53, + 52, + 37, + 30, + 29, + 16, + 6, + 1, + 39, + 95, + 94, + 86, + 31, + 28, + 55, + 54, + 50, + 5, + 67, + 19, + 9, + 2, + 99, + 88, + 87, + 74, + 34, + 26, + 91, + 65, + 61, + 12, + 4, + 76, + 64, + 49, + 47, + 44, + 42, + 38, + 93, + 82, + 72, + 57, + 56, + 35, + 97, + 92, + 89, + 73, + 60, + 58, + 33, + 18, + 3, + 0, + 98, + 84, + 83, + 77, + 62, + 48, + 46, + 45, + 43, + 41, + 29, + 22, + 17, + 15, + 14, + 13, + 81, + 79, + 78, + 75, + 30, + 21, + 11, + 7, + 1, + 99, + 89, + 86, + 72, + 70, + 58, + 46, + 38, + 13, + 56, + 51, + 48, + 11, + 10, + 78, + 71, + 65, + 55, + 52, + 50, + 35, + 33, + 27, + 4, + 98, + 93, + 87, + 77, + 68, + 66, + 64, + 59, + 49, + 29, + 16, + 14, + 12, + 8, + 1, + 0, + 93, + 80, + 49, + 74, + 71, + 47, + 37, + 27, + 10, + 77, + 68, + 59, + 51, + 41, + 35, + 89, + 67, + 34, + 21, + 19, + 7, + 98, + 86, + 82, + 60, + 31, + 13, + 3, + 83, + 58, + 40, + 24, + 23, + 16, + 65, + 62, + 52, + 2, + 85, + 79, + 70, + 32, + 30, + 22, + 17, + 5, + 99, + 97, + 87, + 81, + 64, + 56, + 53, + 33, + 26, + 15, + 9, + 90, + 67, + 65, + 41, + 2, + 95, + 91, + 66, + 38, + 33, + 31, + 22, + 84, + 76, + 60, + 52, + 46, + 24, + 16, + 82, + 81, + 78, + 75, + 98, + 87, + 74, + 40, + 37, + 27, + 9, + 88, + 79, + 69, + 47, + 28, + 15, + 6, + 56, + 51, + 48, + 11, + 8, + 68, + 58, + 50, + 35, + 26, + 17, + 83, + 71, + 64, + 59, + 42, + 34, + 29, + 23, + 21, + 10, + 5, + 4, + 67, + 5, + 74, + 26, + 97, + 82, + 59, + 99, + 92, + 85, + 17, + 56, + 10, + 8, + 96, + 83, + 71, + 90, + 77, + 63, + 61, + 50, + 40, + 22, + 95, + 88, + 84, + 70, + 65, + 49, + 13, + 4, + 20, + 2, + 91, + 80, + 73, + 53, + 51, + 44, + 37, + 31, + 28, + 25, + 23, + 16, + 0, + 89, + 66, + 60, + 55, + 54, + 52, + 43, + 6, + 93, + 86, + 48, + 47, + 41, + 39, + 34, + 33, + 24, + 15, + 12, + 94, + 45, + 3, + 81, + 79, + 78, + 75, + 30, + 21, + 11, + 7, + 1, + 91, + 89, + 83, + 72, + 62, + 61, + 7, + 90, + 54, + 31, + 22, + 97, + 76, + 67, + 56, + 53, + 50, + 27, + 95, + 88, + 84, + 55, + 30, + 13, + 4, + 58, + 21, + 6, + 92, + 85, + 74, + 70, + 65, + 42, + 38, + 17, + 94, + 86, + 48, + 47, + 41, + 39, + 34, + 33, + 24, + 15, + 11, + 98, + 93, + 87, + 77, + 68, + 66, + 64, + 59, + 49, + 29, + 16, + 14, + 12, + 8, + 1, + 0, + 93, + 97, + 59, + 51, + 87, + 34, + 24, + 89, + 78, + 72, + 64, + 58, + 52, + 38, + 8, + 86, + 23, + 9, + 71, + 33, + 28, + 16, + 88, + 70, + 65, + 55, + 49, + 47, + 21, + 12, + 11, + 6, + 82, + 75, + 69, + 60, + 39, + 4, + 0, + 99, + 90, + 79, + 68, + 66, + 31, + 96, + 95, + 91, + 80, + 74, + 73, + 30, + 26, + 3, + 98, + 84, + 83, + 77, + 62, + 48, + 46, + 45, + 43, + 41, + 29, + 22, + 17, + 15, + 14, + 13, + 7, + 51, + 40, + 24, + 88, + 31, + 99, + 89, + 78, + 72, + 70, + 55, + 52, + 38, + 97, + 67, + 56, + 53, + 50, + 27, + 86, + 85, + 76, + 69, + 57, + 28, + 20, + 18, + 5, + 3, + 94, + 92, + 82, + 75, + 74, + 58, + 54, + 44, + 33, + 26, + 84, + 83, + 62, + 48, + 46, + 45, + 43, + 41, + 22, + 17, + 15, + 13, + 7, + 98, + 93, + 87, + 77, + 68, + 66, + 64, + 59, + 49, + 29, + 16, + 14, + 12, + 8, + 1, + 0, + 49, + 82, + 92, + 44, + 20, + 71, + 52, + 38, + 27, + 88, + 79, + 69, + 68, + 59, + 28, + 21, + 10, + 6, + 5, + 50, + 36, + 18, + 58, + 40, + 75, + 70, + 42, + 25, + 23, + 16, + 4, + 96, + 95, + 91, + 74, + 30, + 3, + 98, + 84, + 83, + 77, + 62, + 46, + 45, + 43, + 29, + 22, + 17, + 14, + 13, + 7, + 94, + 93, + 86, + 47, + 41, + 39, + 34, + 24, + 12, + 11, + 99, + 87, + 81, + 64, + 56, + 53, + 33, + 26, + 9, + 97, + 90, + 85, + 80, + 78, + 76, + 73, + 72, + 65, + 60, + 48, + 35, + 31, + 15, + 1, + 39, + 2, + 84, + 21, + 10, + 99, + 89, + 48, + 82, + 60, + 22, + 81, + 58, + 40, + 9, + 96, + 83, + 13, + 78, + 71, + 55, + 50, + 35, + 27, + 97, + 79, + 46, + 32, + 91, + 80, + 73, + 51, + 44, + 41, + 31, + 11, + 86, + 76, + 57, + 28, + 20, + 18, + 5, + 92, + 85, + 74, + 38, + 33, + 24, + 17, + 75, + 72, + 70, + 65, + 62, + 47, + 45, + 42, + 25, + 23, + 15, + 4, + 3, + 98, + 93, + 77, + 68, + 66, + 64, + 59, + 49, + 14, + 12, + 8, + 0, + 94, + 87, + 69, + 56, + 53, + 52, + 37, + 30, + 29, + 16, + 6, + 1, + 95, + 76, + 78, + 75, + 44, + 20, + 11, + 88, + 69, + 59, + 21, + 6, + 86, + 82, + 60, + 81, + 40, + 23, + 9, + 5, + 97, + 87, + 72, + 53, + 47, + 32, + 1, + 0, + 99, + 90, + 79, + 66, + 31, + 30, + 3, + 50, + 35, + 10, + 94, + 93, + 85, + 74, + 70, + 65, + 38, + 33, + 24, + 16, + 12, + 98, + 84, + 83, + 77, + 48, + 46, + 29, + 22, + 15, + 14, + 13, + 7, + 92, + 91, + 68, + 62, + 58, + 57, + 52, + 45, + 43, + 42, + 41, + 28, + 26, + 17, + 2, + 91, + 77, + 99, + 88, + 74, + 64, + 34, + 26, + 83, + 62, + 50, + 43, + 36, + 15, + 70, + 51, + 48, + 47, + 41, + 32, + 31, + 2, + 93, + 82, + 75, + 56, + 35, + 98, + 97, + 92, + 89, + 73, + 60, + 58, + 33, + 30, + 22, + 7, + 86, + 85, + 76, + 69, + 28, + 20, + 16, + 14, + 5, + 87, + 84, + 81, + 72, + 66, + 59, + 57, + 55, + 54, + 49, + 40, + 37, + 18, + 3, + 1, + 0, + 97, + 89, + 67, + 65, + 56, + 34, + 21, + 9, + 7, + 90, + 86, + 63, + 61, + 5, + 2, + 83, + 78, + 57, + 41, + 99, + 88, + 81, + 50, + 49, + 48, + 35, + 30, + 19, + 1, + 98, + 59, + 51, + 50, + 48, + 38, + 92, + 47, + 44, + 17, + 15, + 84, + 82, + 67, + 54, + 43, + 40, + 37, + 60, + 45, + 31, + 30, + 21, + 11, + 2, + 75, + 63, + 49, + 35, + 29, + 0, + 78, + 66, + 46, + 25, + 99, + 94, + 87, + 80, + 74, + 72, + 61, + 26, + 24, + 86, + 85, + 76, + 69, + 57, + 28, + 20, + 18, + 16, + 14, + 5, + 3, + 62, + 82, + 76, + 46, + 16, + 69, + 68, + 28, + 17, + 15, + 99, + 97, + 67, + 56, + 19, + 9, + 91, + 90, + 77, + 63, + 61, + 50, + 40, + 22, + 95, + 88, + 84, + 70, + 65, + 49, + 13, + 0, + 94, + 31, + 25, + 20, + 2, + 58, + 24, + 12, + 89, + 66, + 60, + 55, + 54, + 52, + 47, + 45, + 43, + 39, + 6, + 3, + 83, + 71, + 64, + 59, + 42, + 34, + 29, + 23, + 10, + 5, + 4, + 81, + 79, + 78, + 75, + 30, + 21, + 11, + 7, + 1, + 87, + 81, + 78, + 66, + 38, + 37, + 10, + 57, + 86, + 23, + 16, + 67, + 54, + 12, + 65, + 52, + 51, + 47, + 2, + 88, + 63, + 61, + 50, + 49, + 40, + 21, + 11, + 90, + 82, + 69, + 39, + 4, + 76, + 36, + 97, + 92, + 89, + 60, + 33, + 18, + 0, + 85, + 79, + 70, + 32, + 9, + 5, + 75, + 58, + 31, + 25, + 96, + 95, + 91, + 80, + 74, + 73, + 30, + 26, + 3, + 98, + 84, + 83, + 77, + 62, + 48, + 46, + 45, + 43, + 41, + 29, + 22, + 17, + 15, + 14, + 13, + 7, + 92, + 39, + 98, + 86, + 82, + 22, + 13, + 81, + 58, + 24, + 17, + 9, + 96, + 89, + 77, + 74, + 55, + 1, + 93, + 76, + 69, + 63, + 54, + 46, + 40, + 91, + 80, + 73, + 66, + 53, + 51, + 44, + 41, + 31, + 30, + 28, + 11, + 6, + 0, + 75, + 70, + 65, + 62, + 25, + 16, + 15, + 71, + 64, + 59, + 42, + 29, + 21, + 10, + 5, + 83, + 72, + 60, + 47, + 45, + 37, + 34, + 32, + 23, + 4, + 3, + 59, + 57, + 51, + 50, + 43, + 14, + 62, + 25, + 5, + 0, + 84, + 82, + 60, + 52, + 46, + 10, + 98, + 73, + 29, + 13, + 83, + 81, + 40, + 23, + 9, + 58, + 21, + 6, + 99, + 87, + 80, + 76, + 72, + 61, + 28, + 26, + 20, + 92, + 85, + 74, + 70, + 65, + 42, + 38, + 17, + 16, + 94, + 93, + 86, + 48, + 47, + 41, + 39, + 34, + 33, + 24, + 15, + 12, + 11, + 92, + 74, + 39, + 24, + 86, + 57, + 43, + 36, + 5, + 94, + 60, + 21, + 2, + 88, + 81, + 68, + 52, + 38, + 34, + 33, + 78, + 46, + 20, + 91, + 80, + 73, + 66, + 53, + 51, + 44, + 37, + 30, + 28, + 11, + 6, + 0, + 58, + 48, + 41, + 31, + 29, + 22, + 75, + 72, + 70, + 65, + 62, + 47, + 45, + 42, + 25, + 23, + 16, + 15, + 4, + 3, + 90, + 11, + 78, + 98, + 47, + 39, + 6, + 34, + 18, + 7, + 88, + 77, + 67, + 60, + 55, + 48, + 27, + 50, + 35, + 29, + 10, + 85, + 76, + 72, + 61, + 24, + 20, + 96, + 95, + 80, + 73, + 30, + 22, + 13, + 3, + 94, + 82, + 75, + 74, + 54, + 44, + 14, + 0, + 99, + 97, + 87, + 81, + 64, + 56, + 53, + 33, + 15, + 9, + 92, + 91, + 68, + 62, + 58, + 57, + 52, + 45, + 43, + 42, + 41, + 28, + 26, + 17, + 2, + 98, + 87, + 74, + 47, + 40, + 10, + 9, + 80, + 69, + 42, + 15, + 1, + 97, + 76, + 58, + 53, + 14, + 12, + 78, + 71, + 68, + 66, + 65, + 52, + 50, + 35, + 16, + 8, + 4, + 0, + 85, + 43, + 39, + 38, + 37, + 33, + 6, + 88, + 81, + 77, + 67, + 60, + 56, + 55, + 48, + 29, + 27, + 26, + 50, + 7, + 84, + 60, + 46, + 40, + 82, + 88, + 79, + 47, + 21, + 15, + 10, + 96, + 71, + 55, + 49, + 33, + 13, + 98, + 83, + 78, + 77, + 67, + 64, + 63, + 59, + 73, + 66, + 53, + 51, + 44, + 37, + 31, + 30, + 25, + 23, + 11, + 6, + 0, + 99, + 94, + 87, + 80, + 74, + 72, + 61, + 24, + 86, + 85, + 76, + 69, + 20, + 18, + 16, + 14, + 5, + 3, + 92, + 91, + 68, + 62, + 58, + 57, + 52, + 45, + 43, + 42, + 41, + 28, + 26, + 17, + 2, + 73, + 47, + 39, + 24, + 86, + 63, + 20, + 88, + 81, + 67, + 60, + 55, + 27, + 50, + 35, + 26, + 75, + 58, + 31, + 25, + 84, + 62, + 48, + 46, + 45, + 43, + 41, + 22, + 17, + 15, + 13, + 7, + 83, + 71, + 42, + 34, + 23, + 21, + 10, + 5, + 4, + 98, + 93, + 77, + 68, + 66, + 64, + 59, + 49, + 14, + 12, + 8, + 0, + 94, + 87, + 69, + 56, + 53, + 52, + 37, + 30, + 29, + 16, + 6, + 1, + 76, + 57, + 43, + 86, + 77, + 59, + 83, + 72, + 62, + 61, + 65, + 55, + 47, + 12, + 45, + 20, + 2, + 84, + 82, + 39, + 4, + 98, + 97, + 92, + 89, + 60, + 58, + 33, + 18, + 85, + 70, + 32, + 9, + 5, + 90, + 68, + 46, + 17, + 66, + 51, + 44, + 41, + 31, + 28, + 25, + 23, + 0, + 99, + 88, + 50, + 49, + 48, + 35, + 19, + 96, + 95, + 91, + 80, + 74, + 73, + 26, + 22, + 15, + 13, + 3, + 81, + 79, + 78, + 75, + 21, + 11, + 7, + 94, + 87, + 69, + 56, + 53, + 52, + 37, + 30, + 29, + 16, + 6, + 1, + 88, + 57, + 50, + 14, + 7, + 95, + 81, + 38, + 10, + 4, + 98, + 86, + 83, + 9, + 74, + 67, + 54, + 12, + 70, + 69, + 18, + 45, + 21, + 20, + 2, + 87, + 47, + 32, + 99, + 79, + 68, + 46, + 17, + 13, + 3, + 66, + 53, + 44, + 37, + 30, + 28, + 23, + 16, + 11, + 6, + 41, + 29, + 25, + 22, + 82, + 58, + 56, + 55, + 52, + 33, + 97, + 90, + 78, + 76, + 73, + 72, + 65, + 60, + 48, + 35, + 15, + 1, + 94, + 91, + 85, + 80, + 75, + 63, + 62, + 61, + 51, + 49, + 34, + 31, + 5, + 0, + 82, + 33, + 98, + 57, + 49, + 69, + 58, + 51, + 48, + 41, + 18, + 2, + 92, + 90, + 81, + 74, + 59, + 44, + 43, + 40, + 38, + 85, + 70, + 30, + 22, + 9, + 5, + 97, + 87, + 79, + 66, + 62, + 53, + 46, + 31, + 17, + 16, + 1, + 0, + 83, + 72, + 60, + 47, + 45, + 37, + 34, + 32, + 23, + 4, + 3, + 90, + 80, + 95, + 10, + 59, + 51, + 79, + 32, + 96, + 83, + 49, + 28, + 13, + 78, + 71, + 50, + 35, + 8, + 4, + 43, + 37, + 27, + 6, + 91, + 88, + 68, + 66, + 25, + 98, + 89, + 73, + 30, + 22, + 18, + 7, + 3, + 85, + 70, + 65, + 42, + 38, + 17, + 16, + 92, + 75, + 74, + 54, + 45, + 44, + 14, + 0, + 94, + 93, + 86, + 48, + 47, + 41, + 39, + 34, + 24, + 12, + 11, + 99, + 97, + 87, + 81, + 64, + 53, + 26, + 15, + 9, + 82, + 72, + 60, + 58, + 56, + 55, + 52, + 33, + 31, + 5, + 78, + 50, + 98, + 73, + 13, + 6, + 97, + 89, + 67, + 65, + 56, + 19, + 9, + 2, + 99, + 87, + 82, + 74, + 57, + 26, + 18, + 7, + 88, + 81, + 68, + 66, + 52, + 38, + 25, + 93, + 86, + 48, + 41, + 39, + 33, + 24, + 15, + 12, + 11, + 71, + 64, + 59, + 42, + 29, + 21, + 10, + 83, + 72, + 60, + 47, + 45, + 37, + 32, + 23, + 4, + 3, + 94, + 91, + 85, + 80, + 75, + 63, + 62, + 61, + 51, + 49, + 34, + 31, + 5, + 0, + 69, + 95, + 94, + 46, + 43, + 77, + 70, + 59, + 51, + 9, + 71, + 66, + 55, + 52, + 33, + 27, + 16, + 8, + 4, + 83, + 41, + 93, + 82, + 57, + 56, + 18, + 7, + 3, + 87, + 86, + 75, + 63, + 20, + 0, + 68, + 58, + 29, + 26, + 17, + 10, + 99, + 88, + 81, + 50, + 49, + 30, + 19, + 97, + 90, + 85, + 80, + 78, + 76, + 73, + 72, + 65, + 60, + 48, + 35, + 31, + 15, + 1, + 86, + 70, + 57, + 25, + 5, + 2, + 93, + 87, + 72, + 62, + 60, + 56, + 50, + 43, + 18, + 15, + 89, + 88, + 84, + 81, + 71, + 66, + 46, + 3, + 83, + 76, + 74, + 36, + 22, + 0, + 90, + 75, + 65, + 50, + 48, + 95, + 78, + 22, + 98, + 74, + 71, + 10, + 9, + 82, + 67, + 20, + 5, + 2, + 85, + 43, + 39, + 38, + 33, + 27, + 91, + 80, + 73, + 51, + 44, + 41, + 31, + 28, + 25, + 11, + 94, + 69, + 56, + 53, + 52, + 30, + 29, + 16, + 6, + 83, + 60, + 47, + 45, + 34, + 32, + 23, + 4, + 87, + 84, + 81, + 72, + 66, + 59, + 57, + 55, + 54, + 49, + 40, + 37, + 18, + 3, + 1, + 0, + 51, + 50, + 20, + 95, + 31, + 22, + 10, + 99, + 89, + 86, + 78, + 72, + 58, + 48, + 14, + 13, + 8, + 80, + 71, + 69, + 15, + 1, + 98, + 87, + 57, + 4, + 83, + 77, + 76, + 64, + 49, + 7, + 90, + 79, + 59, + 46, + 44, + 40, + 32, + 55, + 43, + 39, + 37, + 27, + 6, + 91, + 88, + 81, + 68, + 66, + 52, + 47, + 34, + 25, + 94, + 93, + 92, + 85, + 74, + 70, + 65, + 42, + 38, + 33, + 24, + 17, + 16, + 12, + 99, + 65, + 7, + 92, + 74, + 62, + 25, + 23, + 16, + 5, + 98, + 87, + 73, + 29, + 26, + 90, + 84, + 82, + 75, + 69, + 30, + 22, + 13, + 4, + 0, + 85, + 81, + 38, + 37, + 27, + 89, + 78, + 66, + 60, + 55, + 54, + 52, + 45, + 43, + 21, + 6, + 3, + 94, + 93, + 86, + 48, + 47, + 41, + 39, + 34, + 33, + 24, + 15, + 12, + 11, + 51, + 48, + 14, + 52, + 28, + 53, + 80, + 60, + 98, + 71, + 47, + 27, + 10, + 82, + 67, + 20, + 5, + 2, + 83, + 70, + 58, + 24, + 17, + 16, + 15, + 9, + 91, + 88, + 77, + 61, + 50, + 22, + 21, + 11, + 93, + 76, + 69, + 63, + 45, + 41, + 23, + 92, + 90, + 79, + 74, + 46, + 44, + 43, + 38, + 32, + 87, + 84, + 81, + 72, + 66, + 59, + 57, + 55, + 54, + 49, + 40, + 37, + 18, + 3, + 1, + 0, + 88, + 87, + 67, + 65, + 50, + 10, + 5, + 85, + 74, + 9, + 70, + 32, + 18, + 78, + 35, + 19, + 76, + 63, + 59, + 54, + 40, + 82, + 69, + 60, + 4, + 99, + 90, + 79, + 3, + 80, + 73, + 66, + 53, + 51, + 44, + 37, + 30, + 23, + 16, + 6, + 0, + 75, + 31, + 25, + 98, + 84, + 83, + 77, + 46, + 29, + 22, + 14, + 13, + 7, + 94, + 93, + 86, + 48, + 47, + 39, + 34, + 33, + 24, + 15, + 12, + 11, + 92, + 91, + 68, + 62, + 58, + 57, + 52, + 45, + 43, + 42, + 41, + 28, + 26, + 17, + 2, + 80, + 69, + 27, + 1, + 81, + 79, + 77, + 76, + 49, + 44, + 7, + 94, + 93, + 85, + 74, + 38, + 33, + 24, + 12, + 75, + 72, + 70, + 65, + 47, + 25, + 16, + 15, + 3, + 83, + 71, + 64, + 59, + 34, + 29, + 23, + 21, + 10, + 5, + 4, + 92, + 91, + 68, + 62, + 58, + 57, + 52, + 45, + 43, + 42, + 41, + 28, + 26, + 17, + 2, + 51, + 24, + 97, + 95, + 94, + 76, + 65, + 35, + 30, + 86, + 70, + 25, + 88, + 53, + 69, + 20, + 93, + 72, + 56, + 50, + 36, + 18, + 96, + 87, + 82, + 67, + 5, + 90, + 79, + 74, + 59, + 44, + 40, + 32, + 85, + 81, + 38, + 37, + 33, + 27, + 89, + 78, + 66, + 60, + 55, + 54, + 47, + 39, + 21, + 11, + 6, + 3, + 98, + 84, + 83, + 77, + 48, + 46, + 29, + 22, + 15, + 14, + 13, + 7, + 92, + 91, + 68, + 62, + 58, + 57, + 52, + 45, + 43, + 42, + 41, + 28, + 26, + 17, + 2, + 70, + 69, + 60, + 5, + 99, + 85, + 20, + 17, + 15, + 96, + 89, + 71, + 55, + 1, + 83, + 77, + 76, + 64, + 49, + 47, + 42, + 7, + 90, + 81, + 79, + 59, + 46, + 43, + 40, + 38, + 32, + 91, + 80, + 73, + 66, + 53, + 51, + 41, + 37, + 31, + 30, + 28, + 25, + 23, + 16, + 11, + 6, + 94, + 92, + 87, + 82, + 75, + 74, + 58, + 54, + 45, + 44, + 33, + 26, + 14, + 0, + 99, + 85, + 31, + 30, + 20, + 93, + 76, + 69, + 63, + 59, + 40, + 89, + 66, + 55, + 39, + 21, + 6, + 70, + 65, + 25, + 16, + 87, + 82, + 75, + 74, + 54, + 44, + 33, + 0, + 98, + 84, + 77, + 48, + 46, + 29, + 22, + 15, + 14, + 13, + 7, + 94, + 79, + 78, + 11, + 83, + 72, + 60, + 47, + 37, + 34, + 32, + 23, + 4, + 3, + 92, + 91, + 68, + 62, + 58, + 57, + 52, + 45, + 43, + 42, + 41, + 28, + 26, + 17, + 2, + 95, + 94, + 65, + 57, + 35, + 82, + 60, + 28, + 24, + 21, + 10, + 86, + 70, + 64, + 58, + 55, + 52, + 8, + 89, + 88, + 71, + 36, + 93, + 76, + 69, + 63, + 54, + 23, + 92, + 81, + 74, + 59, + 44, + 40, + 38, + 97, + 87, + 72, + 53, + 47, + 32, + 16, + 1, + 0, + 99, + 90, + 79, + 68, + 31, + 30, + 3, + 78, + 66, + 25, + 20, + 98, + 84, + 83, + 77, + 62, + 48, + 46, + 45, + 43, + 41, + 29, + 22, + 17, + 15, + 14, + 13, + 7, + 99, + 92, + 85, + 20, + 73, + 29, + 26, + 98, + 74, + 71, + 40, + 27, + 9, + 59, + 28, + 10, + 5, + 69, + 58, + 51, + 22, + 18, + 2, + 95, + 84, + 30, + 13, + 77, + 76, + 64, + 49, + 44, + 7, + 91, + 88, + 81, + 68, + 38, + 97, + 87, + 79, + 53, + 46, + 31, + 17, + 1, + 0, + 89, + 78, + 66, + 55, + 54, + 52, + 43, + 21, + 6, + 75, + 70, + 65, + 62, + 42, + 25, + 16, + 94, + 93, + 86, + 48, + 41, + 39, + 33, + 24, + 15, + 12, + 11, + 83, + 72, + 60, + 47, + 45, + 37, + 34, + 32, + 23, + 4, + 3, + 59, + 40, + 20, + 87, + 37, + 5, + 82, + 89, + 64, + 52, + 38, + 16, + 10, + 8, + 70, + 69, + 51, + 32, + 18, + 91, + 57, + 2, + 79, + 68, + 66, + 3, + 67, + 56, + 55, + 27, + 26, + 75, + 58, + 25, + 99, + 88, + 81, + 50, + 49, + 30, + 19, + 98, + 84, + 83, + 77, + 62, + 46, + 45, + 43, + 29, + 22, + 17, + 14, + 13, + 7, + 94, + 93, + 86, + 47, + 41, + 39, + 34, + 33, + 24, + 12, + 11, + 97, + 90, + 85, + 80, + 78, + 76, + 73, + 72, + 65, + 60, + 48, + 35, + 31, + 15, + 1, + 15, + 9, + 97, + 82, + 73, + 2, + 74, + 32, + 96, + 71, + 33, + 28, + 90, + 22, + 95, + 70, + 65, + 21, + 13, + 11, + 6, + 4, + 83, + 79, + 76, + 47, + 44, + 42, + 38, + 7, + 86, + 20, + 99, + 88, + 50, + 48, + 35, + 30, + 19, + 98, + 93, + 77, + 68, + 64, + 29, + 16, + 14, + 12, + 8, + 87, + 84, + 81, + 72, + 66, + 59, + 57, + 55, + 54, + 40, + 37, + 18, + 3, + 1, + 94, + 91, + 85, + 80, + 75, + 63, + 62, + 61, + 51, + 49, + 34, + 31, + 5, + 0, + 98, + 59, + 51, + 38, + 24, + 20, + 94, + 86, + 57, + 31, + 28, + 75, + 41, + 37, + 2, + 82, + 64, + 34, + 7, + 5, + 93, + 87, + 83, + 72, + 62, + 60, + 43, + 36, + 18, + 15, + 97, + 76, + 67, + 56, + 53, + 14, + 12, + 78, + 71, + 66, + 65, + 55, + 52, + 33, + 27, + 16, + 8, + 4, + 0, + 91, + 90, + 77, + 63, + 61, + 40, + 22, + 21, + 11, + 3, + 68, + 58, + 29, + 26, + 17, + 10, + 99, + 88, + 81, + 50, + 49, + 48, + 35, + 30, + 19, + 1, + 57, + 50, + 43, + 40, + 38, + 24, + 20, + 14, + 90, + 97, + 82, + 33, + 13, + 4, + 86, + 68, + 60, + 35, + 9, + 56, + 10, + 8, + 70, + 69, + 58, + 48, + 47, + 32, + 22, + 18, + 2, + 96, + 89, + 76, + 74, + 71, + 55, + 1, + 98, + 87, + 83, + 78, + 77, + 72, + 67, + 64, + 59, + 73, + 66, + 53, + 44, + 41, + 37, + 30, + 28, + 25, + 23, + 16, + 11, + 6, + 94, + 91, + 85, + 80, + 75, + 63, + 62, + 61, + 51, + 49, + 34, + 31, + 5, + 0, + 84, + 83, + 76, + 40, + 24, + 10, + 86, + 77, + 70, + 64, + 48, + 46, + 14, + 13, + 80, + 15, + 99, + 79, + 22, + 9, + 71, + 65, + 50, + 35, + 27, + 8, + 4, + 0, + 88, + 81, + 38, + 34, + 25, + 89, + 78, + 66, + 54, + 47, + 39, + 21, + 11, + 3, + 94, + 87, + 69, + 53, + 37, + 30, + 29, + 16, + 6, + 1, + 82, + 72, + 60, + 56, + 55, + 33, + 31, + 5, + 92, + 91, + 68, + 62, + 58, + 57, + 52, + 45, + 43, + 42, + 41, + 28, + 26, + 17, + 2, + 88, + 84, + 43, + 40, + 3, + 59, + 55, + 54, + 2, + 77, + 76, + 67, + 58, + 50, + 27, + 14, + 12, + 79, + 72, + 62, + 47, + 46, + 32, + 17, + 91, + 80, + 73, + 66, + 51, + 44, + 41, + 31, + 28, + 25, + 23, + 11, + 0, + 99, + 97, + 81, + 64, + 33, + 26, + 15, + 9, + 94, + 87, + 69, + 56, + 53, + 52, + 37, + 30, + 29, + 16, + 6, + 1, + 99, + 91, + 62, + 7, + 88, + 20, + 5, + 53, + 2, + 90, + 67, + 31, + 22, + 12, + 93, + 76, + 69, + 63, + 46, + 41, + 23, + 89, + 78, + 60, + 52, + 47, + 43, + 39, + 21, + 11, + 6, + 94, + 92, + 82, + 75, + 74, + 58, + 45, + 44, + 33, + 26, + 14, + 87, + 84, + 81, + 72, + 66, + 59, + 57, + 55, + 54, + 49, + 40, + 37, + 18, + 3, + 1, + 0, + 62, + 7, + 99, + 86, + 64, + 46, + 14, + 53, + 2, + 91, + 83, + 28, + 68, + 50, + 35, + 16, + 8, + 95, + 70, + 65, + 30, + 13, + 12, + 4, + 96, + 76, + 74, + 71, + 51, + 44, + 23, + 85, + 38, + 88, + 77, + 67, + 48, + 29, + 27, + 26, + 89, + 78, + 47, + 45, + 43, + 39, + 21, + 11, + 6, + 82, + 60, + 58, + 56, + 52, + 33, + 31, + 5, + 87, + 84, + 81, + 72, + 66, + 59, + 57, + 55, + 54, + 49, + 40, + 37, + 18, + 3, + 1, + 0, + 95, + 86, + 85, + 80, + 74, + 89, + 65, + 34, + 21, + 19, + 83, + 62, + 43, + 36, + 51, + 11, + 10, + 8, + 76, + 50, + 14, + 12, + 91, + 2, + 93, + 75, + 57, + 35, + 18, + 7, + 3, + 0, + 88, + 77, + 67, + 48, + 27, + 99, + 97, + 81, + 64, + 26, + 15, + 9, + 94, + 87, + 69, + 53, + 37, + 30, + 29, + 16, + 6, + 1, + 82, + 72, + 60, + 58, + 56, + 55, + 52, + 33, + 31, + 5, + 51, + 24, + 95, + 65, + 46, + 30, + 94, + 50, + 31, + 70, + 36, + 25, + 22, + 79, + 99, + 88, + 64, + 34, + 98, + 74, + 38, + 32, + 4, + 48, + 83, + 78, + 19, + 93, + 82, + 75, + 56, + 35, + 7, + 86, + 85, + 76, + 69, + 20, + 16, + 14, + 5, + 87, + 84, + 81, + 72, + 66, + 59, + 55, + 54, + 49, + 40, + 37, + 18, + 3, + 1, + 0, + 92, + 91, + 68, + 62, + 58, + 57, + 52, + 45, + 43, + 42, + 41, + 28, + 26, + 17, + 2, + 90, + 85, + 66, + 99, + 86, + 78, + 64, + 46, + 38, + 13, + 8, + 65, + 61, + 4, + 83, + 81, + 40, + 23, + 16, + 15, + 9, + 77, + 76, + 67, + 53, + 27, + 70, + 69, + 51, + 47, + 32, + 98, + 97, + 89, + 73, + 30, + 18, + 7, + 3, + 50, + 35, + 10, + 24, + 21, + 12, + 6, + 48, + 29, + 25, + 22, + 94, + 87, + 75, + 74, + 54, + 44, + 14, + 0, + 82, + 72, + 60, + 56, + 55, + 33, + 31, + 5, + 92, + 91, + 68, + 62, + 58, + 57, + 52, + 45, + 43, + 42, + 41, + 28, + 26, + 17, + 2, + 50, + 48, + 24, + 20, + 97, + 82, + 73, + 33, + 13, + 11, + 86, + 70, + 60, + 35, + 30, + 9, + 88, + 47, + 17, + 15, + 6, + 53, + 2, + 76, + 69, + 45, + 41, + 92, + 90, + 79, + 74, + 46, + 44, + 43, + 38, + 32, + 78, + 67, + 63, + 51, + 28, + 83, + 71, + 42, + 34, + 23, + 21, + 10, + 5, + 4, + 98, + 93, + 77, + 68, + 64, + 29, + 16, + 14, + 12, + 8, + 87, + 84, + 81, + 72, + 66, + 59, + 57, + 55, + 54, + 49, + 40, + 37, + 18, + 3, + 1, + 0, + 74, + 46, + 28, + 24, + 10, + 40, + 44, + 70, + 68, + 59, + 51, + 93, + 87, + 62, + 50, + 36, + 86, + 17, + 16, + 9, + 94, + 25, + 20, + 2, + 84, + 75, + 69, + 41, + 13, + 98, + 92, + 30, + 22, + 18, + 7, + 0, + 88, + 81, + 77, + 67, + 29, + 27, + 26, + 89, + 66, + 54, + 43, + 39, + 21, + 11, + 6, + 82, + 58, + 56, + 55, + 52, + 33, + 5, + 83, + 47, + 45, + 37, + 34, + 32, + 23, + 4, + 3, + 97, + 90, + 85, + 80, + 78, + 76, + 73, + 72, + 65, + 60, + 48, + 35, + 31, + 15, + 1, + 82, + 73, + 86, + 19, + 2, + 89, + 83, + 65, + 58, + 30, + 12, + 7, + 4, + 90, + 88, + 77, + 50, + 40, + 22, + 21, + 11, + 3, + 99, + 87, + 76, + 74, + 72, + 28, + 26, + 24, + 20, + 94, + 91, + 85, + 80, + 75, + 63, + 62, + 61, + 51, + 49, + 34, + 31, + 5, + 0, + 74, + 39, + 24, + 67, + 55, + 54, + 21, + 99, + 93, + 60, + 56, + 50, + 36, + 18, + 89, + 30, + 12, + 9, + 97, + 87, + 79, + 66, + 53, + 32, + 1, + 72, + 70, + 65, + 47, + 25, + 23, + 16, + 4, + 3, + 98, + 84, + 83, + 77, + 48, + 46, + 29, + 22, + 15, + 14, + 13, + 7, + 92, + 68, + 58, + 57, + 52, + 45, + 43, + 42, + 41, + 28, + 26, + 17, + 2, + 94, + 91, + 85, + 80, + 75, + 63, + 62, + 61, + 51, + 49, + 34, + 31, + 5, + 0, + 19, + 2, + 90, + 88, + 50, + 22, + 21, + 11, + 3, + 93, + 76, + 69, + 54, + 46, + 45, + 41, + 40, + 23, + 86, + 35, + 29, + 20, + 98, + 87, + 83, + 78, + 77, + 72, + 67, + 64, + 59, + 28, + 94, + 91, + 85, + 80, + 75, + 63, + 62, + 61, + 51, + 49, + 34, + 31, + 5, + 0, + 96, + 90, + 73, + 50, + 89, + 86, + 70, + 58, + 55, + 52, + 48, + 46, + 13, + 88, + 82, + 74, + 57, + 18, + 79, + 76, + 47, + 44, + 38, + 7, + 78, + 72, + 67, + 63, + 51, + 28, + 83, + 71, + 42, + 34, + 23, + 21, + 10, + 5, + 4, + 99, + 97, + 81, + 56, + 53, + 33, + 26, + 15, + 9, + 98, + 93, + 87, + 77, + 68, + 66, + 64, + 59, + 49, + 29, + 16, + 14, + 12, + 8, + 1, + 0, + 87, + 86, + 39, + 57, + 46, + 43, + 41, + 37, + 10, + 5, + 99, + 67, + 56, + 34, + 19, + 91, + 89, + 83, + 61, + 58, + 7, + 79, + 22, + 9, + 2, + 71, + 68, + 66, + 52, + 50, + 27, + 8, + 95, + 88, + 84, + 55, + 49, + 30, + 21, + 13, + 11, + 6, + 0, + 94, + 93, + 92, + 74, + 38, + 33, + 24, + 17, + 12, + 75, + 70, + 62, + 47, + 45, + 42, + 25, + 23, + 16, + 4, + 3, + 97, + 90, + 85, + 80, + 78, + 76, + 73, + 72, + 65, + 60, + 48, + 35, + 31, + 15, + 1, + 75, + 67, + 5, + 2, + 95, + 22, + 10, + 94, + 85, + 74, + 58, + 65, + 50, + 35, + 27, + 4, + 76, + 71, + 36, + 88, + 38, + 34, + 33, + 97, + 62, + 32, + 99, + 90, + 79, + 48, + 17, + 13, + 46, + 20, + 91, + 80, + 73, + 53, + 51, + 44, + 41, + 31, + 30, + 28, + 25, + 23, + 89, + 78, + 60, + 52, + 47, + 45, + 43, + 39, + 21, + 11, + 6, + 98, + 93, + 77, + 68, + 64, + 29, + 16, + 14, + 12, + 8, + 87, + 84, + 81, + 72, + 66, + 59, + 57, + 55, + 54, + 49, + 40, + 37, + 18, + 3, + 1, + 0, + 75, + 66, + 41, + 11, + 10, + 91, + 62, + 84, + 69, + 40, + 37, + 20, + 3, + 99, + 89, + 65, + 34, + 21, + 19, + 9, + 7, + 2, + 90, + 74, + 54, + 31, + 22, + 97, + 76, + 58, + 53, + 50, + 14, + 12, + 96, + 82, + 68, + 43, + 5, + 98, + 87, + 83, + 78, + 72, + 64, + 63, + 59, + 51, + 28, + 88, + 81, + 77, + 67, + 60, + 56, + 55, + 48, + 29, + 27, + 26, + 97, + 86, + 70, + 60, + 51, + 9, + 69, + 21, + 15, + 6, + 78, + 71, + 65, + 55, + 27, + 4, + 96, + 82, + 67, + 5, + 88, + 81, + 47, + 38, + 34, + 33, + 25, + 99, + 90, + 79, + 48, + 46, + 31, + 30, + 13, + 3, + 50, + 35, + 10, + 98, + 93, + 87, + 77, + 66, + 64, + 59, + 49, + 29, + 16, + 14, + 12, + 8, + 1, + 0, + 92, + 91, + 68, + 62, + 58, + 57, + 52, + 45, + 43, + 42, + 41, + 28, + 26, + 17, + 2, + 97, + 35, + 77, + 73, + 44, + 80, + 71, + 42, + 38, + 27, + 88, + 79, + 68, + 21, + 17, + 15, + 10, + 67, + 43, + 70, + 58, + 51, + 48, + 47, + 32, + 31, + 2, + 93, + 63, + 59, + 54, + 46, + 45, + 40, + 23, + 90, + 84, + 82, + 75, + 60, + 41, + 39, + 22, + 13, + 4, + 0, + 86, + 85, + 76, + 57, + 28, + 20, + 18, + 14, + 5, + 3, + 94, + 87, + 69, + 56, + 53, + 52, + 37, + 30, + 29, + 16, + 6, + 1, + 98, + 80, + 57, + 43, + 36, + 73, + 44, + 99, + 89, + 78, + 64, + 52, + 46, + 14, + 8, + 86, + 77, + 68, + 60, + 59, + 35, + 83, + 81, + 40, + 69, + 58, + 51, + 48, + 41, + 31, + 18, + 2, + 95, + 88, + 84, + 55, + 49, + 21, + 13, + 11, + 6, + 0, + 79, + 32, + 30, + 22, + 9, + 5, + 94, + 93, + 92, + 85, + 74, + 38, + 33, + 24, + 17, + 12, + 75, + 72, + 70, + 65, + 62, + 47, + 45, + 42, + 25, + 23, + 16, + 15, + 4, + 3, + 98, + 87, + 47, + 40, + 37, + 9, + 80, + 69, + 38, + 15, + 91, + 49, + 28, + 13, + 11, + 6, + 78, + 68, + 65, + 52, + 50, + 35, + 33, + 27, + 16, + 8, + 0, + 88, + 84, + 81, + 66, + 46, + 36, + 3, + 96, + 89, + 77, + 76, + 74, + 55, + 51, + 44, + 1, + 83, + 71, + 64, + 59, + 42, + 34, + 29, + 23, + 21, + 10, + 5, + 4, + 86, + 38, + 14, + 13, + 8, + 50, + 43, + 36, + 91, + 89, + 30, + 12, + 93, + 7, + 79, + 53, + 46, + 17, + 98, + 77, + 67, + 64, + 63, + 51, + 99, + 94, + 74, + 61, + 28, + 26, + 24, + 20, + 75, + 70, + 62, + 42, + 25, + 16, + 82, + 58, + 56, + 52, + 33, + 5, + 83, + 47, + 45, + 34, + 32, + 23, + 4, + 87, + 84, + 81, + 66, + 59, + 57, + 55, + 54, + 49, + 40, + 37, + 18, + 3, + 0, + 97, + 90, + 85, + 80, + 78, + 76, + 73, + 72, + 65, + 60, + 48, + 35, + 31, + 15, + 1, + 99, + 64, + 88, + 86, + 83, + 59, + 49, + 4, + 77, + 70, + 69, + 82, + 61, + 5, + 87, + 47, + 39, + 34, + 29, + 24, + 98, + 92, + 89, + 58, + 33, + 18, + 7, + 66, + 53, + 51, + 44, + 41, + 37, + 28, + 25, + 23, + 16, + 11, + 6, + 0, + 96, + 95, + 91, + 74, + 30, + 26, + 22, + 13, + 3, + 97, + 90, + 85, + 80, + 78, + 76, + 73, + 72, + 65, + 60, + 48, + 35, + 31, + 15, + 1, + 62, + 39, + 25, + 5, + 11, + 78, + 66, + 60, + 41, + 86, + 56, + 2, + 47, + 37, + 27, + 10, + 9, + 88, + 64, + 34, + 18, + 7, + 98, + 57, + 49, + 4, + 67, + 31, + 89, + 77, + 71, + 55, + 51, + 23, + 1, + 90, + 81, + 79, + 59, + 46, + 43, + 40, + 32, + 83, + 36, + 99, + 76, + 72, + 61, + 28, + 20, + 93, + 85, + 70, + 65, + 42, + 38, + 24, + 17, + 16, + 12, + 96, + 95, + 91, + 80, + 73, + 30, + 22, + 15, + 13, + 3, + 94, + 92, + 87, + 82, + 75, + 74, + 58, + 54, + 45, + 44, + 33, + 26, + 14, + 0, + 67, + 66, + 50, + 37, + 10, + 99, + 17, + 2, + 90, + 84, + 69, + 60, + 39, + 13, + 93, + 57, + 56, + 18, + 86, + 35, + 20, + 48, + 41, + 29, + 22, + 72, + 70, + 65, + 47, + 42, + 25, + 23, + 16, + 15, + 4, + 3, + 92, + 87, + 82, + 74, + 58, + 54, + 45, + 44, + 33, + 26, + 14, + 81, + 79, + 78, + 30, + 21, + 11, + 7, + 1, + 94, + 91, + 85, + 80, + 75, + 63, + 62, + 61, + 51, + 49, + 34, + 31, + 5, + 0, + 95, + 43, + 30, + 17, + 52, + 21, + 10, + 91, + 82, + 67, + 58, + 56, + 53, + 50, + 27, + 12, + 88, + 84, + 66, + 96, + 89, + 71, + 55, + 51, + 81, + 79, + 77, + 64, + 49, + 47, + 44, + 42, + 38, + 7, + 93, + 63, + 59, + 54, + 46, + 45, + 41, + 40, + 23, + 83, + 36, + 22, + 0, + 99, + 94, + 87, + 74, + 61, + 26, + 24, + 86, + 69, + 57, + 28, + 20, + 18, + 16, + 14, + 5, + 3, + 97, + 90, + 85, + 80, + 78, + 76, + 73, + 72, + 65, + 60, + 48, + 35, + 31, + 15, + 1, + 18, + 2, + 73, + 69, + 5, + 99, + 52, + 86, + 70, + 35, + 30, + 9, + 97, + 58, + 53, + 91, + 90, + 61, + 50, + 40, + 21, + 11, + 3, + 96, + 89, + 74, + 71, + 23, + 79, + 76, + 47, + 44, + 42, + 38, + 78, + 72, + 63, + 51, + 28, + 88, + 81, + 67, + 60, + 56, + 55, + 27, + 26, + 84, + 83, + 62, + 48, + 46, + 45, + 43, + 41, + 22, + 17, + 15, + 13, + 7, + 98, + 93, + 87, + 77, + 68, + 66, + 64, + 59, + 49, + 29, + 16, + 14, + 12, + 8, + 1, + 0, + 96, + 88, + 17, + 95, + 91, + 74, + 37, + 22, + 34, + 5, + 82, + 26, + 10, + 99, + 86, + 70, + 58, + 38, + 14, + 13, + 71, + 68, + 50, + 33, + 27, + 16, + 8, + 4, + 0, + 57, + 41, + 19, + 98, + 87, + 83, + 77, + 67, + 64, + 63, + 59, + 51, + 28, + 46, + 25, + 20, + 89, + 66, + 55, + 54, + 52, + 47, + 43, + 39, + 6, + 94, + 45, + 3, + 81, + 79, + 75, + 30, + 21, + 11, + 7, + 97, + 90, + 85, + 80, + 78, + 76, + 73, + 72, + 65, + 60, + 48, + 35, + 31, + 15, + 1, + 82, + 33, + 88, + 69, + 28, + 15, + 10, + 6, + 57, + 65, + 52, + 2, + 83, + 77, + 76, + 64, + 49, + 42, + 92, + 74, + 59, + 44, + 43, + 40, + 38, + 85, + 70, + 22, + 9, + 5, + 97, + 87, + 72, + 62, + 53, + 47, + 32, + 16, + 0, + 99, + 90, + 68, + 66, + 48, + 46, + 41, + 31, + 17, + 13, + 94, + 45, + 3, + 81, + 79, + 78, + 75, + 30, + 21, + 11, + 7, + 1, + 98, + 93, + 70, + 33, + 9, + 40, + 82, + 86, + 81, + 56, + 2, + 71, + 69, + 52, + 42, + 38, + 27, + 66, + 53, + 44, + 41, + 37, + 25, + 23, + 16, + 11, + 6, + 99, + 87, + 28, + 24, + 20, + 96, + 95, + 74, + 30, + 26, + 22, + 13, + 3, + 97, + 90, + 78, + 76, + 73, + 72, + 65, + 60, + 48, + 35, + 15, + 1, + 94, + 91, + 85, + 80, + 75, + 63, + 62, + 61, + 51, + 49, + 34, + 31, + 5, + 0, + 31, + 22, + 4, + 82, + 10, + 95, + 86, + 80, + 2, + 70, + 58, + 24, + 23, + 17, + 16, + 89, + 71, + 36, + 83, + 76, + 42, + 92, + 90, + 74, + 46, + 44, + 32, + 85, + 43, + 39, + 6, + 91, + 68, + 52, + 47, + 38, + 34, + 25, + 77, + 67, + 60, + 29, + 27, + 88, + 50, + 48, + 35, + 19, + 99, + 97, + 64, + 56, + 53, + 33, + 26, + 15, + 9, + 79, + 78, + 75, + 30, + 21, + 11, + 7, + 87, + 84, + 81, + 72, + 66, + 59, + 57, + 55, + 54, + 49, + 40, + 37, + 18, + 3, + 1, + 0, + 46, + 24, + 21, + 97, + 59, + 51, + 49, + 11, + 6, + 50, + 79, + 48, + 32, + 81, + 78, + 15, + 10, + 91, + 80, + 76, + 73, + 61, + 28, + 40, + 37, + 20, + 2, + 99, + 88, + 64, + 34, + 98, + 86, + 83, + 23, + 17, + 16, + 9, + 96, + 68, + 67, + 43, + 90, + 84, + 69, + 41, + 39, + 30, + 22, + 13, + 4, + 93, + 57, + 35, + 18, + 7, + 3, + 1, + 94, + 92, + 87, + 75, + 74, + 54, + 45, + 44, + 26, + 14, + 0, + 82, + 72, + 60, + 58, + 56, + 55, + 52, + 33, + 31, + 5, + 52, + 73, + 99, + 97, + 2, + 93, + 56, + 50, + 18, + 89, + 65, + 61, + 30, + 12, + 86, + 82, + 31, + 70, + 58, + 40, + 24, + 9, + 96, + 91, + 55, + 33, + 16, + 11, + 6, + 81, + 79, + 49, + 44, + 38, + 57, + 35, + 19, + 76, + 74, + 36, + 0, + 87, + 78, + 67, + 63, + 51, + 28, + 98, + 84, + 77, + 62, + 48, + 46, + 43, + 41, + 22, + 17, + 15, + 14, + 13, + 7, + 71, + 64, + 59, + 42, + 29, + 21, + 10, + 5, + 83, + 72, + 60, + 47, + 45, + 37, + 34, + 32, + 23, + 4, + 3, + 52, + 28, + 24, + 16, + 10, + 53, + 67, + 20, + 5, + 2, + 95, + 70, + 65, + 47, + 21, + 12, + 11, + 6, + 89, + 88, + 76, + 71, + 36, + 90, + 82, + 75, + 69, + 60, + 39, + 30, + 4, + 98, + 83, + 77, + 62, + 48, + 46, + 45, + 43, + 41, + 29, + 22, + 17, + 15, + 14, + 13, + 7, + 87, + 84, + 81, + 72, + 66, + 59, + 57, + 55, + 54, + 49, + 40, + 37, + 18, + 3, + 1, + 0, + 66, + 58, + 41, + 47, + 45, + 44, + 11, + 95, + 56, + 2, + 81, + 55, + 43, + 39, + 37, + 27, + 6, + 79, + 32, + 30, + 22, + 9, + 99, + 87, + 26, + 86, + 69, + 57, + 28, + 20, + 18, + 14, + 3, + 93, + 92, + 74, + 70, + 42, + 38, + 33, + 24, + 17, + 16, + 12, + 97, + 90, + 78, + 76, + 73, + 72, + 65, + 60, + 48, + 35, + 15, + 1, + 94, + 91, + 85, + 80, + 75, + 63, + 62, + 61, + 51, + 49, + 34, + 31, + 5, + 0, + 65, + 88, + 50, + 7, + 43, + 36, + 25, + 97, + 73, + 6, + 4, + 95, + 81, + 80, + 74, + 56, + 99, + 89, + 78, + 72, + 64, + 58, + 55, + 52, + 46, + 38, + 8, + 77, + 70, + 68, + 59, + 51, + 30, + 90, + 61, + 19, + 2, + 98, + 83, + 82, + 60, + 31, + 23, + 22, + 17, + 13, + 9, + 87, + 75, + 63, + 49, + 35, + 29, + 0, + 85, + 76, + 69, + 57, + 28, + 20, + 18, + 16, + 14, + 5, + 3, + 94, + 93, + 86, + 48, + 47, + 41, + 39, + 34, + 33, + 24, + 15, + 12, + 11, + 65, + 41, + 48, + 2, + 95, + 91, + 22, + 73, + 39, + 13, + 71, + 27, + 10, + 88, + 34, + 7, + 60, + 50, + 36, + 38, + 4, + 96, + 43, + 5, + 79, + 62, + 47, + 46, + 32, + 31, + 17, + 86, + 35, + 83, + 78, + 67, + 63, + 51, + 85, + 80, + 76, + 61, + 28, + 24, + 20, + 92, + 82, + 75, + 74, + 58, + 45, + 44, + 99, + 97, + 33, + 26, + 15, + 9, + 98, + 93, + 77, + 68, + 64, + 14, + 12, + 8, + 94, + 69, + 56, + 53, + 52, + 30, + 29, + 16, + 6, + 87, + 84, + 81, + 72, + 66, + 59, + 57, + 55, + 54, + 49, + 40, + 37, + 18, + 3, + 1, + 0, + 97, + 94, + 86, + 78, + 41, + 31, + 14, + 73, + 54, + 53, + 43, + 79, + 69, + 59, + 28, + 17, + 15, + 10, + 5, + 87, + 82, + 74, + 64, + 57, + 18, + 7, + 90, + 63, + 61, + 40, + 22, + 95, + 70, + 65, + 21, + 13, + 12, + 11, + 6, + 4, + 0, + 89, + 84, + 76, + 71, + 46, + 36, + 3, + 91, + 68, + 66, + 52, + 47, + 38, + 34, + 33, + 25, + 77, + 67, + 60, + 56, + 55, + 29, + 27, + 26, + 99, + 88, + 81, + 50, + 49, + 48, + 35, + 30, + 19, + 1, + 86, + 70, + 64, + 48, + 38, + 16, + 14, + 13, + 8, + 99, + 67, + 56, + 34, + 19, + 9, + 2, + 91, + 83, + 72, + 65, + 62, + 61, + 12, + 4, + 88, + 84, + 81, + 46, + 36, + 96, + 77, + 76, + 74, + 71, + 51, + 44, + 23, + 1, + 98, + 97, + 92, + 73, + 58, + 33, + 30, + 22, + 18, + 7, + 0, + 89, + 78, + 66, + 60, + 55, + 54, + 52, + 47, + 45, + 43, + 39, + 21, + 11, + 6, + 3, + 98, + 96, + 64, + 51, + 33, + 37, + 10, + 26, + 94, + 58, + 86, + 19, + 5, + 2, + 67, + 54, + 12, + 91, + 88, + 77, + 63, + 61, + 50, + 49, + 21, + 11, + 84, + 82, + 75, + 69, + 39, + 22, + 4, + 0, + 92, + 81, + 74, + 59, + 44, + 43, + 40, + 38, + 32, + 99, + 79, + 68, + 66, + 46, + 41, + 30, + 17, + 13, + 3, + 97, + 90, + 85, + 80, + 78, + 76, + 73, + 72, + 65, + 60, + 48, + 35, + 31, + 15, + 1, + 97, + 18, + 99, + 67, + 54, + 87, + 78, + 10, + 82, + 76, + 89, + 72, + 65, + 12, + 7, + 4, + 83, + 71, + 55, + 90, + 77, + 50, + 40, + 21, + 56, + 48, + 88, + 81, + 47, + 38, + 33, + 66, + 53, + 44, + 37, + 25, + 23, + 16, + 11, + 6, + 96, + 95, + 74, + 73, + 30, + 22, + 15, + 13, + 3, + 92, + 68, + 58, + 57, + 52, + 45, + 43, + 42, + 41, + 28, + 26, + 17, + 2, + 94, + 91, + 85, + 80, + 75, + 63, + 62, + 61, + 51, + 49, + 34, + 31, + 5, + 0, + 39, + 25, + 23, + 5, + 99, + 47, + 20, + 15, + 11, + 90, + 81, + 79, + 59, + 46, + 40, + 32, + 98, + 97, + 89, + 73, + 60, + 30, + 22, + 18, + 7, + 3, + 93, + 85, + 70, + 65, + 38, + 24, + 16, + 12, + 94, + 87, + 82, + 75, + 74, + 54, + 44, + 33, + 14, + 0, + 92, + 91, + 68, + 62, + 58, + 57, + 52, + 45, + 43, + 42, + 41, + 28, + 26, + 17, + 2, + 99, + 80, + 13, + 9, + 83, + 62, + 60, + 50, + 43, + 36, + 76, + 69, + 63, + 54, + 46, + 45, + 40, + 23, + 82, + 75, + 72, + 57, + 56, + 35, + 18, + 7, + 3, + 92, + 85, + 74, + 70, + 65, + 42, + 38, + 17, + 94, + 86, + 48, + 47, + 41, + 39, + 34, + 33, + 24, + 15, + 11, + 98, + 93, + 87, + 77, + 68, + 66, + 64, + 59, + 49, + 29, + 16, + 14, + 12, + 8, + 1, + 0, + 95, + 46, + 43, + 35, + 88, + 57, + 50, + 7, + 90, + 66, + 60, + 25, + 21, + 2, + 99, + 76, + 72, + 28, + 20, + 70, + 65, + 42, + 38, + 17, + 92, + 82, + 74, + 58, + 54, + 44, + 26, + 14, + 93, + 86, + 48, + 47, + 41, + 39, + 33, + 24, + 15, + 12, + 79, + 78, + 45, + 11, + 3, + 87, + 69, + 56, + 53, + 52, + 37, + 30, + 29, + 16, + 6, + 1, + 94, + 91, + 85, + 80, + 75, + 63, + 62, + 61, + 51, + 49, + 34, + 31, + 5, + 0, + 94, + 76, + 57, + 46, + 43, + 35, + 17, + 7, + 87, + 78, + 66, + 38, + 37, + 33, + 31, + 10, + 86, + 85, + 81, + 56, + 2, + 88, + 84, + 70, + 65, + 55, + 49, + 47, + 21, + 12, + 11, + 6, + 4, + 0, + 96, + 95, + 91, + 80, + 74, + 73, + 30, + 26, + 22, + 15, + 13, + 3, + 98, + 90, + 78, + 64, + 0, + 83, + 49, + 33, + 28, + 16, + 11, + 6, + 89, + 77, + 76, + 71, + 55, + 51, + 44, + 23, + 1, + 87, + 82, + 68, + 67, + 43, + 5, + 96, + 95, + 91, + 80, + 74, + 73, + 30, + 26, + 22, + 15, + 13, + 3, + 88, + 69, + 68, + 43, + 91, + 86, + 82, + 59, + 51, + 49, + 13, + 11, + 6, + 4, + 83, + 34, + 21, + 19, + 2, + 77, + 67, + 50, + 27, + 14, + 12, + 98, + 92, + 89, + 58, + 30, + 22, + 18, + 7, + 3, + 79, + 66, + 62, + 47, + 46, + 32, + 17, + 16, + 0, + 99, + 87, + 81, + 64, + 56, + 53, + 33, + 26, + 9, + 97, + 90, + 85, + 80, + 78, + 76, + 73, + 72, + 65, + 60, + 48, + 35, + 31, + 15, + 1, + 50, + 20, + 96, + 90, + 99, + 80, + 70, + 39, + 34, + 26, + 24, + 6, + 71, + 47, + 40, + 37, + 27, + 10, + 86, + 82, + 31, + 23, + 9, + 74, + 57, + 38, + 32, + 4, + 97, + 92, + 89, + 73, + 60, + 58, + 33, + 30, + 18, + 3, + 78, + 72, + 67, + 63, + 51, + 28, + 84, + 83, + 62, + 48, + 46, + 45, + 43, + 41, + 22, + 17, + 15, + 13, + 7, + 98, + 93, + 87, + 77, + 68, + 66, + 64, + 59, + 49, + 29, + 16, + 14, + 12, + 8, + 1, + 0, + 73, + 39, + 98, + 93, + 91, + 54, + 92, + 75, + 47, + 45, + 44, + 11, + 86, + 78, + 77, + 70, + 58, + 55, + 38, + 16, + 14, + 8, + 62, + 52, + 89, + 83, + 67, + 65, + 21, + 2, + 82, + 57, + 34, + 18, + 7, + 90, + 79, + 68, + 66, + 46, + 41, + 31, + 17, + 13, + 3, + 94, + 85, + 80, + 76, + 74, + 72, + 61, + 28, + 24, + 20, + 88, + 50, + 49, + 48, + 35, + 30, + 19, + 1, + 99, + 97, + 87, + 81, + 64, + 56, + 53, + 33, + 26, + 15, + 9, +}; + +sparse_int_t H_cp[] = { + + 0, + 89, + 160, + 231, + 320, + 388, + 470, + 538, + 611, + 651, + 708, + 768, + 846, + 909, + 980, + 1048, + 1133, + 1220, + 1296, + 1359, + 1388, + 1444, + 1516, + 1593, + 1658, + 1717, + 1773, + 1841, + 1889, + 1962, + 2027, + 2111, + 2192, + 2242, + 2323, + 2393, + 2455, + 2485, + 2552, + 2620, + 2675, + 2741, + 2822, + 2876, + 2955, + 3016, + 3085, + 3157, + 3242, + 3323, + 3400, + 3475, + 3549, + 3624, + 3681, + 3739, + 3812, + 3876, + 3947, + 4028, + 4104, + 4186, + 4231, + 4304, + 4350, + 4414, + 4492, + 4575, + 4635, + 4704, + 4772, + 4844, + 4899, + 4979, + 5043, + 5128, + 5197, + 5276, + 5352, + 5431, + 5492, + 5558, + 5638, + 5717, + 5797, + 5860, + 5930, + 6008, + 6099, + 6174, + 6238, + 6306, + 6382, + 6441, + 6503, + 6575, + 6621, + 6660, + 6727, + 6800, + 6874, +}; + +real_t H_val[] = { + + 0.0036400623550257604, + 4.3451375820987274e-05, + 2.8154529321024527e-05, + 1.058349284017026e-06, + 1.5817505577012435e-06, + 0.00036269699602366277, + 1.5939223154984972e-06, + 1.9905781613356547e-05, + 0.006617942237573037, + 1.4703237898637284e-05, + 2.532220139804081e-05, + 2.0400045701197958e-05, + 9.786425522897559e-05, + 8.733381168004906e-06, + 0.008630783726605808, + 7.365929642574257e-05, + 5.8718839345831116e-05, + 1.1663596453736771e-05, + 0.007160597590819221, + 0.007847234151793583, + 4.799118855640533e-06, + 2.1017098271407778e-05, + 3.2854142780819036e-05, + 0.00012032027402574883, + 4.695908205301601e-05, + 3.391891618363114e-05, + 6.865839426972015e-08, + 0.00450565985570487, + 5.923465003761426e-07, + 1.6407079694044695e-06, + 1.1026494536511072e-06, + 2.0999175882370937e-06, + 0.0011110333225029594, + 1.8656782760597722e-05, + 0.00016463726515054288, + 1.9764588428937462e-05, + 7.048804349060899e-05, + 0.00016526594818091914, + 1.5739800122089514e-05, + 8.544810389600539e-05, + 0.0044510452107628835, + 0.00010202137810034909, + 3.076454718646216e-05, + 0.007042734309568557, + 0.00010528753431476505, + 0.00016056771047132448, + 3.89090190295633e-05, + 8.310218795996274e-05, + 2.6534495447257202e-05, + 0.005896520474143277, + 0.00010760530953880158, + 4.262629380572652e-05, + 3.7686390290702356e-05, + 1.0482807165536582e-05, + 8.2936366790311e-06, + 9.142508566084441e-05, + 0.0063393024704901345, + 4.2655792352873584e-05, + 0.009014740192242751, + 9.478196456125603e-05, + 0.00972144003206556, + 0.0001277688390982566, + 7.472068481635205e-05, + 1.8734155484644436e-06, + 1.5242491587519319e-05, + 7.71081508500837e-05, + 0.00010322667475459351, + 1.7857945324176098e-05, + 2.2088685428722426e-05, + 9.081164422170525e-05, + 7.412144330241568e-06, + 5.321768311467811e-05, + 8.54482043585373e-06, + 0.0019207585976825402, + 0.00011036718862435829, + 0.005713878505717975, + 0.008965663068428692, + 0.0029512563984702782, + 0.009287224138628118, + 0.008239347700691868, + 0.006329999010846514, + 0.005794533630906074, + 0.00574581527221644, + 0.0015286668560874448, + 0.0034194658432815557, + 0.007546820998713696, + 0.0020986143266744518, + 0.00848804115945128, + 1.0174228790450237, + 3.6211453017926045e-05, + 2.4723271872059743e-05, + 3.655322791892029e-05, + 1.1858073903861733e-05, + 8.138762190459502e-06, + 8.27067019911165e-06, + 8.098320768821391e-05, + 2.244436982658596e-06, + 0.0023922321366585796, + 1.6888929301382213e-05, + 4.8878825131751535e-05, + 3.366232988367765e-05, + 5.6550313371836705e-05, + 2.6958770302895138e-05, + 7.467161408604157e-05, + 5.018358904242168e-05, + 4.6357147705395986e-05, + 4.772181923265292e-06, + 4.1637468351522585e-05, + 0.005018402425556384, + 2.3102054619062538e-05, + 8.287239270239654e-05, + 1.6206885535492838e-05, + 5.422057846185583e-06, + 6.623595464622124e-05, + 7.419416670917138e-05, + 5.3873092159245e-05, + 0.009613346311948063, + 5.408312218936873e-05, + 5.264850636123655e-05, + 6.222207450410723e-05, + 2.5283835845936842e-05, + 0.00674617791236786, + 3.9709134277977404e-05, + 0.00842634005475897, + 5.0148776047508897e-05, + 6.522745373782873e-05, + 9.160651790060595e-05, + 0.00010183618537375991, + 0.0001204369410194575, + 9.45527466148835e-05, + 0.005131700163305644, + 0.00010653288579349231, + 7.014458098379015e-06, + 5.8729422882028494e-05, + 9.399386408590776e-05, + 0.0001129253805894384, + 7.645574527309935e-05, + 5.312082381498302e-05, + 2.8651042860903155e-05, + 0.00012261209406726128, + 5.263317597042702e-06, + 5.524170723711119e-05, + 5.386498799229628e-05, + 0.003258991502252713, + 0.00011036718862435829, + 0.008788743162951177, + 0.0009830902887607762, + 0.007315470196481674, + 0.006357808687633092, + 0.0027643037349795144, + 0.006085598405466598, + 0.0033801536148952, + 0.009060445131141749, + 0.009882759593724188, + 0.0006949372352616699, + 0.004220681095862514, + 0.012006271154335118, + 0.012813625909626442, + 0.00589213577782564, + 1.0096901756319723, + 1.972049328233557e-06, + 2.2433062721085766e-06, + 2.132797269703622e-06, + 1.933607075234137e-05, + 1.5324605124138993e-05, + 2.7934513576924285e-05, + 2.1276079051268394e-05, + 9.514188887823765e-06, + 6.627270386680282e-07, + 2.691506463774306e-06, + 0.0010612541856490243, + 1.1862578488334266e-06, + 1.656838550283511e-06, + 1.990227659369478e-06, + 4.558479926457905e-05, + 3.1492717831146598e-06, + 3.9331586555146806e-05, + 9.849916266201628e-06, + 1.440955553962265e-05, + 4.442344954711435e-05, + 0.0004195966818797722, + 7.092098892430295e-05, + 5.351529579156392e-05, + 0.004634066879474433, + 0.00788135828673028, + 0.0011035844870068423, + 9.108396625983994e-06, + 4.5744979932388834e-06, + 3.658505363849941e-05, + 0.00011449612249317954, + 5.367080479121616e-05, + 0.007536101314779872, + 7.932889293692498e-06, + 6.040915927635078e-05, + 3.0345710219469527e-05, + 1.5765266083114732e-05, + 0.007496747275018019, + 5.477360401773848e-05, + 0.00010740660096765256, + 4.7298225712617244e-05, + 0.007636030670880136, + 3.86650835506941e-05, + 7.339128572956441e-05, + 4.892233214493144e-05, + 8.031746833525979e-06, + 9.500151198094398e-05, + 7.891320233959729e-05, + 0.008774287957556134, + 5.454227235294692e-05, + 7.310290289575026e-06, + 0.00012240969635691026, + 7.473978611656519e-06, + 8.749361914559068e-05, + 6.094138202063724e-05, + 1.0786968122519265e-05, + 3.9008191727962326e-05, + 0.007720895238812851, + 0.009630677550983137, + 0.0008094970202235607, + 0.007513842671876183, + 0.004367331740704896, + 0.009041327173160378, + 0.009395193044154506, + 0.007106771127311314, + 0.0025027531135822763, + 0.001505445880622247, + 0.00032154997618342605, + 0.004275057037133662, + 0.0030972922175133, + 0.0019747358368568304, + 1.000396397501358, + 1.0443226802502651e-05, + 0.009743049631104774, + 3.1492717831146598e-06, + 5.433155133322079e-06, + 1.3878170459442497e-05, + 6.205293339025682e-06, + 5.326649168148768e-05, + 1.984736516522655e-05, + 0.008550548609811963, + 3.1527067534437825e-05, + 4.7248459417462044e-06, + 2.9408081782277706e-06, + 0.00010938912433855871, + 2.4213688635566925e-06, + 0.0005275661483209082, + 4.634868129524442e-05, + 4.3275702448087675e-05, + 6.787198893609816e-05, + 3.0274665047374855e-05, + 0.007790053939240377, + 5.8670941981003886e-05, + 6.37028078542803e-05, + 9.79414383924028e-05, + 1.833190249544069e-05, + 5.616434308975793e-05, + 0.004432264135737421, + 5.393172876158273e-05, + 6.101829323367727e-05, + 6.442624923415236e-05, + 7.583882756894263e-05, + 2.8292786126268883e-06, + 0.00012382073634337326, + 3.194862700383684e-06, + 0.0012815068139153654, + 9.262511050021996e-06, + 5.124321109448016e-05, + 7.419336729443077e-07, + 0.005738400102416387, + 2.6463650851974373e-05, + 3.749231695173124e-05, + 0.00011307173467956233, + 5.276511670132932e-05, + 0.00010015603807410011, + 6.944150722416447e-05, + 3.819063871128943e-06, + 2.6087163904935546e-05, + 6.771638314171035e-05, + 5.4053340630327065e-05, + 2.3321140638181313e-05, + 0.008315295754634805, + 7.755706793911599e-05, + 7.216524130910202e-05, + 0.00010527569821340091, + 6.648775300564829e-05, + 0.00013430194690215467, + 0.00019408068036398684, + 0.006586798633828459, + 6.965275646704858e-05, + 0.00016966285388558808, + 0.007973859332807587, + 9.513935743872953e-05, + 1.1173546844994064e-05, + 4.5523933983688476e-05, + 1.9266161726239038e-05, + 0.0020350525021958785, + 0.00014087934069183532, + 0.00694616003156225, + 0.00010411803164345695, + 0.00011889205758591477, + 3.8513269850336475e-05, + 6.807367336737874e-05, + 0.00013379945568627112, + 0.008665013304399156, + 0.0023031022140271094, + 0.002235762253920633, + 0.004679745180711632, + 0.008164860638231877, + 0.009496872318820002, + 0.007281113407364993, + 0.006620078112091664, + 0.009902295270012016, + 0.00890671898717624, + 0.005873673790252434, + 0.0017204913863231868, + 0.00629538472814543, + 0.007908396123318565, + 1.005946206360871, + 0.003258991502252713, + 0.0019207585976825402, + 2.162203723537085e-05, + 1.8853793968401794e-05, + 4.573845607783466e-06, + 8.17597435056736e-06, + 4.654126826922435e-07, + 8.645709649879834e-07, + 1.3866946691552715e-05, + 8.760010546227632e-06, + 0.0020676055741927837, + 1.66515736182694e-05, + 1.0116095375722495e-05, + 1.3460548600472357e-05, + 0.008441282349888507, + 8.565419016550504e-05, + 0.002284715759170237, + 2.983059461560402e-05, + 8.218202439742403e-05, + 3.453785158693196e-05, + 4.628791292582566e-05, + 1.9429607794752888e-05, + 0.004455228636882102, + 3.5838112986402865e-05, + 8.780755167910766e-05, + 1.9579120926910124e-05, + 2.3726769872314397e-05, + 9.364696675739478e-05, + 5.905432437917108e-05, + 3.191452729950644e-05, + 5.7954976624182934e-05, + 7.705892301173354e-05, + 2.1432104694935766e-05, + 3.1968056060833624e-05, + 2.058697160405831e-05, + 6.841599600088951e-05, + 1.2827787409715243e-05, + 3.2874580211676028e-06, + 2.134225602766022e-05, + 0.003224498097106496, + 9.73683053803303e-05, + 3.398949873757143e-05, + 4.5865172442288695e-05, + 5.8718839345831116e-05, + 5.646706491604017e-05, + 2.3104780332391485e-05, + 5.109858086914298e-05, + 3.781020879821394e-05, + 8.714215975638049e-06, + 0.003131018813857472, + 2.534535230410747e-05, + 7.044948047777424e-05, + 2.0879152531223147e-05, + 4.611385404600837e-05, + 7.846915829260045e-05, + 2.6713893738560452e-06, + 6.289543888777127e-05, + 0.006843301367477539, + 2.8884471967897036e-05, + 0.009827093921226878, + 0.0002095266612916967, + 0.004449428258901354, + 0.015334495722877418, + 0.0067128941927253345, + 0.005189010470211977, + 0.004507380604466488, + 0.00790089919579962, + 0.0034911392760475354, + 1.0002111134045482, + 0.008665013304399156, + 0.0037464921901482874, + 1.9459193714956095e-05, + 3.4937391624894854e-05, + 2.3477716972446635e-05, + 3.1326321629322294e-05, + 3.3405059603801925e-05, + 1.7541023247471673e-05, + 2.2413973752318735e-05, + 4.9736078040864996e-05, + 2.302150539269388e-05, + 5.2465533659413894e-05, + 2.8838670323751205e-05, + 5.2996539510238614e-05, + 8.971261774095474e-05, + 0.008978981047742522, + 4.700870048947649e-05, + 9.822974678059222e-05, + 5.425778203040552e-05, + 1.9888207898990585e-05, + 5.988673040886737e-05, + 1.3264134839712206e-05, + 2.306744948090414e-05, + 2.2085715213219096e-05, + 3.8701093554956196e-05, + 9.824640203003823e-05, + 0.007560260915174101, + 4.783186967344497e-06, + 0.00011449612249317954, + 2.7597202625547482e-05, + 2.799583849796062e-05, + 0.007388783088336085, + 0.006358011194064177, + 0.004193107812289965, + 7.929394171683288e-05, + 0.00016616202787009891, + 0.009362403878072032, + 5.5021419861820435e-05, + 2.6194607769450517e-05, + 4.88493666609293e-05, + 3.8313342227535594e-05, + 0.008601017543635006, + 0.00481031758485341, + 3.3583569172584694e-05, + 3.469139439790145e-05, + 2.1816080408894437e-05, + 5.0340873321860937e-05, + 0.001682110924335416, + 3.120558757653484e-05, + 1.2767150636099418e-05, + 0.00010015603807410011, + 5.311863651417748e-05, + 3.5510223520742805e-05, + 0.00011032302460473533, + 8.058865452382106e-05, + 3.6018542032361736e-05, + 1.6512283763228777e-06, + 7.128019767737525e-05, + 4.413969271119868e-05, + 0.004272437696748578, + 2.8884471967897036e-05, + 0.010279256328935539, + 0.005184694759674665, + 0.0008344352091233543, + 0.009543969020334744, + 0.004544223191595411, + 0.001842198992963593, + 0.006026699609445051, + 0.006615910659592654, + 4.679176487596852e-05, + 0.00012730643180779922, + 9.682822996583617e-05, + 8.369797878943574e-05, + 0.00012168058179273745, + 0.009918597864277588, + 6.717291162328866e-05, + 0.00016112846705804528, + 1.2083727420730855e-05, + 6.798716119619028e-05, + 0.0001841780532802329, + 0.006124314870517229, + 1.0007289097506258, + 0.00848804115945128, + 1.692812113220369e-05, + 3.025985047345458e-05, + 2.7396178308899984e-05, + 2.411402431329091e-05, + 7.91477008687552e-07, + 4.8643705562024125e-05, + 8.844973558735425e-06, + 0.0017964531586413168, + 2.80291057979106e-05, + 2.4093961985278423e-06, + 1.4570802453701416e-05, + 4.348502496106574e-07, + 1.3264134839712206e-05, + 5.066528936150447e-07, + 0.003405796470211449, + 7.01836851398739e-07, + 1.9466631885063608e-05, + 5.237202499739881e-05, + 3.717180985853054e-05, + 1.4378863651314058e-05, + 2.4633857595563536e-05, + 3.711164678999354e-05, + 3.272912969732364e-05, + 3.1968056060833624e-05, + 5.801413329136704e-05, + 4.3330251548595315e-05, + 3.061178252104105e-05, + 5.44501718787695e-05, + 7.50989203964441e-05, + 5.030491643952388e-05, + 0.00710973449326894, + 8.85326354907516e-05, + 2.0442660856813986e-05, + 2.0262792069064637e-05, + 0.0050024275339864265, + 2.6320072321074858e-05, + 6.948461639102615e-06, + 8.017101377762257e-06, + 1.0976407265594007e-05, + 4.990940581764883e-06, + 1.736187378464362e-05, + 0.0025523243434428344, + 3.076454718646216e-05, + 7.045607431884256e-05, + 6.305125415772337e-05, + 2.2346628787836468e-05, + 2.350896238431244e-05, + 0.00022920125990033514, + 6.570378455831617e-05, + 0.004427875840624922, + 6.060744515201521e-05, + 0.00012431712551823294, + 0.00011067717192639689, + 0.0074307455469537894, + 9.413567699746329e-05, + 9.262511050021996e-06, + 0.007738007485690339, + 0.0014518138740913999, + 0.0073028517638831615, + 0.0015313480060440388, + 0.0094797029371434, + 0.005788183044113987, + 0.014410087504995148, + 0.0024285342700700054, + 0.008170787291719226, + 0.003847059050273734, + 1.0002261925286142, + 0.005131700163305644, + 3.0438108375714784e-05, + 0.00961631256625307, + 0.004912962484832755, + 9.915672087837691e-05, + 4.968771746824327e-06, + 2.6361602054917756e-07, + 5.292434468074637e-06, + 1.2001044159749209e-05, + 3.746600959227912e-05, + 8.971261774095474e-05, + 5.356863279872683e-05, + 3.4603896728465273e-05, + 2.9001661252149522e-05, + 5.351529579156392e-05, + 0.0077918063111136705, + 4.0955284985322874e-05, + 7.076122568641112e-05, + 3.6412947427721105e-05, + 0.00019557453083133506, + 1.484422174725565e-05, + 1.6002638384314436e-05, + 0.007245395472591905, + 0.004990979010645134, + 4.2537623301663954e-05, + 1.0116095375722495e-05, + 4.419183138808709e-05, + 0.005248188198912619, + 7.256143633448298e-05, + 5.70986654635919e-05, + 1.7466550890309995e-05, + 0.00821078361998241, + 2.2283096906311314e-05, + 2.8118112264122915e-05, + 0.009180813294514662, + 2.3261520739724016e-05, + 0.00014086511687519626, + 7.199308136705757e-05, + 0.00509972235949859, + 4.9384061889323554e-05, + 6.264312554818843e-05, + 0.0012873218666964255, + 9.519664087722381e-05, + 1.8264595375149003e-05, + 6.813742258479065e-05, + 0.007255851338711169, + 5.314382935454645e-05, + 5.8670941981003886e-05, + 4.695908205301601e-05, + 6.162322138123376e-05, + 4.5873095412197237e-07, + 0.0002192081488419424, + 5.742437076531531e-05, + 4.014318685652859e-05, + 3.8142605394287925e-05, + 6.518935957422784e-05, + 8.167398243961086e-06, + 5.6797153003323836e-05, + 6.278689984787101e-05, + 4.713844281200795e-05, + 6.85314599261555e-05, + 0.000114720592022372, + 0.00011241173024402446, + 6.934688987924458e-05, + 0.007029917261468195, + 0.0039026607996137945, + 0.007621533699389588, + 0.0006133619759453804, + 0.0047020195291187054, + 0.008526010875557077, + 0.00930010985615086, + 0.003773876249747763, + 1.000556336660357, + 0.00674617791236786, + 2.9297849743894987e-05, + 3.447538930700454e-05, + 1.4517033957637429e-05, + 0.0036591943541357543, + 5.375142952456956e-06, + 3.4815135325005485e-05, + 3.084836036525695e-05, + 8.464235497657132e-06, + 4.948738034557916e-06, + 0.009283357720056219, + 5.763283032282485e-05, + 6.509424345376619e-05, + 7.083136365453295e-05, + 7.492454513155434e-06, + 4.036930180264357e-05, + 1.5593738377884085e-05, + 1.9541155247926564e-06, + 4.425405285903667e-05, + 5.7314371833237866e-05, + 0.005343984402739459, + 4.2987315002756274e-05, + 3.903353172128735e-05, + 2.348488155839762e-05, + 2.3726769872314397e-05, + 0.0024031231029667446, + 0.003277712058412189, + 0.0018293532128421254, + 0.0010902598840878482, + 0.000605441247258067, + 0.0024404954301714054, + 0.00689029288331709, + 0.009295057053681489, + 0.007342720305307154, + 0.00817565329544597, + 0.0002642212429301426, + 0.007719854747045573, + 0.005603989538199428, + 1.0001280303623055, + 0.009613346311948063, + 0.00972144003206556, + 0.004346782317554877, + 1.8428138804039813e-05, + 2.7871435289212096e-06, + 5.424328468668677e-05, + 0.006068265635885829, + 4.4092287379431386e-05, + 1.7494555237466507e-05, + 1.1148407990794493e-06, + 2.4756254396915698e-05, + 2.026619213012e-06, + 2.3765530992957984e-06, + 6.843153149414602e-07, + 1.9833815079607923e-06, + 3.4857573364954245e-06, + 9.286554580186971e-07, + 7.809001938097258e-06, + 2.813328553469004e-05, + 3.843436658672674e-05, + 4.97397276280948e-06, + 1.953667039460254e-05, + 2.9001661252149522e-05, + 4.0027338875076087e-05, + 3.3563580092853017e-06, + 5.6874060280116495e-06, + 0.0007922004510952769, + 4.2994741473518604e-08, + 2.2427517869522524e-05, + 5.433155133322079e-06, + 4.4844266449640813e-05, + 0.0033616025774451984, + 4.7368254369153736e-05, + 2.452345987381312e-05, + 3.085198020461461e-05, + 1.6112585805222823e-05, + 0.004060612310993983, + 4.73731084926689e-05, + 0.006076959034976081, + 5.477360401773848e-05, + 3.155285473097504e-05, + 4.2474491256049146e-05, + 0.0004400256081269027, + 0.004092254801917959, + 2.7418689915131593e-05, + 2.7100601453882536e-05, + 2.562502621448758e-05, + 3.8313342227535594e-05, + 0.008111144119919436, + 0.001357161489069189, + 0.0008191279921094674, + 0.008272674602401412, + 0.009532371787812329, + 0.004090065904547754, + 0.0012857957851166912, + 0.009640569433551922, + 0.004073822791191404, + 0.008813855862781005, + 1.00013773783821, + 0.006037442885632564, + 5.800260442591195e-05, + 2.6905188075855888e-05, + 1.8052719752213758e-05, + 2.7934513576924285e-05, + 6.684710209514219e-06, + 1.7917148373883355e-05, + 2.6281148204999713e-05, + 2.6075990744894606e-06, + 5.636155674345554e-06, + 1.9600997227302497e-06, + 3.082805406460417e-06, + 0.00640193868537032, + 5.49233249363574e-05, + 4.35156286886779e-05, + 2.8591836887176645e-06, + 1.437187119899864e-06, + 4.5311896319640864e-05, + 4.5190161299316886e-05, + 6.757292987282388e-05, + 9.782597090310911e-05, + 0.009832220847402985, + 5.66267224832227e-05, + 1.2987571936806203e-05, + 0.0009155504675766507, + 1.78718978296062e-05, + 4.334605723171568e-05, + 7.63198582473916e-05, + 7.494947992189717e-07, + 2.4756254396915698e-05, + 1.778782434313251e-06, + 1.1918029804950755e-06, + 3.9338609163468106e-07, + 3.0294756990803786e-05, + 4.412902333975753e-05, + 5.669926894785835e-05, + 4.348502496106574e-07, + 0.0008070845419398598, + 5.010532596552045e-06, + 1.7419893057828467e-05, + 4.62165565302197e-05, + 7.492454513155434e-06, + 0.00025118900478544144, + 2.1078685517739725e-05, + 2.9901307237916217e-05, + 1.5200482383733676e-05, + 0.002681107746571281, + 1.959416426729882e-05, + 0.0003744931963655796, + 0.012483629336950668, + 0.0030543276608787084, + 0.006164328751618406, + 0.00852430417569119, + 0.007254780340154869, + 0.00041322251086869325, + 0.009116386897353035, + 0.004851393663705584, + 1.0001992453416453, + 0.004272437696748578, + 0.006843301367477539, + 6.374362258410816e-05, + 4.9736078040864996e-05, + 5.1116032814248954e-05, + 3.4306264474122114e-05, + 3.557441043217354e-05, + 5.757301024859485e-05, + 3.101156235952684e-05, + 5.951938020031008e-06, + 6.782242961139645e-05, + 2.2621518051178686e-05, + 3.3820810315839816e-05, + 0.007629929362896941, + 4.62165565302197e-05, + 7.083136365453295e-05, + 1.6867752071647554e-06, + 0.007158975274909028, + 2.3365918073951653e-06, + 0.006691148114714365, + 1.8160182746121535e-05, + 8.119893134280176e-06, + 1.951610783233207e-05, + 4.794687006752578e-05, + 7.097168045875709e-05, + 2.529100990073698e-05, + 1.0025578146460832e-05, + 0.006330940003646736, + 1.914398375550642e-05, + 7.405308840517132e-06, + 4.2254995780583525e-05, + 0.0031233784413476104, + 1.992624250485789e-05, + 2.1432104694935766e-05, + 7.142381266046672e-05, + 3.9008191727962326e-05, + 0.00010016745206491854, + 0.009083110322041153, + 9.155010186532908e-05, + 4.351836384074313e-05, + 0.00014331101054724154, + 9.297493441906668e-05, + 0.0001581423678117155, + 5.128940535339805e-05, + 1.2029221063479777e-05, + 7.861658049290633e-05, + 0.009849147660169047, + 4.2143961054239465e-05, + 0.00010202137810034909, + 4.5377225727068476e-05, + 0.00010429519486518364, + 4.324578616775226e-05, + 0.0005189204241672527, + 4.231651410967184e-05, + 1.0605426200807425e-05, + 4.5049929939845996e-05, + 9.413567699746329e-05, + 1.380184495252424e-07, + 6.865750563308246e-05, + 5.7243482353636986e-05, + 0.002314784955476499, + 5.392157334207365e-05, + 2.47563889274485e-05, + 2.467467834180957e-06, + 1.5766822889265075e-05, + 1.590347727310638e-06, + 2.2944254966470916e-05, + 0.0014219585134118678, + 0.005835945780210611, + 0.005215496332165455, + 0.0020350525021958785, + 1.4573046498807523e-05, + 0.005903640664409296, + 0.0044026206126353655, + 0.007118970625743312, + 0.0001406914175397761, + 0.004809264790915783, + 1.0180586134528515, + 0.003773876249747763, + 2.5283835845936842e-05, + 8.181167154527567e-06, + 3.683536136168756e-05, + 5.0087594202736606e-05, + 2.8684972057005484e-06, + 5.259205737729365e-05, + 0.008694167441570979, + 4.2537623301663954e-05, + 5.6189019332360594e-06, + 0.0024160246204003987, + 2.398559145833957e-05, + 7.358615837206509e-06, + 3.269166597623609e-05, + 1.8323805044617538e-05, + 5.168247156296229e-05, + 4.279874378483436e-05, + 0.006810501117304453, + 6.547496387070687e-05, + 4.862023104542222e-05, + 4.0123999081499147e-05, + 8.073755821739811e-05, + 7.661734569325919e-05, + 4.548301416806034e-06, + 0.00013666632960500865, + 3.1424659084850304e-05, + 7.705892301173354e-05, + 0.0001423670210546449, + 0.00010264068062069862, + 8.85326354907516e-05, + 4.837751437608723e-05, + 2.1516653637500003e-05, + 5.7681226031826427e-05, + 5.950574219013195e-05, + 0.0001055661057078594, + 3.293840406858189e-05, + 3.0768169071865856e-05, + 0.005221264934321769, + 0.003566473707317041, + 0.003614653284985154, + 0.007559658489312481, + 0.015694012931671365, + 0.00224369175698486, + 0.009118215936367427, + 0.0017603968215497067, + 0.003501122986141881, + 0.008105714809448456, + 0.006834344870539171, + 0.0014219585134118678, + 1.3467076728030982e-05, + 0.00015990344757346706, + 1.0251676266438782e-05, + 5.597548049290373e-05, + 3.160726188317129e-06, + 1.3433271666820882e-05, + 3.8611487076955e-05, + 5.208940248579786e-05, + 0.00010829417935510544, + 4.581627553562489e-05, + 3.7911742073489405e-05, + 5.09326705826915e-05, + 1.0003144202198913, + 0.005603989538199428, + 5.3873092159245e-05, + 9.478196456125603e-05, + 0.003514649711063711, + 5.52110992687459e-06, + 4.812960853350476e-06, + 1.0436275612713423e-06, + 1.5202867029995339e-05, + 3.9574365777364284e-07, + 1.719028176153091e-05, + 1.274185590414587e-05, + 1.6007448693199368e-06, + 0.0013524119124650137, + 1.083030484391954e-07, + 1.286742358858376e-05, + 1.2569418638884622e-05, + 3.1283205561362908e-06, + 4.948738034557916e-06, + 4.64572228654459e-05, + 7.236902666097318e-05, + 2.2427517869522524e-05, + 4.1328595096240814e-05, + 6.343447748240056e-05, + 1.5676400112376638e-05, + 1.7404626310910644e-05, + 3.122237635000989e-05, + 4.413367626682505e-05, + 1.9635237808574706e-05, + 0.00855284750328267, + 5.6265324282509934e-05, + 0.003516730555426826, + 1.5901806361230987e-05, + 3.1424659084850304e-05, + 1.992624250485789e-05, + 3.272912969732364e-05, + 8.61084221273961e-05, + 6.511645296408814e-05, + 6.911311528819053e-06, + 0.009151840802452679, + 0.006803726876170835, + 4.5865172442288695e-05, + 7.365929642574257e-05, + 5.966011299312112e-05, + 6.304818718883307e-05, + 2.1655730003934487e-05, + 1.1621207799905132e-05, + 2.7073737897301418e-05, + 3.8941321970515616e-05, + 3.689614821820535e-05, + 2.2086846522067662e-05, + 4.129705794276378e-05, + 1.9452907879640914e-05, + 3.709196423785288e-05, + 0.0025021376078974, + 0.004193048518656666, + 2.6451525648099112e-05, + 9.513935743872953e-05, + 0.007525119344665386, + 0.00012090014934069268, + 0.00571553669088225, + 5.7475994530403656e-05, + 0.0013346887928212846, + 0.005471422643999203, + 0.007214311791655111, + 0.0011618057425408913, + 0.007812569537828521, + 0.0029778643265331926, + 0.006714025703901893, + 0.0011608902738247868, + 0.004095080169476463, + 0.006021015435910667, + 0.004094639868977095, + 1.0002535656443527, + 0.007029917261468195, + 6.526940843802335e-05, + 3.3864510266791785e-05, + 7.474339543658002e-05, + 2.7642468420145466e-05, + 8.453434392048e-06, + 4.431658039795528e-06, + 5.214824211776975e-06, + 7.623227138481154e-05, + 0.000553497892180952, + 8.130561009949154e-07, + 1.5070953927305015e-06, + 5.144251287968885e-06, + 1.3780010086691152e-05, + 5.414460890939888e-06, + 8.159669202728204e-06, + 7.088415884733152e-06, + 0.0011279691886657696, + 3.5019940290114174e-05, + 8.052582566310962e-06, + 0.00011214618521792638, + 8.100221253346378e-07, + 4.4724072133743586e-05, + 1.103134707835397e-06, + 0.00015054319828436234, + 3.20055874953058e-05, + 0.00012069185503087766, + 0.007589957624907277, + 1.2767150636099418e-05, + 5.276511670132932e-05, + 0.015956462186832294, + 0.006532895409013626, + 0.00795786731176502, + 0.0009234583894543225, + 0.007715697260558262, + 0.0018410580341127881, + 0.008406326448191252, + 0.0016311467511667876, + 0.006740073564627112, + 0.008032634006271282, + 2.6714321060972634e-07, + 1.817098185835928e-05, + 5.464070852933514e-06, + 3.108609273131704e-05, + 3.3996998096963766e-05, + 0.009300587252411117, + 4.146895381538172e-05, + 8.40175663732779e-05, + 4.488390245325977e-06, + 9.936512573515954e-05, + 2.1595110644548335e-05, + 0.004094639868977095, + 6.934688987924458e-05, + 0.008467305956396259, + 2.5296822458611236e-05, + 0.007255646153887324, + 1.858511569018207e-05, + 4.352960566006824e-06, + 1.8500337692731853e-05, + 5.322016823308476e-05, + 0.00014935807139830338, + 5.666986257986792e-05, + 9.054949682981293e-05, + 7.16441690773409e-05, + 1.000275395407536, + 5.09326705826915e-05, + 0.007719854747045573, + 7.419416670917138e-05, + 0.009014740192242751, + 4.8084221300370924e-06, + 1.843783095389692e-05, + 1.8221410812353872e-05, + 1.777519615716201e-05, + 1.877302672780624e-05, + 4.107847715552589e-05, + 3.63114731874677e-05, + 1.4482501638671528e-05, + 2.141230278799636e-05, + 8.572392299435928e-05, + 3.9934496549270716e-05, + 0.004934645058048987, + 0.00813513284380525, + 5.9923237944393764e-05, + 8.294525405860026e-06, + 2.6203882320019604e-05, + 5.669926894785835e-05, + 1.4570802453701416e-05, + 5.988673040886737e-05, + 1.839517068585072e-05, + 1.0439763834962318e-05, + 1.1519857580317528e-05, + 0.0012684392689259717, + 1.2510973873916954e-05, + 0.0019700424201241754, + 7.582184626453817e-05, + 7.501128852404918e-05, + 2.321148905500842e-05, + 5.887316971243261e-05, + 0.008222564658297488, + 2.534535230410747e-05, + 0.009809863027986832, + 0.009127873853865254, + 0.008073456212003685, + 0.008334515044103877, + 0.00883762015458032, + 0.007973859332807587, + 6.783584304793724e-05, + 3.4421275378160735e-07, + 4.485651296957946e-05, + 2.8032026778863344e-07, + 0.0019337748315410668, + 3.779260422389367e-05, + 5.31320982239297e-05, + 6.381972097879172e-05, + 3.537073978440055e-05, + 0.005804125652252279, + 4.280316431475197e-05, + 2.1595110644548335e-05, + 0.006021015435910667, + 0.00011241173024402446, + 3.627360518329618e-05, + 0.007507237381039352, + 9.10611133788154e-05, + 0.0001035434114937968, + 3.0625251536410894e-05, + 0.00010091988110382644, + 1.2031158987471699e-05, + 1.7007876674383676e-05, + 0.006834344870539171, + 2.2944254966470916e-05, + 0.009864768684482637, + 8.688208808112132e-05, + 0.00013652022364646203, + 8.366686264344738e-05, + 4.279985052176947e-05, + 1.1285596254064168e-05, + 0.00022212792443789914, + 0.0030008506551227453, + 0.008813855862781005, + 0.003047843274389201, + 5.699201280114511e-06, + 4.848704502905711e-05, + 0.0064067636604403086, + 0.0055860723141447684, + 3.5152894511271435e-05, + 0.007505476440510395, + 8.319739106311735e-05, + 0.00010981446149796692, + 4.7269354886358105e-06, + 0.00010448432381559467, + 2.2821029286700005e-05, + 2.5786673808607915e-05, + 1.000543071106035, + 0.00589213577782564, + 4.1662899268953135e-05, + 2.132797269703622e-06, + 0.007058824446817216, + 5.481084580463887e-05, + 4.5190161299316886e-05, + 7.190953694790406e-05, + 8.461744813480758e-05, + 0.00013449665841190302, + 7.395084545201742e-05, + 7.642218699679069e-05, + 1.594467635630258e-07, + 8.574514082806994e-05, + 0.004871900036639932, + 8.44689701773998e-05, + 1.6112585805222823e-05, + 6.324948152687383e-08, + 0.004448178781097971, + 1.7404626310910644e-05, + 7.490029829638944e-05, + 2.7897221652101157e-05, + 0.00010372821586498543, + 0.009530370211735932, + 7.666284096464855e-05, + 4.18825353448943e-05, + 0.00010345871344829712, + 3.2669094648244773e-06, + 0.00010548489137167106, + 7.806830397465771e-05, + 0.007404914265770819, + 8.805908936468158e-06, + 5.803857831012882e-06, + 1.4148013360018128e-05, + 3.019698382825305e-06, + 3.4841133653436712e-06, + 0.008750829676035217, + 4.2143961054239465e-05, + 0.0001088050593768327, + 0.00010779998862338913, + 8.445107658541375e-05, + 8.543183096335565e-05, + 6.936458064177405e-05, + 0.008659453264464056, + 3.120558757653484e-05, + 0.004533179197600133, + 3.004152528081633e-05, + 7.860681144132016e-05, + 6.242079514647868e-05, + 0.00011293821770791351, + 0.00015398277994120403, + 0.007125817969637223, + 0.0082645365245498, + 0.01169005897156178, + 0.0005409447801154472, + 0.0032229912057087124, + 0.00826115681055757, + 0.0034405225796962364, + 0.005204560921393831, + 0.0065922905508567185, + 0.0028683464195861283, + 0.007219324060662954, + 0.008222564658297488, + 0.003131018813857472, + 0.008315295754634805, + 5.841394323541241e-07, + 5.88847363590114e-05, + 8.651694171316354e-05, + 7.398325825980472e-05, + 0.0001284645428770314, + 1.9635793154361086e-06, + 2.058832098831185e-05, + 6.6127942078603766e-06, + 7.16441690773409e-05, + 3.7911742073489405e-05, + 0.0002642212429301426, + 4.2655792352873584e-05, + 4.119423434434955e-05, + 0.00013392696754589646, + 2.9204211939985304e-05, + 5.8641039681199165e-06, + 5.855432409621465e-05, + 0.0001502896301746381, + 3.689155146280462e-05, + 1.8660644278303113e-05, + 3.2699517481831474e-05, + 1.0005539499928202, + 0.003847059050273734, + 9.45527466148835e-05, + 0.00391967740274463, + 1.1461727965227623e-05, + 9.075276578589366e-05, + 0.0047951923711135385, + 4.498148682255461e-05, + 4.750657303075888e-05, + 3.3820810315839816e-05, + 4.918019805390054e-05, + 2.1796536959262597e-06, + 9.908776278140068e-06, + 4.333016980302816e-06, + 2.4093961985278423e-06, + 0.00011464695819708957, + 3.9953097404302765e-05, + 0.005562525093049638, + 9.862047675441458e-06, + 1.2380803640812112e-05, + 5.314728789067926e-05, + 2.562502621448758e-05, + 4.88493666609293e-05, + 5.5854783266968745e-05, + 6.77279581052288e-05, + 8.557631805263534e-06, + 1.1931230595413092e-05, + 6.619848851781917e-05, + 0.004213442564747276, + 5.018358904242168e-05, + 1.1026494536511072e-06, + 4.3880021412216516e-05, + 2.436312083575389e-05, + 4.928443982842512e-05, + 6.735818788402423e-05, + 0.006047231430546131, + 0.00408344249254145, + 6.442624923415236e-05, + 4.9810654609521915e-05, + 6.373008761573134e-05, + 1.959416426729882e-05, + 0.01165854614591907, + 0.0082483715939574, + 0.005454660455186017, + 0.00784335809733372, + 0.005760547974782387, + 0.008434198729491096, + 0.005892857278628511, + 0.0054098623552808365, + 0.005825670528245169, + 0.007125817969637223, + 0.005221264934321769, + 5.9320029439863275e-05, + 2.628279587583401e-07, + 7.454297128879022e-05, + 2.1404205094684842e-07, + 5.6973288496865745e-05, + 9.20890698185028e-05, + 8.76974162781124e-05, + 3.926594144929374e-05, + 4.280316431475197e-05, + 9.936512573515954e-05, + 0.004095080169476463, + 0.000114720592022372, + 0.009326835203001295, + 1.8417197291495864e-05, + 0.0013789509831549367, + 4.4290465341956033e-05, + 0.0013262776517449749, + 7.964997756107978e-05, + 1.0572160482083514e-05, + 1.5799611749605832e-05, + 3.7121389807687816e-05, + 0.006311483244382031, + 0.00014456637776158663, + 1.0352222185209052e-05, + 0.0072258859519244495, + 1.0003156453417406, + 0.0019747358368568304, + 0.00793893361762072, + 6.176049961778198e-05, + 4.005987306107562e-05, + 8.943649925289279e-06, + 3.369506848055413e-05, + 0.004710837294839253, + 3.9686777895044975e-05, + 1.3736242288739475e-05, + 5.458421368513962e-05, + 0.006195682247786596, + 6.129640226876825e-05, + 3.539059879489178e-05, + 3.47873892853305e-05, + 1.1519857580317528e-05, + 6.956014306610032e-06, + 0.0007520202876280246, + 7.868933400378229e-05, + 3.807858887188459e-06, + 4.543184892775909e-06, + 7.227804363621828e-06, + 7.000542902825968e-06, + 8.031746833525979e-06, + 5.5480085827694036e-05, + 4.7380954835658765e-05, + 1.2695145626776906e-05, + 4.909709825223077e-05, + 0.005511413361947338, + 2.4324983724006634e-07, + 1.4090856331832103e-06, + 1.649098475312688e-06, + 6.861453876372358e-07, + 7.863280354198881e-07, + 2.8074432059582885e-06, + 2.2152551541613593e-06, + 0.00018927640511463451, + 8.895582859343049e-07, + 3.5530845401021354e-06, + 5.314382935454645e-05, + 0.003988215269240574, + 0.00010672287848834117, + 0.005492684933484426, + 0.00014991626842961953, + 0.00415774313581574, + 0.008064959461052453, + 0.008659453264464056, + 0.007589957624907277, + 0.001682110924335416, + 9.067980198600438e-05, + 2.052195184514316e-06, + 5.267454634504788e-05, + 3.996606173962012e-05, + 8.942891187852903e-06, + 6.895434020954211e-06, + 0.009874079931003811, + 9.369045968381743e-06, + 8.382334225368937e-06, + 3.3215104390041955e-06, + 1.5398702046158918e-06, + 5.880937526079813e-06, + 1.0001554837903515, + 0.007908396123318565, + 5.386498799229628e-05, + 8.54482043585373e-06, + 6.360723619574272e-06, + 9.317462688392536e-06, + 3.356777733560644e-05, + 0.004828100933283703, + 3.2901582192803755e-05, + 4.585871273468841e-05, + 5.934792435440277e-06, + 1.953667039460254e-05, + 3.4603896728465273e-05, + 3.16864353202332e-06, + 4.154972671783279e-06, + 0.00048644854934731753, + 4.014886379571267e-06, + 4.783186967344497e-06, + 3.658505363849941e-05, + 3.232509725475268e-05, + 4.156106397999411e-06, + 9.853135724398703e-08, + 0.0004915262872471038, + 0.009262863782751712, + 0.0009509364771072949, + 0.0058645951237479765, + 0.00829695684417064, + 0.008106382247233694, + 0.009276745414995192, + 0.0077722776138475, + 0.006597636404530838, + 1.0000237879905225, + 0.005018402425556384, + 0.00706549802282827, + 6.51473398838025e-05, + 5.478106217644566e-05, + 4.202569748398294e-06, + 3.990835206191733e-06, + 1.049107635947085e-05, + 9.526712031344487e-05, + 4.552346662069953e-05, + 9.293417333806772e-05, + 4.750657303075888e-05, + 1.877302672780624e-05, + 2.147224746167066e-05, + 2.9990147075282934e-05, + 0.005850778163732161, + 2.055840385903111e-05, + 6.0060345185960196e-05, + 6.444748122258493e-05, + 2.4771419462574535e-05, + 1.3621500339103099e-06, + 0.0013096420345198375, + 9.563744905355311e-06, + 1.3926506083939243e-06, + 9.64519742464365e-06, + 7.142381266046672e-05, + 1.0786968122519265e-05, + 0.009924221952596258, + 1.6298167845171424e-06, + 1.9067817376664148e-05, + 2.9750955246120755e-05, + 0.00298039332094451, + 1.8656782760597722e-05, + 1.1752268666632123e-05, + 3.8907724284033985e-05, + 8.884186737477239e-06, + 0.006037553521700404, + 0.0008118108024197676, + 0.0017900443001192285, + 0.003607489004396031, + 0.0007179782566983814, + 0.009983239643101386, + 0.007382232899732989, + 0.006850510061810733, + 0.0027436258125378976, + 0.008189686869970838, + 3.316459337939621e-05, + 0.0017614905000378658, + 0.00215782461676853, + 1.6457045280624036e-05, + 0.00012218969694670703, + 0.0037919118349826818, + 1.0177223023903816, + 0.008064959461052453, + 6.936458064177405e-05, + 0.00012069185503087766, + 5.0340873321860937e-05, + 0.00011307173467956233, + 1.5169365522255912e-06, + 4.2505389300810915e-05, + 6.661613518538756e-05, + 1.7431546902319922e-06, + 5.481084580463887e-05, + 5.2504102984330765e-06, + 0.003230710684057512, + 5.652742040649498e-05, + 4.333016980302816e-06, + 2.6203882320019604e-05, + 1.6709407581142358e-05, + 1.6194195528969006e-06, + 1.8504975325063464e-05, + 8.37663585323914e-06, + 5.934792435440277e-06, + 4.97397276280948e-06, + 3.9045702490191184e-05, + 4.170074180386796e-05, + 4.953655337972678e-05, + 2.2149089869145255e-05, + 5.3235186612166245e-05, + 7.084291599007136e-05, + 9.830265710848967e-05, + 6.89877122653197e-05, + 2.0303929538564436e-05, + 8.257332596159574e-05, + 0.0078036394547676404, + 1.4997326509518679e-05, + 0.001254912207654518, + 0.008480512053198986, + 1.5901806361230987e-05, + 2.0400045701197958e-05, + 5.913696972297344e-05, + 5.5649786206448084e-05, + 7.238555613669371e-05, + 9.64519742464365e-06, + 6.094138202063724e-05, + 6.301974197764083e-05, + 0.008918644968355796, + 0.00010264068062069862, + 0.012865204471301449, + 0.00040951532149479774, + 0.003262568127085023, + 0.007320563611416953, + 0.008980663561578098, + 0.002246202067281234, + 0.005543813403275388, + 0.01574616148972817, + 0.009526728664990757, + 0.002532528169657162, + 0.0074307455469537894, + 0.0012815068139153654, + 8.163737875101414e-05, + 4.0346791468329965e-05, + 1.4663526011589675e-05, + 5.345428422257456e-05, + 4.0924344042050054e-05, + 4.6504964415883905e-05, + 1.8761291921232777e-06, + 4.376687482265514e-05, + 0.004851393663705584, + 4.413969271119868e-05, + 6.289543888777127e-05, + 3.586343427183496e-05, + 8.654641647049102e-05, + 0.008592458769033464, + 4.356112667058918e-05, + 0.00013146806430429055, + 1.0004190150021024, + 0.004809264790915783, + 0.00930010985615086, + 6.222207450410723e-05, + 0.003520165825018783, + 9.03558246672859e-06, + 2.1787544078622775e-05, + 4.221448294680072e-06, + 1.0481439960144256e-05, + 2.7583452473090147e-05, + 3.082805406460417e-06, + 4.470429515463049e-06, + 0.0021123970544425484, + 4.445366420884142e-05, + 1.594467635630258e-07, + 3.0453043375824447e-06, + 0.0030457536628856843, + 7.358615837206509e-06, + 7.288720745849373e-06, + 0.0031276072742181596, + 0.0025955043327308257, + 1.3142350549209993e-05, + 4.892233214493144e-05, + 1.7393470899108238e-05, + 2.1430325576489996e-05, + 5.15076415312748e-05, + 6.85439791623251e-05, + 0.008172434288961817, + 5.545703057791173e-05, + 6.89877122653197e-05, + 2.529100990073698e-05, + 5.6017542851683475e-05, + 4.266113161881524e-05, + 1.7160912740953665e-05, + 0.001344901064955023, + 3.398949873757143e-05, + 4.6518092916010685e-05, + 0.007620250945392171, + 4.699549064728338e-05, + 7.370596526041767e-05, + 3.066706376961309e-05, + 0.0056379696535372795, + 0.008482307511236168, + 3.5530845401021354e-06, + 0.00012032027402574883, + 6.902350664223597e-06, + 1.6306202238306393e-05, + 4.100952759170509e-05, + 0.0009201478342575923, + 2.7100601453882536e-05, + 2.6194607769450517e-05, + 0.0033159955720434213, + 0.005102547594472177, + 0.003043158741887113, + 0.007275297032222334, + 5.688094456474576e-05, + 7.979623164228452e-05, + 6.0430188781166103e-05, + 3.667290377192227e-05, + 0.00010056316074184729, + 7.807000346171727e-05, + 0.00010504777710321347, + 1.71528140695156e-05, + 0.00016966285388558808, + 4.8675343537910945e-05, + 5.233154862039399e-06, + 6.841527427324271e-05, + 4.798729591851256e-05, + 2.5844655406679966e-05, + 0.009360155982221886, + 7.854924150935622e-06, + 1.2737606264021523e-06, + 1.4874198614900185e-05, + 0.00557935728804668, + 0.008832053506273614, + 1.0003077707693604, + 3.926594144929374e-05, + 0.005804125652252279, + 4.488390245325977e-06, + 0.0011608902738247868, + 6.85314599261555e-05, + 0.008744145541964786, + 8.154231257388808e-05, + 4.1856189126207785e-05, + 2.7089114924897626e-05, + 5.706019083774347e-05, + 4.445366420884142e-05, + 7.236902666097318e-05, + 5.747989602628534e-05, + 0.007316043405194684, + 0.00010816771859609541, + 5.314728789067926e-05, + 3.085198020461461e-05, + 3.499529266183106e-05, + 2.401893992812954e-05, + 1.7230684945129012e-05, + 6.982511354897124e-05, + 6.226152553836605e-05, + 1.6888929301382213e-05, + 3.745663236051577e-05, + 7.431313644927198e-05, + 5.079816090900735e-06, + 3.117548029508032e-06, + 3.0856925473438306e-05, + 2.2756773597648387e-05, + 0.005638980724112857, + 0.007773325140821933, + 0.007938956551945167, + 0.003242508738519706, + 0.0075773494450229375, + 0.004418490344777326, + 0.009065125655137866, + 0.009782309454680381, + 0.0031757414411978605, + 0.004300984806407466, + 0.008664274028987562, + 0.0011313593767402364, + 0.009849147660169047, + 0.0025523243434428344, + 0.0044510452107628835, + 4.988319262381871e-05, + 4.055292891554118e-05, + 1.9073452472447576e-05, + 9.490674478102146e-05, + 0.006889523406357306, + 0.007219324060662954, + 5.887316971243261e-05, + 0.00010865683469747918, + 2.78444326678576e-05, + 7.564088304664701e-05, + 0.00011723158728588356, + 3.5625642103399774e-06, + 4.376687482265514e-05, + 0.009116386897353035, + 7.128019767737525e-05, + 0.00013616695276437934, + 1.6958464549274786e-05, + 0.007944636963792108, + 5.002017546540117e-05, + 0.00010459660272650717, + 0.009636119219212608, + 8.13393389642432e-05, + 2.6870034435190565e-05, + 1.0004047736401767, + 0.0034911392760475354, + 0.00013379945568627112, + 8.186621732546018e-05, + 5.403445097854669e-05, + 6.883962337457583e-05, + 5.281082680604117e-06, + 1.0003977443525997e-05, + 7.474339543658002e-05, + 3.2533800384630557e-05, + 5.023417761546015e-05, + 2.3477716972446635e-05, + 4.3451375820987274e-05, + 0.0070778397836248255, + 3.8744548382065554e-05, + 4.810990280897296e-05, + 3.1610493407164625e-06, + 1.5889218365970699e-06, + 4.5311896319640864e-05, + 0.008911991690964146, + 0.0068864505226439, + 2.3781942172827e-05, + 1.719028176153091e-05, + 9.548755468020766e-05, + 5.731589450935227e-05, + 0.000145030445193013, + 0.00010816771859609541, + 2.452345987381312e-05, + 0.014405048700368052, + 0.008918644968355796, + 0.00710973449326894, + 6.4177551223725635e-06, + 7.060536541393035e-05, + 5.73502575314267e-06, + 7.760430092050088e-05, + 5.896737874814423e-05, + 5.472011340191899e-05, + 7.853535375098192e-05, + 8.901347096340515e-05, + 0.008189686869970838, + 0.0063204791660593125, + 3.7779296004229136e-05, + 0.00015788936748717885, + 7.092654206774545e-05, + 4.89366368790601e-05, + 3.669353473460797e-05, + 4.7459302796212956e-05, + 0.005825670528245169, + 0.00015398277994120403, + 2.7271073892822847e-05, + 4.808848753479633e-05, + 4.101264839737831e-06, + 1.3592364534603364e-05, + 2.279851190786204e-05, + 2.545741842614761e-06, + 0.00013713865786819753, + 3.089131374698755e-06, + 3.5406938460700636e-05, + 1.0003688756664544, + 1.7007876674383676e-05, + 0.008105714809448456, + 1.590347727310638e-06, + 0.008016194859820336, + 4.163593054971914e-05, + 7.475390977604764e-05, + 5.023417761546015e-05, + 0.0026360543980688145, + 5.629750213349031e-06, + 7.944851687717692e-06, + 7.131101283954011e-06, + 5.2465533659413894e-05, + 7.627186117384875e-05, + 1.0222702906452622e-05, + 7.238555613669371e-05, + 8.749361914559068e-05, + 1.2511572762084668e-05, + 1.2234782130969098e-05, + 9.324987802129278e-06, + 2.1402630556665295e-05, + 1.2594651748272449e-05, + 0.002518284793421295, + 7.44429777262454e-06, + 0.0019505472223636333, + 0.0014745260047490116, + 0.006037553521700404, + 7.710549309795944e-05, + 5.400377972758566e-05, + 2.2056768611094835e-05, + 0.00652056301061857, + 3.005623947511771e-05, + 6.161934999922442e-05, + 1.851882951395248e-05, + 6.542968016277152e-05, + 6.938926754019389e-05, + 7.695933612238808e-06, + 7.861658049290633e-05, + 1.736187378464362e-05, + 8.544810389600539e-05, + 3.681826033099115e-05, + 6.785098793438811e-05, + 6.172582231664433e-05, + 0.0001226963844664554, + 6.415363463656095e-05, + 0.007275297032222334, + 4.735984999341235e-05, + 7.6171374432633975e-06, + 1.3632792315744896e-05, + 8.927093181596704e-06, + 6.478983772859016e-05, + 2.1376951580614815e-05, + 0.009676960075387354, + 1.849718928212902e-05, + 1.0002779240850257, + 0.006889523406357306, + 0.0028683464195861283, + 2.321148905500842e-05, + 8.714215975638049e-06, + 2.3321140638181313e-05, + 3.52533981816771e-05, + 3.4306264474122114e-05, + 0.001232839274524128, + 4.706223389482264e-05, + 2.1638565938509677e-05, + 9.671370476470335e-05, + 4.8643705562024125e-05, + 2.6109734895727233e-05, + 1.3736242288739475e-05, + 1.484422174725565e-05, + 0.005453446633799271, + 2.3242003711048557e-05, + 1.741084018960257e-05, + 8.738491375979277e-06, + 1.9299368127396475e-05, + 1.6946522582387045e-05, + 0.002988631887868677, + 0.0037110609109953898, + 0.005695212786820327, + 0.008459663950100319, + 0.002681107746571281, + 4.662078208548067e-06, + 5.699395700018925e-06, + 1.990714084779318e-05, + 1.847328180131288e-05, + 8.901347096340515e-05, + 0.0027436258125378976, + 2.9019803498547727e-05, + 2.700232458322728e-05, + 2.0646085382212123e-05, + 0.009813729259187031, + 2.614368819921816e-05, + 1.71528140695156e-05, + 2.6451525648099112e-05, + 6.965275646704858e-05, + 6.607100977039375e-05, + 7.923441900497486e-05, + 9.019246741974433e-06, + 0.0001783375337444304, + 6.752494369555874e-05, + 1.310240486264126e-05, + 0.008032634006271282, + 0.00010760530953880158, + 5.987655235048369e-05, + 5.50711807066434e-06, + 0.00013417932789838304, + 6.479496401931944e-05, + 0.002954714475054873, + 3.2475583311200885e-05, + 5.238104174226221e-06, + 9.334297135713388e-05, + 0.0030008506551227453, + 0.004073822791191404, + 7.639022655726693e-05, + 5.2769736697683524e-05, + 0.0034227338913006555, + 2.3174984669763992e-05, + 0.007925813749040412, + 3.750389361508163e-05, + 1.6582000373062033e-05, + 7.528097178324361e-05, + 7.669424770295681e-06, + 4.662805809938742e-06, + 8.102003010137707e-07, + 2.3376055606366328e-05, + 1.0002503655015804, + 0.0072258859519244495, + 0.0030972922175133, + 5.848653372189761e-07, + 1.7920640048420202e-06, + 4.762214563038365e-07, + 1.3348925708514831e-06, + 4.302624219575653e-07, + 7.494947992189717e-07, + 1.1148407990794493e-06, + 1.1992982759795414e-05, + 0.004357343568433076, + 1.8808918578478595e-05, + 2.141230278799636e-05, + 3.655322791892029e-05, + 3.426856622257189e-05, + 1.920766372314651e-05, + 2.410980125288674e-05, + 0.00713900933396598, + 8.052582566310962e-06, + 4.862023104542222e-05, + 2.973840254558375e-05, + 0.0002330089418659586, + 3.4185747076641285e-05, + 3.5817131940039534e-05, + 1.6125188709193586e-06, + 5.142917252934526e-05, + 0.004478441911544396, + 3.5472752645703684e-05, + 4.18825353448943e-05, + 2.348488155839762e-05, + 1.9579120926910124e-05, + 1.5939223154984972e-06, + 7.667920282896653e-05, + 7.186162010213901e-05, + 5.621054680408905e-05, + 5.330234599939667e-05, + 0.009963497689544864, + 9.795274955841379e-05, + 7.50989203964441e-05, + 0.0020341300219831504, + 0.00648503653023617, + 0.00782914362550076, + 0.00587733230650688, + 0.002923910238477404, + 0.00537362751138068, + 0.006523181202208075, + 0.005670327835012276, + 0.006685049011509828, + 1.0001886258980548, + 0.002988631887868677, + 1.2456287254784247e-07, + 2.6361602054917756e-07, + 0.006854405223712914, + 4.65911604680687e-05, + 1.538762457161008e-06, + 3.617988384313475e-05, + 3.942136473014121e-05, + 7.694523948548027e-06, + 5.035059539802786e-06, + 2.7545876117955095e-06, + 5.652742040649498e-05, + 8.294525405860026e-06, + 4.412902333975753e-05, + 6.401808159144565e-06, + 8.868053332557463e-06, + 0.0018340534860973967, + 5.732217749423728e-06, + 1.0291812167812526e-05, + 1.5676400112376638e-05, + 0.006243726979236103, + 0.0007991026022771701, + 0.0019808005861819576, + 0.009439959067106114, + 0.0013354308950555116, + 0.003925877503611112, + 0.005796324582018182, + 0.006162464895893152, + 1.106115656959078e-05, + 8.572705345464126e-06, + 4.998900482600028e-06, + 0.005005735433951281, + 3.0800189049306255e-06, + 1.0882148447506776e-05, + 4.920404084443367e-06, + 9.802407665341985e-06, + 7.695933612238808e-06, + 0.0011313593767402364, + 1.2029221063479777e-05, + 4.990940581764883e-06, + 1.5739800122089514e-05, + 2.9679459951328885e-06, + 6.0329364738038516e-05, + 0.00983724045435927, + 1.6037235818269438e-05, + 3.687809075046072e-05, + 0.009742433538967666, + 3.555021927781079e-05, + 7.853535375098192e-05, + 1.7099755476563073e-05, + 6.830114907139503e-06, + 0.0016040258767245185, + 2.266246567558815e-06, + 0.0037919118349826818, + 0.00415774313581574, + 8.543183096335565e-05, + 3.20055874953058e-05, + 2.1816080408894437e-05, + 3.749231695173124e-05, + 3.3007267523658666e-05, + 6.668280050031122e-05, + 0.001026103455904006, + 3.1987418151162497e-05, + 1.8606361438029243e-05, + 7.92758331939025e-05, + 2.5948670913940536e-05, + 8.43286912301128e-07, + 1.05857717104082e-05, + 6.43586700597802e-06, + 5.140845459602858e-06, + 1.0001044156480565, + 2.3376055606366328e-05, + 1.0352222185209052e-05, + 0.004275057037133662, + 0.0034534397792633023, + 7.66947463026765e-06, + 3.4278764461559064e-05, + 2.3781942172827e-05, + 0.00033545871412157813, + 0.0005468462075336555, + 0.00298039332094451, + 1.3598258892740924e-05, + 4.296992740599398e-05, + 3.8945017106828324e-05, + 1.9546483249476834e-05, + 4.31693251840473e-05, + 0.006685049011509828, + 3.1195312461147066e-05, + 0.01003009867110116, + 0.008459663950100319, + 0.005765427248372032, + 0.00011108092659027222, + 2.6302692348604317e-05, + 6.415363463656095e-05, + 4.3755520141460105e-07, + 8.949628991663872e-06, + 0.00015665184080786005, + 4.804107451422301e-05, + 7.790378110650544e-06, + 5.238644335009593e-05, + 6.842886526534604e-05, + 0.008832053506273614, + 8.76974162781124e-05, + 3.537073978440055e-05, + 0.006714025703901893, + 4.713844281200795e-05, + 2.988522877189406e-05, + 3.284174067021099e-06, + 3.331186062669915e-06, + 3.382565471615017e-06, + 3.5625642103399774e-06, + 1.8761291921232777e-06, + 0.00041322251086869325, + 1.6512283763228777e-06, + 2.6713893738560452e-06, + 8.629260269443107e-05, + 2.6797437391880606e-05, + 6.116235985298115e-05, + 3.336172852818558e-05, + 1.959778315481159e-05, + 5.752384109440578e-05, + 7.840140364717967e-05, + 0.006457783551165847, + 9.054949682981293e-05, + 4.581627553562489e-05, + 0.00817565329544597, + 0.0063393024704901345, + 6.309220182886564e-05, + 0.006382219318046553, + 5.9520335109750265e-05, + 4.810896760486375e-05, + 7.720124525653074e-05, + 4.7059955452611104e-05, + 5.583329608951207e-05, + 1.9269813166188358e-05, + 1.0003835897306816, + 3.2699517481831474e-05, + 0.008170787291719226, + 0.0001204369410194575, + 5.105886593647359e-06, + 1.4344908058887058e-05, + 3.4053751828548573e-07, + 1.78710524516326e-05, + 5.518628161876147e-05, + 1.8634392412703953e-05, + 3.2394319262609834e-05, + 1.8552101725878217e-06, + 3.401408920663357e-05, + 0.005622981904158817, + 7.174147412406096e-05, + 4.967058051043821e-06, + 0.009915476597542466, + 0.00013666632960500865, + 0.0010816938755075934, + 1.3926506083939243e-06, + 7.473978611656519e-06, + 0.0001087401656131354, + 3.8048334218202605e-05, + 0.006531871891578125, + 9.73683053803303e-05, + 6.039959268436595e-06, + 2.610848019012817e-05, + 4.0947561295588445e-05, + 4.0860568906730575e-05, + 7.511646879857002e-05, + 6.354986925006403e-05, + 0.004714008058034636, + 8.895582859343049e-07, + 4.5312749216232344e-05, + 0.009658027123380798, + 0.005894124979405421, + 2.7418689915131593e-05, + 5.5021419861820435e-05, + 0.0048535845820513075, + 0.0028935743279264107, + 0.00934538949869626, + 0.00408344249254145, + 0.006655999042995089, + 0.00013249423111395283, + 2.3587666620726074e-05, + 0.008487759100771796, + 0.009403452575118026, + 9.802407665341985e-06, + 6.938926754019389e-05, + 0.008664274028987562, + 0.00016526594818091914, + 0.009891145193876386, + 9.717628586914298e-05, + 5.4740304521921515e-05, + 0.00012679733007272525, + 0.00877995928880234, + 8.6638070301256e-05, + 0.006597636404530838, + 8.669584320980875e-05, + 0.0018705960191203576, + 0.00014399155572362174, + 0.0001246807859027139, + 7.30700720386402e-05, + 0.00011304389453428674, + 2.614368819921816e-05, + 0.00010504777710321347, + 0.00883762015458032, + 0.004193048518656666, + 0.006586798633828459, + 7.131459924188185e-05, + 0.011055507216417616, + 4.5797633600523134e-06, + 0.00010236722183861859, + 0.00013146806430429055, + 0.0001406914175397761, + 0.008526010875557077, + 3.224942461389203e-05, + 3.3593084677221634e-06, + 2.3911820891969514e-05, + 3.6191356626329917e-06, + 6.0660365159832946e-05, + 1.3640677423618407e-05, + 9.952230383561446e-05, + 1.0006292240898653, + 1.9269813166188358e-05, + 1.8660644278303113e-05, + 0.0024285342700700054, + 0.00010183618537375991, + 3.3857206954811586e-06, + 3.035721643280287e-06, + 2.3478257525078564e-06, + 8.453434392048e-06, + 4.968771746824327e-06, + 1.70842049509094e-05, + 5.744975875099374e-06, + 6.664276479027353e-06, + 1.9600997227302497e-06, + 1.8853793968401794e-05, + 2.875512039779854e-07, + 9.945503597024794e-06, + 5.068234755661218e-07, + 4.2994741473518604e-08, + 8.747730094430352e-05, + 9.92624527811888e-06, + 0.009927709865127338, + 2.398559145833957e-05, + 8.610593246983417e-05, + 5.663119294446125e-05, + 7.000542902825968e-06, + 0.007428312764656902, + 5.5649786206448084e-05, + 9.563744905355311e-06, + 0.00012240969635691026, + 0.011109083184725779, + 0.0068070609766084575, + 0.009015583601663752, + 9.19925473013565e-05, + 0.00042286073353053205, + 2.647290542189767e-05, + 0.0033100343649935427, + 0.006047231430546131, + 3.8941321970515616e-05, + 6.101829323367727e-05, + 0.004924228234314472, + 0.002007918983284649, + 1.1707850048249682e-05, + 5.890353781510846e-05, + 0.009403452575118026, + 4.920404084443367e-06, + 0.004300984806407466, + 0.008750829676035217, + 5.128940535339805e-05, + 1.0976407265594007e-05, + 0.0001730131989390535, + 2.6302692348604317e-05, + 0.0001226963844664554, + 0.003043158741887113, + 2.843055287948848e-06, + 9.171185102672263e-05, + 2.7758845583371817e-05, + 1.1253258306963982e-05, + 3.681470226756574e-05, + 5.481835722109314e-05, + 0.009349294168833915, + 7.245178783852634e-05, + 3.527685498118427e-05, + 2.6724663523493806e-05, + 2.8841903361718384e-05, + 0.0014978319467007927, + 4.35561991898656e-05, + 7.028971907680665e-05, + 0.00020232834080867164, + 1.2133601264377871e-05, + 2.5786673808607915e-05, + 0.012813625909626442, + 0.0010867090112958687, + 5.315905599966685e-05, + 3.7744090451044085e-05, + 7.774943916630372e-05, + 2.4967263474904864e-05, + 1.1796041331419004e-05, + 0.00403467118712389, + 1.0623499542258326e-05, + 0.00935065634121103, + 6.0942507176717e-06, + 1.4071215559756605e-05, + 1.0004218519602772, + 0.006124314870517229, + 0.0020986143266744518, + 1.4425087088570349e-05, + 7.582968560795405e-06, + 5.5673337197063254e-05, + 0.00944967063640076, + 3.2010750229393997e-05, + 5.8469634307341134e-05, + 1.8910845561383668e-05, + 0.009611182680216403, + 0.00010507947812848234, + 5.8064098366541744e-05, + 7.227804363621828e-06, + 7.339128572956441e-05, + 4.712760169925774e-06, + 6.279997697755538e-05, + 2.0880117819139736e-05, + 0.00011036325907642369, + 8.7581123233078e-06, + 7.37269460960388e-05, + 4.036902259548693e-05, + 8.2327661535784e-05, + 0.008398373248306222, + 0.007710383702448548, + 0.00814747827758538, + 0.005894124979405421, + 0.0009201478342575923, + 0.004092254801917959, + 0.009362403878072032, + 8.311017407393698e-05, + 0.00015183555325760058, + 0.007699851554496911, + 4.3088882703026115e-05, + 3.5918105428542704e-05, + 1.7753298709646568e-05, + 7.23500655525631e-05, + 0.009015583601663752, + 0.004213442564747276, + 7.806830397465771e-05, + 7.467161408604157e-05, + 1.6407079694044695e-06, + 7.007217650806319e-05, + 1.4313504055806974e-05, + 3.5011884286798186e-05, + 0.00017742194051728995, + 5.2766472087971785e-05, + 4.0365730413813014e-05, + 3.512428669001458e-05, + 1.0004028442802682, + 2.6870034435190565e-05, + 0.00790089919579962, + 6.807367336737874e-05, + 1.5309273798143577e-06, + 1.7199603304863812e-05, + 4.912466317868146e-05, + 5.636155674345554e-06, + 4.960478974867715e-06, + 8.569855998237978e-05, + 0.0024985379607832957, + 7.582968560795405e-06, + 0.009964003685006098, + 0.0011979513772529824, + 2.1511734531140814e-05, + 1.0291812167812526e-05, + 6.343447748240056e-05, + 0.0001594947964237924, + 4.852011383706507e-05, + 0.007329413538344493, + 5.895822008701363e-05, + 3.903353172128735e-05, + 8.780755167910766e-05, + 4.7595573412324026e-05, + 0.006649128264608228, + 9.795274955841379e-05, + 5.44501718787695e-05, + 6.124403934534732e-05, + 1.4892552717406243e-05, + 6.791867953427332e-05, + 8.085035701929519e-05, + 7.44429777262454e-06, + 0.0013328777498254356, + 0.003625097313221236, + 0.004318123334226994, + 0.004714008058034636, + 0.008482307511236168, + 0.00018927640511463451, + 0.007255851338711169, + 0.007790053939240377, + 7.308022435673637e-05, + 6.63684483593648e-05, + 7.144392268361971e-05, + 3.412817285756006e-05, + 9.283171180278325e-05, + 0.0054098623552808365, + 0.00011293821770791351, + 0.008806804007942875, + 6.224177478794206e-06, + 0.00018398308294319499, + 5.665925866907958e-05, + 6.265458442021338e-05, + 1.0994049097566663e-05, + 0.006740073564627112, + 0.005896520474143277, + 7.276064269692673e-05, + 0.00410196302462687, + 8.081471592653644e-05, + 4.9006522974493814e-05, + 3.7046042910373765e-05, + 7.792064738492659e-06, + 0.00010268918814354037, + 0.003003633597689924, + 3.5406938460700636e-05, + 0.003501122986141881, + 1.5766822889265075e-05, + 0.008643936765229692, + 0.005573949689002543, + 0.006554729173032643, + 0.00014836819241966453, + 0.00015854687935395274, + 1.2373222472231526e-05, + 9.334297135713388e-05, + 0.00022212792443789914, + 0.009640569433551922, + 9.175661661202585e-05, + 3.41674962668119e-05, + 0.0025456088283974092, + 0.003961812646855485, + 6.91575555913188e-05, + 0.0056954290527608375, + 9.731186228103503e-05, + 1.0005973513724646, + 5.481835722109314e-05, + 0.006615910659592654, + 2.7198580063679282e-05, + 2.656716793804512e-05, + 7.657450367907001e-07, + 0.0001585354537356698, + 3.9574365777364284e-07, + 7.91477008687552e-07, + 1.2513410853218346e-05, + 1.83301846932302e-05, + 6.603767343972547e-05, + 0.009498292054863657, + 6.472707200050332e-05, + 4.585871273468841e-05, + 3.843436658672674e-05, + 7.092098892430295e-05, + 0.00012167373322091522, + 1.2505689816741404e-05, + 0.009295247913139942, + 6.025817506004486e-05, + 2.8207005358445007e-05, + 2.6109734895727233e-05, + 3.9686777895044975e-05, + 0.00019557453083133506, + 0.005053902503785076, + 0.004926455754866431, + 0.0037547983552217367, + 0.0046012907750768986, + 0.008617980389554532, + 0.005071360807378818, + 0.002518284793421295, + 1.7334319453500232e-07, + 6.3632241538920716e-06, + 1.3307998776586948e-05, + 3.949787837533425e-06, + 1.7625297649508442e-05, + 0.003003633597689924, + 3.089131374698755e-06, + 1.2031158987471699e-05, + 0.0017603968215497067, + 2.467467834180957e-06, + 6.096919802748503e-05, + 0.008538605385254245, + 4.470787698074131e-05, + 6.18419543473045e-05, + 3.382565471615017e-06, + 4.6504964415883905e-05, + 0.007254780340154869, + 0.00014728026048875834, + 1.999352945584506e-05, + 1.9808276545164153e-05, + 0.004811970719232071, + 2.9853088250532845e-05, + 2.2837261326316132e-05, + 3.512428669001458e-05, + 8.13393389642432e-05, + 0.004507380604466488, + 3.8513269850336475e-05, + 4.816330275016268e-05, + 0.009821730370983375, + 2.1903716683254796e-05, + 6.244920472937696e-05, + 6.0194675001078164e-05, + 4.695475624562457e-05, + 4.27333714582164e-05, + 4.2287392648719884e-05, + 1.0820437241554723e-05, + 2.425848205412946e-05, + 1.01439085131741, + 1.4071215559756605e-05, + 0.0001841780532802329, + 0.007546820998713696, + 5.689189388216512e-06, + 0.005768832749769458, + 1.7916668586350402e-05, + 8.89251286687329e-06, + 1.035275889637705e-05, + 1.5211346445822785e-05, + 0.0026401284607189303, + 5.136316317798199e-06, + 1.4886813989585618e-05, + 9.286554580186971e-07, + 2.3553570961174583e-05, + 6.556057476266936e-05, + 5.179424309578726e-05, + 3.520187008799863e-05, + 5.895822008701363e-05, + 3.5472752645703684e-05, + 7.666284096464855e-05, + 4.2987315002756274e-05, + 3.5838112986402865e-05, + 3.503912963572349e-06, + 0.0005045514329730584, + 0.005574292792643197, + 0.005304731871977922, + 0.006044533045230626, + 0.004589697180653488, + 0.005511413361947338, + 0.00509972235949859, + 0.0005275661483209082, + 6.323381054764368e-05, + 8.274536257263668e-06, + 0.002360689141632851, + 5.458741613905111e-06, + 2.9750955246120755e-05, + 0.0011110333225029594, + 0.0001185655905667058, + 4.497861352315392e-05, + 0.01003009867110116, + 0.005695212786820327, + 6.373008761573134e-05, + 1.5200482383733676e-05, + 7.17937085081615e-05, + 3.652138838893042e-05, + 4.5579882391700233e-05, + 0.00815744384912862, + 0.0001268512726099513, + 8.6638070301256e-05, + 0.0077722776138475, + 0.0023218250123088584, + 2.6816888588111612e-06, + 1.9955252480012823e-05, + 1.7279945498281717e-05, + 6.600953573744792e-05, + 3.3409698001656547e-05, + 9.220435186640806e-06, + 0.0005756933364419036, + 6.052485692047022e-05, + 1.5696421917549157e-05, + 8.348550647548584e-05, + 1.0003106846527967, + 1.2133601264377871e-05, + 2.2821029286700005e-05, + 0.012006271154335118, + 0.0027052178017184657, + 1.2649299473656828e-05, + 5.7774606273442145e-06, + 7.131101283954011e-06, + 2.302150539269388e-05, + 2.1276079051268394e-05, + 2.243657506251215e-05, + 2.5151047401374303e-05, + 2.6479781054830162e-05, + 0.005614779437366768, + 2.108479944985597e-06, + 2.1569779244003335e-05, + 5.5549294698932425e-05, + 4.0225705652420965e-05, + 3.47873892853305e-05, + 1.0439763834962318e-05, + 8.7746997810561e-06, + 4.87111811559589e-06, + 6.052271248082022e-06, + 6.901220565399228e-06, + 7.794108624284254e-06, + 3.8655259029171693e-07, + 0.001080774936663883, + 4.7248459417462044e-06, + 0.0015357985919753874, + 0.006116514527944604, + 0.00028570917724010436, + 1.0000400120259487, + 0.007620250945392171, + 0.007847234151793583, + 0.009556394617234216, + 6.942689596137118e-05, + 4.258700237407619e-05, + 3.165157237555567e-05, + 2.2362468666237055e-05, + 5.981155540148864e-05, + 4.849876254314921e-05, + 2.7583452473090147e-05, + 9.177955235317567e-06, + 7.276203856300719e-05, + 0.002882958045542563, + 7.63198582473916e-05, + 1.7494555237466507e-05, + 2.170212323715844e-05, + 0.004325677183490168, + 2.4771419462574535e-05, + 9.824640203003823e-05, + 4.558479926457905e-05, + 0.007696421638836545, + 0.00725057399154552, + 0.005641947917987453, + 0.0040844313409666155, + 0.006649128264608228, + 0.009963497689544864, + 0.00011225674094685073, + 7.636203446290959e-05, + 3.1188552603485446e-05, + 8.713054812012184e-05, + 2.6185861521000763e-05, + 5.878795178602236e-05, + 5.890353781510846e-05, + 1.0882148447506776e-05, + 6.542968016277152e-05, + 0.0001581423678117155, + 5.298779824764253e-05, + 6.104874933017689e-05, + 1.0486260105233297e-05, + 0.00010733714305272089, + 3.952316376324563e-05, + 9.952230383561446e-05, + 5.583329608951207e-05, + 3.689155146280462e-05, + 0.014410087504995148, + 4.5559832168017325e-05, + 2.2764179043432686e-05, + 6.543058866391555e-05, + 3.430793407922378e-05, + 2.2837261326316132e-05, + 4.0365730413813014e-05, + 0.009636119219212608, + 0.005189010470211977, + 0.007887920773598681, + 2.8923941111746002e-05, + 0.0057750436745369355, + 5.1312749912381697e-05, + 0.0001805488747476753, + 4.497641852423167e-05, + 4.045190920950058e-05, + 0.003804170827353817, + 6.955184983029764e-05, + 2.1665009509667407e-05, + 4.2864901433654665e-05, + 1.0003829763539198, + 5.880937526079813e-06, + 0.00629538472814543, + 5.524170723711119e-05, + 5.321768311467811e-05, + 1.151237528350908e-05, + 8.831803944007171e-07, + 1.049107635947085e-05, + 2.2727801295909092e-05, + 6.664276479027353e-06, + 1.0481439960144256e-05, + 2.6075990744894606e-06, + 1.8520492490083216e-05, + 2.1793448813973866e-05, + 9.176872048322657e-06, + 2.116693775127853e-05, + 0.002313141822622935, + 2.200821759837018e-05, + 1.805138943886443e-05, + 1.3780010086691152e-05, + 3.1283205561362908e-06, + 8.464235497657132e-06, + 8.111616680886158e-06, + 2.4636259992210228e-05, + 0.0029471484685646876, + 1.4482501638671528e-05, + 2.4723271872059743e-05, + 0.0014970770754504084, + 0.0029935243072698762, + 0.0020874736505889233, + 2.983059461560402e-05, + 2.2622216737783084e-05, + 2.627011625477693e-05, + 5.312316031361682e-06, + 2.225316986181994e-05, + 3.102418440017793e-05, + 2.2283096906311314e-05, + 0.007495164151567807, + 0.008963041275584496, + 0.0010589697528595465, + 0.005221329997523486, + 0.008805068794976455, + 0.00983176233371314, + 0.008398373248306222, + 2.149929346326834e-05, + 0.0048489996336509, + 2.2912513589703315e-05, + 0.0040844313409666155, + 5.330234599939667e-05, + 3.061178252104105e-05, + 5.3005380202982966e-05, + 2.519599844706269e-05, + 0.0025612490314566227, + 1.877880444362138e-05, + 2.6583074685513483e-05, + 8.637677701681919e-05, + 4.268506539575916e-05, + 0.005071360807378818, + 1.2594651748272449e-05, + 9.64121073613786e-06, + 4.860647658428452e-05, + 0.0006170670814896797, + 5.5540199060968216e-05, + 0.005621853829576654, + 3.710823378319444e-05, + 4.957894886944058e-05, + 0.0027637787011062917, + 1.0001133734472036, + 9.283171180278325e-05, + 4.7459302796212956e-05, + 0.005892857278628511, + 6.242079514647868e-05, + 3.0768169071865856e-05, + 0.003949451860214621, + 1.0730957657725968e-05, + 3.0438108375714784e-05, + 0.00932536085802224, + 4.843570844089803e-05, + 4.8413826881802706e-05, + 7.475390977604764e-05, + 8.154231257388808e-05, + 4.1662899268953135e-05, + 3.4937391624894854e-05, + 4.794364658652151e-05, + 8.949778834480208e-05, + 0.009959454332578336, + 3.4278764461559064e-05, + 9.671370476470335e-05, + 0.006384550706521437, + 0.003837912559068474, + 0.0016826044433800413, + 0.009605685363234352, + 0.0010195254958027743, + 0.006531871891578125, + 0.001344901064955023, + 0.006803726876170835, + 0.003224498097106496, + 0.008630783726605808, + 4.3422810041187425e-05, + 3.2432119128314313e-05, + 2.2912513589703315e-05, + 0.005641947917987453, + 5.621054680408905e-05, + 2.430199355672523e-05, + 2.174789309648852e-05, + 1.0371090875917845e-06, + 0.0018398040804846942, + 3.9616146869272896e-05, + 2.2662814589453177e-05, + 5.679787494029275e-06, + 2.0904964629571314e-05, + 6.482136076334683e-05, + 0.002532528169657162, + 0.00011067717192639689, + 3.194862700383684e-06, + 3.244198568147392e-05, + 8.978547674713963e-07, + 5.9772051130068166e-05, + 6.893059851074438e-05, + 8.47381590041747e-05, + 0.006639242346381749, + 1.0003224726853233, + 1.7625297649508442e-05, + 0.00010268918814354037, + 0.00013713865786819753, + 0.00010091988110382644, + 0.009118215936367427, + 2.47563889274485e-05, + 3.118964717770214e-05, + 2.272185625473179e-06, + 3.3864510266791785e-05, + 2.357371016367183e-06, + 3.617988384313475e-05, + 1.4998249072389926e-05, + 0.005641913561175485, + 5.2689843753786996e-05, + 0.004030203448740924, + 0.002341990597880902, + 1.70170076060978e-05, + 4.302624219575653e-07, + 4.334605723171568e-05, + 6.045509972018361e-05, + 0.006157260534451727, + 6.444748122258493e-05, + 3.8701093554956196e-05, + 1.990227659369478e-06, + 8.886247607167789e-05, + 5.0907829920540994e-05, + 0.009863281735601262, + 0.000145030445193013, + 1.2380803640812112e-05, + 8.44689701773998e-05, + 1.2510973873916954e-05, + 4.7368254369153736e-05, + 7.174832499906487e-06, + 4.904713082344558e-05, + 3.982086179258424e-05, + 4.279407556548083e-05, + 5.9341106802033e-05, + 5.545703057791173e-05, + 9.830265710848967e-05, + 7.097168045875709e-05, + 0.006728550378096911, + 0.0018061101135306693, + 0.0009286021346292216, + 0.0005778280391964555, + 0.009043811346655235, + 0.006223166372485518, + 0.005638980724112857, + 5.5266816322073946e-06, + 0.0001071678049589081, + 8.80187196272973e-05, + 6.0474015681588885e-05, + 0.004140227199330784, + 8.646002429487938e-05, + 0.00014266893334484952, + 0.00983176233371314, + 8.2327661535784e-05, + 2.657005871295784e-05, + 0.005316713458998503, + 0.005263923874568061, + 1.3166789154235854e-05, + 2.8191053266072524e-05, + 0.003554991012200417, + 3.5073730595340513e-05, + 1.600133368842961e-05, + 0.00559334195236974, + 0.00679557347143215, + 1.0003877656218436, + 4.2864901433654665e-05, + 1.5398702046158918e-06, + 0.0017204913863231868, + 5.263317597042702e-06, + 7.412144330241568e-06, + 2.8897167742560854e-05, + 1.2642191068013989e-05, + 2.8726589223701957e-05, + 1.3325165197173029e-05, + 2.9942269848555094e-05, + 1.8052719752213758e-05, + 2.2413973752318735e-05, + 0.009339513385827183, + 2.956871823131433e-05, + 3.4857573364954245e-06, + 0.009965742385508356, + 5.8064098366541744e-05, + 4.543184892775909e-06, + 0.008534519561254493, + 0.0005045514329730584, + 0.0004915262872471038, + 1.0957915206616842e-05, + 3.485116857707309e-06, + 4.103470307486917e-05, + 3.449505512877965e-05, + 0.006223166372485518, + 1.1136795167012167e-05, + 4.917905109956431e-05, + 0.0001391716422599186, + 2.134225602766022e-05, + 8.181076850756026e-05, + 0.003107753790333846, + 4.3871349822661094e-05, + 5.393172876158273e-05, + 2.4937042062898712e-05, + 1.0185038332521287e-05, + 0.00017606248522604556, + 1.3878912028461374e-05, + 0.006125638375565562, + 8.551342755536584e-06, + 5.878795178602236e-05, + 0.008487759100771796, + 0.0031757414411978605, + 3.4841133653436712e-06, + 8.017101377762257e-06, + 7.048804349060899e-05, + 0.00010363848198497155, + 0.0001730131989390535, + 6.172582231664433e-05, + 2.160030838240172e-05, + 2.5591472821463486e-05, + 0.007337281118937193, + 5.7250640224978076e-05, + 0.00012396204296597862, + 6.842886526534604e-05, + 0.00557935728804668, + 8.40175663732779e-05, + 0.0029778643265331926, + 6.278689984787101e-05, + 0.008723263430352006, + 4.2093820849666625e-05, + 0.00010989645420088088, + 0.00021230858415933394, + 4.543103795564365e-05, + 0.006639242346381749, + 3.949787837533425e-06, + 7.792064738492659e-06, + 2.545741842614761e-06, + 3.0625251536410894e-05, + 0.00224369175698486, + 5.392157334207365e-05, + 2.0196582070012896e-06, + 3.511630656969946e-05, + 9.071001496701286e-05, + 5.826260311688797e-06, + 8.051282580337352e-05, + 0.00022871279642392865, + 1.400441455646313e-06, + 5.970059231580564e-05, + 2.3294854918457073e-05, + 3.9379968694698984e-07, + 1.0005122858742035, + 5.140845459602858e-06, + 8.102003010137707e-07, + 0.00014456637776158663, + 0.00032154997618342605, + 1.188084764263294e-05, + 0.004316602141437835, + 1.8808918578478595e-05, + 3.6211453017926045e-05, + 0.005005808894482987, + 0.00188385009334873, + 0.006948275793281259, + 0.0019574602954816533, + 0.008837333888313868, + 0.002127269661302731, + 0.00821078361998241, + 1.0321254222034239e-05, + 5.203493787178862e-05, + 2.5997154839160077e-05, + 4.9454216424904526e-05, + 0.0027637787011062917, + 3.412817285756006e-05, + 3.669353473460797e-05, + 3.293840406858189e-05, + 5.411376477769995e-05, + 1.765487079884287e-05, + 3.9117221191864173e-05, + 7.376706734812109e-05, + 0.006976247125852938, + 1.849718928212902e-05, + 0.0065922905508567185, + 7.501128852404918e-05, + 5.4053340630327065e-05, + 0.008338421645317543, + 0.0001077222898127599, + 0.0081575359016717, + 5.253136891324345e-05, + 6.18419543473045e-05, + 3.331186062669915e-06, + 0.00011723158728588356, + 4.0924344042050054e-05, + 0.00852430417569119, + 3.6018542032361736e-05, + 7.846915829260045e-05, + 7.007475291609435e-05, + 1.4040406457210514e-05, + 1.2186539544715434e-06, + 6.497358014457847e-05, + 6.552162915475501e-06, + 1.3483569982537823e-05, + 3.9956313402664994e-05, + 3.4374901122417665e-05, + 3.7277412385885987e-06, + 1.0001762329550616, + 3.9379968694698984e-07, + 6.43586700597802e-06, + 4.662805809938742e-06, + 0.006311483244382031, + 0.001505445880622247, + 8.735938285280393e-06, + 1.0003977443525997e-05, + 0.004015417380052825, + 0.0001950264761052023, + 6.057074090214067e-07, + 5.702868336995201e-07, + 1.034996127455612e-06, + 1.035275889637705e-05, + 3.4053751828548573e-07, + 0.003013917957663592, + 1.4092747286854697e-05, + 7.944851687717692e-06, + 8.241318856450491e-05, + 2.0365071098452272e-05, + 3.320383246689815e-05, + 6.0060345185960196e-05, + 2.282562280992101e-05, + 2.6938937550086616e-05, + 2.1943796847118125e-05, + 5.718269734234039e-05, + 4.0225705652420965e-05, + 3.539059879489178e-05, + 0.006712215563463177, + 0.006834759289973527, + 0.004525181008797196, + 0.0090398684568361, + 0.004193107812289965, + 3.611195890619833e-05, + 4.315960899625176e-05, + 2.6676388625680194e-05, + 1.5425238648487882e-05, + 4.239530929527569e-05, + 0.00014266893334484952, + 4.036902259548693e-05, + 5.551330944747475e-05, + 0.00706018696690996, + 0.0048489996336509, + 0.00725057399154552, + 4.7595573412324026e-05, + 7.186162010213901e-05, + 9.141793619796793e-05, + 8.181005804706189e-05, + 2.1441172414522936e-05, + 3.2648313100976816e-05, + 9.658299046784831e-05, + 0.00013607125408058739, + 8.960823855955737e-06, + 6.482136076334683e-05, + 0.009526728664990757, + 4.5049929939845996e-05, + 0.00012431712551823294, + 0.00012382073634337326, + 0.0011849502227732189, + 4.985196467268206e-05, + 8.500073672303659e-05, + 4.1517316058143174e-07, + 4.302550318241803e-05, + 8.133660879343081e-05, + 5.238644335009593e-05, + 1.4874198614900185e-05, + 6.381972097879172e-05, + 4.146895381538172e-05, + 0.007812569537828521, + 5.6797153003323836e-05, + 2.1828240989408474e-05, + 2.3093786328915213e-05, + 0.0013164853450756745, + 0.005741093990493656, + 1.0777056264245487e-05, + 3.7073972839090896e-05, + 3.4622617627696845e-05, + 8.820430628239255e-05, + 1.0004204390472344, + 3.7277412385885987e-06, + 2.3294854918457073e-05, + 1.05857717104082e-05, + 7.669424770295681e-06, + 3.7121389807687816e-05, + 0.0025027531135822763, + 2.9691546746360525e-05, + 2.8683298392619073e-06, + 1.9556388210223286e-05, + 4.700870048947649e-05, + 7.916043971640084e-06, + 3.0086491323618898e-05, + 9.293417333806772e-05, + 4.498148682255461e-05, + 1.777519615716201e-05, + 0.004956907702287139, + 0.003402162384553347, + 0.004538686199959361, + 0.008819032847634595, + 0.0023922321366585796, + 1.773236913896812e-05, + 0.007690836904536741, + 0.00914181407893777, + 1.7297893003350107e-05, + 1.879939226741259e-05, + 5.7897047412305844e-05, + 0.002127269661302731, + 1.7466550890309995e-05, + 6.595216521287041e-05, + 3.25768819028559e-05, + 8.283092032568344e-05, + 9.197717876650045e-06, + 4.577243436511334e-05, + 4.239530929527569e-05, + 8.646002429487938e-05, + 0.008805068794976455, + 7.37269460960388e-05, + 2.1162142534132394e-05, + 2.1613058386334702e-05, + 5.243876354047514e-05, + 2.062861723670921e-05, + 1.2028922085198997e-05, + 0.0009628796387270497, + 8.551342755536584e-06, + 2.6185861521000763e-05, + 1.1707850048249682e-05, + 2.3587666620726074e-05, + 3.0800189049306255e-06, + 1.851882951395248e-05, + 0.009782309454680381, + 3.019698382825305e-06, + 9.297493441906668e-05, + 6.948461639102615e-06, + 7.16707002124421e-05, + 0.00010580887260818803, + 1.1792268179702386e-05, + 1.298044941180189e-05, + 0.009382044831691094, + 0.0035186077058957845, + 2.9882322235776724e-06, + 1.3711952075214602e-05, + 3.615448220528084e-05, + 1.0002074290941974, + 1.0994049097566663e-05, + 1.310240486264126e-05, + 0.0016311467511667876, + 2.6534495447257202e-05, + 1.8884198800659427e-06, + 7.177313382859093e-06, + 0.007428312764656902, + 0.0010816938755075934, + 0.0013096420345198375, + 6.085174025597421e-05, + 1.592458114561165e-05, + 8.252627901419628e-06, + 5.064743170214215e-06, + 3.161582560257577e-05, + 0.009043811346655235, + 7.921050259260159e-05, + 3.3803783166902323e-06, + 6.029281872575666e-05, + 2.0904964629571314e-05, + 0.01574616148972817, + 6.060744515201521e-05, + 2.407729671365154e-06, + 1.6446658316063207e-05, + 0.009676960075387354, + 0.005204560921393831, + 6.720359856629058e-05, + 7.397498922067364e-05, + 0.0022893814596128765, + 7.172381736447735e-05, + 0.00020214142289124118, + 3.615448220528084e-05, + 6.265458442021338e-05, + 8.310218795996274e-05, + 8.657135190825022e-06, + 7.581259308717127e-08, + 6.174032240952402e-08, + 6.303672765175599e-06, + 4.529426116266005e-05, + 7.790378110650544e-06, + 1.2737606264021523e-06, + 5.31320982239297e-05, + 0.009300587252411117, + 0.0011618057425408913, + 8.167398243961086e-06, + 0.00800148732862001, + 2.2852157316310878e-05, + 8.784487795116046e-05, + 0.005215496332165455, + 6.471299638717376e-05, + 1.537618440707853e-05, + 0.0011141911866881654, + 9.379407508341833e-05, + 3.430793407922378e-05, + 2.9853088250532845e-05, + 5.2766472087971785e-05, + 0.00010459660272650717, + 0.0067128941927253345, + 0.00011889205758591477, + 8.377027048123183e-05, + 1.839704114108649e-06, + 1.5967932983625997e-07, + 4.571840485343565e-05, + 1.7888324242610096e-05, + 1.7667422410700649e-06, + 1.9568895044000717e-05, + 1.0003300690091148, + 8.820430628239255e-05, + 3.4374901122417665e-05, + 5.970059231580564e-05, + 8.43286912301128e-07, + 7.528097178324361e-05, + 1.5799611749605832e-05, + 0.007106771127311314, + 0.0015414752433633417, + 4.7874678062921025e-06, + 8.180534967924788e-06, + 1.2663767548591473e-05, + 8.89251286687329e-06, + 1.2288862401220086e-06, + 1.5259333259623386e-06, + 1.538762457161008e-06, + 1.5889218365970699e-06, + 1.7431546902319922e-06, + 1.437187119899864e-06, + 3.3445602506082165e-05, + 1.2383720746665643e-05, + 6.751158464193462e-07, + 8.021012974644137e-05, + 2.2954687209557798e-05, + 7.845275276930699e-05, + 3.084836036525695e-05, + 0.00819832382907284, + 0.004509471864731448, + 0.007211592682138772, + 0.001080774936663883, + 2.7505844109233254e-05, + 0.006896939223886141, + 3.7303041062276185e-06, + 2.2893352845326236e-06, + 2.2659425801912526e-05, + 2.2756773597648387e-05, + 2.9258570574108967e-06, + 0.00639840042891731, + 2.880137609004941e-05, + 1.9728161055912034e-05, + 4.577243436511334e-05, + 0.004140227199330784, + 0.005221329997523486, + 3.000535237006113e-05, + 2.858263139481979e-05, + 0.008434966654025614, + 6.409491851623345e-06, + 2.1784560596789215e-05, + 7.23500655525631e-05, + 0.00010548489137167106, + 2.6958770302895138e-05, + 5.923465003761426e-07, + 0.00015933951733862196, + 8.394452031494062e-05, + 9.705123470081156e-05, + 2.6429175994417655e-05, + 0.0033100343649935427, + 0.00934538949869626, + 0.004432264135737421, + 1.2854505722798077e-05, + 0.00044431236058949623, + 0.0014745260047490116, + 8.884186737477239e-06, + 5.3386122069419955e-05, + 0.0058248967139245935, + 3.390535436114262e-05, + 2.7398964806537252e-05, + 2.2529968517451576e-05, + 0.00018257796352744485, + 1.0002684437688334, + 4.529426116266005e-05, + 8.133660879343081e-05, + 0.00012396204296597862, + 4.804107451422301e-05, + 7.854924150935622e-06, + 9.20890698185028e-05, + 3.779260422389367e-05, + 3.3996998096963766e-05, + 0.007214311791655111, + 6.518935957422784e-05, + 3.87764533289644e-06, + 4.4185831029026516e-05, + 1.473775828964842e-05, + 4.552346662069953e-05, + 0.0022208218820898985, + 7.66947463026765e-06, + 2.1638565938509677e-05, + 3.3858432172866734e-05, + 1.8834701174318686e-05, + 0.0072660443733186895, + 1.70170076060978e-05, + 1.3348925708514831e-06, + 4.4092287379431386e-05, + 1.9900331944692724e-05, + 2.7545876117955095e-06, + 3.0294756990803786e-05, + 1.9888207898990585e-05, + 3.5181354807464185e-05, + 9.962891593689917e-06, + 0.005063505532808123, + 1.3142350549209993e-05, + 3.807858887188459e-06, + 3.86650835506941e-05, + 0.004483194454930572, + 0.008560723438005933, + 0.009915476597542466, + 0.003516730555426826, + 4.831905131488414e-05, + 1.3612387774774914e-05, + 5.654731790071036e-05, + 0.007563873760525239, + 5.7897047412305844e-05, + 5.70986654635919e-05, + 4.580812393541896e-05, + 0.00906453844049525, + 5.794297254880646e-05, + 0.002711227563482645, + 4.268506539575916e-05, + 6.294100436684671e-05, + 0.000144358736576273, + 2.8887654452486578e-05, + 1.3444929746094877e-05, + 2.1784560596789215e-05, + 0.0068070609766084575, + 6.619848851781917e-05, + 5.6550313371836705e-05, + 0.00450565985570487, + 9.025925841730478e-06, + 8.077315543870918e-06, + 5.4622505552109676e-05, + 0.000515067873673531, + 8.417123614646206e-06, + 4.257501182633146e-05, + 8.960823855955737e-06, + 0.005543813403275388, + 0.004427875840624922, + 0.004622968368555527, + 0.0033598743762273376, + 0.005683899652143301, + 5.493834356565433e-05, + 0.006976247125852938, + 2.1376951580614815e-05, + 0.0034405225796962364, + 5.2530022158616034e-05, + 6.513160904765917e-07, + 2.3909045231668042e-05, + 9.080223448683296e-05, + 4.543103795564365e-05, + 8.47381590041747e-05, + 3.7046042910373765e-05, + 2.279851190786204e-05, + 0.0001035434114937968, + 0.015694012931671365, + 0.002314784955476499, + 0.0001351869158332422, + 2.0501915098524828e-05, + 4.159463451217095e-05, + 1.0148477207275832, + 9.379407508341833e-05, + 6.543058866391555e-05, + 0.004811970719232071, + 0.00017742194051728995, + 5.002017546540117e-05, + 0.015334495722877418, + 0.00010411803164345695, + 5.208047344244813e-06, + 2.272185625473179e-06, + 3.990835206191733e-06, + 6.256499749409017e-05, + 2.2362468666237055e-05, + 1.7541023247471673e-05, + 4.328259607237442e-05, + 7.010848482190836e-05, + 5.959071178316483e-07, + 6.915969718176827e-05, + 1.805138943886443e-05, + 0.00013449665841190302, + 1.7419893057828467e-05, + 6.509424345376619e-05, + 8.546051687200953e-05, + 4.901761593493149e-05, + 0.008087170381398456, + 0.00010507947812848234, + 7.868933400378229e-05, + 0.00951396970838286, + 0.007820308463700465, + 0.008774287957556134, + 0.00915211765251319, + 2.451747705959345e-05, + 6.689722171556712e-05, + 5.616434308975793e-05, + 5.551480015170474e-05, + 0.006489894070843838, + 5.687817152330025e-05, + 0.005670327835012276, + 1.6946522582387045e-05, + 0.0071044223349299536, + 0.00013392222673275266, + 6.785098793438811e-05, + 0.00023047033185757222, + 2.035577968764197e-05, + 0.00015039691379098406, + 8.505517007946614e-05, + 7.51821387975411e-05, + 0.00877995928880234, + 0.009276745414995192, + 0.0006052639682745074, + 3.5405275164337536e-07, + 2.408253652537229e-05, + 0.00013940450826643473, + 7.241693757591757e-06, + 0.00018257796352744485, + 6.303672765175599e-06, + 4.302550318241803e-05, + 0.00015665184080786005, + 0.009360155982221886, + 5.6973288496865745e-05, + 3.108609273131704e-05, + 0.005471422643999203, + 3.8142605394287925e-05, + 2.6896745391710108e-05, + 7.443863429482305e-07, + 5.6847103838554745e-05, + 9.080223448683296e-05, + 0.00021230858415933394, + 6.893059851074438e-05, + 1.3307998776586948e-05, + 4.9006522974493814e-05, + 1.3592364534603364e-05, + 0.007559658489312481, + 5.7243482353636986e-05, + 3.6438697281287586e-05, + 0.002385822926232189, + 3.0255537649567676e-05, + 2.619931980962859e-05, + 2.0225316812531166e-05, + 2.5078590911148673e-05, + 1.3979739129546218e-05, + 0.007478559973594072, + 5.130159250113782e-05, + 1.945367154999441e-05, + 1.000693637634093, + 8.348550647548584e-05, + 0.00020232834080867164, + 0.00010448432381559467, + 0.004220681095862514, + 4.8084221300370924e-06, + 2.7871435289212096e-06, + 5.961322642576858e-06, + 9.647701407466116e-06, + 6.06595718656155e-07, + 4.5744979932388834e-06, + 2.863731908220287e-05, + 3.2010750229393997e-05, + 1.0909411956329585e-05, + 1.5112175287129863e-05, + 2.1511734531140814e-05, + 5.732217749423728e-06, + 0.004967052543479441, + 0.008172434288961817, + 3.315445346260335e-05, + 3.0110710713604018e-05, + 4.195497660194445e-05, + 0.008480512053198986, + 5.6265324282509934e-05, + 0.0031233784413476104, + 3.711164678999354e-05, + 5.7954976624182934e-05, + 0.0013023827143545978, + 1.6648212270453975e-05, + 1.7298730204288893e-05, + 0.007563873760525239, + 1.879939226741259e-05, + 0.008837333888313868, + 3.102418440017793e-05, + 7.256143633448298e-05, + 4.832756745625646e-05, + 1.9067817376664148e-05, + 7.641123007827406e-05, + 0.0022039957819478574, + 0.008459447326873511, + 7.51821387975411e-05, + 0.0001268512726099513, + 0.00012679733007272525, + 0.008106382247233694, + 4.00526336990222e-05, + 0.0006679276000648783, + 0.005937531341288544, + 4.1413939487704946e-06, + 0.00012245212128581448, + 0.006457783551165847, + 6.6127942078603766e-06, + 5.666986257986792e-05, + 0.00010829417935510544, + 0.007342720305307154, + 8.804415323161467e-05, + 7.08690593428671e-05, + 9.546069637881966e-05, + 2.840085319715022e-05, + 5.054622426696256e-05, + 9.885006688172613e-05, + 0.0034103459841710953, + 0.003163709767952356, + 3.087999998307821e-05, + 0.00679557347143215, + 2.1665009509667407e-05, + 3.3215104390041955e-06, + 0.005873673790252434, + 0.00012261209406726128, + 1.8146882092870154e-05, + 0.001098848492576027, + 9.486510994712678e-06, + 2.9776421787722422e-05, + 6.276963263902074e-05, + 0.006806823890020743, + 1.8507845222880758e-05, + 0.006358998048098247, + 5.813175701629659e-06, + 1.000951998583775, + 2.425848205412946e-05, + 6.0942507176717e-06, + 6.798716119619028e-05, + 0.0034194658432815557, + 0.0005948016310838955, + 5.484361314441554e-06, + 4.611686965275673e-06, + 8.831803944007171e-07, + 5.281082680604117e-06, + 4.202569748398294e-06, + 0.002307342766061188, + 2.2130008087780147e-05, + 1.050353687539633e-05, + 2.3478257525078564e-06, + 1.2456287254784247e-07, + 2.4062175400161237e-05, + 2.9942269848555094e-05, + 3.165157237555567e-05, + 1.5324605124138993e-05, + 0.0028681574720703117, + 2.8449049102145023e-05, + 2.656716793804512e-05, + 3.746600959227912e-05, + 5.2996539510238614e-05, + 3.9533904636675386e-05, + 4.7675626079801785e-05, + 0.00010228567311313031, + 5.2572209354611396e-05, + 0.009893406378396238, + 3.7152036280563222e-06, + 5.718269734234039e-05, + 5.5549294698932425e-05, + 6.129640226876825e-05, + 1.839517068585072e-05, + 4.6148138070912694e-05, + 2.5866209626581253e-05, + 0.00010136556747827229, + 9.842205408662057e-05, + 0.009613824701437153, + 3.5019940290114174e-05, + 6.547496387070687e-05, + 0.006796385353731588, + 0.0029280711260348193, + 0.008164029212026792, + 0.0003816885689634088, + 0.006438821015870284, + 0.004376133859150393, + 0.007329413538344493, + 0.004478441911544396, + 0.009530370211735932, + 0.005343984402739459, + 0.004455228636882102, + 0.00036269699602366277, + 1.8017238244775715e-05, + 0.0033535155434166993, + 0.00011970197773206852, + 2.2006625594661942e-05, + 5.2892774698968354e-05, + 5.9341106802033e-05, + 6.85439791623251e-05, + 7.084291599007136e-05, + 4.794687006752578e-05, + 1.984736516522655e-05, + 0.007791658840435856, + 6.177626701645455e-05, + 3.1195312461147066e-05, + 0.0037110609109953898, + 4.9810654609521915e-05, + 2.9901307237916217e-05, + 7.664256895218439e-05, + 3.3428408975038574e-05, + 4.865829265027054e-05, + 1.0038200792272656, + 0.008459447326873511, + 8.505517007946614e-05, + 0.00815744384912862, + 5.4740304521921515e-05, + 0.00829695684417064, + 4.1637468351522585e-05, + 4.7185395178301896e-05, + 4.611686965275673e-06, + 8.735938285280393e-06, + 3.118964717770214e-05, + 1.151237528350908e-05, + 6.883962337457583e-05, + 5.478106217644566e-05, + 6.526940843802335e-05, + 1.3190033228713383e-06, + 4.673612943620091e-06, + 1.9953765773175086e-05, + 8.569855998237978e-05, + 1.0436275612713423e-06, + 8.645709649879834e-07, + 1.8874859837226256e-05, + 3.809734129067859e-05, + 2.9475059591468917e-05, + 1.4886813989585618e-05, + 1.9833815079607923e-06, + 0.006208188035058918, + 5.010532596552045e-06, + 5.763283032282485e-05, + 0.014888439801268014, + 0.006083500465316787, + 0.0019675877767165563, + 0.008087170381398456, + 0.005063505532808123, + 0.009611182680216403, + 0.0025955043327308257, + 0.0007520202876280246, + 0.007636030670880136, + 0.008572476068270435, + 3.191972451121407e-06, + 8.573114353939069e-06, + 3.243705960449583e-06, + 4.25828037495546e-06, + 8.274181744819948e-06, + 2.244436982658596e-06, + 0.007812326963274855, + 4.907519256652523e-05, + 0.0009434926438126656, + 7.040445704723166e-05, + 8.193477229159464e-05, + 4.853197343199784e-05, + 6.671127692826823e-06, + 7.717911239137264e-05, + 0.00011728024289987551, + 0.00010792890575392393, + 6.86394345037373e-05, + 4.0024903276032146e-05, + 0.0009628796387270497, + 0.006125638375565562, + 8.713054812012184e-05, + 0.00013249423111395283, + 0.005005735433951281, + 6.161934999922442e-05, + 0.009065125655137866, + 1.4148013360018128e-05, + 0.00014331101054724154, + 2.6320072321074858e-05, + 8.09437286214573e-06, + 8.315043882107788e-05, + 4.231435282329788e-06, + 8.39792052135796e-05, + 1.1628614234344098e-05, + 3.802634538910261e-05, + 8.255379593155514e-06, + 8.169223873696375e-06, + 1.000314224235949, + 5.813175701629659e-06, + 1.0820437241554723e-05, + 0.00935065634121103, + 1.2083727420730855e-05, + 0.0015286668560874448, + 0.0004466121637889875, + 4.18806829585507e-06, + 3.831561999862129e-06, + 2.357371016367183e-06, + 3.1610493407164625e-06, + 2.8591836887176645e-06, + 3.6872163354419606e-05, + 2.9786294750743373e-05, + 1.3652454735223686e-05, + 7.442826532368355e-07, + 6.915969718176827e-05, + 7.845275276930699e-05, + 5.144251287968885e-06, + 1.2569418638884622e-05, + 2.0337974678940336e-05, + 3.63114731874677e-05, + 7.48601038810743e-05, + 0.003910368997623035, + 0.0031276072742181596, + 0.006076959034976081, + 7.45391906916999e-05, + 0.0023320464877719343, + 0.004376133859150393, + 3.520187008799863e-05, + 5.142917252934526e-05, + 5.7314371833237866e-05, + 1.9429607794752888e-05, + 1.5817505577012435e-06, + 4.281663812917758e-05, + 4.186941554450491e-05, + 8.637677701681919e-05, + 0.008617980389554532, + 2.1402630556665295e-05, + 0.00010908601690073171, + 5.977129380080876e-05, + 0.0033216559080485038, + 2.006953745216285e-05, + 4.257501182633146e-05, + 5.679787494029275e-06, + 0.002246202067281234, + 1.0605426200807425e-05, + 2.8292786126268883e-06, + 4.466158367344553e-05, + 8.20396676808335e-06, + 0.007431416098998833, + 5.464906557027554e-05, + 3.952316376324563e-05, + 1.3640677423618407e-05, + 4.7059955452611104e-05, + 0.0001502896301746381, + 0.005788183044113987, + 9.160651790060595e-05, + 4.862973927123171e-06, + 0.009325200209838529, + 1.5043418041883717e-05, + 3.622517432977772e-05, + 8.087032305166897e-05, + 9.731186228103503e-05, + 3.681470226756574e-05, + 0.006026699609445051, + 4.13354242155286e-05, + 0.00013284441629376648, + 7.017012962279487e-05, + 0.007838582074793548, + 0.0001692474180237501, + 5.344940792856073e-05, + 1.0003473717192444, + 1.9568895044000717e-05, + 3.4622617627696845e-05, + 3.9956313402664994e-05, + 1.400441455646313e-06, + 2.5948670913940536e-05, + 1.6582000373062033e-05, + 1.0572160482083514e-05, + 0.009395193044154506, + 1.958894495909591e-05, + 6.9481289418868506e-06, + 2.0365071098452272e-05, + 1.4998249072389926e-05, + 1.0443226802502651e-05, + 0.004026712082539978, + 4.238725016304624e-06, + 3.981529552547065e-05, + 3.0345710219469527e-05, + 0.007331530231065854, + 0.0026905222874216293, + 0.007233946888549284, + 0.003377191445622171, + 0.009613824701437153, + 0.00713900933396598, + 0.0011279691886657696, + 0.006810501117304453, + 7.429189137403037e-07, + 2.8372766896015674e-06, + 8.003274135724149e-06, + 1.3444929746094877e-05, + 6.409491851623345e-06, + 1.7753298709646568e-05, + 1.1931230595413092e-05, + 3.434636208153656e-05, + 3.5078202872376415e-05, + 1.4326993554005429e-05, + 5.039565961946691e-05, + 4.0024903276032146e-05, + 1.2028922085198997e-05, + 1.3878912028461374e-05, + 0.002007918983284649, + 4.998900482600028e-06, + 3.005623947511771e-05, + 0.004418490344777326, + 4.351836384074313e-05, + 1.9764588428937462e-05, + 1.0388433136278484e-05, + 0.004820441889805756, + 0.0029571873238747764, + 1.2256683466934352e-05, + 1.2373222472231526e-05, + 5.238104174226221e-06, + 1.1285596254064168e-05, + 0.0012857957851166912, + 7.326674752573379e-05, + 3.207616483694981e-05, + 6.911886475228355e-05, + 0.006303951277465212, + 1.000139489888943, + 5.464906557027554e-05, + 0.00010733714305272089, + 6.0660365159832946e-05, + 7.720124525653074e-05, + 5.855432409621465e-05, + 0.0094797029371434, + 6.522745373782873e-05, + 3.0658884688565634e-05, + 9.023068062958051e-05, + 4.544248644969524e-06, + 1.2001044159749209e-05, + 1.8785954384074086e-05, + 2.055840385903111e-05, + 2.2085715213219096e-05, + 3.981529552547065e-05, + 6.040915927635078e-05, + 0.0023256807425682856, + 0.0045434752542678775, + 0.009927709865127338, + 0.0030457536628856843, + 0.0024160246204003987, + 3.729640223912626e-05, + 9.760272777704633e-06, + 1.4237690377161014e-05, + 3.104211937400289e-06, + 2.2659425801912526e-05, + 3.449505512877965e-05, + 3.0856925473438306e-05, + 0.009872411943305133, + 7.684621219798062e-05, + 2.8652478623502918e-05, + 2.006953745216285e-05, + 8.417123614646206e-06, + 0.00013607125408058739, + 2.2662814589453177e-05, + 0.008980663561578098, + 4.231651410967184e-05, + 6.570378455831617e-05, + 6.429821139034277e-05, + 5.4917651460058454e-05, + 8.490755068004092e-05, + 7.762892683073968e-06, + 0.006997835355462587, + 1.5400242532702548e-05, + 0.00020214142289124118, + 1.3711952075214602e-05, + 5.665925866907958e-05, + 6.752494369555874e-05, + 0.008406326448191252, + 8.105068432626227e-05, + 3.8638061642113294e-05, + 0.002859745735827901, + 7.167385084465495e-05, + 9.382078897977693e-05, + 0.00794874308179511, + 5.765771555038821e-05, + 0.00020298304343537954, + 1.0004371964060472, + 3.087999998307821e-05, + 0.00559334195236974, + 6.955184983029764e-05, + 8.382334225368937e-06, + 0.00890671898717624, + 2.8651042860903155e-05, + 9.081164422170525e-05, + 2.0040038050023106e-06, + 5.292434468074637e-06, + 3.5321432741907855e-05, + 1.0802323681468716e-05, + 2.180501874404649e-07, + 2.2954687209557798e-05, + 1.5070953927305015e-06, + 4.238725016304624e-06, + 7.932889293692498e-06, + 0.004191427400667957, + 0.009546401607162315, + 0.0018340534860973967, + 4.991506895964298e-05, + 0.006438821015870284, + 5.179424309578726e-05, + 0.00010372821586498543, + 4.425405285903667e-05, + 2.245811070471092e-06, + 5.658566875586513e-06, + 5.196399985490808e-06, + 4.967058051043821e-06, + 0.00855284750328267, + 4.548301416806034e-06, + 3.191452729950644e-05, + 0.003534239376464677, + 8.058523579155135e-05, + 3.049006450511041e-05, + 0.004894035966285886, + 8.274181744819948e-06, + 0.008819032847634595, + 6.226152553836605e-05, + 2.880816747198646e-05, + 2.149929346326834e-05, + 1.7654607315174462e-05, + 8.046991690297857e-05, + 5.077626632758732e-05, + 5.687817152330025e-05, + 4.31693251840473e-05, + 0.006523181202208075, + 1.9299368127396475e-05, + 0.004441591003607541, + 0.00010936821654083165, + 0.000515067873673531, + 6.029281872575666e-05, + 9.658299046784831e-05, + 3.9616146869272896e-05, + 0.007320563611416953, + 0.0005189204241672527, + 0.00022920125990033514, + 7.391753503787828e-07, + 4.3743752451769124e-05, + 4.348830887366919e-05, + 4.2782354320608835e-05, + 8.087032305166897e-05, + 0.0056954290527608375, + 1.1253258306963982e-05, + 0.001842198992963593, + 2.266465386200731e-05, + 2.5613491124066854e-05, + 7.991859104992195e-05, + 0.0028124813517910368, + 0.0001482169747593478, + 0.0011243045085116564, + 6.444479221415082e-05, + 1.0003563067916093, + 0.00020298304343537954, + 0.003163709767952356, + 1.600133368842961e-05, + 0.003804170827353817, + 9.369045968381743e-06, + 0.009902295270012016, + 5.312082381498302e-05, + 2.2088685428722426e-05, + 6.182638644992776e-05, + 4.6149482328255726e-05, + 4.30662229714024e-06, + 1.7490310600702375e-05, + 0.0068963851965890615, + 1.3151090432536203e-05, + 0.00681460115425272, + 6.472707200050332e-05, + 8.37663585323914e-06, + 3.2901582192803755e-05, + 7.438842701197541e-05, + 0.003841607579534625, + 2.1943796847118125e-05, + 2.1569779244003335e-05, + 0.006208188035058918, + 0.007629929362896941, + 0.0008070845419398598, + 0.009283357720056219, + 1.6907856271275485e-05, + 9.842205408662057e-05, + 7.088415884733152e-06, + 4.279874378483436e-05, + 8.545533305049899e-07, + 7.891320233959729e-05, + 4.0935322624666356e-05, + 2.7372743738309747e-05, + 4.61354304564752e-05, + 0.004589697180653488, + 4.909709825223077e-05, + 7.199308136705757e-05, + 2.4213688635566925e-06, + 4.799118855640533e-06, + 1.0839399538239977e-05, + 8.751376430531743e-05, + 0.00012388258501309837, + 0.006489894070843838, + 0.00537362751138068, + 6.871895392907351e-05, + 4.463507283417051e-05, + 0.00010310363765821542, + 3.872517421314511e-05, + 3.2475583311200885e-05, + 4.279985052176947e-05, + 0.004090065904547754, + 1.1849582333965748e-05, + 2.2472137285700316e-05, + 1.1178736689857231e-05, + 0.006303951277465212, + 1.0486260105233297e-05, + 3.6191356626329917e-06, + 4.810896760486375e-05, + 5.8641039681199165e-06, + 0.0015313480060440388, + 5.0148776047508897e-05, + 2.6170465216380154e-05, + 4.411509974638011e-05, + 2.0662887478761327e-05, + 6.459296738261779e-05, + 1.000242876722117, + 4.2782354320608835e-05, + 3.622517432977772e-05, + 6.91575555913188e-05, + 2.7758845583371817e-05, + 0.004544223191595411, + 4.7185395178301896e-05, + 5.403445097854669e-05, + 0.00821535577889686, + 4.3598497940565115e-05, + 1.2663767548591473e-05, + 1.4344908058887058e-05, + 0.003008892442669965, + 1.050353687539633e-05, + 3.035721643280287e-06, + 9.986170939792048e-06, + 5.7774606273442145e-06, + 5.629750213349031e-06, + 4.470429515463049e-06, + 4.962050411035719e-06, + 2.8704814649242224e-05, + 2.9134358931703176e-05, + 0.0033481834471345106, + 2.8207005358445007e-05, + 0.011977395320336965, + 0.006793715977169662, + 0.0020874736505889233, + 0.00944967063640076, + 0.002284715759170237, + 0.007820308463700465, + 1.468252114735999e-06, + 2.883557709799689e-05, + 9.853135724398703e-08, + 3.3429279893770895e-05, + 4.470866250334624e-05, + 6.897424097163955e-05, + 4.61354304564752e-05, + 0.006044533045230626, + 0.00014086511687519626, + 0.0022034474410589774, + 1.0479176239748488e-06, + 7.795590519058728e-05, + 1.42711447725146e-06, + 0.00012218969694670703, + 8.445107658541375e-05, + 0.00015054319828436234, + 3.469139439790145e-05, + 0.0077137338986100305, + 1.4115982854095151e-05, + 6.897019142137336e-06, + 5.633371613685428e-05, + 0.0017554784915360983, + 0.00010354443959710574, + 6.444479221415082e-05, + 5.765771555038821e-05, + 0.0034103459841710953, + 3.5073730595340513e-05, + 4.045190920950058e-05, + 0.009874079931003811, + 0.006620078112091664, + 7.645574527309935e-05, + 1.7857945324176098e-05, + 6.915242362438579e-05, + 8.633795911073606e-05, + 7.250283695571141e-06, + 6.857877591054047e-05, + 3.8981566327742296e-05, + 1.0004484710811958, + 5.344940792856073e-05, + 1.7667422410700649e-06, + 3.7073972839090896e-05, + 1.3483569982537823e-05, + 0.00022871279642392865, + 7.92758331939025e-05, + 3.750389361508163e-05, + 7.964997756107978e-05, + 0.009041327173160378, + 1.5943467644657593e-05, + 0.004215542482180343, + 3.832907709147249e-05, + 7.617858133867746e-05, + 3.774635551090802e-05, + 1.1261487041142267e-05, + 7.61928649524494e-07, + 8.021012974644137e-05, + 2.200821759837018e-05, + 1.286742358858376e-05, + 3.4815135325005485e-05, + 1.026479569747631e-05, + 0.008215388579910384, + 1.66515736182694e-05, + 0.004038422827637369, + 0.007856691498778193, + 0.009863281735601262, + 0.007316043405194684, + 0.004871900036639932, + 0.0012684392689259717, + 0.0033616025774451984, + 5.5252471143096764e-05, + 9.086408853336123e-06, + 2.4430423550093762e-05, + 0.003377191445622171, + 2.410980125288674e-05, + 0.005193523917210944, + 1.1969821155206793e-05, + 0.0019675877767165563, + 9.962891593689917e-06, + 1.8910845561383668e-05, + 4.994533857957476e-06, + 3.780064200939412e-05, + 0.00013853609608595324, + 1.614530164100325e-05, + 6.354986925006403e-05, + 2.2152551541613593e-06, + 6.813742258479065e-05, + 3.0274665047374855e-05, + 6.177626701645455e-05, + 4.497861352315392e-05, + 2.1078685517739725e-05, + 0.014405048700368052, + 6.301974197764083e-05, + 0.0001423670210546449, + 5.030491643952388e-05, + 0.00013392222673275266, + 0.00011108092659027222, + 3.681826033099115e-05, + 0.005102547594472177, + 2.77877047137349e-05, + 1.3244196667398672e-05, + 1.8420403038691553e-05, + 2.74813477149931e-05, + 1.5400242532702548e-05, + 2.9882322235776724e-06, + 0.0018410580341127881, + 3.89090190295633e-05, + 1.8408154591897332e-05, + 0.00956642620888577, + 5.147977149152313e-05, + 6.459296738261779e-05, + 4.348830887366919e-05, + 0.003961812646855485, + 9.171185102672263e-05, + 0.009543969020334744, + 7.943201654792854e-05, + 4.832204262125161e-05, + 3.053482229077703e-05, + 8.226129661953519e-05, + 1.0004567971543645, + 3.8981566327742296e-05, + 0.0001692474180237501, + 1.7888324242610096e-05, + 1.0777056264245487e-05, + 6.552162915475501e-06, + 8.051282580337352e-05, + 1.8606361438029243e-05, + 0.007925813749040412, + 0.0013262776517449749, + 0.004367331740704896, + 5.484361314441554e-06, + 5.208047344244813e-06, + 8.186621732546018e-05, + 6.51473398838025e-05, + 2.155358575807791e-05, + 3.4881950218393824e-05, + 2.193189938950662e-06, + 4.960478974867715e-06, + 4.812960853350476e-06, + 3.101156235952684e-05, + 4.2157943183771885e-05, + 0.001945479696999113, + 1.0169619211581902e-05, + 5.136316317798199e-06, + 1.8634392412703953e-05, + 6.843153149414602e-07, + 5.429085810404545e-05, + 1.9900331944692724e-05, + 9.908776278140068e-06, + 5.9923237944393764e-05, + 2.80291057979106e-05, + 0.004026712082539978, + 0.007536101314779872, + 6.155588174262378e-06, + 1.5196701226806156e-05, + 3.161582560257577e-05, + 4.103470307486917e-05, + 5.879348156754798e-07, + 7.834536780450026e-06, + 4.573898088787692e-05, + 5.787477450346718e-06, + 1.9728161055912034e-05, + 9.197717876650045e-06, + 1.5425238648487882e-05, + 0.0010589697528595465, + 8.7581123233078e-06, + 1.2188625738568068e-05, + 8.219456431663026e-06, + 3.76336116087435e-05, + 0.00011728024289987551, + 0.006162464895893152, + 0.004340989890632332, + 5.179000999773563e-05, + 5.253136891324345e-05, + 4.470787698074131e-05, + 7.564088304664701e-05, + 5.345428422257456e-05, + 0.006164328751618406, + 8.058865452382106e-05, + 4.611385404600837e-05, + 0.009281254762723639, + 5.3988536601202625e-05, + 7.933617991373189e-05, + 0.007406400889151284, + 0.00010702878044929721, + 7.840140364717967e-05, + 2.058832098831185e-05, + 0.00014935807139830338, + 5.208940248579786e-05, + 0.009295057053681489, + 9.414993358493272e-05, + 1.5694842719006986e-05, + 0.006161186192549629, + 0.00011875593959169661, + 9.067481939191294e-05, + 1.0003904807244115, + 0.00010354443959710574, + 0.0011243045085116564, + 0.00794874308179511, + 9.885006688172613e-05, + 0.003554991012200417, + 4.497641852423167e-05, + 6.895434020954211e-06, + 0.007281113407364993, + 0.0001129253805894384, + 0.00010322667475459351, + 2.5507526232547014e-05, + 1.5259333259623386e-06, + 4.65911604680687e-05, + 4.810990280897296e-05, + 4.35156286886779e-05, + 5.2689843753786996e-05, + 1.9556388210223286e-05, + 0.005248491323114544, + 3.5317987962918195e-05, + 1.0169619211581902e-05, + 2.9475059591468917e-05, + 1.5005851203904687e-06, + 1.6821322945941589e-06, + 0.00037552320060045606, + 3.7152036280563222e-06, + 2.108479944985597e-06, + 0.0034308146917214903, + 0.005562525093049638, + 7.642218699679069e-05, + 0.0007922004510952769, + 3.467896560878684e-05, + 1.0222702906452622e-05, + 1.3621500339103099e-06, + 7.310290289575026e-06, + 0.006804287846315139, + 1.7594688486085036e-05, + 3.913977044227693e-06, + 0.0001391716422599186, + 0.009151840802452679, + 0.005289247804570505, + 2.213282547714912e-05, + 7.511646879857002e-05, + 0.0056379696535372795, + 2.8074432059582885e-06, + 1.8264595375149003e-05, + 3.2854142780819036e-05, + 5.947613597670801e-06, + 1.879420935773223e-05, + 0.0037882592550023573, + 1.7033791982717998e-05, + 1.9546483249476834e-05, + 0.002923910238477404, + 8.738491375979277e-06, + 3.993375566796682e-05, + 7.456582558012644e-05, + 2.8652478623502918e-05, + 3.2648313100976816e-05, + 0.0018398040804846942, + 0.003262568127085023, + 4.324578616775226e-05, + 2.350896238431244e-05, + 0.0072466957647136405, + 5.147977149152313e-05, + 2.0662887478761327e-05, + 4.3743752451769124e-05, + 1.5043418041883717e-05, + 0.0025456088283974092, + 0.0008344352091233543, + 0.009423377551926036, + 4.159463451217095e-05, + 0.0011141911866881654, + 2.2764179043432686e-05, + 1.9808276545164153e-05, + 3.5011884286798186e-05, + 0.007944636963792108, + 0.004449428258901354, + 0.00694616003156225, + 2.01100155359697e-05, + 4.2842658647721135e-05, + 0.008061790939854345, + 0.0030345791284893233, + 2.9396639749410458e-05, + 6.24900923096088e-05, + 4.399702131495049e-05, + 1.3007037389759159e-05, + 6.804885467463613e-06, + 1.001620013315965, + 1.945367154999441e-05, + 1.5696421917549157e-05, + 7.028971907680665e-05, + 4.7269354886358105e-06, + 0.0006949372352616699, + 8.484749056658531e-06, + 3.3014866340073654e-05, + 7.073516401505625e-05, + 4.014886379571267e-06, + 9.108396625983994e-06, + 0.004321927299556481, + 0.0058768241372289, + 0.001274567154347896, + 0.008215388579910384, + 0.005622981904158817, + 0.008694167441570979, + 0.004990979010645134, + 0.0020676055741927837, + 8.507831038245505e-05, + 1.3421878168480512e-05, + 3.698500719033811e-05, + 5.2892774698968354e-05, + 4.279407556548083e-05, + 5.15076415312748e-05, + 5.3235186612166245e-05, + 1.951610783233207e-05, + 5.326649168148768e-05, + 5.409762971466342e-06, + 2.416269384841492e-05, + 0.006778124499406896, + 6.72187870424122e-05, + 0.0003862692349598243, + 3.555021927781079e-05, + 1.847328180131288e-05, + 5.472011340191899e-05, + 0.006850510061810733, + 4.319694231074623e-05, + 0.0010627994318390286, + 2.817754802475255e-05, + 7.164637249194579e-05, + 4.5445832281131216e-05, + 0.00833339346667911, + 0.006202938017977235, + 1.0203266725336442, + 8.169223873696375e-06, + 0.006358998048098247, + 4.2287392648719884e-05, + 1.0623499542258326e-05, + 0.00016112846705804528, + 0.00574581527221644, + 2.696520810397456e-05, + 4.8413826881802706e-05, + 3.2533800384630557e-05, + 1.4154750529256727e-06, + 2.0040038050023106e-06, + 4.544248644969524e-06, + 1.5169365522255912e-06, + 1.5813697966072556e-06, + 0.0039959851162086795, + 0.00037552320060045606, + 0.003841607579534625, + 0.009893406378396238, + 0.005614779437366768, + 0.006195682247786596, + 0.0004904804093198068, + 3.401408920663357e-05, + 5.259205737729365e-05, + 4.73731084926689e-05, + 3.746647411616235e-05, + 0.004515126381855252, + 3.46151188786036e-05, + 0.0009421147252950182, + 8.003274135724149e-06, + 3.5918105428542704e-05, + 3.366232988367765e-05, + 0.004745979425066099, + 3.7947580282532233e-06, + 5.1798205991187264e-05, + 5.493834356565433e-05, + 6.478983772859016e-05, + 9.490674478102146e-05, + 0.00826115681055757, + 3.781020879821394e-05, + 6.771638314171035e-05, + 9.945364267061394e-06, + 8.709392167994599e-08, + 0.008851514555513171, + 7.092762014150933e-08, + 7.241693757591757e-06, + 2.2529968517451576e-05, + 8.949628991663872e-06, + 2.5844655406679966e-05, + 0.0019337748315410668, + 5.464070852933514e-06, + 0.0013346887928212846, + 4.014318685652859e-05, + 0.005249400737137344, + 6.056929639322962e-06, + 8.226129661953519e-05, + 6.857877591054047e-05, + 0.007838582074793548, + 4.571840485343565e-05, + 0.005741093990493656, + 6.497358014457847e-05, + 5.826260311688797e-06, + 3.1987418151162497e-05, + 2.3174984669763992e-05, + 4.4290465341956033e-05, + 0.007513842671876183, + 3.19672703161189e-05, + 0.00013016863433750942, + 1.671129286964195e-05, + 4.764519943351331e-05, + 0.00011371720186554668, + 3.582381449643013e-05, + 1.0002999647818855, + 0.006202938017977235, + 8.255379593155514e-06, + 1.8507845222880758e-05, + 4.27333714582164e-05, + 0.00403467118712389, + 6.717291162328866e-05, + 0.005794533630906074, + 0.00048644854934731753, + 0.0011035844870068423, + 0.006548836331007934, + 5.5843212860730985e-06, + 2.2006625594661942e-05, + 2.1430325576489996e-05, + 2.2149089869145255e-05, + 8.119893134280176e-06, + 6.205293339025682e-06, + 3.7681435698580956e-06, + 9.861034013834767e-07, + 5.110303605181262e-07, + 3.104211937400289e-06, + 2.2893352845326236e-06, + 5.064743170214215e-06, + 3.485116857707309e-06, + 0.0005778280391964555, + 3.117548029508032e-06, + 0.008570542520500277, + 5.458741613905111e-06, + 0.0005468462075336555, + 1.6298167845171424e-06, + 3.619066817315635e-05, + 6.040661971505374e-05, + 4.157804352074367e-06, + 1.1478516439581388e-05, + 7.01050892693061e-05, + 5.631224140776579e-05, + 7.740590924596806e-06, + 2.2755660280173264e-05, + 3.76336116087435e-05, + 0.005796324582018182, + 3.5125133690867506e-05, + 5.803877605658419e-05, + 1.836210569087713e-05, + 5.235179554840961e-05, + 5.359866281977652e-05, + 1.0034658106515606, + 3.582381449643013e-05, + 0.00833339346667911, + 3.802634538910261e-05, + 0.006806823890020743, + 4.695475624562457e-05, + 1.1796041331419004e-05, + 0.009918597864277588, + 0.006329999010846514, + 0.006765004772106684, + 1.041461905701894e-06, + 6.165144402688587e-05, + 2.8449049102145023e-05, + 7.544933136494426e-07, + 3.177050433723157e-07, + 1.176349128772483e-07, + 7.61928649524494e-07, + 2.180501874404649e-07, + 7.442826532368355e-07, + 5.959071178316483e-07, + 6.751158464193462e-07, + 1.083030484391954e-07, + 0.0018985266027096914, + 0.013780337834186657, + 0.007152670825092443, + 0.0033481834471345106, + 0.004710837294839253, + 1.5318526814856903e-05, + 1.5917088164935347e-05, + 5.654731790071036e-05, + 1.7297893003350107e-05, + 2.225316986181994e-05, + 0.005248188198912619, + 8.477351939698314e-05, + 0.00013867448984484528, + 5.242738108525685e-06, + 2.2755660280173264e-05, + 7.717911239137264e-05, + 0.003925877503611112, + 0.00012386310278921677, + 2.5668579786795284e-05, + 0.0081575359016717, + 0.008538605385254245, + 2.78444326678576e-05, + 1.4663526011589675e-05, + 0.0030543276608787084, + 0.00011032302460473533, + 2.0879152531223147e-05, + 0.00858142603278076, + 1.2886151317740457e-05, + 0.00011931118425226127, + 3.872517421314511e-05, + 1.2256683466934352e-05, + 0.00015854687935395274, + 0.002954714475054873, + 8.366686264344738e-05, + 0.009532371787812329, + 6.303360450230218e-05, + 2.2583435590428477e-05, + 0.0014282378997911738, + 0.0001012477669236068, + 3.88605346505195e-06, + 1.6515955131066794e-05, + 1.0003730467323628, + 0.00010702878044929721, + 0.00012245212128581448, + 5.752384109440578e-05, + 1.9635793154361086e-06, + 5.322016823308476e-05, + 3.8611487076955e-05, + 0.00689029288331709, + 6.623595464622124e-05, + 9.142508566084441e-05, + 1.9982365220095112e-05, + 1.844624633903237e-05, + 1.0730957657725968e-05, + 4.3598497940565115e-05, + 8.180534967924788e-06, + 1.034996127455612e-06, + 1.3325165197173029e-05, + 4.258700237407619e-05, + 2.6905188075855888e-05, + 3.3405059603801925e-05, + 0.007984668065463083, + 0.006995397184540966, + 0.00681460115425272, + 0.009498292054863657, + 0.004828100933283703, + 1.3509640250550743e-05, + 0.001935240152718257, + 0.005956877741835263, + 0.001274567154347896, + 1.026479569747631e-05, + 0.007245395472591905, + 9.09074558996317e-06, + 7.288720745849373e-06, + 0.004060612310993983, + 0.007496747275018019, + 1.0706972202517327e-06, + 2.844506535959634e-06, + 2.16038287937511e-05, + 0.0023320464877719343, + 0.0003816885689634088, + 1.6125188709193586e-06, + 1.9541155247926564e-06, + 0.005332022790581705, + 5.8749181656967195e-05, + 4.787322589202522e-05, + 5.196399985490808e-06, + 4.195497660194445e-05, + 7.174147412406096e-05, + 0.001254912207654518, + 1.9635237808574706e-05, + 4.2254995780583525e-05, + 2.4633857595563536e-05, + 2.532220139804081e-05, + 3.0247199102358532e-05, + 6.939682639117589e-05, + 7.795414495027033e-05, + 6.595502583296869e-05, + 4.957894886944058e-05, + 7.144392268361971e-05, + 4.89366368790601e-05, + 0.008434198729491096, + 0.0001055661057078594, + 5.849183962449663e-05, + 6.810953124830916e-05, + 5.1798205991187264e-05, + 0.005683899652143301, + 1.6446658316063207e-05, + 7.376706734812109e-05, + 8.927093181596704e-06, + 1.9073452472447576e-05, + 0.0032229912057087124, + 5.109858086914298e-05, + 2.6087163904935546e-05, + 0.001402735417636479, + 0.004466014513292503, + 0.00010630503753370316, + 6.203012046578658e-05, + 2.9507190624179216e-05, + 7.489498443709168e-05, + 5.6129781407169457e-05, + 9.723714884303621e-05, + 1.0002718330049372, + 6.804885467463613e-06, + 5.130159250113782e-05, + 6.052485692047022e-05, + 4.35561991898656e-05, + 0.00010981446149796692, + 0.009882759593724188, + 3.0360842724742417e-05, + 4.01489884515465e-05, + 3.1326321629322294e-05, + 1.933607075234137e-05, + 9.153726814948286e-06, + 4.221448294680072e-06, + 2.6281148204999713e-05, + 2.9711268059919924e-05, + 0.009092323764615015, + 3.877812615061973e-05, + 3.832907709147249e-05, + 2.16038287937511e-05, + 0.008164029212026792, + 6.556057476266936e-05, + 3.5817131940039534e-05, + 4.628791292582566e-05, + 2.461900532024616e-06, + 2.636155130685005e-05, + 3.8655259029171693e-07, + 4.134393643718326e-05, + 2.6583074685513483e-05, + 0.0046012907750768986, + 8.085035701929519e-05, + 4.494637145322238e-05, + 0.0009421147252950182, + 4.3088882703026115e-05, + 0.00020211630792040222, + 0.004245174591239174, + 0.002965796072866161, + 6.689722171556712e-05, + 6.735818788402423e-05, + 2.7073737897301418e-05, + 0.00044431236058949623, + 3.8907724284033985e-05, + 0.00011641156866472645, + 6.015624802294293e-05, + 2.4569621790304322e-05, + 5.039565961946691e-05, + 6.86394345037373e-05, + 2.062861723670921e-05, + 0.00017606248522604556, + 0.004924228234314472, + 0.006655999042995089, + 8.572705345464126e-06, + 0.00652056301061857, + 0.0075773494450229375, + 6.833509523082159e-06, + 7.849728077354606e-05, + 7.456582558012644e-05, + 0.0033216559080485038, + 5.4622505552109676e-05, + 3.3803783166902323e-06, + 2.1441172414522936e-05, + 1.0371090875917845e-06, + 0.00040951532149479774, + 0.00010429519486518364, + 2.2346628787836468e-05, + 5.760504239152818e-06, + 7.85697336266132e-06, + 2.5853406633669654e-06, + 0.00010021526772651202, + 1.6515955131066794e-05, + 1.959778315481159e-05, + 0.0001284645428770314, + 1.8500337692731853e-05, + 1.3433271666820882e-05, + 0.0024404954301714054, + 0.001268052671563556, + 2.8342207263042518e-05, + 0.002554135913483182, + 8.335327060635427e-05, + 1.000455544525457, + 9.067481939191294e-05, + 0.0017554784915360983, + 0.0001482169747593478, + 9.382078897977693e-05, + 5.054622426696256e-05, + 2.8191053266072524e-05, + 0.0001805488747476753, + 8.942891187852903e-06, + 0.009496872318820002, + 9.399386408590776e-05, + 7.71081508500837e-05, + 6.979561412464874e-05, + 4.01489884515465e-05, + 2.8726589223701957e-05, + 6.374362258410816e-05, + 5.800260442591195e-05, + 5.464438004534413e-05, + 1.4154750529256727e-06, + 0.0036699814726822077, + 0.002612451324535824, + 0.006157260534451727, + 0.004325677183490168, + 0.005850778163732161, + 0.009743049631104774, + 4.617323056512292e-05, + 0.003061799067835776, + 0.006995397184540966, + 6.603767343972547e-05, + 1.8504975325063464e-05, + 3.356777733560644e-05, + 2.813328553469004e-05, + 5.356863279872683e-05, + 0.0004195966818797722, + 0.009609472854344313, + 6.9319518972996804e-06, + 0.0045434752542678775, + 9.92624527811888e-06, + 3.0453043375824447e-06, + 4.3883882401521954e-05, + 1.94630953296662e-05, + 2.4430423550093762e-05, + 0.007233946888549284, + 0.00010136556747827229, + 8.159669202728204e-06, + 5.168247156296229e-05, + 9.073084147842132e-07, + 0.005126444542508474, + 1.7327129637714894e-07, + 0.0090398684568361, + 0.006358011194064177, + 8.338065908363515e-06, + 1.4039561271931087e-05, + 4.232256890170172e-05, + 2.6445664430825162e-06, + 1.2973929579280214e-05, + 5.242738108525685e-06, + 7.740590924596806e-06, + 8.219456431663026e-06, + 6.671127692826823e-06, + 0.0013354308950555116, + 1.185020908107824e-05, + 3.744616336372351e-05, + 0.00011094755414201958, + 1.0002389983320283, + 1.7033791982717998e-05, + 0.00012388258501309837, + 5.077626632758732e-05, + 5.551480015170474e-05, + 3.8945017106828324e-05, + 0.00587733230650688, + 1.741084018960257e-05, + 0.008126126390881718, + 1.260606554655423e-05, + 0.006756440638648885, + 3.5317987962918195e-05, + 3.809734129067859e-05, + 2.3765530992957984e-06, + 0.0016452738524017194, + 0.003230710684057512, + 0.00813513284380525, + 0.0017964531586413168, + 5.245897082846726e-05, + 2.2699011482774208e-05, + 2.844506535959634e-06, + 4.991506895964298e-05, + 3.4185747076641285e-05, + 3.453785158693196e-05, + 8.604060923538484e-06, + 5.742099408205895e-06, + 1.7327129637714894e-07, + 0.007388783088336085, + 0.0074382588194354445, + 1.824223373856259e-05, + 0.002711227563482645, + 1.877880444362138e-05, + 0.0037547983552217367, + 6.791867953427332e-05, + 9.324987802129278e-06, + 2.7808250649402162e-05, + 1.3612134800845368e-05, + 0.004938488230247744, + 2.451747705959345e-05, + 2.6429175994417655e-05, + 2.647290542189767e-05, + 0.0028935743279264107, + 1.1621207799905132e-05, + 1.833190249544069e-05, + 0.007791658840435856, + 0.0001185655905667058, + 0.00025118900478544144, + 1.3553940587364827e-06, + 1.8486741044336282e-06, + 9.760124850673267e-06, + 3.9536170159753443e-05, + 0.00010021526772651202, + 3.88605346505195e-06, + 0.007406400889151284, + 4.1413939487704946e-06, + 3.336172852818558e-05, + 7.398325825980472e-05, + 4.352960566006824e-06, + 3.160726188317129e-06, + 0.000605441247258067, + 5.422057846185583e-06, + 8.2936366790311e-06, + 6.25004168927728e-06, + 4.367459088655561e-05, + 1.0002082081931074, + 6.056929639322962e-06, + 3.053482229077703e-05, + 7.250283695571141e-06, + 7.017012962279487e-05, + 1.5967932983625997e-07, + 0.0013164853450756745, + 1.2186539544715434e-06, + 9.071001496701286e-05, + 0.001026103455904006, + 0.0034227338913006555, + 0.0013789509831549367, + 0.0008094970202235607, + 0.0024756450814178467, + 5.689189388216512e-06, + 0.0005478704792354883, + 4.5637951432835935e-06, + 2.8683298392619073e-06, + 0.002752361059311225, + 0.008359354900165079, + 0.004316602141437835, + 0.0029471484685646876, + 0.004357343568433076, + 3.3602864974098526e-05, + 8.001581192602237e-06, + 0.0016452738524017194, + 5.2504102984330765e-06, + 2.1796536959262597e-06, + 0.004934645058048987, + 3.9338609163468106e-07, + 0.002612451324535824, + 3.320383246689815e-05, + 5.937810771779099e-05, + 1.1969821155206793e-05, + 0.006083500465316787, + 4.901761593493149e-05, + 3.5181354807464185e-05, + 5.8469634307341134e-05, + 5.663119294446125e-05, + 4.7298225712617244e-05, + 6.139913854674415e-06, + 5.110303605181262e-07, + 1.5196701226806156e-05, + 1.4237690377161014e-05, + 3.7303041062276185e-06, + 8.252627901419628e-06, + 0.0009286021346292216, + 5.079816090900735e-06, + 6.509212224544221e-06, + 1.3500497663962548e-05, + 1.5106463096119683e-05, + 9.793241132476954e-06, + 3.913977044227693e-06, + 4.917905109956431e-05, + 0.0010195254958027743, + 1.7160912740953665e-05, + 6.911311528819053e-06, + 3.2874580211676028e-06, + 8.733381168004906e-06, + 5.796526019303194e-07, + 1.5511247519254373e-08, + 2.4050974985867775e-06, + 1.42711447725146e-06, + 2.266246567558815e-06, + 1.6457045280624036e-05, + 0.00014991626842961953, + 1.103134707835397e-06, + 3.3583569172584694e-05, + 2.6463650851974373e-05, + 5.648693036805958e-05, + 1.0376186007173165e-05, + 1.0001080862476222, + 1.1178736689857231e-05, + 6.911886475228355e-05, + 0.007431416098998833, + 6.104874933017689e-05, + 2.3911820891969514e-05, + 5.9520335109750265e-05, + 2.9204211939985304e-05, + 0.0073028517638831615, + 0.00842634005475897, + 3.335370314286377e-05, + 3.716813088547636e-05, + 9.986170939792048e-06, + 1.4092747286854697e-05, + 1.2649299473656828e-05, + 4.724217381934257e-05, + 2.9691546746360525e-05, + 3.283564120768238e-05, + 1.3839749949607112e-05, + 1.7386720499088466e-06, + 1.176349128772483e-07, + 1.3652454735223686e-05, + 1.2383720746665643e-05, + 8.130561009949154e-07, + 5.375142952456956e-06, + 0.00654750217444128, + 0.011437588139071007, + 0.006756440638648885, + 0.005248491323114544, + 0.001945479696999113, + 0.0026401284607189303, + 2.059942267026535e-05, + 4.05511193210967e-05, + 5.0907829920540994e-05, + 5.937810771779099e-05, + 0.005193523917210944, + 0.014888439801268014, + 8.546051687200953e-05, + 0.009965742385508356, + 8.610593246983417e-05, + 6.956014306610032e-06, + 0.00010740660096765256, + 1.4633962622208773e-05, + 2.9446476827046725e-05, + 2.7943759314982804e-05, + 5.658566875586513e-06, + 3.0110710713604018e-05, + 1.4997326509518679e-05, + 4.413367626682505e-05, + 7.405308840517132e-06, + 1.4378863651314058e-05, + 1.4703237898637284e-05, + 3.6960655441931726e-05, + 0.00814747827758538, + 0.009658027123380798, + 4.100952759170509e-05, + 0.0004400256081269027, + 0.00016616202787009891, + 9.35929561527854e-06, + 0.008814308982101544, + 5.30035956401809e-05, + 8.570889656902395e-05, + 0.00012252356756068845, + 3.710823378319444e-05, + 6.63684483593648e-05, + 7.092654206774545e-05, + 0.005760547974782387, + 5.950574219013195e-05, + 3.823333055521334e-06, + 0.0014701890195581973, + 1.0003536160802096, + 6.810953124830916e-05, + 3.7947580282532233e-06, + 0.0033598743762273376, + 2.407729671365154e-06, + 3.9117221191864173e-05, + 1.3632792315744896e-05, + 4.055292891554118e-05, + 0.0005409447801154472, + 7.582184626453817e-05, + 2.3104780332391485e-05, + 3.819063871128943e-06, + 0.003183520221360109, + 0.009754505241349513, + 0.0072660443733186895, + 0.002341990597880902, + 0.002882958045542563, + 0.006068265635885829, + 2.3007962908176834e-05, + 0.008359354900165079, + 2.4636259992210228e-05, + 4.107847715552589e-05, + 2.0074075568947277e-05, + 1.5112175287129863e-05, + 8.868053332557463e-06, + 4.1328595096240814e-05, + 2.3365918073951653e-06, + 7.01836851398739e-07, + 1.974601693940481e-05, + 2.2699011482774208e-05, + 1.0706972202517327e-06, + 7.45391906916999e-05, + 0.0029280711260348193, + 2.3553570961174583e-05, + 4.852011383706507e-05, + 0.0002330089418659586, + 2.7897221652101157e-05, + 1.5593738377884085e-05, + 1.058349284017026e-06, + 3.250308511474092e-05, + 4.038446263170618e-05, + 4.6049172717572536e-05, + 2.636155130685005e-05, + 0.007211592682138772, + 7.794108624284254e-06, + 3.1527067534437825e-05, + 3.937530357228339e-05, + 7.399152158740839e-05, + 1.1077299584837934e-05, + 9.111253699030105e-05, + 0.002607844948965233, + 0.004894035966285886, + 4.25828037495546e-06, + 0.004538686199959361, + 8.098320768821391e-05, + 4.880167751546794e-05, + 1.0002450362935638, + 2.5668579786795284e-05, + 5.179000999773563e-05, + 0.0001077222898127599, + 6.096919802748503e-05, + 3.284174067021099e-06, + 0.00010865683469747918, + 4.0346791468329965e-05, + 0.012483629336950668, + 3.5510223520742805e-05, + 7.044948047777424e-05, + 0.003967276004683859, + 0.002313141822622935, + 0.000553497892180952, + 0.0013524119124650137, + 0.0036591943541357543, + 5.2572209354611396e-05, + 2.6938937550086616e-05, + 2.6479781054830162e-05, + 3.167044894012793e-07, + 0.009423005118956355, + 1.8552101725878217e-06, + 2.8684972057005484e-06, + 2.1917380980842736e-05, + 2.3261520739724016e-05, + 5.328558922832335e-07, + 2.8372766896015674e-06, + 0.008434966654025614, + 8.557631805263534e-06, + 6.065882887747172e-05, + 0.003296579722968024, + 1.2973929579280214e-05, + 0.00013867448984484528, + 5.631224140776579e-05, + 4.853197343199784e-05, + 0.00801246907316579, + 1.2460811952974336e-05, + 7.243617434429084e-05, + 0.0003862692349598243, + 0.009742433538967666, + 1.990714084779318e-05, + 5.896737874814423e-05, + 0.007382232899732989, + 2.3553444460228956e-05, + 0.0014701890195581973, + 0.004745979425066099, + 1.765487079884287e-05, + 7.6171374432633975e-06, + 0.01169005897156178, + 0.002066966424496967, + 0.00956642620888577, + 4.411509974638011e-05, + 0.009325200209838529, + 3.41674962668119e-05, + 0.005184694759674665, + 6.311322749339541e-05, + 2.0501915098524828e-05, + 1.537618440707853e-05, + 1.999352945584506e-05, + 1.4313504055806974e-05, + 1.6958464549274786e-05, + 0.0002095266612916967, + 0.0001739067643966113, + 1.754746680391694e-05, + 8.573630025876962e-06, + 8.335327060635427e-05, + 0.00011875593959169661, + 5.633371613685428e-05, + 0.0028124813517910368, + 7.167385084465495e-05, + 2.840085319715022e-05, + 1.3166789154235854e-05, + 5.1312749912381697e-05, + 3.996606173962012e-05, + 0.008164860638231877, + 1.5242491587519319e-05, + 9.110823057042535e-05, + 8.783274600292875e-06, + 7.790316917247569e-05, + 6.180610405893971e-05, + 0.0012335807356279886, + 6.951085703673046e-05, + 3.0199481909460294e-05, + 1.000357354602237, + 9.723714884303621e-05, + 1.3007037389759159e-05, + 0.007478559973594072, + 0.0005756933364419036, + 0.0014978319467007927, + 8.319739106311735e-05, + 0.009060445131141749, + 0.008476403295092551, + 6.165144402688587e-05, + 0.00888209193214149, + 6.204363681200837e-05, + 0.0005059685367658173, + 2.193189938950662e-06, + 6.06595718656155e-07, + 4.654126826922435e-07, + 0.008330062152010861, + 4.724217381934257e-05, + 4.5637951432835935e-06, + 2.3463588718664166e-05, + 3.3014866340073654e-05, + 9.822974678059222e-05, + 0.006152628018747152, + 0.0022208218820898985, + 0.009959454332578336, + 0.0001585354537356698, + 0.0034534397792633023, + 0.0068864505226439, + 0.004865248238712459, + 3.6195734375041716e-05, + 1.5060068616501702e-05, + 1.614530164100325e-05, + 0.004318123334226994, + 7.863280354198881e-07, + 9.519664087722381e-05, + 2.4569621790304322e-05, + 1.4326993554005429e-05, + 0.00010792890575392393, + 5.243876354047514e-05, + 1.0185038332521287e-05, + 3.1188552603485446e-05, + 1.106115656959078e-05, + 2.2056768611094835e-05, + 0.003242508738519706, + 5.803857831012882e-06, + 9.155010186532908e-05, + 0.0050024275339864265, + 0.00016463726515054288, + 0.009248274563630471, + 6.757392944389293e-05, + 0.00011849937708924003, + 0.0001332272819942979, + 0.00011304389453428674, + 0.009813729259187031, + 7.807000346171727e-05, + 0.0025021376078974, + 0.00019408068036398684, + 5.4768435409716286e-05, + 6.224525801469073e-05, + 2.4500541892901417e-05, + 0.00010797040109734197, + 7.405061225080043e-05, + 0.004901352788596833, + 1.000421730166304, + 3.0199481909460294e-05, + 5.6129781407169457e-05, + 4.399702131495049e-05, + 1.3979739129546218e-05, + 9.220435186640806e-06, + 2.8841903361718384e-05, + 0.007505476440510395, + 0.0033801536148952, + 2.696520810397456e-05, + 4.843570844089803e-05, + 4.163593054971914e-05, + 1.9459193714956095e-05, + 5.1116032814248954e-05, + 5.157027738322318e-05, + 3.877812615061973e-05, + 2.5507526232547014e-05, + 2.956871823131433e-05, + 0.00669183652199143, + 0.0068963851965890615, + 0.0010612541856490243, + 1.8834701174318686e-05, + 7.276203856300719e-05, + 4.762214563038365e-07, + 1.78718978296062e-05, + 5.424328468668677e-05, + 0.008121860669464572, + 0.007152670825092443, + 6.025817506004486e-05, + 3.369506848055413e-05, + 3.6412947427721105e-05, + 8.198454746167677e-05, + 0.006793715977169662, + 2.863731908220287e-05, + 8.565419016550504e-05, + 6.9319518972996804e-06, + 8.747730094430352e-05, + 1.1762304592131597e-05, + 8.43803120629424e-06, + 0.002607844948965233, + 3.049006450511041e-05, + 3.243705960449583e-06, + 6.982511354897124e-05, + 8.27067019911165e-06, + 0.00012212415535175345, + 0.005161235266164338, + 4.959806571644058e-05, + 5.787477450346718e-06, + 2.880137609004941e-05, + 2.6676388625680194e-05, + 6.0474015681588885e-05, + 0.00011036325907642369, + 4.246587373330859e-07, + 0.00028570917724010436, + 9.009488664252652e-05, + 5.4075447940124195e-05, + 7.243617434429084e-05, + 6.72187870424122e-05, + 3.687809075046072e-05, + 0.009983239643101386, + 0.008961675208398875, + 0.003839725262471517, + 0.00012252356756068845, + 6.595502583296869e-05, + 4.9454216424904526e-05, + 0.005621853829576654, + 0.00015788936748717885, + 0.00784335809733372, + 7.860681144132016e-05, + 5.7681226031826427e-05, + 9.824617476956339e-05, + 0.009104111949848063, + 7.854359390138303e-05, + 0.0026332132949579883, + 0.0001332272819942979, + 7.30700720386402e-05, + 0.00010056316074184729, + 0.008334515044103877, + 3.709196423785288e-05, + 0.00013430194690215467, + 9.903821108325084e-05, + 0.005320131680220553, + 0.00851023050101972, + 8.894990992311741e-05, + 7.12512536575226e-06, + 1.0007327698873956, + 2.74813477149931e-05, + 0.006997835355462587, + 7.172381736447735e-05, + 0.0035186077058957845, + 0.00018398308294319499, + 0.0001783375337444304, + 0.007715697260558262, + 0.00016056771047132448, + 6.979561412464874e-05, + 3.0360842724742417e-05, + 2.4062175400161237e-05, + 6.942689596137118e-05, + 5.66267224832227e-05, + 0.0008438794789498705, + 0.0047951923711135385, + 9.500151198094398e-05, + 0.0073262954486466875, + 3.686578049401734e-05, + 9.793241132476954e-06, + 1.7594688486085036e-05, + 0.009605685363234352, + 6.511645296408814e-05, + 1.2839983888251582e-05, + 6.897424097163955e-05, + 2.7372743738309747e-05, + 1.2695145626776906e-05, + 1.9242846360984317e-06, + 0.002360689141632851, + 0.009924221952596258, + 0.0071044223349299536, + 0.00010363848198497155, + 0.005765427248372032, + 0.0033159955720434213, + 2.3553444460228956e-05, + 3.823333055521334e-06, + 5.849183962449663e-05, + 0.004622968368555527, + 5.411376477769995e-05, + 4.735984999341235e-05, + 4.988319262381871e-05, + 0.0082645365245498, + 0.0019700424201241754, + 5.646706491604017e-05, + 6.944150722416447e-05, + 0.009622053112821669, + 4.301334828362342e-05, + 4.003025947351584e-05, + 7.12512536575226e-06, + 1.8420403038691553e-05, + 7.762892683073968e-06, + 0.0022893814596128765, + 0.009382044831691094, + 6.224177478794206e-06, + 9.019246741974433e-06, + 0.0009234583894543225, + 3.0746562325406976e-05, + 3.567549464296331e-05, + 0.00130153079327133, + 0.00010236722183861859, + 4.356112667058918e-05, + 0.007118970625743312, + 0.0047020195291187054, + 5.264850636123655e-05, + 0.006362434526919624, + 9.34511827892779e-05, + 0.0032308706257639114, + 6.711352737675126e-05, + 1.000401498616877, + 5.359866281977652e-05, + 0.00011371720186554668, + 4.5445832281131216e-05, + 1.1628614234344098e-05, + 6.276963263902074e-05, + 6.0194675001078164e-05, + 2.4967263474904864e-05, + 0.00012168058179273745, + 0.008239347700691868, + 0.0029241508388424798, + 5.702868336995201e-07, + 5.105886593647359e-06, + 1.1461727965227623e-05, + 3.831561999862129e-06, + 6.661613518538756e-05, + 5.49233249363574e-05, + 0.006868664937349099, + 0.0013013807746215947, + 1.94630953296662e-05, + 9.086408853336123e-06, + 1.6907856271275485e-05, + 0.0026905222874216293, + 2.5866209626581253e-05, + 1.920766372314651e-05, + 1.8323805044617538e-05, + 3.559764352524221e-05, + 0.008617716809513676, + 2.461900532024616e-06, + 4.529448782957032e-05, + 8.697263095435295e-05, + 9.111253699030105e-05, + 8.058523579155135e-05, + 8.573114353939069e-06, + 5.375160122425016e-05, + 3.6875617603695455e-06, + 5.562833465377535e-05, + 1.5917088164935347e-05, + 1.7298730204288893e-05, + 1.3612387774774914e-05, + 0.00914181407893777, + 0.0019574602954816533, + 5.312316031361682e-06, + 4.419183138808709e-05, + 1.184780867061854e-05, + 9.861034013834767e-07, + 6.155588174262378e-06, + 9.760272777704633e-06, + 0.006896939223886141, + 1.592458114561165e-05, + 1.0957915206616842e-05, + 0.0018061101135306693, + 7.431313644927198e-05, + 0.00010584745468589411, + 0.006116514527944604, + 4.6518092916010685e-05, + 0.007160597590819221, + 1.669025577009584e-06, + 1.2649259146947333e-05, + 7.454698894418567e-06, + 5.4075447940124195e-05, + 0.006778124499406896, + 5.699395700018925e-06, + 7.760430092050088e-05, + 2.1906009920850237e-05, + 2.4050974985867775e-06, + 7.795590519058728e-05, + 0.0016040258767245185, + 0.00215782461676853, + 0.005492684933484426, + 0.00010779998862338913, + 4.4724072133743586e-05, + 0.00481031758485341, + 0.005738400102416387, + 6.52507212958729e-05, + 5.906509606247966e-06, + 4.812969575941697e-05, + 0.002946774207824383, + 1.658640530590938e-05, + 1.0003355129147409, + 0.004901352788596833, + 6.951085703673046e-05, + 7.489498443709168e-05, + 6.24900923096088e-05, + 2.5078590911148673e-05, + 3.3409698001656547e-05, + 2.6724663523493806e-05, + 3.5152894511271435e-05, + 0.006085598405466598, + 6.176049961778198e-05, + 2.2433062721085766e-06, + 0.008330062152010861, + 0.0005478704792354883, + 0.008978981047742522, + 2.5660230268410952e-05, + 2.9786294750743373e-05, + 2.3464494097835496e-05, + 0.011437588139071007, + 1.5211346445822785e-05, + 5.518628161876147e-05, + 2.026619213012e-06, + 3.554312579674117e-05, + 5.5252471143096764e-05, + 0.007331530231065854, + 0.007785646161814149, + 2.8971481713675734e-05, + 3.698500719033811e-05, + 0.00011970197773206852, + 3.982086179258424e-05, + 4.953655337972678e-05, + 1.8160182746121535e-05, + 1.3878170459442497e-05, + 1.2098027758146606e-05, + 3.8498380768415485e-05, + 8.43803120629424e-06, + 1.1077299584837934e-05, + 1.7230684945129012e-05, + 1.3089510001785621e-05, + 5.562833465377535e-05, + 4.831905131488414e-05, + 0.007690836904536741, + 0.006948275793281259, + 2.627011625477693e-05, + 2.2487394622544145e-05, + 0.003296579722968024, + 7.01050892693061e-05, + 8.193477229159464e-05, + 0.009439959067106114, + 2.830839327894561e-05, + 0.00013540300672868085, + 0.00011094755414201958, + 0.0037882592550023573, + 8.751376430531743e-05, + 8.046991690297857e-05, + 0.00782914362550076, + 2.3242003711048557e-05, + 3.4677134824006374e-09, + 6.492634734915772e-05, + 7.092762014150933e-08, + 0.00013940450826643473, + 2.7398964806537252e-05, + 6.174032240952402e-08, + 4.1517316058143174e-07, + 5.7250640224978076e-05, + 4.798729591851256e-05, + 2.1404205094684842e-07, + 2.8032026778863344e-07, + 5.7475994530403656e-05, + 5.742437076531531e-05, + 6.192835638460486e-05, + 3.5351194579500076e-06, + 0.0001479121002112239, + 1.0003971464594963, + 3.9536170159753443e-05, + 2.5853406633669654e-06, + 0.0001012477669236068, + 7.933617991373189e-05, + 0.005937531341288544, + 6.116235985298115e-05, + 8.651694171316354e-05, + 1.858511569018207e-05, + 5.597548049290373e-05, + 0.0010902598840878482, + 1.6206885535492838e-05, + 1.0482807165536582e-05, + 0.007111014770507566, + 3.026971897764431e-05, + 9.075276578589366e-05, + 4.7243792305993805e-05, + 8.759244847284295e-06, + 5.157027738322318e-05, + 4.849876254314921e-05, + 2.1787544078622775e-05, + 2.7198580063679282e-05, + 2.8838670323751205e-05, + 0.006256769866490425, + 0.001232839274524128, + 0.009832220847402985, + 9.476836787913726e-06, + 9.194877552631466e-05, + 1.7386720499088466e-06, + 1.1261487041142267e-05, + 2.116693775127853e-05, + 7.623227138481154e-05, + 1.6007448693199368e-06, + 1.974601693940481e-05, + 5.245897082846726e-05, + 0.006796385353731588, + 0.0001594947964237924, + 2.973840254558375e-05, + 7.490029829638944e-05, + 4.036930180264357e-05, + 8.218202439742403e-05, + 2.8154529321024527e-05, + 2.883557709799689e-05, + 0.008534519561254493, + 4.156106397999411e-06, + 3.54518836652093e-05, + 0.006222048667824248, + 7.883599940851821e-05, + 2.2487394622544145e-05, + 2.6445664430825162e-06, + 8.477351939698314e-05, + 1.1478516439581388e-05, + 1.2188625738568068e-05, + 7.040445704723166e-05, + 0.0019808005861819576, + 1.2854505722798077e-05, + 0.0019505472223636333, + 1.1752268666632123e-05, + 9.355601373532127e-05, + 7.849728077354606e-05, + 0.00010936821654083165, + 7.684621219798062e-05, + 5.977129380080876e-05, + 8.077315543870918e-06, + 8.181005804706189e-05, + 2.174789309648852e-05, + 6.305125415772337e-05, + 0.009122020485873628, + 8.784487795116046e-05, + 1.9266161726239038e-05, + 0.009744246327290896, + 2.9295282855615235e-05, + 0.00130153079327133, + 4.5797633600523134e-06, + 0.008592458769033464, + 0.0044026206126353655, + 0.0006133619759453804, + 2.3827168497977226e-05, + 3.783818615351871e-06, + 2.001031923930151e-05, + 1.732762971576925e-05, + 1.0004064404683561, + 1.658640530590938e-05, + 7.405061225080043e-05, + 0.0012335807356279886, + 2.9507190624179216e-05, + 2.9396639749410458e-05, + 2.0225316812531166e-05, + 6.600953573744792e-05, + 3.527685498118427e-05, + 0.0055860723141447684, + 0.0027643037349795144, + 0.004752970738232557, + 0.0024985379607832957, + 3.61809234611927e-05, + 8.001581192602237e-06, + 5.035059539802786e-06, + 3.9934496549270716e-05, + 1.1918029804950755e-06, + 8.844973558735425e-06, + 4.962050411035719e-06, + 9.09074558996317e-06, + 0.003910368997623035, + 1.5765266083114732e-05, + 1.5703286642692057e-05, + 1.3089510001785621e-05, + 3.6875617603695455e-06, + 1.5318526814856903e-05, + 1.6648212270453975e-05, + 0.00188385009334873, + 5.038538789141869e-06, + 4.959806571644058e-05, + 4.573898088787692e-05, + 8.283092032568344e-05, + 4.315960899625176e-05, + 8.80187196272973e-05, + 0.008963041275584496, + 3.5363666992940155e-05, + 3.6960655441931726e-05, + 1.6306202238306393e-05, + 4.2474491256049146e-05, + 7.929394171683288e-05, + 3.4778956437108256e-06, + 3.312989228982466e-06, + 5.328558922832335e-07, + 3.46151188786036e-05, + 7.429189137403037e-07, + 2.8887654452486578e-05, + 0.007699851554496911, + 3.2669094648244773e-06, + 6.865839426972015e-08, + 5.2222019800368575e-05, + 9.250690181223868e-05, + 0.004938488230247744, + 0.002965796072866161, + 0.00915211765251319, + 9.705123470081156e-05, + 4.3871349822661094e-05, + 0.00042286073353053205, + 4.928443982842512e-05, + 2.1655730003934487e-05, + 3.3352789969766985e-05, + 2.2852157316310878e-05, + 4.5523933983688476e-05, + 6.112496302509246e-05, + 1.000272566936319, + 2.9295282855615235e-05, + 3.567549464296331e-05, + 0.011055507216417616, + 8.654641647049102e-05, + 0.005903640664409296, + 0.007621533699389588, + 5.408312218936873e-05, + 1.619573616404499e-05, + 0.004257099225473964, + 3.716813088547636e-05, + 1.7199603304863812e-05, + 1.8428138804039813e-05, + 0.005641913561175485, + 3.6468725047509243e-06, + 1.697154319579523e-05, + 1.300046522527695e-05, + 1.7490310600702375e-05, + 2.691506463774306e-06, + 2.3007962908176834e-05, + 0.002752361059311225, + 2.0337974678940336e-05, + 1.188084764263294e-05, + 8.111616680886158e-06, + 1.1992982759795414e-05, + 6.015624802294293e-05, + 3.5078202872376415e-05, + 2.1613058386334702e-05, + 2.4937042062898712e-05, + 7.636203446290959e-05, + 5.400377972758566e-05, + 0.007938956551945167, + 8.805908936468158e-06, + 0.009083110322041153, + 2.0262792069064637e-05, + 1.0800165987017764e-05, + 2.5324083389253696e-06, + 1.6037235818269438e-05, + 5.73502575314267e-06, + 0.0007179782566983814, + 6.204465674665756e-05, + 8.04680136256436e-05, + 0.0026332132949579883, + 0.0001246807859027139, + 2.0646085382212123e-05, + 3.667290377192227e-05, + 1.9452907879640914e-05, + 6.648775300564829e-05, + 5.467452991247206e-05, + 6.170463670825358e-06, + 1.732762971576925e-05, + 0.002946774207824383, + 0.00010797040109734197, + 6.180610405893971e-05, + 6.203012046578658e-05, + 0.0030345791284893233, + 2.619931980962859e-05, + 1.7279945498281717e-05, + 0.0064067636604403086, + 0.006357808687633092, + 4.7927871872026924e-05, + 0.0002062465091986742, + 7.31414159273588e-05, + 1.017183487279046, + 6.711352737675126e-05, + 5.235179554840961e-05, + 4.764519943351331e-05, + 7.164637249194579e-05, + 8.39792052135796e-05, + 2.9776421787722422e-05, + 6.244920472937696e-05, + 7.774943916630372e-05, + 8.369797878943574e-05, + 0.009287224138628118, + 5.744975875099374e-06, + 9.03558246672859e-06, + 2.162203723537085e-05, + 3.219552204844843e-05, + 9.782597090310911e-05, + 6.554788593807364e-05, + 3.4302692151672156e-05, + 1.300046522527695e-05, + 5.367080479121616e-05, + 4.05511193210967e-05, + 0.007856691498778193, + 5.731589450935227e-05, + 5.747989602628534e-05, + 9.862047675441458e-06, + 8.574514082806994e-05, + 5.184270392431239e-05, + 4.6049172717572536e-05, + 6.901220565399228e-06, + 7.308391734018726e-05, + 5.375160122425016e-05, + 0.005005808894482987, + 1.4016888306636507e-06, + 1.867823167771344e-05, + 0.005161235266164338, + 0.00639840042891731, + 3.25768819028559e-05, + 2.0880117819139736e-05, + 4.744312810238377e-05, + 0.00706018696690996, + 3.2432119128314313e-05, + 4.3330251548595315e-05, + 0.006559693924237348, + 1.824223373856259e-05, + 4.186941554450491e-05, + 5.794297254880646e-05, + 0.0025612490314566227, + 0.004926455754866431, + 1.2234782130969098e-05, + 0.00013540300672868085, + 3.744616336372351e-05, + 1.879420935773223e-05, + 4.296992740599398e-05, + 0.00648503653023617, + 0.006811594638544919, + 4.865829265027054e-05, + 0.00015039691379098406, + 4.5579882391700233e-05, + 0.0058645951237479765, + 0.00012079849373020242, + 1.1440732422000322e-05, + 0.00011931118425226127, + 0.00010310363765821542, + 0.0029571873238747764, + 0.00014836819241966453, + 6.479496401931944e-05, + 0.00013652022364646203, + 0.008272674602401412, + 6.112496302509246e-05, + 0.009744246327290896, + 3.0746562325406976e-05, + 7.131459924188185e-05, + 3.586343427183496e-05, + 1.4573046498807523e-05, + 0.0039026607996137945, + 0.0026200093998360965, + 0.00242858334084194, + 1.0058255821628395, + 8.573630025876962e-06, + 0.002554135913483182, + 0.006161186192549629, + 6.897019142137336e-06, + 7.991859104992195e-05, + 0.002859745735827901, + 9.546069637881966e-05, + 0.005263923874568061, + 0.0057750436745369355, + 5.267454634504788e-05, + 0.004679745180711632, + 5.8729422882028494e-05, + 1.8734155484644436e-06, + 1.2288862401220086e-06, + 3.8744548382065554e-05, + 4.2505389300810915e-05, + 4.001426304671741e-05, + 3.4881950218393824e-05, + 1.9953765773175086e-05, + 9.647701407466116e-06, + 5.757301024859485e-05, + 2.7396178308899984e-05, + 0.0028681574720703117, + 0.004752970738232557, + 4.328259607237442e-05, + 1.4425087088570349e-05, + 3.219552204844843e-05, + 0.006256769866490425, + 1.843783095389692e-05, + 6.757292987282388e-05, + 8.616175865337904e-06, + 3.6468725047509243e-06, + 0.0013013807746215947, + 2.3463588718664166e-05, + 8.484749056658531e-06, + 3.942136473014121e-05, + 6.045509972018361e-05, + 2.170212323715844e-05, + 2.9990147075282934e-05, + 1.656838550283511e-06, + 3.275334088345922e-05, + 7.312414951957388e-06, + 0.013780337834186657, + 0.009295247913139942, + 4.276492816919655e-05, + 9.614526501090822e-05, + 0.013438832548117487, + 5.706019083774347e-05, + 3.9953097404302765e-05, + 7.395084545201742e-05, + 5.6874060280116495e-06, + 0.0014860797174881262, + 5.742099408205895e-06, + 0.005126444542508474, + 0.004525181008797196, + 1.0966824173649002e-05, + 0.00549933348301436, + 1.5106463096119683e-05, + 1.1136795167012167e-05, + 0.0016826044433800413, + 3.8048334218202605e-05, + 4.266113161881524e-05, + 8.61084221273961e-05, + 1.2827787409715243e-05, + 2.957012864087119e-05, + 4.470866250334624e-05, + 0.005304731871977922, + 4.7380954835658765e-05, + 0.009180813294514662, + 0.00010938912433855871, + 4.8878825131751535e-05, + 6.086804239422096e-05, + 5.198791482656931e-05, + 9.330886000894899e-05, + 4.003025947351584e-05, + 8.894990992311741e-05, + 8.490755068004092e-05, + 7.397498922067364e-05, + 1.298044941180189e-05, + 7.923441900497486e-05, + 0.00795786731176502, + 0.00010528753431476505, + 1.0003394409324793, + 0.002066966424496967, + 0.0072466957647136405, + 1.8408154591897332e-05, + 2.6170465216380154e-05, + 7.391753503787828e-07, + 4.862973927123171e-06, + 9.175661661202585e-05, + 2.843055287948848e-06, + 0.010279256328935539, + 4.18806829585507e-06, + 0.0005059685367658173, + 3.133972759601782e-05, + 0.004980246622128062, + 4.442344954711435e-05, + 3.5204792102386216e-05, + 7.438842701197541e-05, + 0.00010228567311313031, + 5.458421368513962e-05, + 3.6380520404962396e-05, + 0.005956877741835263, + 0.0058768241372289, + 3.2394319262609834e-05, + 5.0087594202736606e-05, + 0.0089202536935198, + 0.013438832548117487, + 5.068234755661218e-07, + 2.059942267026535e-05, + 0.004038422827637369, + 8.886247607167789e-05, + 9.548755468020766e-05, + 4.4844266449640813e-05, + 3.3321946258636567e-05, + 4.51632447994695e-05, + 0.009546401607162315, + 0.0011979513772529824, + 0.004448178781097971, + 0.007158975274909028, + 0.003405796470211449, + 7.308391734018726e-05, + 1.5703286642692057e-05, + 0.0013023827143545978, + 1.773236913896812e-05, + 2.2622216737783084e-05, + 1.468252114735999e-06, + 3.503912963572349e-06, + 3.232509725475268e-05, + 0.00010584745468589411, + 4.246587373330859e-07, + 0.0015357985919753874, + 1.1663596453736771e-05, + 4.6510875847825296e-05, + 7.883599940851821e-05, + 4.232256890170172e-05, + 4.157804352074367e-06, + 0.0009434926438126656, + 0.0007991026022771701, + 8.673170287506496e-05, + 0.009377706183599573, + 6.492634734915772e-05, + 0.008851514555513171, + 2.408253652537229e-05, + 3.390535436114262e-05, + 8.500073672303659e-05, + 0.007337281118937193, + 6.841527427324271e-05, + 7.454297128879022e-05, + 4.485651296957946e-05, + 1.817098185835928e-05, + 0.00571553669088225, + 0.0002192081488419424, + 4.880167751546794e-05, + 0.00012386310278921677, + 0.004340989890632332, + 0.008338421645317543, + 2.988522877189406e-05, + 8.163737875101414e-05, + 0.0003744931963655796, + 5.311863651417748e-05, + 1.0006811004413325, + 6.311322749339541e-05, + 0.009423377551926036, + 0.0001351869158332422, + 6.471299638717376e-05, + 4.5559832168017325e-05, + 0.00014728026048875834, + 7.007217650806319e-05, + 0.00013616695276437934, + 0.009827093921226878, + 0.00014087934069183532, + 0.0004466121637889875, + 0.006854405223712914, + 0.0070778397836248255, + 0.007058824446817216, + 0.00640193868537032, + 6.9481289418868506e-06, + 0.0036699814726822077, + 2.147224746167066e-05, + 2.306744948090414e-05, + 1.1862578488334266e-06, + 3.783128411679979e-05, + 2.7943759314982804e-05, + 4.787322589202522e-05, + 0.008560723438005933, + 0.0078036394547676404, + 7.661734569325919e-05, + 1.914398375550642e-05, + 3.717180985853054e-05, + 4.5465306232506115e-05, + 0.00011739049928613754, + 0.008617716809513676, + 4.038446263170618e-05, + 6.052271248082022e-06, + 2.450334734056812e-05, + 0.00549933348301436, + 3.686578049401734e-05, + 1.3500497663962548e-05, + 0.006804287846315139, + 0.003837912559068474, + 0.0001087401656131354, + 6.841599600088951e-05, + 4.862375713081473e-07, + 0.009377706183599573, + 3.4677134824006374e-09, + 8.709392167994599e-08, + 3.5405275164337536e-07, + 0.0058248967139245935, + 7.581259308717127e-08, + 4.985196467268206e-05, + 2.5591472821463486e-05, + 4.3755520141460105e-07, + 5.233154862039399e-06, + 2.628279587583401e-07, + 3.4421275378160735e-07, + 2.6714321060972634e-07, + 0.00012090014934069268, + 4.5873095412197237e-07, + 4.9644642230663515e-06, + 1.000142157056739, + 0.00242858334084194, + 1.754746680391694e-05, + 2.8342207263042518e-05, + 1.5694842719006986e-05, + 1.4115982854095151e-05, + 2.5613491124066854e-05, + 3.8638061642113294e-05, + 7.08690593428671e-05, + 0.005316713458998503, + 2.8923941111746002e-05, + 2.052195184514316e-06, + 0.002235762253920633, + 7.014458098379015e-06, + 7.472068481635205e-05, + 0.009092323764615015, + 0.004215542482180343, + 0.009339513385827183, + 1.473775828964842e-05, + 7.177313382859093e-06, + 3.0086491323618898e-05, + 2.2621518051178686e-05, + 5.598447718045988e-06, + 4.30662229714024e-06, + 6.627270386680282e-07, + 4.744312810238377e-05, + 2.880816747198646e-05, + 5.551330944747475e-05, + 4.3422810041187425e-05, + 0.007696421638836545, + 7.667920282896653e-05, + 5.801413329136704e-05, + 3.5363666992940155e-05, + 0.007710383702448548, + 4.5312749216232344e-05, + 6.902350664223597e-06, + 3.155285473097504e-05, + 4.071855624915881e-06, + 6.0979077600877525e-06, + 4.662078208548067e-06, + 4.604520513321305e-06, + 1.5511247519254373e-08, + 1.0479176239748488e-06, + 6.830114907139503e-06, + 0.0017614905000378658, + 0.00010672287848834117, + 8.100221253346378e-07, + 7.419336729443077e-07, + 3.3991256312993264e-05, + 6.902447524591277e-05, + 0.003839725262471517, + 8.570889656902395e-05, + 2.5997154839160077e-05, + 5.5540199060968216e-05, + 7.308022435673637e-05, + 3.7779296004229136e-05, + 0.005454660455186017, + 3.004152528081633e-05, + 2.1516653637500003e-05, + 6.313932232818006e-05, + 0.003789193622807026, + 2.001031923930151e-05, + 4.812969575941697e-05, + 2.4500541892901417e-05, + 7.790316917247569e-05, + 0.00010630503753370316, + 0.008061790939854345, + 3.0255537649567676e-05, + 1.9955252480012823e-05, + 4.848704502905711e-05, + 0.007315470196481674, + 0.0033140161641720288, + 2.5780883983877218e-05, + 1.0002108841077482, + 7.31414159273588e-05, + 0.0032308706257639114, + 1.836210569087713e-05, + 1.671129286964195e-05, + 2.817754802475255e-05, + 4.231435282329788e-06, + 9.486510994712678e-06, + 2.1903716683254796e-05, + 3.7744090451044085e-05, + 9.682822996583617e-05, + 0.0029512563984702782, + 1.844624633903237e-05, + 3.191294170529035e-05, + 2.2130008087780147e-05, + 9.915672087837691e-05, + 0.003013917957663592, + 0.0027052178017184657, + 0.0026360543980688145, + 4.419688041692284e-05, + 6.204363681200837e-05, + 3.025985047345458e-05, + 8.17597435056736e-06, + 5.9992598886879715e-05, + 3.4302692151672156e-05, + 1.697154319579523e-05, + 0.00669183652199143, + 4.6149482328255726e-05, + 0.006820772970732364, + 3.7378004968560184e-05, + 9.194877552631466e-05, + 0.003967276004683859, + 3.177050433723157e-07, + 3.774635551090802e-05, + 1.0802323681468716e-05, + 3.6872163354419606e-05, + 3.3445602506082165e-05, + 9.176872048322657e-06, + 1.4517033957637429e-05, + 2.3464494097835496e-05, + 0.00654750217444128, + 1.260606554655423e-05, + 4.2157943183771885e-05, + 1.8874859837226256e-05, + 1.78710524516326e-05, + 5.5825868717821875e-05, + 7.073516401505625e-05, + 4.154972671783279e-06, + 0.00788135828673028, + 1.805825071175295e-05, + 0.0089202536935198, + 9.614526501090822e-05, + 0.0034308146917214903, + 9.945503597024794e-06, + 2.7089114924897626e-05, + 0.0021123970544425484, + 0.00011464695819708957, + 4.64572228654459e-05, + 3.3563580092853017e-06, + 6.601542168847671e-05, + 1.9242846360984317e-06, + 0.008570542520500277, + 4.832756745625646e-05, + 8.274536257263668e-06, + 0.00033545871412157813, + 2.0999175882370937e-06, + 4.604520513321305e-06, + 2.1906009920850237e-05, + 5.796526019303194e-07, + 0.0022034474410589774, + 1.7099755476563073e-05, + 3.316459337939621e-05, + 0.003988215269240574, + 0.0001088050593768327, + 0.00011214618521792638, + 0.008601017543635006, + 5.124321109448016e-05, + 0.009603983607945473, + 3.5592858376339366e-07, + 1.0003950600403508, + 5.6847103838554745e-05, + 2.3909045231668042e-05, + 0.00010989645420088088, + 5.9772051130068166e-05, + 6.3632241538920716e-06, + 8.081471592653644e-05, + 4.101264839737831e-06, + 9.10611133788154e-05, + 0.003614653284985154, + 6.865750563308246e-05, + 1.9982365220095112e-05, + 1.2642191068013989e-05, + 6.256499749409017e-05, + 1.972049328233557e-06, + 0.007633076152122106, + 0.008253979436132665, + 0.003520165825018783, + 0.006152628018747152, + 8.949778834480208e-05, + 1.5202867029995339e-05, + 0.009754505241349513, + 1.7920640048420202e-06, + 0.0009155504675766507, + 7.444172154719142e-06, + 1.2505689816741404e-05, + 7.076122568641112e-05, + 1.6821322945941589e-06, + 4.7675626079801785e-05, + 2.5151047401374303e-05, + 0.0029935243072698762, + 0.008441282349888507, + 4.5704631119594805e-05, + 0.006834759289973527, + 2.799583849796062e-05, + 3.312989228982466e-06, + 0.004515126381855252, + 0.000144358736576273, + 2.858263139481979e-05, + 0.00015183555325760058, + 0.011109083184725779, + 6.77279581052288e-05, + 6.601542168847671e-05, + 6.323381054764368e-05, + 4.6510875847825296e-05, + 0.006222048667824248, + 1.4039561271931087e-05, + 6.040661971505374e-05, + 4.907519256652523e-05, + 6.0979077600877525e-06, + 2.5324083389253696e-06, + 7.454698894418567e-06, + 2.416269384841492e-05, + 0.00983724045435927, + 7.060536541393035e-05, + 0.003607489004396031, + 4.722913778170408e-05, + 9.330886000894899e-05, + 4.301334828362342e-05, + 0.00851023050101972, + 1.3244196667398672e-05, + 6.720359856629058e-05, + 1.1792268179702386e-05, + 0.007374988275636387, + 8.391767317401229e-05, + 0.006554729173032643, + 0.00013417932789838304, + 8.688208808112132e-05, + 0.0008191279921094674, + 0.0001715093884257497, + 2.3895854276530894e-05, + 0.0001479121002112239, + 9.760124850673267e-06, + 0.0014282378997911738, + 0.007255646153887324, + 1.0251676266438782e-05, + 0.0018293532128421254, + 0.0015280277596831245, + 1.0376186007173165e-05, + 2.2472137285700316e-05, + 3.207616483694981e-05, + 8.20396676808335e-06, + 3.3593084677221634e-06, + 0.006382219318046553, + 0.00013392696754589646, + 0.0014518138740913999, + 1.0006541024900906, + 4.9644642230663515e-06, + 0.0026200093998360965, + 0.0001739067643966113, + 0.001268052671563556, + 9.414993358493272e-05, + 0.0077137338986100305, + 2.266465386200731e-05, + 8.105068432626227e-05, + 8.804415323161467e-05, + 2.657005871295784e-05, + 0.007887920773598681, + 9.067980198600438e-05, + 0.0023031022140271094, + 0.00010653288579349231, + 0.0001277688390982566, + 0.008749394056026713, + 0.003332199800398498, + 3.191294170529035e-05, + 3.026971897764431e-05, + 2.8897167742560854e-05, + 3.3857206954811586e-06, + 2.7642468420145466e-05, + 0.00888209193214149, + 1.8785954384074086e-05, + 1.958894495909591e-05, + 8.241318856450491e-05, + 3.61809234611927e-05, + 3.3602864974098526e-05, + 5.429085810404545e-05, + 7.694523948548027e-06, + 4.918019805390054e-05, + 8.572392299435928e-05, + 1.778782434313251e-06, + 5.425778203040552e-05, + 7.444172154719142e-06, + 7.312414951957388e-06, + 0.008121860669464572, + 0.0018985266027096914, + 2.9134358931703176e-05, + 8.943649925289279e-06, + 4.0955284985322874e-05, + 0.006488736813887829, + 5.5843212860730985e-06, + 1.3421878168480512e-05, + 4.904713082344558e-05, + 1.7393470899108238e-05, + 0.001604134906301068, + 2.9446476827046725e-05, + 5.8749181656967195e-05, + 8.257332596159574e-05, + 3.122237635000989e-05, + 8.073755821739811e-05, + 0.006330940003646736, + 5.237202499739881e-05, + 5.905432437917108e-05, + 0.006617942237573037, + 3.659235809869866e-05, + 0.00011739049928613754, + 3.559764352524221e-05, + 3.250308511474092e-05, + 0.004509471864731448, + 4.87111811559589e-06, + 0.008550548609811963, + 5.0719985763207966e-05, + 0.0074382588194354445, + 4.134393643718326e-05, + 4.281663812917758e-05, + 0.00906453844049525, + 2.519599844706269e-05, + 0.005053902503785076, + 1.4892552717406243e-05, + 1.2511572762084668e-05, + 2.830839327894561e-05, + 1.185020908107824e-05, + 5.947613597670801e-06, + 1.0839399538239977e-05, + 1.7654607315174462e-05, + 1.3598258892740924e-05, + 0.0020341300219831504, + 0.005453446633799271, + 2.492884242619572e-05, + 1.0003279959391775, + 0.006811594638544919, + 3.3428408975038574e-05, + 0.0022039957819478574, + 2.035577968764197e-05, + 3.652138838893042e-05, + 9.717628586914298e-05, + 0.0009509364771072949, + 4.772181923265292e-06, + 3.7378004968560184e-05, + 1.3839749949607112e-05, + 7.544933136494426e-07, + 7.010848482190836e-05, + 2.1793448813973866e-05, + 8.461744813480758e-05, + 5.214824211776975e-06, + 1.274185590414587e-05, + 3.447538930700454e-05, + 0.0032183609103764335, + 0.003061799067835776, + 1.3151090432536203e-05, + 1.83301846932302e-05, + 9.317462688392536e-06, + 7.809001938097258e-06, + 1.440955553962265e-05, + 0.009223941671165107, + 3.6380520404962396e-05, + 0.009423005118956355, + 0.001935240152718257, + 0.0004904804093198068, + 0.004321927299556481, + 3.683536136168756e-05, + 8.760010546227632e-06, + 3.659235809869866e-05, + 4.5465306232506115e-05, + 5.184270392431239e-05, + 0.00819832382907284, + 8.7746997810561e-06, + 1.6864204928424063e-05, + 3.8498380768415485e-05, + 8.697263095435295e-05, + 1.1762304592131597e-05, + 7.399152158740839e-05, + 3.191972451121407e-06, + 0.003402162384553347, + 2.401893992812954e-05, + 8.138762190459502e-06, + 4.658818043835977e-06, + 2.2680768964021368e-05, + 3.158419269677393e-05, + 1.5060068616501702e-05, + 0.00013853609608595324, + 0.003625097313221236, + 4.0860568906730575e-05, + 3.066706376961309e-05, + 6.861453876372358e-07, + 0.0012873218666964255, + 2.1017098271407778e-05, + 1.000293516157589, + 9.355601373532127e-05, + 6.833509523082159e-06, + 3.993375566796682e-05, + 0.004441591003607541, + 0.009872411943305133, + 0.00010908601690073171, + 9.025925841730478e-06, + 7.921050259260159e-05, + 9.141793619796793e-05, + 2.430199355672523e-05, + 0.012865204471301449, + 4.5377225727068476e-05, + 7.045607431884256e-05, + 7.583882756894263e-05, + 5.032455958925542e-07, + 0.00015500191455285152, + 1.041461905701894e-06, + 1.3190033228713383e-06, + 1.5309273798143577e-06, + 0.009556394617234216, + 0.006037442885632564, + 3.52533981816771e-05, + 1.2358780250946126e-05, + 1.5943467644657593e-05, + 5.5825868717821875e-05, + 3.16864353202332e-06, + 0.007560260915174101, + 0.004634066879474433, + 0.009609472854344313, + 0.0023256807425682856, + 5.6189019332360594e-06, + 0.002767609432052601, + 0.006488736813887829, + 2.8971481713675734e-05, + 0.006548836331007934, + 8.507831038245505e-05, + 0.0033535155434166993, + 0.004967052543479441, + 4.170074180386796e-05, + 0.006691148114714365, + 2.450334734056812e-05, + 1.0966824173649002e-05, + 0.0073262954486466875, + 6.509212224544221e-06, + 0.006384550706521437, + 5.6017542851683475e-05, + 2.058697160405831e-05, + 9.786425522897559e-05, + 4.215782068752736e-06, + 1.867823167771344e-05, + 0.00012212415535175345, + 7.834536780450026e-06, + 6.595216521287041e-05, + 3.611195890619833e-05, + 0.0001071678049589081, + 0.007495164151567807, + 6.279997697755538e-05, + 4.7301757573742176e-05, + 9.250690181223868e-05, + 1.3612134800845368e-05, + 0.004245174591239174, + 8.394452031494062e-05, + 0.003107753790333846, + 0.0048535845820513075, + 2.436312083575389e-05, + 6.304818718883307e-05, + 9.79414383924028e-05, + 8.484984963731137e-06, + 1.000249718175502, + 0.003789193622807026, + 6.170463670825358e-06, + 3.783818615351871e-06, + 5.906509606247966e-06, + 6.224525801469073e-05, + 8.783274600292875e-06, + 0.004466014513292503, + 4.2842658647721135e-05, + 0.002385822926232189, + 2.6816888588111612e-06, + 7.245178783852634e-05, + 5.699201280114511e-06, + 0.0009830902887607762, + 4.504480980288661e-05, + 0.00793893361762072, + 2.888365587897267e-05, + 5.464438004534413e-05, + 9.023068062958051e-05, + 0.008253979436132665, + 8.759244847284295e-06, + 1.7917148373883355e-05, + 8.616175865337904e-06, + 0.006868664937349099, + 0.009223941671165107, + 3.167044894012793e-07, + 1.3509640250550743e-05, + 8.181167154527567e-06, + 1.6002638384314436e-05, + 1.3866946691552715e-05, + 4.51632447994695e-05, + 2.0074075568947277e-05, + 0.004191427400667957, + 0.002767609432052601, + 0.007785646161814149, + 1.8017238244775715e-05, + 7.174832499906487e-06, + 3.9045702490191184e-05, + 8.545533305049899e-07, + 0.00951396970838286, + 5.0719985763207966e-05, + 0.006559693924237348, + 4.580812393541896e-05, + 5.3005380202982966e-05, + 6.124403934534732e-05, + 0.00011641156866472645, + 3.434636208153656e-05, + 2.1162142534132394e-05, + 0.00011225674094685073, + 7.710549309795944e-05, + 0.007773325140821933, + 0.007404914265770819, + 0.00010016745206491854, + 2.0442660856813986e-05, + 9.369088524743714e-05, + 8.449591102227881e-05, + 7.854359390138303e-05, + 0.00011849937708924003, + 0.00014399155572362174, + 6.0430188781166103e-05, + 0.008073456212003685, + 4.129705794276378e-05, + 0.00010527569821340091, + 7.200823939394418e-05, + 4.367459088655561e-05, + 4.832204262125161e-05, + 8.633795911073606e-05, + 0.00013284441629376648, + 1.839704114108649e-06, + 2.3093786328915213e-05, + 1.4040406457210514e-05, + 3.511630656969946e-05, + 6.668280050031122e-05, + 5.2769736697683524e-05, + 1.8417197291495864e-05, + 0.009630677550983137, + 4.931662042727166e-05, + 1.000545246656902, + 2.5780883983877218e-05, + 0.0002062465091986742, + 9.34511827892779e-05, + 5.803877605658419e-05, + 0.00013016863433750942, + 0.0010627994318390286, + 8.315043882107788e-05, + 0.001098848492576027, + 0.009821730370983375, + 5.315905599966685e-05, + 0.00012730643180779922, + 0.008965663068428692, + 0.00932536085802224, + 0.008016194859820336, + 0.008744145541964786, + 0.0037464921901482874, + 8.114762162992688e-06, + 4.4185831029026516e-05, + 9.526712031344487e-05, + 1.8221410812353872e-05, + 6.782242961139645e-05, + 4.215782068752736e-06, + 1.4016888306636507e-06, + 5.038538789141869e-06, + 5.879348156754798e-07, + 2.9258570574108967e-06, + 5.5266816322073946e-06, + 4.712760169925774e-06, + 1.1197116341924697e-05, + 4.840093735853481e-05, + 3.158419269677393e-05, + 3.6195734375041716e-05, + 2.213282547714912e-05, + 4.0947561295588445e-05, + 7.370596526041767e-05, + 1.649098475312688e-06, + 6.264312554818843e-05, + 6.787198893609816e-05, + 7.642510395190615e-05, + 6.902447524591277e-05, + 5.30035956401809e-05, + 7.795414495027033e-05, + 0.0006170670814896797, + 0.0063204791660593125, + 0.004533179197600133, + 4.837751437608723e-05, + 0.00012580821005702604, + 4.722913778170408e-05, + 5.198791482656931e-05, + 0.009622053112821669, + 0.005320131680220553, + 5.4917651460058454e-05, + 0.00010580887260818803, + 0.008806804007942875, + 0.006532895409013626, + 0.007042734309568557, + 1.0003568344545164, + 7.200823939394418e-05, + 6.25004168927728e-06, + 0.005249400737137344, + 7.943201654792854e-05, + 6.915242362438579e-05, + 4.13354242155286e-05, + 8.377027048123183e-05, + 2.1828240989408474e-05, + 7.007475291609435e-05, + 2.0196582070012896e-06, + 3.3007267523658666e-05, + 7.639022655726693e-05, + 0.009326835203001295, + 0.007720895238812851, + 0.0024137781207065954, + 0.004257099225473964, + 0.003514649711063711, + 0.004346782317554877, + 3.5204792102386216e-05, + 0.0039959851162086795, + 1.5005851203904687e-06, + 3.9533904636675386e-05, + 2.282562280992101e-05, + 2.243657506251215e-05, + 1.184780867061854e-05, + 6.139913854674415e-06, + 3.7681435698580956e-06, + 3.729640223912626e-05, + 2.7505844109233254e-05, + 6.085174025597421e-05, + 0.006728550378096911, + 3.745663236051577e-05, + 2.957012864087119e-05, + 1.2839983888251582e-05, + 2.1917380980842736e-05, + 3.3429279893770895e-05, + 4.0935322624666356e-05, + 0.005574292792643197, + 5.5480085827694036e-05, + 2.8118112264122915e-05, + 2.9408081782277706e-06, + 7.642510395190615e-05, + 3.3991256312993264e-05, + 0.008961675208398875, + 0.008814308982101544, + 6.939682639117589e-05, + 5.203493787178862e-05, + 4.860647658428452e-05, + 0.0082483715939574, + 1.384537377720797e-05, + 3.5592858376339366e-07, + 7.443863429482305e-07, + 6.513160904765917e-07, + 4.2093820849666625e-05, + 8.978547674713963e-07, + 1.7334319453500232e-07, + 0.00410196302462687, + 4.808848753479633e-05, + 0.007507237381039352, + 1.380184495252424e-07, + 0.0038280856297285516, + 1.004324795871614, + 2.3895854276530894e-05, + 3.5351194579500076e-06, + 1.8486741044336282e-06, + 7.85697336266132e-06, + 2.2583435590428477e-05, + 5.3988536601202625e-05, + 0.0006679276000648783, + 2.6797437391880606e-05, + 5.88847363590114e-05, + 2.5296822458611236e-05, + 0.00015990344757346706, + 0.003277712058412189, + 8.287239270239654e-05, + 3.7686390290702356e-05, + 0.0031057701555078734, + 4.7874678062921025e-06, + 6.057074090214067e-07, + 1.7916668586350402e-05, + 0.003332199800398498, + 0.003008892442669965, + 0.002307342766061188, + 0.004912962484832755, + 1.2358780250946126e-05, + 2.9711268059919924e-05, + 3.467896560878684e-05, + 7.627186117384875e-05, + 5.913696972297344e-05, + 5.454227235294692e-05, + 6.681348932005854e-06, + 1.2649259146947333e-05, + 1.2460811952974336e-05, + 6.0329364738038516e-05, + 0.0017900443001192285, + 9.35929561527854e-06, + 3.0247199102358532e-05, + 1.0321254222034239e-05, + 9.64121073613786e-06, + 0.01165854614591907, + 0.00012580821005702604, + 6.086804239422096e-05, + 9.903821108325084e-05, + 2.77877047137349e-05, + 6.429821139034277e-05, + 7.16707002124421e-05, + 6.607100977039375e-05, + 0.015956462186832294, + 1.384537377720797e-05, + 0.009603983607945473, + 2.6896745391710108e-05, + 5.2530022158616034e-05, + 0.008723263430352006, + 3.244198568147392e-05, + 7.276064269692673e-05, + 2.7271073892822847e-05, + 3.627360518329618e-05, + 0.003566473707317041, + 3.3352789969766985e-05, + 0.009122020485873628, + 0.00800148732862001, + 0.005835945780210611, + 1.1173546844994064e-05, + 0.0015280277596831245, + 5.648693036805958e-05, + 1.1849582333965748e-05, + 7.326674752573379e-05, + 4.466158367344553e-05, + 5.298779824764253e-05, + 3.224942461389203e-05, + 6.309220182886564e-05, + 4.119423434434955e-05, + 0.007738007485690339, + 3.9709134277977404e-05, + 1.0003232118112266, + 4.931662042727166e-05, + 0.0033140161641720288, + 4.7927871872026924e-05, + 0.006362434526919624, + 3.5125133690867506e-05, + 3.19672703161189e-05, + 4.319694231074623e-05, + 8.09437286214573e-06, + 1.8146882092870154e-05, + 4.816330275016268e-05, + 0.0010867090112958687, + 4.679176487596852e-05, + 0.005713878505717975, + 0.0031057701555078734, + 0.0029241508388424798, + 0.00821535577889686, + 0.0015414752433633417, + 0.0001950264761052023, + 0.005768832749769458, + 0.00391967740274463, + 0.00961631256625307, + 0.007633076152122106, + 4.7243792305993805e-05, + 9.153726814948286e-06, + 2.2727801295909092e-05, + 5.981155540148864e-05, + 4.912466317868146e-05, + 1.70842049509094e-05, + 6.684710209514219e-06, + 5.9992598886879715e-05, + 5.598447718045988e-06, + 6.554788593807364e-05, + 6.182638644992776e-05, + 9.514188887823765e-06, + 0.001604134906301068, + 3.783128411679979e-05, + 1.4633962622208773e-05, + 0.005332022790581705, + 2.245811070471092e-06, + 3.315445346260335e-05, + 0.004483194454930572, + 2.0303929538564436e-05, + 4.0123999081499147e-05, + 1.0025578146460832e-05, + 1.9466631885063608e-05, + 9.364696675739478e-05, + 1.9905781613356547e-05, + 8.954319224316044e-05, + 1.0002417659140435, + 8.449591102227881e-05, + 8.04680136256436e-05, + 0.009104111949848063, + 6.757392944389293e-05, + 0.0018705960191203576, + 2.700232458322728e-05, + 7.979623164228452e-05, + 0.009127873853865254, + 2.2086846522067662e-05, + 7.216524130910202e-05, + 0.0032689230773739766, + 0.00015500191455285152, + 0.007111014770507566, + 0.006765004772106684, + 0.0036400623550257604, + 3.3321946258636567e-05, + 1.0909411956329585e-05, + 0.009964003685006098, + 6.401808159144565e-06, + 6.324948152687383e-08, + 1.6867752071647554e-06, + 5.066528936150447e-07, + 1.6864204928424063e-05, + 1.2098027758146606e-05, + 4.529448782957032e-05, + 3.937530357228339e-05, + 0.003534239376464677, + 0.008572476068270435, + 0.004956907702287139, + 3.499529266183106e-05, + 1.1858073903861733e-05, + 4.5704631119594805e-05, + 0.0014860797174881262, + 8.604060923538484e-06, + 9.073084147842132e-07, + 0.006712215563463177, + 2.7597202625547482e-05, + 1.00702110158417, + 8.954319224316044e-05, + 9.369088524743714e-05, + 6.204465674665756e-05, + 9.824617476956339e-05, + 0.009248274563630471, + 8.669584320980875e-05, + 2.9019803498547727e-05, + 5.688094456474576e-05, + 0.009809863027986832, + 3.689614821820535e-05, + 7.755706793911599e-05, + 0.008749394056026713, + 0.0024756450814178467, + 0.008126126390881718, + 0.004015417380052825, + 4.504480980288661e-05, + 4.419688041692284e-05, + 4.001426304671741e-05, + 2.155358575807791e-05, + 4.673612943620091e-06, + 5.961322642576858e-06, + 5.52110992687459e-06, + 3.557441043217354e-05, + 1.692812113220369e-05, + 4.573845607783466e-06, + 0.004980246622128062, + 1.2513410853218346e-05, + 1.6194195528969006e-06, + 6.360723619574272e-06, + 9.849916266201628e-06, + 3.554312579674117e-05, + 4.3883882401521954e-05, + 4.6148138070912694e-05, + 3.426856622257189e-05, + 5.414460890939888e-06, + 3.269166597623609e-05, + 7.139367545954369e-06, + 4.840093735853481e-05, + 2.2680768964021368e-05, + 3.780064200939412e-05, + 2.610848019012817e-05, + 4.699549064728338e-05, + 1.4090856331832103e-06, + 4.9384061889323554e-05, + 4.3275702448087675e-05, + 3.4778956437108256e-06, + 4.494637145322238e-05, + 3.746647411616235e-05, + 6.294100436684671e-05, + 3.000535237006113e-05, + 8.311017407393698e-05, + 5.5854783266968745e-05, + 0.00010345871344829712, + 3.391891618363114e-05, + 1.7861680053057874e-05, + 8.391767317401229e-05, + 1.1440732422000322e-05, + 1.2886151317740457e-05, + 4.463507283417051e-05, + 0.004820441889805756, + 0.005573949689002543, + 5.50711807066434e-06, + 0.001357161489069189, + 1.0002440682359617, + 8.484984963731137e-06, + 6.313932232818006e-05, + 5.467452991247206e-05, + 2.3827168497977226e-05, + 6.52507212958729e-05, + 5.4768435409716286e-05, + 9.110823057042535e-05, + 0.001402735417636479, + 2.01100155359697e-05, + 3.6438697281287586e-05, + 0.0023218250123088584, + 0.009349294168833915, + 0.003047843274389201, + 0.008788743162951177, + 0.0005948016310838955, + 0.00706549802282827, + 0.0032689230773739766, + 5.032455958925542e-07, + 9.182993285094491e-06, + 1.619573616404499e-05, + 3.335370314286377e-05, + 4.794364658652151e-05, + 7.657450367907001e-07, + 4.706223389482264e-05, + 0.008911991690964146, + 2.411402431329091e-05, + 0.003183520221360109, + 3.3858432172866734e-05, + 0.004030203448740924, + 9.177955235317567e-06, + 5.848653372189761e-07, + 1.2987571936806203e-05, + 1.805825071175295e-05, + 4.276492816919655e-05, + 2.875512039779854e-07, + 4.1856189126207785e-05, + 4.0027338875076087e-05, + 8.198454746167677e-05, + 0.011977395320336965, + 0.0014970770754504084, + 5.5673337197063254e-05, + 1.3460548600472357e-05, + 7.139367545954369e-06, + 1.1197116341924697e-05, + 4.658818043835977e-06, + 0.004865248238712459, + 0.005289247804570505, + 4.994533857957476e-06, + 0.0013328777498254356, + 6.039959268436595e-06, + 2.4324983724006634e-07, + 4.634868129524442e-05, + 3.54518836652093e-05, + 6.065882887747172e-05, + 8.338065908363515e-06, + 3.619066817315635e-05, + 0.007812326963274855, + 0.006243726979236103, + 4.862375713081473e-07, + 8.673170287506496e-05, + 9.945364267061394e-06, + 0.0006052639682745074, + 5.3386122069419955e-05, + 8.657135190825022e-06, + 0.0011849502227732189, + 2.160030838240172e-05, + 4.8675343537910945e-05, + 5.9320029439863275e-05, + 6.783584304793724e-05, + 0.007525119344665386, + 6.162322138123376e-05, + 1.000223159397379, + 0.0038280856297285516, + 0.0001715093884257497, + 6.192835638460486e-05, + 1.3553940587364827e-06, + 5.760504239152818e-06, + 6.303360450230218e-05, + 0.009281254762723639, + 4.00526336990222e-05, + 8.629260269443107e-05, + 5.841394323541241e-07, + 0.008467305956396259, + 1.3467076728030982e-05, + 0.0024031231029667446, + 2.3102054619062538e-05, + 4.262629380572652e-05, + 0.008476403295092551, + 0.003949451860214621, + 9.182993285094491e-06, + 0.0024137781207065954, + 2.888365587897267e-05, + 3.0658884688565634e-05, + 8.114762162992688e-06, + 0.0008438794789498705, + 3.87764533289644e-06, + 1.8884198800659427e-06, + 7.916043971640084e-06, + 5.951938020031008e-06, + 0.006820772970732364, + 9.476836787913726e-06, + 2.5660230268410952e-05, + 3.283564120768238e-05, + 7.617858133867746e-05, + 3.5321432741907855e-05, + 1.8520492490083216e-05, + 7.190953694790406e-05, + 4.431658039795528e-06, + 2.9297849743894987e-05, + 1.5813697966072556e-06, + 7.48601038810743e-05, + 0.0032183609103764335, + 3.133972759601782e-05, + 4.617323056512292e-05, + 0.007984668065463083, + 1.6709407581142358e-05, + 3.9331586555146806e-05, + 3.275334088345922e-05, + 2.8704814649242224e-05, + 0.00012167373322091522, + 4.005987306107562e-05, + 0.0077918063111136705, + 4.7301757573742176e-05, + 5.2222019800368575e-05, + 2.7808250649402162e-05, + 0.00020211630792040222, + 0.00015933951733862196, + 8.181076850756026e-05, + 9.19925473013565e-05, + 4.3880021412216516e-05, + 5.966011299312112e-05, + 6.37028078542803e-05, + 6.681348932005854e-06, + 4.071855624915881e-06, + 1.0800165987017764e-05, + 1.669025577009584e-06, + 9.009488664252652e-05, + 0.00801246907316579, + 5.409762971466342e-06, + 2.9679459951328885e-06, + 6.4177551223725635e-06, + 0.0008118108024197676, + 2.492884242619572e-05, + 7.664256895218439e-05, + 7.641123007827406e-05, + 0.00023047033185757222, + 7.17937085081615e-05, + 0.009891145193876386, + 0.009262863782751712, + 4.6357147705395986e-05, + 1.000428389132395, + 1.7861680053057874e-05, + 0.007374988275636387, + 0.00012079849373020242, + 0.00858142603278076, + 6.871895392907351e-05, + 1.0388433136278484e-05, + 0.008643936765229692, + 5.987655235048369e-05, + 0.009864768684482637, + 0.008111144119919436, +}; + +sparse_int_t A_ri[] = { + + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, +}; + +sparse_int_t A_cp[] = { + + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, +}; + +real_t A_val[] = { + + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, +}; + +real_t g[] = { + + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, +}; + +real_t lb[] = { + + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, +}; + +real_t ub[] = { + + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, +}; + +real_t lbA[] = { + + -1.0, + -1.0, + -1.0, + -1.0, + -1.0, + -1.0, + -1.0, + -1.0, + -1.0, + -1.0, +}; + +real_t ubA[] = { + + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, +}; + +long H_nnz = 6874; +long A_nnz = 10; \ No newline at end of file diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/generate_sparse_qp/trivial_qp_data.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/generate_sparse_qp/trivial_qp_data.hpp new file mode 100644 index 0000000..100b32e --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/generate_sparse_qp/trivial_qp_data.hpp @@ -0,0 +1,826 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \author Andrea Zanelli + * \version 3.2 + * \date 2022 + * + * QP data generated by a Python script for testing purposes. + */ + +USING_NAMESPACE_QPOASES + +#define NV 100 +#define NC 10 + +const real_t Inf = INFTY; + +sparse_int_t H_ri[] = { + + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 41, + 42, + 43, + 44, + 45, + 46, + 47, + 48, + 49, + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + 58, + 59, + 60, + 61, + 62, + 63, + 64, + 65, + 66, + 67, + 68, + 69, + 70, + 71, + 72, + 73, + 74, + 75, + 76, + 77, + 78, + 79, + 80, + 81, + 82, + 83, + 84, + 85, + 86, + 87, + 88, + 89, + 90, + 91, + 92, + 93, + 94, + 95, + 96, + 97, + 98, + 99, +}; + +sparse_int_t H_cp[] = { + + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 41, + 42, + 43, + 44, + 45, + 46, + 47, + 48, + 49, + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + 58, + 59, + 60, + 61, + 62, + 63, + 64, + 65, + 66, + 67, + 68, + 69, + 70, + 71, + 72, + 73, + 74, + 75, + 76, + 77, + 78, + 79, + 80, + 81, + 82, + 83, + 84, + 85, + 86, + 87, + 88, + 89, + 90, + 91, + 92, + 93, + 94, + 95, + 96, + 97, + 98, + 99, + 100, +}; + +real_t H_val[] = { + + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, +}; + +sparse_int_t A_ri[] = { + + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, +}; + +sparse_int_t A_cp[] = { + + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, +}; + +real_t A_val[] = { + + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, +}; + +real_t g[] = { + + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, +}; + +real_t lb[] = { + + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, + -10000000000.0, +}; + +real_t ub[] = { + + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, + 10000000000.0, +}; + +real_t lbA[] = { + + -1.0, + -1.0, + -1.0, + -1.0, + -1.0, + -1.0, + -1.0, + -1.0, + -1.0, + -1.0, +}; + +real_t ubA[] = { + + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, + 1.0, +}; + +long H_nnz = 100; +long A_nnz = 10; \ No newline at end of file diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/qrecipe.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/qrecipe.cpp new file mode 100644 index 0000000..e268724 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/qrecipe.cpp @@ -0,0 +1,112 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file examples/qrecipe.cpp + * \author Andreas Potschka + * \version 3.2 + * \date 2007-2017 + * + * QRECIPE example from the CUTEr test set with sparse matrices. + */ + +#include + +#include "qrecipe_data.hpp" + +int main() +{ + USING_NAMESPACE_QPOASES + + long i; + int_t nWSR; + real_t err, tic, toc; + real_t * x1 = new real_t[180]; + real_t * y1 = new real_t[271]; + real_t * x2 = new real_t[180]; + real_t * y2 = new real_t[271]; + + /* create sparse matrices */ + SymSparseMat * H = new SymSparseMat(180, 180, H_ri, H_cp, H_val); + SparseMatrix * A = new SparseMatrix(91, 180, A_ri, A_cp, A_val); + + H->createDiagInfo(); + + real_t * H_full = H->full(); + real_t * A_full = A->full(); + + SymDenseMat * Hd = new SymDenseMat(180, 180, 180, H_full); + DenseMatrix * Ad = new DenseMatrix(91, 180, 180, A_full); + + /* solve with dense matrices */ + nWSR = 1000; + QProblem qrecipeD(180, 91); + tic = getCPUtime(); + qrecipeD.init(Hd, g, Ad, lb, ub, lbA, ubA, nWSR, 0); + toc = getCPUtime(); + qrecipeD.getPrimalSolution(x1); + qrecipeD.getDualSolution(y1); + + fprintf(stdFile, "Solved dense problem in %d iterations, %.3f seconds.\n", (int)nWSR, toc - tic); + + /* solve with sparse matrices */ + nWSR = 1000; + QProblem qrecipeS(180, 91); + tic = getCPUtime(); + qrecipeS.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + toc = getCPUtime(); + qrecipeS.getPrimalSolution(x2); + qrecipeS.getDualSolution(y2); + + fprintf(stdFile, "Solved sparse problem in %d iterations, %.3f seconds.\n", (int)nWSR, toc - tic); + + /* check distance of solutions */ + err = 0.0; + for (i = 0; i < 180; i++) + if (getAbs(x1[i] - x2[i]) > err) + err = getAbs(x1[i] - x2[i]); + fprintf(stdFile, "Primal error: %9.2e\n", err); + err = 0.0; + for (i = 0; i < 271; i++) + if (getAbs(y1[i] - y2[i]) > err) + err = getAbs(y1[i] - y2[i]); + fprintf(stdFile, "Dual error: %9.2e (might not be unique)\n", err); + + delete H; + delete A; + delete[] H_full; + delete[] A_full; + delete Hd; + delete Ad; + + delete[] y2; + delete[] x2; + delete[] y1; + delete[] x1; + + return 0; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/qrecipeSchur.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/qrecipeSchur.cpp new file mode 100644 index 0000000..339c706 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/qrecipeSchur.cpp @@ -0,0 +1,164 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file examples/qrecipeSchur.cpp + * \author Dennis Janka + * \version 3.2 + * \date 2007-2017 + * + * QRECIPE example from the CUTEr test set with sparse matrices. + * Comparison between nullspace factorization (dense and sparse) and + * Schur complement approach. + */ + +#include "qrecipe_data.hpp" +#include +// #include "generate_sparse_qp/qp_data.hpp" +// #include "generate_sparse_qp/simple_qp_data.hpp" +// #include "generate_sparse_qp/trivial_qp_data.hpp" + +int main() +{ + USING_NAMESPACE_QPOASES + + long i; + int_t nWSR; + real_t errP1, errP2, errP3, errD1, errD2, errD3, tic, toc; + real_t * x1 = new real_t[NV]; + real_t * y1 = new real_t[NV + NC]; + real_t * x2 = new real_t[NV]; + real_t * y2 = new real_t[NV + NC]; + real_t * x3 = new real_t[NV]; + real_t * y3 = new real_t[NV + NC]; + + /* create sparse matrices */ + SymSparseMat * H = new SymSparseMat(NV, NV, H_ri, H_cp, H_val); + SparseMatrix * A = new SparseMatrix(NC, NV, A_ri, A_cp, A_val); + + H->createDiagInfo(); + + real_t * H_full = H->full(); + for (int i = 0; i < NV; i++) + for (int j = 0; j < NV; j++) + printf("H[%i,%i] = %f\n", i, j, H_full[i * NV + j]); + real_t * A_full = A->full(); + + SymDenseMat * Hd = new SymDenseMat(NV, NV, NV, H_full); + DenseMatrix * Ad = new DenseMatrix(NC, NV, NV, A_full); + + /* solve with dense matrices */ + nWSR = 1000; + QProblem qrecipeD(NV, NC); + tic = getCPUtime(); + qrecipeD.init(Hd, g, Ad, lb, ub, lbA, ubA, nWSR, 0); + toc = getCPUtime(); + qrecipeD.getPrimalSolution(x1); + qrecipeD.getDualSolution(y1); + + fprintf(stdFile, "Solved dense problem in %d iterations, %.3f seconds.\n", (int)nWSR, toc - tic); + + /* solve with sparse matrices (nullspace factorization) */ + nWSR = 1000; + QProblem qrecipeS(NV, NC); + tic = getCPUtime(); + qrecipeS.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + toc = getCPUtime(); + qrecipeS.getPrimalSolution(x2); + qrecipeS.getDualSolution(y2); + + fprintf(stdFile, "Solved sparse problem in %d iterations, %.3f seconds.\n", (int)nWSR, toc - tic); + + /* solve with sparse matrices (Schur complement) */ + nWSR = 1000; + SQProblemSchur qrecipeSchur(NV, NC); + tic = getCPUtime(); + qrecipeSchur.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + toc = getCPUtime(); + qrecipeSchur.getPrimalSolution(x3); + qrecipeSchur.getDualSolution(y3); + + fprintf(stdFile, + "Solved sparse problem (Schur complement approach) in %d iterations, %.3f seconds.\n", + (int)nWSR, + toc - tic); + + /* check distance of solutions */ + errP1 = 0.0; + errP2 = 0.0; + errP3 = 0.0; +#ifndef SOLVER_NONE + for (i = 0; i < NV; i++) { + fprintf(stdFile, "x3[%i]=%f\n", i, x3[i]); + if (getAbs(x1[i] - x2[i]) > errP1) + errP1 = getAbs(x1[i] - x2[i]); + } + for (i = 0; i < NV; i++) + if (getAbs(x1[i] - x3[i]) > errP2) + errP2 = getAbs(x1[i] - x3[i]); + for (i = 0; i < NV; i++) + if (getAbs(x2[i] - x3[i]) > errP3) + errP3 = getAbs(x2[i] - x3[i]); +#endif /* SOLVER_NONE */ + fprintf(stdFile, "Primal error (dense and sparse): %9.2e\n", errP1); + fprintf(stdFile, "Primal error (dense and Schur): %9.2e\n", errP2); + fprintf(stdFile, "Primal error (sparse and Schur): %9.2e\n", errP3); + + errD1 = 0.0; + errD2 = 0.0; + errD3 = 0.0; + for (i = 0; i < NV + NC; i++) + if (getAbs(y1[i] - y2[i]) > errD1) + errD1 = getAbs(y1[i] - y2[i]); +#ifndef SOLVER_NONE + for (i = 0; i < NV + NC; i++) + if (getAbs(y1[i] - y3[i]) > errD2) + errD2 = getAbs(y1[i] - y3[i]); + for (i = 0; i < NV + NC; i++) + if (getAbs(y2[i] - y3[i]) > errD3) + errD3 = getAbs(y2[i] - y3[i]); +#endif /* SOLVER_NONE */ + fprintf(stdFile, "Dual error (dense and sparse): %9.2e (might not be unique)\n", errD1); + fprintf(stdFile, "Dual error (dense and Schur): %9.2e (might not be unique)\n", errD2); + fprintf(stdFile, "Dual error (sparse and Schur): %9.2e (might not be unique)\n", errD3); + + delete H; + delete A; + delete[] H_full; + delete[] A_full; + delete Hd; + delete Ad; + + delete[] y3; + delete[] x3; + delete[] y2; + delete[] x2; + delete[] y1; + delete[] x1; + + return 0; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/qrecipe_data.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/qrecipe_data.hpp new file mode 100644 index 0000000..da9ecbe --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/examples/qrecipe_data.hpp @@ -0,0 +1,2622 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_qrecipe.cpp + * \author Andreas Potschka + * \version 3.2 + * \date 2007-2017 + * + * QRECIPE example from the CUTEr test set with sparse matrices. + */ + +USING_NAMESPACE_QPOASES + +#define NV 180 +#define NC 91 + +const real_t Inf = INFTY; + +sparse_int_t H_cp[] = {0, + 4, + 8, + 12, + 16, + 20, + 20, + 20, + 20, + 20, + 20, + 24, + 28, + 32, + 36, + 40, + 40, + 40, + 40, + 40, + 40, + 44, + 48, + 52, + 56, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 64, + 68, + 72, + 76, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80}; + +sparse_int_t H_ri[] = {0, + 10, + 20, + 34, + 1, + 11, + 21, + 35, + 2, + 12, + 22, + 36, + 3, + 13, + 23, + 37, + 4, + 14, + 24, + 38, + 0, + 10, + 20, + 34, + 1, + 11, + 21, + 35, + 2, + 12, + 22, + 36, + 3, + 13, + 23, + 37, + 4, + 14, + 24, + 38, + 0, + 10, + 20, + 34, + 1, + 11, + 21, + 35, + 2, + 12, + 22, + 36, + 3, + 13, + 23, + 37, + 4, + 14, + 24, + 38, + 0, + 10, + 20, + 34, + 1, + 11, + 21, + 35, + 2, + 12, + 22, + 36, + 3, + 13, + 23, + 37, + 4, + 14, + 24, + 38}; + +real_t H_val[] = {10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10}; + +sparse_int_t A_cp[] = {0, + 10, + 20, + 30, + 40, + 50, + 60, + 70, + 80, + 90, + 100, + 110, + 120, + 130, + 140, + 150, + 160, + 170, + 180, + 190, + 200, + 210, + 220, + 230, + 240, + 250, + 260, + 270, + 280, + 290, + 300, + 301, + 302, + 303, + 304, + 305, + 306, + 307, + 308, + 309, + 310, + 311, + 312, + 313, + 314, + 318, + 319, + 320, + 321, + 322, + 323, + 324, + 325, + 326, + 327, + 328, + 329, + 331, + 333, + 335, + 337, + 339, + 341, + 343, + 345, + 347, + 349, + 351, + 353, + 355, + 357, + 359, + 361, + 363, + 365, + 367, + 369, + 371, + 373, + 383, + 393, + 403, + 405, + 408, + 410, + 413, + 415, + 418, + 420, + 422, + 424, + 426, + 428, + 430, + 432, + 434, + 436, + 438, + 440, + 442, + 444, + 446, + 448, + 450, + 452, + 454, + 456, + 458, + 460, + 462, + 472, + 482, + 492, + 494, + 497, + 499, + 502, + 504, + 507, + 509, + 511, + 513, + 515, + 517, + 519, + 521, + 523, + 525, + 527, + 529, + 531, + 533, + 535, + 537, + 539, + 541, + 543, + 545, + 547, + 549, + 551, + 561, + 571, + 581, + 583, + 586, + 588, + 591, + 593, + 596, + 597, + 598, + 599, + 600, + 601, + 602, + 603, + 604, + 605, + 606, + 607, + 608, + 609, + 610, + 611, + 612, + 613, + 614, + 615, + 616, + 617, + 618, + 628, + 638, + 648, + 650, + 653, + 655, + 658, + 660, + 663}; + +sparse_int_t A_ri[] = {0, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 1, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 2, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 3, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 4, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 5, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 6, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 7, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 8, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 9, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 0, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 1, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 2, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 3, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 4, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 5, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 6, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 7, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 8, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 9, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 0, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 1, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 2, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 3, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 4, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 5, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 6, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 7, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 8, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 9, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 10, + 11, + 12, + 13, + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 47, + 48, + 49, + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + 47, + 58, + 48, + 59, + 49, + 60, + 50, + 61, + 51, + 62, + 52, + 63, + 53, + 64, + 54, + 65, + 55, + 66, + 46, + 56, + 45, + 57, + 47, + 58, + 48, + 59, + 49, + 60, + 50, + 61, + 51, + 62, + 52, + 63, + 53, + 64, + 54, + 65, + 55, + 66, + 46, + 56, + 45, + 57, + 10, + 14, + 71, + 72, + 85, + 86, + 87, + 88, + 89, + 90, + 11, + 15, + 69, + 70, + 79, + 80, + 81, + 82, + 83, + 84, + 12, + 16, + 67, + 68, + 73, + 74, + 75, + 76, + 77, + 78, + 35, + 90, + 36, + 89, + 90, + 37, + 84, + 38, + 83, + 84, + 39, + 78, + 40, + 77, + 78, + 44, + 58, + 43, + 59, + 42, + 60, + 41, + 61, + 34, + 62, + 33, + 63, + 32, + 64, + 31, + 65, + 30, + 66, + 29, + 46, + 28, + 45, + 44, + 58, + 43, + 59, + 42, + 60, + 41, + 61, + 34, + 62, + 33, + 63, + 32, + 64, + 31, + 65, + 30, + 66, + 29, + 46, + 28, + 45, + 10, + 14, + 71, + 72, + 85, + 86, + 87, + 88, + 89, + 90, + 11, + 15, + 69, + 70, + 79, + 80, + 81, + 82, + 83, + 84, + 12, + 16, + 67, + 68, + 73, + 74, + 75, + 76, + 77, + 78, + 35, + 90, + 36, + 89, + 90, + 37, + 84, + 38, + 83, + 84, + 39, + 78, + 40, + 77, + 78, + 27, + 44, + 26, + 43, + 25, + 42, + 24, + 41, + 23, + 34, + 22, + 33, + 21, + 32, + 20, + 31, + 19, + 30, + 18, + 29, + 17, + 28, + 27, + 44, + 26, + 43, + 25, + 42, + 24, + 41, + 23, + 34, + 22, + 33, + 21, + 32, + 20, + 31, + 19, + 30, + 18, + 29, + 17, + 28, + 10, + 14, + 71, + 72, + 85, + 86, + 87, + 88, + 89, + 90, + 11, + 15, + 69, + 70, + 79, + 80, + 81, + 82, + 83, + 84, + 12, + 16, + 67, + 68, + 73, + 74, + 75, + 76, + 77, + 78, + 35, + 90, + 36, + 89, + 90, + 37, + 84, + 38, + 83, + 84, + 39, + 78, + 40, + 77, + 78, + 27, + 26, + 25, + 24, + 23, + 22, + 21, + 20, + 19, + 18, + 17, + 27, + 26, + 25, + 24, + 23, + 22, + 21, + 20, + 19, + 18, + 17, + 10, + 14, + 71, + 72, + 85, + 86, + 87, + 88, + 89, + 90, + 11, + 15, + 69, + 70, + 79, + 80, + 81, + 82, + 83, + 84, + 12, + 16, + 67, + 68, + 73, + 74, + 75, + 76, + 77, + 78, + 35, + 90, + 36, + 89, + 90, + 37, + 84, + 38, + 83, + 84, + 39, + 78, + 40, + 77, + 78}; + +real_t A_val[] = {-1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.8678200000000004e+01, + 9.3617050000000006e+01, + 1.6000000000000000e+01, + 8.1999999999999993e+00, + 9.9000000000000000e+01, + 8.0000000000000000e+01, + 1.2000000000000000e+01, + 9.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.0062830000000005e+01, + 9.9224010000000007e+01, + 1.0000000000000000e+02, + 2.1100000000000001e+01, + 1.0000000000000000e+02, + 1.0000000000000000e+02, + 1.1400000000000000e+02, + 1.1680000000000000e+02, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.4697360000000003e+01, + 8.3801220000000001e+01, + -8.1999999999999993e+00, + 2.0000000000000000e+00, + 9.0000000000000000e+01, + 2.3999999999999999e+00, + -1.2000000000000000e+01, + -1.4800000000000001e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.9194209999999998e+01, + 9.0175110000000004e+01, + 4.3000000000000000e+01, + 8.0000000000000000e+00, + 1.0000000000000000e+02, + 9.5000000000000000e+01, + 9.0000000000000000e+00, + 2.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.8568219999999997e+01, + 8.5996200000000002e+01, + -1.2500000000000000e+01, + 1.0000000000000000e+00, + 9.6500000000000000e+01, + 4.0000000000000000e+00, + -1.8000000000000000e+01, + -2.1899999999999999e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.2922240000000002e+01, + 8.6963380000000001e+01, + 6.5000000000000000e+01, + 1.2500000000000000e+01, + 1.0000000000000000e+02, + 9.8000000000000000e+01, + 4.9000000000000000e+01, + 3.7000000000000000e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.2592740000000006e+01, + 9.3147599999999997e+01, + -1.2000000000000000e+01, + 1.0000000000000000e+00, + 9.6500000000000000e+01, + 4.0000000000000000e+00, + -1.8000000000000000e+01, + -2.1899999999999999e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.6506460000000004e+01, + 7.8210250000000002e+01, + 7.9000000000000000e+01, + 1.2000000000000000e+01, + 1.0000000000000000e+02, + 9.5000000000000000e+01, + 6.8000000000000000e+01, + 6.1000000000000000e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.8357460000000003e+01, + 9.4257840000000002e+01, + 1.2500000000000000e+02, + 6.1299999999999997e+01, + 1.0000000000000000e+02, + 1.0000000000000000e+02, + 1.4500000000000000e+02, + 1.4500000000000000e+02, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 9.0590469999999996e+01, + 1.0582863000000000e+02, + 6.2000000000000002e+00, + 6.0000000000000000e+00, + 9.7000000000000000e+01, + 2.8500000000000000e+01, + 4.0000000000000000e+00, + 3.6000000000000001e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.8678200000000004e+01, + 9.3617050000000006e+01, + 1.6000000000000000e+01, + 8.1999999999999993e+00, + 9.9000000000000000e+01, + 8.0000000000000000e+01, + 1.2000000000000000e+01, + 9.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.0062830000000005e+01, + 9.9224010000000007e+01, + 1.0000000000000000e+02, + 2.1100000000000001e+01, + 1.0000000000000000e+02, + 1.0000000000000000e+02, + 1.1400000000000000e+02, + 1.1680000000000000e+02, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.4697360000000003e+01, + 8.3801220000000001e+01, + -8.1999999999999993e+00, + 2.0000000000000000e+00, + 9.0000000000000000e+01, + 2.3999999999999999e+00, + -1.2000000000000000e+01, + -1.4800000000000001e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.9194209999999998e+01, + 9.0175110000000004e+01, + 4.3000000000000000e+01, + 8.0000000000000000e+00, + 1.0000000000000000e+02, + 9.5000000000000000e+01, + 9.0000000000000000e+00, + 2.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.8568219999999997e+01, + 8.5996200000000002e+01, + -1.2500000000000000e+01, + 1.0000000000000000e+00, + 9.6500000000000000e+01, + 4.0000000000000000e+00, + -1.8000000000000000e+01, + -2.1899999999999999e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.2922240000000002e+01, + 8.6963380000000001e+01, + 6.5000000000000000e+01, + 1.2500000000000000e+01, + 1.0000000000000000e+02, + 9.8000000000000000e+01, + 4.9000000000000000e+01, + 3.7000000000000000e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.2592740000000006e+01, + 9.3147599999999997e+01, + -1.2000000000000000e+01, + 1.0000000000000000e+00, + 9.6500000000000000e+01, + 4.0000000000000000e+00, + -1.8000000000000000e+01, + -2.1899999999999999e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.6506460000000004e+01, + 7.8210250000000002e+01, + 7.9000000000000000e+01, + 1.2000000000000000e+01, + 1.0000000000000000e+02, + 9.5000000000000000e+01, + 6.8000000000000000e+01, + 6.1000000000000000e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.8357460000000003e+01, + 9.4257840000000002e+01, + 1.2500000000000000e+02, + 6.1299999999999997e+01, + 1.0000000000000000e+02, + 1.0000000000000000e+02, + 1.4500000000000000e+02, + 1.4500000000000000e+02, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 9.0590469999999996e+01, + 1.0582863000000000e+02, + 6.2000000000000002e+00, + 6.0000000000000000e+00, + 9.7000000000000000e+01, + 2.8500000000000000e+01, + 4.0000000000000000e+00, + 3.6000000000000001e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.8678200000000004e+01, + 9.3617050000000006e+01, + 1.6000000000000000e+01, + 8.1999999999999993e+00, + 9.9000000000000000e+01, + 8.0000000000000000e+01, + 1.2000000000000000e+01, + 9.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.0062830000000005e+01, + 9.9224010000000007e+01, + 1.0000000000000000e+02, + 2.1100000000000001e+01, + 1.0000000000000000e+02, + 1.0000000000000000e+02, + 1.1400000000000000e+02, + 1.1680000000000000e+02, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.4697360000000003e+01, + 8.3801220000000001e+01, + -8.1999999999999993e+00, + 2.0000000000000000e+00, + 9.0000000000000000e+01, + 2.3999999999999999e+00, + -1.2000000000000000e+01, + -1.4800000000000001e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.9194209999999998e+01, + 9.0175110000000004e+01, + 4.3000000000000000e+01, + 8.0000000000000000e+00, + 1.0000000000000000e+02, + 9.5000000000000000e+01, + 9.0000000000000000e+00, + 2.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.8568219999999997e+01, + 8.5996200000000002e+01, + -1.2500000000000000e+01, + 1.0000000000000000e+00, + 9.6500000000000000e+01, + 4.0000000000000000e+00, + -1.8000000000000000e+01, + -2.1899999999999999e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.2922240000000002e+01, + 8.6963380000000001e+01, + 6.5000000000000000e+01, + 1.2500000000000000e+01, + 1.0000000000000000e+02, + 9.8000000000000000e+01, + 4.9000000000000000e+01, + 3.7000000000000000e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.2592740000000006e+01, + 9.3147599999999997e+01, + -1.2000000000000000e+01, + 1.0000000000000000e+00, + 9.6500000000000000e+01, + 4.0000000000000000e+00, + -1.8000000000000000e+01, + -2.1899999999999999e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.6506460000000004e+01, + 7.8210250000000002e+01, + 7.9000000000000000e+01, + 1.2000000000000000e+01, + 1.0000000000000000e+02, + 9.5000000000000000e+01, + 6.8000000000000000e+01, + 6.1000000000000000e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.8357460000000003e+01, + 9.4257840000000002e+01, + 1.2500000000000000e+02, + 6.1299999999999997e+01, + 1.0000000000000000e+02, + 1.0000000000000000e+02, + 1.4500000000000000e+02, + 1.4500000000000000e+02, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 9.0590469999999996e+01, + 1.0582863000000000e+02, + 6.2000000000000002e+00, + 6.0000000000000000e+00, + 9.7000000000000000e+01, + 2.8500000000000000e+01, + 4.0000000000000000e+00, + 3.6000000000000001e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.2000000000000000e-01, + -3.8000000000000000e-01, + -5.0000000000000000e-01, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.3000000000000000e+01, + -8.9000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -8.9000000000000000e+01, + -8.5000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.1000000000000000e+01, + -8.8000000000000000e+01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.3000000000000000e+01, + -8.9000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -8.9000000000000000e+01, + -8.5000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.1000000000000000e+01, + -8.8000000000000000e+01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.3000000000000000e+01, + -8.9000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -8.9000000000000000e+01, + -8.5000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.1000000000000000e+01, + -8.8000000000000000e+01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.3000000000000000e+01, + -8.9000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -8.9000000000000000e+01, + -8.5000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.1000000000000000e+01, + -8.8000000000000000e+01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01}; + +real_t g[] = {+0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + -2e+00, + -2e+00, + -2e+00, + -2e+00, + -2e+00, + -2e+00, + -2e+00, + -2e+00, + +0e+00, + -2e+00, + +0e+00, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +1e-03, + +2e-03, + +2e-03, + +2e-03, + +0e+00, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -1e-03, + -2e-03, + -2e-03, + -2e-03, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +1e-03, + +2e-03, + +2e-03, + +2e-03, + +0e+00, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -1e-03, + -2e-03, + -2e-03, + -2e-03, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +1e-03, + +2e-03, + +2e-03, + +2e-03, + +0e+00, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -1e-03, + -2e-03, + -2e-03, + -2e-03, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +1e-01, + +1e-01, + +1e-01, + +1e-01, + +1e-01, + +1e-01, + +1e-01, + +1e-01, + +1e-01, + +1e-01, + +0e+00, + -1e-01, + -1e-01, + -1e-01, + -1e-01, + -1e-01, + -1e-01, + -1e-01, + -1e-01, + -1e-01, + -1e-01, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00}; + +real_t lb[] = {0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + -Inf, + 0, + -Inf, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 10, + 5, + 10, + 5, + 0, + 10, + 0, + 2, + 0, + 10, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 10, + 5, + 10, + 5, + 0, + 10, + 0, + 5, + 0, + 10, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 10, + 5, + 10, + 5, + 0, + 10, + 0, + 5, + 0, + 10, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0}; + +real_t ub[] = {Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + 0, + 92, + 39, + 87, + 29, + 0, + 20, + 0, + 28, + 20, + 71, + Inf, + 130, + 45, + 53, + 55, + 75, + 112, + 0, + 73, + 480, + 154, + 121, + 50, + 30, + 77, + 20, + 0, + 18, + 0, + 5, + 20, + 71, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + 130, + 55, + 93, + 60, + 75, + 115, + 0, + 67, + 480, + 154, + 121, + 50, + 20, + 37, + 15, + 0, + 15, + 0, + 8, + 20, + 71, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + 130, + 55, + 93, + 60, + 75, + 105, + 0, + 67, + 4980, + 154, + 110, + 50, + 20, + 37, + 15, + 0, + 25, + 0, + 8, + 20, + 71, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + 20, + 20, + 20, + 20, + 0, + 20, + 0, + 20, + 0, + 20, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf}; + +real_t lbA[] = {0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + -Inf, + -Inf, + -Inf, + -Inf, + -Inf, + -Inf, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0}; + +real_t ubA[] = {0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf}; + +long H_nnz = (long)sizeof(H_val) / (long)sizeof(real_t); +long A_nnz = (long)sizeof(A_val) / (long)sizeof(real_t); diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES.hpp new file mode 100644 index 0000000..f5b30e6 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES.hpp @@ -0,0 +1,71 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + */ + +#if defined(__SINGLE_OBJECT__) || defined(__C_WRAPPER__) + +#include +#include +#include +#include +#include +#include + +#if !defined(__MATLAB__) || defined(WIN32) +#include +#include +#endif + +#include +#include +#include +#include +#include +#include + +#if defined(SOLVER_MA27) || defined(SOLVER_MA57) +#include +#include +#endif + +#if !defined(__C_WRAPPER__) && !defined(__MATLAB__) +#include +#include +#endif + +#else /* default compilation mode */ + +#include +#include +#include +#include +#include +#include + +#endif diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Bounds.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Bounds.hpp new file mode 100644 index 0000000..539a588 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Bounds.hpp @@ -0,0 +1,240 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/Bounds.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Declaration of the Bounds class designed to manage working sets of + * bounds within a QProblem. + */ + +#ifndef QPOASES_BOUNDS_HPP +#define QPOASES_BOUNDS_HPP + +#include + +BEGIN_NAMESPACE_QPOASES + +/** + * \brief Manages working sets of bounds (i.e. box constraints). + * + * This class manages working sets of bounds (= box constraints) + * by storing index sets and other status information. + * + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + */ +class Bounds : public SubjectTo +{ + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + Bounds(); + + /** Constructor which takes the number of bounds. */ + Bounds(int_t _n /**< Number of bounds. */ + ); + + /** Copy constructor (deep copy). */ + Bounds(const Bounds & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + virtual ~Bounds(); + + /** Assignment operator (deep copy). */ + Bounds & operator=(const Bounds & rhs /**< Rhs object. */ + ); + + /** Initialises object with given number of bounds. + * \return SUCCESSFUL_RETURN \n + RET_INVALID_ARGUMENTS */ + returnValue init(int_t _n = 0 /**< Number of bounds. */ + ); + + /** Initially adds number of a new (i.e. not yet in the list) bound to + * given index set. + * \return SUCCESSFUL_RETURN \n + RET_SETUP_BOUND_FAILED \n + RET_INDEX_OUT_OF_BOUNDS \n + RET_INVALID_ARGUMENTS */ + returnValue setupBound(int_t number, /**< Number of new bound. */ + SubjectToStatus _status /**< Status of new bound. */ + ); + + /** Initially adds all numbers of new (i.e. not yet in the list) bounds to + * to the index set of free bounds; the order depends on the SujectToType + * of each index. + * \return SUCCESSFUL_RETURN \n + RET_SETUP_BOUND_FAILED */ + returnValue setupAllFree(); + + /** Initially adds all numbers of new (i.e. not yet in the list) bounds to + * to the index set of fixed bounds (on their lower bounds); + * the order depends on the SujectToType of each index. + * \return SUCCESSFUL_RETURN \n + RET_SETUP_BOUND_FAILED */ + returnValue setupAllLower(); + + /** Initially adds all numbers of new (i.e. not yet in the list) bounds to + * to the index set of fixed bounds (on their upper bounds); + * the order depends on the SujectToType of each index. + * \return SUCCESSFUL_RETURN \n + RET_SETUP_BOUND_FAILED */ + returnValue setupAllUpper(); + + /** Moves index of a bound from index list of fixed to that of free bounds. + * \return SUCCESSFUL_RETURN \n + RET_MOVING_BOUND_FAILED \n + RET_INDEX_OUT_OF_BOUNDS */ + returnValue moveFixedToFree(int_t number /**< Number of bound to be freed. */ + ); + + /** Moves index of a bound from index list of free to that of fixed bounds. + * \return SUCCESSFUL_RETURN \n + RET_MOVING_BOUND_FAILED \n + RET_INDEX_OUT_OF_BOUNDS */ + returnValue moveFreeToFixed(int_t number, /**< Number of bound to be fixed. */ + SubjectToStatus _status /**< Status of bound to be fixed. */ + ); + + /** Flip fixed bound. + * \return SUCCESSFUL_RETURN \n + RET_MOVING_BOUND_FAILED \n + RET_INDEX_OUT_OF_BOUNDS */ + returnValue flipFixed(int_t number); + + /** Swaps the indices of two free bounds within the index set. + * \return SUCCESSFUL_RETURN \n + RET_SWAPINDEX_FAILED */ + returnValue swapFree(int_t number1, /**< Number of first constraint or bound. */ + int_t number2 /**< Number of second constraint or bound. */ + ); + + /** Returns number of variables. + * \return Number of variables. */ + inline int_t getNV() const; + + /** Returns number of implicitly fixed variables. + * \return Number of implicitly fixed variables. */ + inline int_t getNFV() const; + + /** Returns number of bounded (but possibly free) variables. + * \return Number of bounded (but possibly free) variables. */ + inline int_t getNBV() const; + + /** Returns number of unbounded variables. + * \return Number of unbounded variables. */ + inline int_t getNUV() const; + + /** Returns number of free variables. + * \return Number of free variables. */ + inline int_t getNFR() const; + + /** Returns number of fixed variables. + * \return Number of fixed variables. */ + inline int_t getNFX() const; + + /** Returns a pointer to free variables index list. + * \return Pointer to free variables index list. */ + inline Indexlist * getFree(); + + /** Returns a pointer to fixed variables index list. + * \return Pointer to fixed variables index list. */ + inline Indexlist * getFixed(); + + /** Shifts forward type and status of all bounds by a given + * offset. This offset has to lie within the range [0,n/2] and has to + * be an integer divisor of the total number of bounds n. + * Type and status of the first \ bounds is thrown away, + * type and status of the last \ bounds is doubled, + * e.g. for offset = 2: \n + * shift( {b1,b2,b3,b4,b5,b6} ) = {b3,b4,b5,b6,b5,b6} + * \return SUCCESSFUL_RETURN \n + RET_INDEX_OUT_OF_BOUNDS \n + RET_INVALID_ARGUMENTS \n + RET_SHIFTING_FAILED */ + virtual returnValue shift( + int_t offset /**< Shift offset within the range [0,n/2] and integer divisor of n. */ + ); + + /** Rotates forward type and status of all bounds by a given + * offset. This offset has to lie within the range [0,n]. + * Example for offset = 2: \n + * rotate( {b1,b2,b3,b4,b5,b6} ) = {b3,b4,b5,b6,b1,b2} + * \return SUCCESSFUL_RETURN \n + RET_INDEX_OUT_OF_BOUNDS \n + RET_ROTATING_FAILED */ + virtual returnValue rotate(int_t offset /**< Rotation offset within the range [0,n]. */ + ); + + /** Prints information on bounds object + * (in particular, lists of free and fixed bounds. + * \return SUCCESSFUL_RETURN \n + RET_INDEXLIST_CORRUPTED */ + returnValue print(); + + /* + * PROTECTED MEMBER FUNCTIONS + */ +protected: + /** Frees all allocated memory. + * \return SUCCESSFUL_RETURN */ + returnValue clear(); + + /** Copies all members from given rhs object. + * \return SUCCESSFUL_RETURN */ + returnValue copy(const Bounds & rhs /**< Rhs object. */ + ); + + /** Initially adds all numbers of new (i.e. not yet in the list) bounds to + * to the index set corresponding to the desired status; + * the order depends on the SujectToType of each index. + * \return SUCCESSFUL_RETURN \n + RET_SETUP_BOUND_FAILED */ + returnValue setupAll(SubjectToStatus _status /**< Desired initial status for all bounds. */ + ); + + /* + * PROTECTED MEMBER VARIABLES + */ +protected: + Indexlist freee; /**< Index list of free variables. */ + Indexlist fixed; /**< Index list of fixed variables. */ +}; + +END_NAMESPACE_QPOASES + +#include + +#endif /* QPOASES_BOUNDS_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Bounds.ipp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Bounds.ipp new file mode 100755 index 0000000..1aa1508 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Bounds.ipp @@ -0,0 +1,120 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file include/qpOASES/Bounds.ipp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of inlined member functions of the Bounds class designed + * to manage working sets of bounds within a QProblem. + */ + + +BEGIN_NAMESPACE_QPOASES + + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +/* + * g e t N V + */ +inline int_t Bounds::getNV( ) const +{ + return n; +} + + +/* + * g e t N F V + */ +inline int_t Bounds::getNFV( ) const +{ + return getNumberOfType( ST_EQUALITY ); +} + + +/* + * g e t N B V + */ +inline int_t Bounds::getNBV( ) const +{ + return getNumberOfType( ST_BOUNDED ); +} + + +/* + * g e t N U V + */ +inline int_t Bounds::getNUV( ) const +{ + return getNumberOfType( ST_UNBOUNDED ); +} + + +/* + * g e t N F R + */ +inline int_t Bounds::getNFR( ) const +{ + return freee.getLength( ); +} + + +/* + * g e t N F X + */ +inline int_t Bounds::getNFX( ) const +{ + return fixed.getLength( ); +} + + +/* + * g e t F r e e + */ +inline Indexlist* Bounds::getFree( ) +{ + return &freee; +} + + +/* + * g e t F i x e d + */ +inline Indexlist* Bounds::getFixed( ) +{ + return &fixed; +} + + +END_NAMESPACE_QPOASES + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Constants.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Constants.hpp new file mode 100644 index 0000000..24f001b --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Constants.hpp @@ -0,0 +1,67 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/Constants.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Definition of all global constants. + */ + +#ifndef QPOASES_CONSTANTS_HPP +#define QPOASES_CONSTANTS_HPP + +#include + +BEGIN_NAMESPACE_QPOASES + +/** Numerical value of machine precision (min eps, s.t. 1+eps > 1). + * Note: this value has to be positive! */ +#ifdef __USE_SINGLE_PRECISION__ +const real_t EPS = 1.193e-07f; +#else +const real_t EPS = 2.221e-16; +#endif /* __USE_SINGLE_PRECISION__ */ + +/** Numerical value of zero (for situations in which it would be + * unreasonable to compare with 0.0). + * Note: this value has to be positive! */ +const real_t ZERO = 1.0e-25; + +/** Numerical value of infinity (e.g. for non-existing bounds). + Note: this value has to be positive! */ +const real_t INFTY = 1.0e20; + +/** Maximum number of characters within a string. + * Note: this value should be at least 41! */ +const uint_t MAX_STRING_LENGTH = 160; + +END_NAMESPACE_QPOASES + +#endif /* QPOASES_CONSTANTS_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/ConstraintProduct.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/ConstraintProduct.hpp new file mode 100644 index 0000000..15cad09 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/ConstraintProduct.hpp @@ -0,0 +1,87 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/ConstraintProduct.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2009-2017 + * + * Declaration of the ConstraintProduct class which allows to specify a + * user-defined function for evaluating the constraint product at the + * current iterate to speed-up QP solution in case of a specially structured + * constraint matrix. + */ + +#ifndef QPOASES_CONSTRAINT_PRODUCT_HPP +#define QPOASES_CONSTRAINT_PRODUCT_HPP + +#include + +BEGIN_NAMESPACE_QPOASES + +/** + * \brief Interface for specifying user-defined evaluations of constraint products. + * + * A class which allows to specify a user-defined function for evaluating the + * constraint product at the current iterate to speed-up QP solution in case + * of a specially structured constraint matrix. + * + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2009-2017 + */ +class ConstraintProduct +{ +public: + /** Default constructor. */ + ConstraintProduct(){}; + + /** Copy constructor. */ + ConstraintProduct(const ConstraintProduct & toCopy /**< Rhs object. */ + ){}; + + /** Destructor. */ + virtual ~ConstraintProduct(){}; + + /** Assignment operator. */ + ConstraintProduct & operator=(const ConstraintProduct & toCopy /**< Rhs object. */ + ) + { + return *this; + } + + /** Evaluates the product of a given constraint with the current iterate. + * This function needs to be implemented in a derived class for the + * user-defined constraint product function. + * \return 0: successful \n + otherwise: not successful */ + virtual int_t operator()(int_t constrIndex, /**< Number of constraint to be evaluated. */ + const real_t * const x, /**< Array containing current primal iterate. */ + real_t * const constrValue /**< Output: Scalar value of the evaluated constraint. */ + ) const = 0; +}; + +END_NAMESPACE_QPOASES + +#endif /* QPOASES_CONSTRAINT_PRODUCT_HPP */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Constraints.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Constraints.hpp new file mode 100644 index 0000000..48b7830 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Constraints.hpp @@ -0,0 +1,231 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/Constraints.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Declaration of the Constraints class designed to manage working sets of + * constraints within a QProblem. + */ + +#ifndef QPOASES_CONSTRAINTS_HPP +#define QPOASES_CONSTRAINTS_HPP + +#include + +BEGIN_NAMESPACE_QPOASES + +/** + * \brief Manages working sets of constraints. + * + * This class manages working sets of constraints by storing + * index sets and other status information. + * + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + */ +class Constraints : public SubjectTo +{ + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + Constraints(); + + /** Constructor which takes the number of constraints. */ + Constraints(int_t _n /**< Number of constraints. */ + ); + + /** Copy constructor (deep copy). */ + Constraints(const Constraints & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + virtual ~Constraints(); + + /** Assignment operator (deep copy). */ + Constraints & operator=(const Constraints & rhs /**< Rhs object. */ + ); + + /** Initialises object with given number of constraints. + * \return SUCCESSFUL_RETURN \n + RET_INVALID_ARGUMENTS */ + returnValue init(int_t _n = 0 /**< Number of constraints. */ + ); + + /** Initially adds number of a new (i.e. not yet in the list) constraint to + * a given index set. + * \return SUCCESSFUL_RETURN \n + RET_SETUP_CONSTRAINT_FAILED \n + RET_INDEX_OUT_OF_BOUNDS \n + RET_INVALID_ARGUMENTS */ + returnValue setupConstraint(int_t number, /**< Number of new constraint. */ + SubjectToStatus _status /**< Status of new constraint. */ + ); + + /** Initially adds all enabled numbers of new (i.e. not yet in the list) constraints to + * to the index set of inactive constraints; the order depends on the SujectToType + * of each index. Only disabled constraints are added to index set of disabled constraints! + * \return SUCCESSFUL_RETURN \n + RET_SETUP_CONSTRAINT_FAILED */ + returnValue setupAllInactive(); + + /** Initially adds all enabled numbers of new (i.e. not yet in the list) constraints to + * to the index set of active constraints (on their lower bounds); the order depends on the SujectToType + * of each index. Only disabled constraints are added to index set of disabled constraints! + * \return SUCCESSFUL_RETURN \n + RET_SETUP_CONSTRAINT_FAILED */ + returnValue setupAllLower(); + + /** Initially adds all enabled numbers of new (i.e. not yet in the list) constraints to + * to the index set of active constraints (on their upper bounds); the order depends on the SujectToType + * of each index. Only disabled constraints are added to index set of disabled constraints! + * \return SUCCESSFUL_RETURN \n + RET_SETUP_CONSTRAINT_FAILED */ + returnValue setupAllUpper(); + + /** Moves index of a constraint from index list of active to that of inactive constraints. + * \return SUCCESSFUL_RETURN \n + RET_MOVING_CONSTRAINT_FAILED */ + returnValue moveActiveToInactive(int_t number /**< Number of constraint to become inactive. */ + ); + + /** Moves index of a constraint from index list of inactive to that of active constraints. + * \return SUCCESSFUL_RETURN \n + RET_MOVING_CONSTRAINT_FAILED */ + returnValue moveInactiveToActive(int_t number, /**< Number of constraint to become active. */ + SubjectToStatus _status /**< Status of constraint to become active. */ + ); + + /** Flip fixed constraint. + * \return SUCCESSFUL_RETURN \n + RET_MOVING_CONSTRAINT_FAILED \n + RET_INDEX_OUT_OF_BOUNDS */ + returnValue flipFixed(int_t number); + + /** Returns the number of constraints. + * \return Number of constraints. */ + inline int_t getNC() const; + + /** Returns the number of implicit equality constraints. + * \return Number of implicit equality constraints. */ + inline int_t getNEC() const; + + /** Returns the number of "real" inequality constraints. + * \return Number of "real" inequality constraints. */ + inline int_t getNIC() const; + + /** Returns the number of unbounded constraints (i.e. without any bounds). + * \return Number of unbounded constraints (i.e. without any bounds). */ + inline int_t getNUC() const; + + /** Returns the number of active constraints. + * \return Number of active constraints. */ + inline int_t getNAC() const; + + /** Returns the number of inactive constraints. + * \return Number of inactive constraints. */ + inline int_t getNIAC() const; + + /** Returns a pointer to active constraints index list. + * \return Pointer to active constraints index list. */ + inline Indexlist * getActive(); + + /** Returns a pointer to inactive constraints index list. + * \return Pointer to inactive constraints index list. */ + inline Indexlist * getInactive(); + + /** Shifts forward type and status of all constraints by a given + * offset. This offset has to lie within the range [0,n/2] and has to + * be an integer divisor of the total number of constraints n. + * Type and status of the first \ constraints is thrown away, + * type and status of the last \ constraints is doubled, + * e.g. for offset = 2: \n + * shift( {c1,c2,c3,c4,c5,c6} ) = {c3,c4,c5,c6,c5,c6} + * \return SUCCESSFUL_RETURN \n + RET_INDEX_OUT_OF_BOUNDS \n + RET_INVALID_ARGUMENTS \n + RET_SHIFTING_FAILED */ + virtual returnValue shift( + int_t offset /**< Shift offset within the range [0,n/2] and integer divisor of n. */ + ); + + /** Rotates forward type and status of all constraints by a given + * offset. This offset has to lie within the range [0,n]. + * Example for offset = 2: \n + * rotate( {c1,c2,c3,c4,c5,c6} ) = {c3,c4,c5,c6,c1,c2} + * \return SUCCESSFUL_RETURN \n + RET_INDEX_OUT_OF_BOUNDS \n + RET_ROTATING_FAILED */ + virtual returnValue rotate(int_t offset /**< Rotation offset within the range [0,n]. */ + ); + + /** Prints information on constraints object + * (in particular, lists of inactive and active constraints. + * \return SUCCESSFUL_RETURN \n + RET_INDEXLIST_CORRUPTED */ + returnValue print(); + + /* + * PROTECTED MEMBER FUNCTIONS + */ +protected: + /** Frees all allocated memory. + * \return SUCCESSFUL_RETURN */ + returnValue clear(); + + /** Copies all members from given rhs object. + * \return SUCCESSFUL_RETURN */ + returnValue copy(const Constraints & rhs /**< Rhs object. */ + ); + + /** Initially adds all numbers of new (i.e. not yet in the list) bounds to + * to the index set corresponding to the desired status; + * the order depends on the SujectToType of each index. + * \return SUCCESSFUL_RETURN \n + RET_SETUP_CONSTRAINT_FAILED */ + returnValue setupAll(SubjectToStatus _status /**< Desired initial status for all bounds. */ + ); + + /* + * PROTECTED MEMBER VARIABLES + */ +protected: + Indexlist active; /**< Index list of active constraints. */ + Indexlist inactive; /**< Index list of inactive constraints. */ +}; + +END_NAMESPACE_QPOASES + +#include + +#endif /* QPOASES_CONSTRAINTS_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Constraints.ipp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Constraints.ipp new file mode 100755 index 0000000..d5bd3aa --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Constraints.ipp @@ -0,0 +1,122 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file include/qpOASES/Constraints.ipp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Declaration of inlined member functions of the Constraints class designed + * to manage working sets of constraints within a QProblem. + */ + + +BEGIN_NAMESPACE_QPOASES + + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + + +/* + * g e t N C + */ +inline int_t Constraints::getNC( ) const +{ + return n; +} + + +/* + * g e t N E C + */ +inline int_t Constraints::getNEC( ) const +{ + return getNumberOfType( ST_EQUALITY ); +} + + +/* + * g e t N I C + */ +inline int_t Constraints::getNIC( ) const +{ + return getNumberOfType( ST_BOUNDED ); +} + + +/* + * g e t N U C + */ +inline int_t Constraints::getNUC( ) const +{ + return getNumberOfType( ST_UNBOUNDED ); +} + + +/* + * g e t N A C + */ +inline int_t Constraints::getNAC( ) const +{ + return active.getLength( ); +} + + +/* + * g e t N I A C + */ +inline int_t Constraints::getNIAC( ) const +{ + return inactive.getLength( ); +} + + + +/* + * g e t A c t i v e + */ +inline Indexlist* Constraints::getActive( ) +{ + return &active; +} + + +/* + * g e t I n a c t i v e + */ +inline Indexlist* Constraints::getInactive( ) +{ + return &inactive; +} + + +END_NAMESPACE_QPOASES + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Flipper.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Flipper.hpp new file mode 100644 index 0000000..f250335 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Flipper.hpp @@ -0,0 +1,143 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/Flipper.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Declaration of the Options class designed to manage user-specified + * options for solving a QProblem. + */ + +#ifndef QPOASES_FLIPPER_HPP +#define QPOASES_FLIPPER_HPP + +#include +#include + +BEGIN_NAMESPACE_QPOASES + +/** + * \brief Auxiliary class for storing a copy of the current matrix factorisations. + * + * This auxiliary class stores a copy of the current matrix factorisations. It + * is used by the classe QProblemB and QProblem in case flipping bounds are enabled. + * + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + */ +class Flipper +{ + friend class QProblemB; + friend class QProblem; + + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + Flipper(); + + /** Constructor which takes the number of bounds and constraints. */ + Flipper(uint_t _nV, /**< Number of bounds. */ + uint_t _nC = 0 /**< Number of constraints. */ + ); + + /** Copy constructor (deep copy). */ + Flipper(const Flipper & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + ~Flipper(); + + /** Assignment operator (deep copy). */ + Flipper & operator=(const Flipper & rhs /**< Rhs object. */ + ); + + /** Initialises object with given number of bounds and constraints. + * \return SUCCESSFUL_RETURN \n + RET_INVALID_ARGUMENTS */ + returnValue init(uint_t _nV = 0, /**< Number of bounds. */ + uint_t _nC = 0 /**< Number of constraints. */ + ); + + /** Copies current values to non-null arguments (assumed to be allocated with consistent size). + * \return SUCCESSFUL_RETURN */ + returnValue get(Bounds * const _bounds, /**< Pointer to new bounds. */ + real_t * const R, /**< New matrix R. */ + Constraints * const _constraints = 0, /**< Pointer to new constraints. */ + real_t * const _Q = 0, /**< New matrix Q. */ + real_t * const _T = 0 /**< New matrix T. */ + ) const; + + /** Assigns new values to non-null arguments. + * \return SUCCESSFUL_RETURN */ + returnValue set(const Bounds * const _bounds, /**< Pointer to new bounds. */ + const real_t * const _R, /**< New matrix R. */ + const Constraints * const _constraints = 0, /**< Pointer to new constraints. */ + const real_t * const _Q = 0, /**< New matrix Q. */ + const real_t * const _T = 0 /**< New matrix T. */ + ); + + /* + * PROTECTED MEMBER FUNCTIONS + */ +protected: + /** Frees all allocated memory. + * \return SUCCESSFUL_RETURN */ + returnValue clear(); + + /** Copies all members from given rhs object. + * \return SUCCESSFUL_RETURN */ + returnValue copy(const Flipper & rhs /**< Rhs object. */ + ); + + /** Returns dimension of matrix T. + * \return Dimension of matrix T. */ + uint_t getDimT() const; + + /* + * PROTECTED MEMBER VARIABLES + */ +protected: + uint_t nV; /**< Number of variables. */ + uint_t nC; /**< Number of constraints. */ + + Bounds bounds; /**< Data structure for problem's bounds. */ + Constraints constraints; /**< Data structure for problem's constraints. */ + + real_t * R; /**< Cholesky factor of H (i.e. H = R^T*R). */ + real_t * Q; /**< Orthonormal quadratic matrix, A = [0 T]*Q'. */ + real_t * T; /**< Reverse triangular matrix, A = [0 T]*Q'. */ +}; + +END_NAMESPACE_QPOASES + +#endif /* QPOASES_FLIPPER_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Indexlist.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Indexlist.hpp new file mode 100644 index 0000000..fe41ced --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Indexlist.hpp @@ -0,0 +1,185 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/Indexlist.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Declaration of the Indexlist class designed to manage index lists of + * constraints and bounds within a SubjectTo object. + */ + +#ifndef QPOASES_INDEXLIST_HPP +#define QPOASES_INDEXLIST_HPP + +#include + +BEGIN_NAMESPACE_QPOASES + +/** + * \brief Stores and manages index lists. + * + * This class manages index lists of active/inactive bounds/constraints. + * + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + */ +class Indexlist +{ + /* + * FRIENDS + */ + friend class DenseMatrix; + friend class SymDenseMat; + friend class SparseMatrix; + friend class SparseMatrixRow; + friend class SymSparseMat; + + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + Indexlist(); + + /** Constructor which takes the desired physical length of the index list. */ + Indexlist(int_t n /**< Physical length of index list. */ + ); + + /** Copy constructor (deep copy). */ + Indexlist(const Indexlist & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + ~Indexlist(); + + /** Assingment operator (deep copy). */ + Indexlist & operator=(const Indexlist & rhs /**< Rhs object. */ + ); + + /** Initialises index list of desired physical length. + * \return SUCCESSFUL_RETURN \n + RET_INVALID_ARGUMENTS */ + returnValue init(int_t n = 0 /**< Physical length of index list. */ + ); + + /** Creates an array of all numbers within the index set in correct order. + * \return SUCCESSFUL_RETURN \n + RET_INDEXLIST_CORRUPTED */ + returnValue getNumberArray(int_t ** const numberarray /**< Output: Array of numbers (NULL on error). */ + ) const; + + /** Creates an array of all numbers within the index set in correct order. + * \return SUCCESSFUL_RETURN \n + RET_INDEXLIST_CORRUPTED */ + returnValue getISortArray(int_t ** const iSortArray /**< Output: iSort Array. */ + ) const; + + /** Determines the index within the index list at which a given number is stored. + * \return >= 0: Index of given number. \n + -1: Number not found. */ + int_t getIndex(int_t givennumber /**< Number whose index shall be determined. */ + ) const; + + /** Returns the number stored at a given physical index. + * \return >= 0: Number stored at given physical index. \n + -RET_INDEXLIST_OUTOFBOUNDS */ + int_t getNumber(int_t physicalindex /**< Physical index of the number to be returned. */ + ) const; + + /** Returns the current length of the index list. + * \return Current length of the index list. */ + inline int_t getLength() const; + + /** Returns last number within the index list. + * \return Last number within the index list. */ + inline int_t getLastNumber() const; + + /** Adds number to index list. + * \return SUCCESSFUL_RETURN \n + RET_INDEXLIST_MUST_BE_REORDERD \n + RET_INDEXLIST_EXCEEDS_MAX_LENGTH */ + returnValue addNumber(int_t addnumber /**< Number to be added. */ + ); + + /** Removes number from index list. + * \return SUCCESSFUL_RETURN */ + returnValue removeNumber(int_t removenumber /**< Number to be removed. */ + ); + + /** Swaps two numbers within index list. + * \return SUCCESSFUL_RETURN */ + returnValue swapNumbers(int_t number1, /**< First number for swapping. */ + int_t number2 /**< Second number for swapping. */ + ); + + /** Determines if a given number is contained in the index set. + * \return BT_TRUE iff number is contain in the index set */ + inline BooleanType isMember(int_t _number /**< Number to be tested for membership. */ + ) const; + + /* + * PROTECTED MEMBER FUNCTIONS + */ +protected: + /** Frees all allocated memory. + * \return SUCCESSFUL_RETURN */ + returnValue clear(); + + /** Copies all members from given rhs object. + * \return SUCCESSFUL_RETURN */ + returnValue copy(const Indexlist & rhs /**< Rhs object. */ + ); + + /** Find first index j between -1 and length in sorted list of indices + * iSort such that numbers[iSort[j]] <= i < numbers[iSort[j+1]]. Uses + * bisection. + * \return j. */ + int_t findInsert(int_t i) const; + + /* + * PROTECTED MEMBER VARIABLES + */ +protected: + int_t * number; /**< Array to store numbers of constraints or bounds. */ + int_t * iSort; /**< Index list to sort vector \a number */ + + int_t length; /**< Length of index list. */ + int_t first; /**< Physical index of first element. */ + int_t last; /**< Physical index of last element. */ + int_t lastusedindex; /**< Physical index of last entry in index list. */ + int_t physicallength; /**< Physical length of index list. */ +}; + +END_NAMESPACE_QPOASES + +#include + +#endif /* QPOASES_INDEXLIST_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Indexlist.ipp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Indexlist.ipp new file mode 100755 index 0000000..178252f --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Indexlist.ipp @@ -0,0 +1,92 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file include/qpOASES/Indexlist.ipp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of inlined member functions of the Indexlist class designed + * to manage index lists of constraints and bounds within a QProblem_SubjectTo. + */ + + +BEGIN_NAMESPACE_QPOASES + + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + + +/* + * g e t N u m b e r + */ +inline int_t Indexlist::getNumber( int_t physicalindex ) const +{ + /* consistency check */ + if ( ( physicalindex < 0 ) || ( physicalindex > length ) ) + return -RET_INDEXLIST_OUTOFBOUNDS; + + return number[physicalindex]; +} + + +/* + * g e t L e n g t h + */ +inline int_t Indexlist::getLength( ) const +{ + return length; +} + + +/* + * g e t L a s t N u m b e r + */ +inline int_t Indexlist::getLastNumber( ) const +{ + return number[length-1]; +} + + +/* + * g e t L a s t N u m b e r + */ +inline BooleanType Indexlist::isMember( int_t _number ) const +{ + if ( getIndex( _number ) >= 0 ) + return BT_TRUE; + else + return BT_FALSE; +} + + +END_NAMESPACE_QPOASES + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/LapackBlasReplacement.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/LapackBlasReplacement.hpp new file mode 100644 index 0000000..4e020c6 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/LapackBlasReplacement.hpp @@ -0,0 +1,177 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/LapackBlasReplacement.hpp + * \author Andreas Potschka, Hans Joachim Ferreau, Christian Kirches + * \version 3.2 + * \date 2009-2017 + * + * Declarations for external LAPACK/BLAS functions. + */ + +#ifndef QPOASES_LAPACKBLASREPLACEMENT_HPP +#define QPOASES_LAPACKBLASREPLACEMENT_HPP + +#include + +#ifdef __AVOID_LA_NAMING_CONFLICTS__ + +#define SGEMM qpOASES_sgemm +#define DGEMM qpOASES_gemm +#define SPOTRF qpOASES_spotrf +#define DPOTRF qpOASES_dpotrf +#define STRTRS qpOASES_strtrs +#define DTRTRS qpOASES_dtrtrs +#define STRCON qpOASES_strcon +#define DTRCON qpOASES_dtrcon + +#else + +#define SGEMM sgemm_ +#define DGEMM dgemm_ +#define SPOTRF spotrf_ +#define DPOTRF dpotrf_ +#define STRTRS strtrs_ +#define DTRTRS dtrtrs_ +#define STRCON strcon_ +#define DTRCON dtrcon_ + +#endif + +#ifdef __USE_SINGLE_PRECISION__ + +/** Macro for calling level 3 BLAS operation in single precision. */ +#define GEMM SGEMM +/** Macro for calling level 3 BLAS operation in single precision. */ +#define POTRF SPOTRF + +/** Macro for calling level 3 BLAS operation in single precision. */ +#define TRTRS STRTRS +/** Macro for calling level 3 BLAS operation in single precision. */ +#define TRCON strcon_ + +#else + +/** Macro for calling level 3 BLAS operation in double precision. */ +#define GEMM DGEMM +/** Macro for calling level 3 BLAS operation in double precision. */ +#define POTRF DPOTRF + +/** Macro for calling level 3 BLAS operation in double precision. */ +#define TRTRS DTRTRS +/** Macro for calling level 3 BLAS operation in double precision. */ +#define TRCON DTRCON + +#endif /* __USE_SINGLE_PRECISION__ */ + +extern "C" +{ + /** Performs one of the matrix-matrix operation in double precision. */ + void DGEMM(const char *, + const char *, + const la_uint_t *, + const la_uint_t *, + const la_uint_t *, + const double *, + const double *, + const la_uint_t *, + const double *, + const la_uint_t *, + const double *, + double *, + const la_uint_t *); + /** Performs one of the matrix-matrix operation in single precision. */ + void SGEMM(const char *, + const char *, + const la_uint_t *, + const la_uint_t *, + const la_uint_t *, + const float *, + const float *, + const la_uint_t *, + const float *, + const la_uint_t *, + const float *, + float *, + const la_uint_t *); + + /** Calculates the Cholesky factorization of a real symmetric positive definite matrix in double + * precision. */ + void DPOTRF(const char *, const la_uint_t *, double *, const la_uint_t *, la_int_t *); + /** Calculates the Cholesky factorization of a real symmetric positive definite matrix in single + * precision. */ + void SPOTRF(const char *, const la_uint_t *, float *, const la_uint_t *, la_int_t *); + + /** Solves a triangular system (double precision) */ + void DTRTRS(const char * UPLO, + const char * TRANS, + const char * DIAG, + const la_uint_t * N, + const la_uint_t * NRHS, + double * A, + const la_uint_t * LDA, + double * B, + const la_uint_t * LDB, + la_int_t * INFO); + /** Solves a triangular system (single precision) */ + void STRTRS(const char * UPLO, + const char * TRANS, + const char * DIAG, + const la_uint_t * N, + const la_uint_t * NRHS, + float * A, + const la_uint_t * LDA, + float * B, + const la_uint_t * LDB, + la_int_t * INFO); + + /** Estimate the reciprocal of the condition number of a triangular matrix in double precision */ + void DTRCON(const char * NORM, + const char * UPLO, + const char * DIAG, + const la_uint_t * N, + double * A, + const la_uint_t * LDA, + double * RCOND, + double * WORK, + const la_uint_t * IWORK, + la_int_t * INFO); + /** Estimate the reciprocal of the condition number of a triangular matrix in single precision */ + void STRCON(const char * NORM, + const char * UPLO, + const char * DIAG, + const la_uint_t * N, + float * A, + const la_uint_t * LDA, + float * RCOND, + float * WORK, + const la_uint_t * IWORK, + la_int_t * INFO); +} + +#endif /* QPOASES_LAPACKBLASREPLACEMENT_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Matrices.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Matrices.hpp new file mode 100644 index 0000000..c851794 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Matrices.hpp @@ -0,0 +1,971 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/Matrices.hpp + * \author Andreas Potschka, Hans Joachim Ferreau, Christian Kirches + * \version 3.2 + * \date 2009-2017 + * + * Various matrix classes: Abstract base matrix class, dense and sparse matrices, + * including symmetry exploiting specializations. + */ + +#ifndef QPOASES_MATRICES_HPP +#define QPOASES_MATRICES_HPP + +#include +#include + +BEGIN_NAMESPACE_QPOASES + +/** + * \brief Abstract base class for interfacing tailored matrix-vector operations. + * + * Abstract base matrix class. Supplies interface to matrix vector + * products, including products with submatrices given by (ordered) working set + * index lists (see \a SubjectTo). + * + * \author Andreas Potschka, Christian Kirches, Hans Joachim Ferreau + * \version 3.2 + * \date 2011-2017 + */ +class Matrix +{ +public: + /** Default constructor. */ + Matrix() { doNotFreeMemory(); }; + + /** Destructor. */ + virtual ~Matrix(){}; + + /** Frees all internal memory. */ + virtual void free() = 0; + + /** Returns a deep-copy of the Matrix object. + * \return Deep-copy of Matrix object */ + virtual Matrix * duplicate() const = 0; + + /** Returns i-th diagonal entry. + * \return i-th diagonal entry */ + virtual real_t diag(int_t i /**< Index. */ + ) const = 0; + + /** Checks whether matrix is square and diagonal. + * \return BT_TRUE iff matrix is square and diagonal; \n + * BT_FALSE otherwise. */ + virtual BooleanType isDiag() const = 0; + + /** Get the N-norm of the matrix + * \return N-norm of the matrix + */ + virtual real_t getNorm(int_t type = 2 /**< Norm type, 1: one-norm, 2: Euclidean norm. */ + ) const = 0; + + /** Get the N-norm of a row + * \return N-norm of row \a rNum + */ + virtual real_t getRowNorm(int_t rNum, /**< Row number. */ + int_t type = 2 /**< Norm type, 1: one-norm, 2: Euclidean norm. */ + ) const = 0; + + /** Get the N-norm of all rows + * \return SUCCESSFUL_RETURN */ + virtual returnValue getRowNorm(real_t * norm, /**< Norm of each row. */ + int_t type = 2 /**< Norm type, 1: one-norm, 2: Euclidean norm. */ + ) const = 0; + + /** Retrieve indexed entries of matrix row multiplied by alpha. + * \return SUCCESSFUL_RETURN */ + virtual returnValue getRow(int_t rNum, /**< Row number. */ + const Indexlist * const icols, /**< Index list specifying columns. */ + real_t alpha, /**< Scalar factor. */ + real_t * row /**< Output row vector. */ + ) const = 0; + + /** Retrieve indexed entries of matrix column multiplied by alpha. + * \return SUCCESSFUL_RETURN */ + virtual returnValue getCol(int_t cNum, /**< Column number. */ + const Indexlist * const irows, /**< Index list specifying rows. */ + real_t alpha, /**< Scalar factor. */ + real_t * col /**< Output column vector. */ + ) const = 0; + + /** Retrieve entries of submatrix in Harwell-Boeing sparse format. + * If irn, jcn, and avals are null, this only counts the number of nonzeros. + * Otherwise, numNonzeros containts the size of irn, jcn, and avals on entry, + * and the written number of entries on return. + * \return SUCCESSFUL_RETURN */ + virtual returnValue getSparseSubmatrix(const Indexlist * const irows, /**< Index list specifying rows. */ + const Indexlist * const icols, /**< Index list specifying columns. */ + int_t rowoffset, /**< Offset for row entries. */ + int_t coloffset, /**< Offset for row entries. */ + int_t & numNonzeros, /**< Number of nonzeros in submatrix. */ + int_t * irn, /**< Row position of entries (as position in irows) plus rowoffset. */ + int_t * jcn, /**< Column position of entries (as position in irows) plus coloffset. */ + real_t * avals, /**< Numerical values of the entries. */ + BooleanType only_lower_triangular = + BT_FALSE /**< if true, only the lower triangular portion is returned. This can only be true for + symmetric matrices and if irows==jcols. */ + ) const; + + /** Retrieve entries of submatrix in Harwell-Boeing sparse format. + * If irn, jcn, and avals are null, this only counts the number of nonzeros. + * Otherwise, numNonzeros containts the size of irn, jcn, and avals on entry, + * and the written number of entries on return. This version retrieves one + * column. + * \return SUCCESSFUL_RETURN */ + virtual returnValue getSparseSubmatrix(const Indexlist * const irows, /**< Index list specifying rows. */ + int_t idx_icol, /**< Index list specifying columns. */ + int_t rowoffset, /**< Offset for row entries. */ + int_t coloffset, /**< Offset for row entries. */ + int_t & numNonzeros, /**< Number of nonzeros in submatrix. */ + int_t * irn, /**< Row position of entries (as position in irows) plus rowoffset. */ + int_t * jcn, /**< Column position of entries (as position in irows) plus coloffset. */ + real_t * avals, /**< Numerical values of the entries. */ + BooleanType only_lower_triangular = + BT_FALSE /**< if true, only the lower triangular portion is returned. This can only be true for + symmetric matrices and if irows==jcols. */ + ) const; + + /** Retrieve entries of submatrix in Harwell-Boeing sparse format. + * If irn, jcn, and avals are null, this only counts the number of nonzeros. + * Otherwise, numNonzeros containts the size of irn, jcn, and avals on entry, + * and the written number of entries on return. This version retrieves one row. + * \return SUCCESSFUL_RETURN */ + virtual returnValue getSparseSubmatrix(int_t idx_row, /**< Row number. */ + const Indexlist * const icols, /**< Index list specifying columns. */ + int_t rowoffset, /**< Offset for row entries. */ + int_t coloffset, /**< Offset for row entries. */ + int_t & numNonzeros, /**< Number of nonzeros in submatrix. */ + int_t * irn, /**< Row position of entries (as position in irows) plus rowoffset. */ + int_t * jcn, /**< Column position of entries (as position in irows) plus coloffset. */ + real_t * avals, /**< Numerical values of the entries. */ + BooleanType only_lower_triangular = + BT_FALSE /**< if true, only the lower triangular portion is returned. This can only be true for + symmetric matrices and if irows==jcols. */ + ) const; + + /** Retrieve entries of submatrix in Harwell-Boeing sparse format. + * If irn, jcn, and avals are null, this only counts the number of nonzeros. + * Otherwise, numNonzeros containts the size of irn, jcn, and avals on entry, + * and the written number of entries on return. + * \return SUCCESSFUL_RETURN */ + virtual returnValue getSparseSubmatrix(int_t irowsLength, /**< Number of rows. */ + const int_t * const irowsNumber, /**< Array with row numbers. */ + int_t icolsLength, /**< Number of columns. */ + const int_t * const icolsNumber, /**< Array with column numbers. */ + int_t rowoffset, /**< Offset for row entries. */ + int_t coloffset, /**< Offset for row entries. */ + int_t & numNonzeros, /**< Number of nonzeros in submatrix. */ + int_t * irn, /**< Row position of entries (as position in irows) plus rowoffset. */ + int_t * jcn, /**< Column position of entries (as position in irows) plus coloffset. */ + real_t * avals, /**< Numerical values of the entries. */ + BooleanType only_lower_triangular = + BT_FALSE /**< if true, only the lower triangular portion is returned. This can only be true for + symmetric matrices and if irows==jcols. */ + ) const = 0; + + /** Evaluate Y=alpha*A*X + beta*Y. + * \return SUCCESSFUL_RETURN */ + virtual returnValue times(int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD /**< Leading dimension of output y. */ + ) const = 0; + + /** Evaluate Y=alpha*A'*X + beta*Y. + * \return SUCCESSFUL_RETURN */ + virtual returnValue transTimes(int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD /**< Leading dimension of output y. */ + ) const = 0; + + /** Evaluate matrix vector product with submatrix given by Indexlist. + * \return SUCCESSFUL_RETURN */ + virtual returnValue times(const Indexlist * const irows, /**< Index list specifying rows. */ + const Indexlist * const icols, /**< Index list specifying columns. */ + int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD, /**< Leading dimension of output y. */ + BooleanType yCompr = BT_TRUE /**< Compressed storage for y. */ + ) const = 0; + + /** Evaluate matrix transpose vector product. + * \return SUCCESSFUL_RETURN */ + virtual returnValue transTimes(const Indexlist * const irows, /**< Index list specifying rows. */ + const Indexlist * const icols, /**< Index list specifying columns. */ + int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD /**< Leading dimension of output y. */ + ) const = 0; + + /** Adds given offset to diagonal of matrix. + * \return SUCCESSFUL_RETURN \n + RET_NO_DIAGONAL_AVAILABLE */ + virtual returnValue addToDiag(real_t alpha /**< Diagonal offset. */ + ) = 0; + + /** Allocates and creates dense matrix array in row major format. + * + * Note: Calling function has to free allocated memory! + * + * \return Pointer to matrix array. + */ + virtual real_t * full() const = 0; + + /** Prints matrix to screen. + * \return SUCCESSFUL_RETURN */ + virtual returnValue print(const char * name = 0 /** Name of matrix. */ + ) const = 0; + + /** Write matrix to file. + * \return SUCCESSFUL_RETURN */ + virtual returnValue writeToFile(FILE * output_file, const char * prefix) const = 0; + + /** Returns whether internal memory needs to be de-allocated. + * \return BT_TRUE iff internal memory needs to be de-allocated, \n + BT_FALSE otherwise */ + BooleanType needToFreeMemory() const { return freeMemory; }; + + /** Enables de-allocation of internal memory. */ + void doFreeMemory() { freeMemory = BT_TRUE; }; + + /** Disables de-allocation of internal memory. */ + void doNotFreeMemory() { freeMemory = BT_FALSE; }; + +protected: + BooleanType freeMemory; /**< Indicating whether internal memory needs to be de-allocated. */ +}; + +/** + * \brief Abstract base class for interfacing matrix-vector operations tailored to symmetric matrices. + * + * Abstract base class for symmetric matrices. Extends Matrix interface with + * bilinear form evaluation. + * + * \author Andreas Potschka, Christian Kirches, Hans Joachim Ferreau + * \version 3.2 + * \date 2011-2017 + */ +class SymmetricMatrix : public virtual Matrix +{ +public: + /** Default constructor. */ + SymmetricMatrix(){}; + + /** Destructor. */ + virtual ~SymmetricMatrix(){}; + + /** Returns a deep-copy of the SymmetricMatrix object. + * \return Deep-copy of SymmetricMatrix object */ + virtual SymmetricMatrix * duplicateSym() const = 0; + + /** Compute bilinear form y = x'*H*x using submatrix given by index list. + * \return SUCCESSFUL_RETURN */ + virtual returnValue bilinear(const Indexlist * const icols, /**< Index list specifying columns of x. */ + int_t xN, /**< Number of vectors to multiply. */ + const real_t * x, /**< Input vector to be multiplied (uncompressed). */ + int_t xLD, /**< Leading dimension of input x. */ + real_t * y, /**< Output vector of results (compressed). */ + int_t yLD /**< Leading dimension of output y. */ + ) const = 0; +}; + +/** + * \brief Interfaces matrix-vector operations tailored to general dense matrices. + * + * Dense matrix class (row major format). + * + * \author Andreas Potschka, Christian Kirches, Hans Joachim Ferreau + * \version 3.2 + * \date 2011-2017 + */ +class DenseMatrix : public virtual Matrix +{ +public: + /** Default constructor. */ + DenseMatrix() : nRows(0), nCols(0), leaDim(0), val(0){}; + + /** Constructor from vector of values. + * Caution: Data pointer must be valid throughout lifetime + */ + DenseMatrix(int_t m, /**< Number of rows. */ + int_t n, /**< Number of columns. */ + int_t lD, /**< Leading dimension. */ + real_t * v /**< Values. */ + ) + : nRows(m), nCols(n), leaDim(lD), val(v) + { + } + + /** Destructor. */ + virtual ~DenseMatrix(); + + /** Frees all internal memory. */ + virtual void free(); + + /** Returns a deep-copy of the Matrix object. + * \return Deep-copy of Matrix object */ + virtual Matrix * duplicate() const; + + /** Returns i-th diagonal entry. + * \return i-th diagonal entry */ + virtual real_t diag(int_t i /**< Index. */ + ) const; + + /** Checks whether matrix is square and diagonal. + * \return BT_TRUE iff matrix is square and diagonal; \n + * BT_FALSE otherwise. */ + virtual BooleanType isDiag() const; + + /** Get the N-norm of the matrix + * \return N-norm of the matrix + */ + virtual real_t getNorm(int_t type = 2 /**< Norm type, 1: one-norm, 2: Euclidean norm. */ + ) const; + + /** Get the N-norm of a row + * \return N-norm of row \a rNum + */ + virtual real_t getRowNorm(int_t rNum, /**< Row number. */ + int_t type = 2 /**< Norm type, 1: one-norm, 2: Euclidean norm. */ + ) const; + + /** Get the N-norm of all rows + * \return SUCCESSFUL_RETURN */ + virtual returnValue getRowNorm(real_t * norm, /**< Norm of each row. */ + int_t type = 2 /**< Norm type, 1: one-norm, 2: Euclidean norm. */ + ) const; + + /** Retrieve indexed entries of matrix row multiplied by alpha. + * \return SUCCESSFUL_RETURN */ + virtual returnValue getRow(int_t rNum, /**< Row number. */ + const Indexlist * const icols, /**< Index list specifying columns. */ + real_t alpha, /**< Scalar factor. */ + real_t * row /**< Output row vector. */ + ) const; + + /** Retrieve indexed entries of matrix column multiplied by alpha. + * \return SUCCESSFUL_RETURN */ + virtual returnValue getCol(int_t cNum, /**< Column number. */ + const Indexlist * const irows, /**< Index list specifying rows. */ + real_t alpha, /**< Scalar factor. */ + real_t * col /**< Output column vector. */ + ) const; + + /** Retrieve entries of submatrix in Harwell-Boeing sparse format. + * If irn, jcn, and avals are null, this only counts the number of nonzeros. + * Otherwise, numNonzeros containts the size of irn, jcn, and avals on entry, + * and the written number of entries on return. + * \return SUCCESSFUL_RETURN */ + virtual returnValue getSparseSubmatrix(int_t irowsLength, /**< Number of rows. */ + const int_t * const irowsNumber, /**< Array with row numbers. */ + int_t icolsLength, /**< Number of columns. */ + const int_t * const icolsNumber, /**< Array with column numbers. */ + int_t rowoffset, /**< Offset for row entries. */ + int_t coloffset, /**< Offset for row entries. */ + int_t & numNonzeros, /**< Number of nonzeros in submatrix. */ + int_t * irn, /**< Row position of entries (as position in irows) plus rowoffset. */ + int_t * jcn, /**< Column position of entries (as position in irows) plus coloffset. */ + real_t * avals, /**< Numerical values of the entries. */ + BooleanType only_lower_triangular = + BT_FALSE /**< if true, only the lower triangular portion is returned. This can only be true for + symmetric matrices and if irows==jcols. */ + ) const; + + /** Evaluate Y=alpha*A*X + beta*Y. + * \return SUCCESSFUL_RETURN. */ + virtual returnValue times(int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD /**< Leading dimension of output y. */ + ) const; + + /** Evaluate Y=alpha*A'*X + beta*Y. + * \return SUCCESSFUL_RETURN. */ + virtual returnValue transTimes(int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD /**< Leading dimension of output y. */ + ) const; + + /** Evaluate matrix vector product with submatrix given by Indexlist. + * \return SUCCESSFUL_RETURN */ + virtual returnValue times(const Indexlist * const irows, /**< Index list specifying rows. */ + const Indexlist * const icols, /**< Index list specifying columns. */ + int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD, /**< Leading dimension of output y. */ + BooleanType yCompr = BT_TRUE /**< Compressed storage for y. */ + ) const; + + /** Evaluate matrix transpose vector product. + * \return SUCCESSFUL_RETURN */ + virtual returnValue transTimes(const Indexlist * const irows, /**< Index list specifying rows. */ + const Indexlist * const icols, /**< Index list specifying columns. */ + int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD /**< Leading dimension of output y. */ + ) const; + + /** Adds given offset to diagonal of matrix. + * \return SUCCESSFUL_RETURN \n + RET_NO_DIAGONAL_AVAILABLE */ + virtual returnValue addToDiag(real_t alpha /**< Diagonal offset. */ + ); + + /** Allocates and creates dense matrix array in row major format. + * + * Note: Calling function has to free allocated memory! + * + * \return Pointer to matrix array. + */ + virtual real_t * full() const; + + /** Prints matrix to screen. + * \return SUCCESSFUL_RETURN */ + virtual returnValue print(const char * name = 0 /** Name of matrix. */ + ) const; + + /** Write matrix to file. + * \return SUCCESSFUL_RETURN */ + virtual returnValue writeToFile(FILE * output_file, const char * prefix) const; + +protected: + int_t nRows; /**< Number of rows. */ + int_t nCols; /**< Number of columns. */ + int_t leaDim; /**< Leading dimension. */ + real_t * val; /**< Vector of entries. */ +}; + +/** + * \brief Interfaces matrix-vector operations tailored to symmetric dense matrices. + * + * Symmetric dense matrix class. + * + * \author Andreas Potschka, Christian Kirches, Hans Joachim Ferreau + * \version 3.2 + * \date 2011-2017 + */ +class SymDenseMat +: public DenseMatrix +, public SymmetricMatrix +{ +public: + /** Default constructor. */ + SymDenseMat() : DenseMatrix(){}; + + /** Constructor from vector of values. */ + SymDenseMat(int_t m, /**< Number of rows. */ + int_t n, /**< Number of columns. */ + int_t lD, /**< Leading dimension. */ + real_t * v /**< Values. */ + ) + : DenseMatrix(m, n, lD, v){}; + + /** Destructor. */ + virtual ~SymDenseMat(){}; + + /** Returns a deep-copy of the Matrix object. + * \return Deep-copy of Matrix object */ + virtual Matrix * duplicate() const; + + /** Returns a deep-copy of the SymmetricMatrix object. + * \return Deep-copy of SymmetricMatrix object */ + virtual SymmetricMatrix * duplicateSym() const; + + /** Compute bilinear form y = x'*H*x using submatrix given by index list. + * \return SUCCESSFUL_RETURN */ + virtual returnValue bilinear(const Indexlist * const icols, /**< Index list specifying columns of x. */ + int_t xN, /**< Number of vectors to multiply. */ + const real_t * x, /**< Input vector to be multiplied (uncompressed). */ + int_t xLD, /**< Leading dimension of input x. */ + real_t * y, /**< Output vector of results (compressed). */ + int_t yLD /**< Leading dimension of output y. */ + ) const; +}; + +/** + * \brief Interfaces matrix-vector operations tailored to general sparse matrices. + * + * Sparse matrix class (col compressed format). + * + * \author Andreas Potschka, Christian Kirches, Hans Joachim Ferreau + * \version 3.2 + * \date 2011-2017 + */ +class SparseMatrix : public virtual Matrix +{ +public: + /** Default constructor. */ + SparseMatrix(); + + /** Constructor with arguments. */ + SparseMatrix(int_t nr, /**< Number of rows. */ + int_t nc, /**< Number of columns. */ + sparse_int_t * r, /**< Row indices (length). */ + sparse_int_t * c, /**< Indices to first entry of columns (nCols+1). */ + real_t * v /**< Vector of entries (length). */ + ); + + /** Constructor from dense matrix. */ + SparseMatrix(int_t nr, /**< Number of rows. */ + int_t nc, /**< Number of columns. */ + int_t ld, /**< Leading dimension. */ + const real_t * const v /**< Row major stored matrix elements. */ + ); + + /** Destructor. */ + virtual ~SparseMatrix(); + + /** Frees all internal memory. */ + virtual void free(); + + /** Returns a deep-copy of the Matrix object. + * \return Deep-copy of Matrix object */ + virtual Matrix * duplicate() const; + + /** Sets value array. + * + * Thanks to Frank Chuang. + */ + virtual void setVal(const real_t * newVal /**< ... */ + ); + + /** Returns i-th diagonal entry. + * \return i-th diagonal entry (or INFTY if diagonal does not exist)*/ + virtual real_t diag(int_t i /**< Index. */ + ) const; + + /** Checks whether matrix is square and diagonal. + * \return BT_TRUE iff matrix is square and diagonal; \n + * BT_FALSE otherwise. */ + virtual BooleanType isDiag() const; + + /** Get the N-norm of the matrix + * \return N-norm of the matrix + */ + virtual real_t getNorm(int_t type = 2 /**< Norm type, 1: one-norm, 2: Euclidean norm. */ + ) const; + + /** Get the N-norm of a row + * \return N-norm of row \a rNum + */ + virtual real_t getRowNorm(int_t rNum, /**< Row number. */ + int_t type = 2 /**< Norm type, 1: one-norm, 2: Euclidean norm. */ + ) const; + + /** Get the N-norm of all rows + * \return SUCCESSFUL_RETURN */ + virtual returnValue getRowNorm(real_t * norm, /**< Norm of each row. */ + int_t type = 2 /**< Norm type, 1: one-norm, 2: Euclidean norm. */ + ) const; + + /** Retrieve indexed entries of matrix row multiplied by alpha. */ + virtual returnValue getRow(int_t rNum, /**< Row number. */ + const Indexlist * const icols, /**< Index list specifying columns. */ + real_t alpha, /**< Scalar factor. */ + real_t * row /**< Output row vector. */ + ) const; + + /** Retrieve indexed entries of matrix column multiplied by alpha. */ + virtual returnValue getCol(int_t cNum, /**< Column number. */ + const Indexlist * const irows, /**< Index list specifying rows. */ + real_t alpha, /**< Scalar factor. */ + real_t * col /**< Output column vector. */ + ) const; + + /** Retrieve entries of submatrix in Harwell-Boeing sparse format. + * If irn, jcn, and avals are null, this only counts the number of nonzeros. + * Otherwise, numNonzeros containts the size of irn, jcn, and avals on entry, + * and the written number of entries on return. + * \return SUCCESSFUL_RETURN */ + virtual returnValue getSparseSubmatrix(int_t irowsLength, /**< Number of rows. */ + const int_t * const irowsNumber, /**< Array with row numbers. */ + int_t icolsLength, /**< Number of columns. */ + const int_t * const icolsNumber, /**< Array with column numbers. */ + int_t rowoffset, /**< Offset for row entries. */ + int_t coloffset, /**< Offset for row entries. */ + int_t & numNonzeros, /**< Number of nonzeros in submatrix. */ + int_t * irn, /**< Row position of entries (as position in irows) plus rowoffset. */ + int_t * jcn, /**< Column position of entries (as position in irows) plus coloffset. */ + real_t * avals, /**< Numerical values of the entries. */ + BooleanType only_lower_triangular = + BT_FALSE /**< if true, only the lower triangular portion is returned. This can only be true for + symmetric matrices and if irows==jcols. */ + ) const; + + /** Evaluate Y=alpha*A*X + beta*Y. */ + virtual returnValue times(int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD /**< Leading dimension of output y. */ + ) const; + + /** Evaluate Y=alpha*A'*X + beta*Y. */ + virtual returnValue transTimes(int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD /**< Leading dimension of output y. */ + ) const; + + /** Evaluate matrix vector product with submatrix given by Indexlist. */ + virtual returnValue times(const Indexlist * const irows, /**< Index list specifying rows. */ + const Indexlist * const icols, /**< Index list specifying columns. */ + int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD, /**< Leading dimension of output y. */ + BooleanType yCompr = BT_TRUE /**< Compressed storage for y. */ + ) const; + + /** Evaluate matrix transpose vector product. */ + virtual returnValue transTimes(const Indexlist * const irows, /**< Index list specifying rows. */ + const Indexlist * const icols, /**< Index list specifying columns. */ + int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD /**< Leading dimension of output y. */ + ) const; + + /** Adds given offset to diagonal of matrix. + * \return SUCCESSFUL_RETURN \n + RET_NO_DIAGONAL_AVAILABLE */ + virtual returnValue addToDiag(real_t alpha /**< Diagonal offset. */ + ); + + /** Create jd field from ir and jc. + * \return Pointer to jd. */ + sparse_int_t * createDiagInfo(); + + /** Allocates and creates dense matrix array in row major format. + * + * Note: Calling function has to free allocated memory! + * + * \return Pointer to matrix array. + */ + virtual real_t * full() const; + + /** Prints matrix to screen. + * \return SUCCESSFUL_RETURN */ + virtual returnValue print(const char * name = 0 /** Name of matrix. */ + ) const; + + /** Write matrix to file. + * \return SUCCESSFUL_RETURN */ + virtual returnValue writeToFile(FILE * output_file, const char * prefix) const; + +protected: + int_t nRows; /**< Number of rows. */ + int_t nCols; /**< Number of columns. */ + sparse_int_t * ir; /**< Row indices (length). */ + sparse_int_t * jc; /**< Indices to first entry of columns (nCols+1). */ + sparse_int_t * jd; /**< Indices to first entry of lower triangle (including diagonal) (nCols). */ + real_t * val; /**< Vector of entries (length). */ +}; + +/** + * \brief Interfaces matrix-vector operations tailored to general sparse matrices. + * + * Sparse matrix class (row compressed format). + * + * \author Andreas Potschka, Christian Kirches, Hans Joachim Ferreau + * \version 3.2 + * \date 2011-2017 + */ +class SparseMatrixRow : public virtual Matrix +{ +public: + /** Default constructor. */ + SparseMatrixRow(); + + /** Constructor with arguments. */ + SparseMatrixRow(int_t nr, /**< Number of rows. */ + int_t nc, /**< Number of columns. */ + sparse_int_t * r, /**< Indices to first entry of rows (nRows+1). */ + sparse_int_t * c, /**< Column indices (length). */ + real_t * v /**< Vector of entries (length). */ + ); + + /** Constructor from dense matrix. */ + SparseMatrixRow(int_t nr, /**< Number of rows. */ + int_t nc, /**< Number of columns. */ + int_t ld, /**< Leading dimension. */ + const real_t * const v /**< Row major stored matrix elements. */ + ); + + /** Destructor. */ + virtual ~SparseMatrixRow(); + + /** Frees all internal memory. */ + virtual void free(); + + /** Returns a deep-copy of the Matrix object. + * \return Deep-copy of Matrix object */ + virtual Matrix * duplicate() const; + + /** Returns i-th diagonal entry. + * \return i-th diagonal entry (or INFTY if diagonal does not exist)*/ + virtual real_t diag(int_t i /**< Index. */ + ) const; + + /** Checks whether matrix is square and diagonal. + * \return BT_TRUE iff matrix is square and diagonal; \n + * BT_FALSE otherwise. */ + virtual BooleanType isDiag() const; + + /** Get the N-norm of the matrix + * \return N-norm of the matrix + */ + virtual real_t getNorm(int_t type = 2 /**< Norm type, 1: one-norm, 2: Euclidean norm. */ + ) const; + + /** Get the N-norm of a row + * \return N-norm of row \a rNum + */ + virtual real_t getRowNorm(int_t rNum, /**< Row number. */ + int_t type = 2 /**< Norm type, 1: one-norm, 2: Euclidean norm. */ + ) const; + + /** Get the N-norm of all rows + * \return SUCCESSFUL_RETURN */ + virtual returnValue getRowNorm(real_t * norm, /**< Norm of each row. */ + int_t type = 2 /**< Norm type, 1: one-norm, 2: Euclidean norm. */ + ) const; + + /** Retrieve indexed entries of matrix row multiplied by alpha. */ + virtual returnValue getRow(int_t rNum, /**< Row number. */ + const Indexlist * const icols, /**< Index list specifying columns. */ + real_t alpha, /**< Scalar factor. */ + real_t * row /**< Output row vector. */ + ) const; + + /** Retrieve indexed entries of matrix column multiplied by alpha. */ + virtual returnValue getCol(int_t cNum, /**< Column number. */ + const Indexlist * const irows, /**< Index list specifying rows. */ + real_t alpha, /**< Scalar factor. */ + real_t * col /**< Output column vector. */ + ) const; + + /** Retrieve entries of submatrix in Harwell-Boeing sparse format. + * If irn, jcn, and avals are null, this only counts the number of nonzeros. + * Otherwise, numNonzeros containts the size of irn, jcn, and avals on entry, + * and the written number of entries on return. + * \return SUCCESSFUL_RETURN */ + virtual returnValue getSparseSubmatrix(int_t irowsLength, /**< Number of rows. */ + const int_t * const irowsNumber, /**< Array with row numbers. */ + int_t icolsLength, /**< Number of columns. */ + const int_t * const icolsNumber, /**< Array with column numbers. */ + int_t rowoffset, /**< Offset for row entries. */ + int_t coloffset, /**< Offset for row entries. */ + int_t & numNonzeros, /**< Number of nonzeros in submatrix. */ + int_t * irn, /**< Row position of entries (as position in irows) plus rowoffset. */ + int_t * jcn, /**< Column position of entries (as position in irows) plus coloffset. */ + real_t * avals, /**< Numerical values of the entries. */ + BooleanType only_lower_triangular = + BT_FALSE /**< if true, only the lower triangular portion is returned. This can only be true for + symmetric matrices and if irows==jcols. */ + ) const; + + /** Evaluate Y=alpha*A*X + beta*Y. */ + virtual returnValue times(int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD /**< Leading dimension of output y. */ + ) const; + + /** Evaluate Y=alpha*A'*X + beta*Y. */ + virtual returnValue transTimes(int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD /**< Leading dimension of output y. */ + ) const; + + /** Evaluate matrix vector product with submatrix given by Indexlist. */ + virtual returnValue times(const Indexlist * const irows, /**< Index list specifying rows. */ + const Indexlist * const icols, /**< Index list specifying columns. */ + int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD, /**< Leading dimension of output y. */ + BooleanType yCompr = BT_TRUE /**< Compressed storage for y. */ + ) const; + + /** Evaluate matrix transpose vector product. */ + virtual returnValue transTimes(const Indexlist * const irows, /**< Index list specifying rows. */ + const Indexlist * const icols, /**< Index list specifying columns. */ + int_t xN, /**< Number of vectors to multiply. */ + real_t alpha, /**< Scalar factor for matrix vector product. */ + const real_t * x, /**< Input vector to be multiplied. */ + int_t xLD, /**< Leading dimension of input x. */ + real_t beta, /**< Scalar factor for y. */ + real_t * y, /**< Output vector of results. */ + int_t yLD /**< Leading dimension of output y. */ + ) const; + + /** Adds given offset to diagonal of matrix. + * \return SUCCESSFUL_RETURN \n + RET_NO_DIAGONAL_AVAILABLE */ + virtual returnValue addToDiag(real_t alpha /**< Diagonal offset. */ + ); + + /** Create jd field from ir and jc. + * \return Pointer to jd. */ + sparse_int_t * createDiagInfo(); + + /** Allocates and creates dense matrix array in row major format. + * + * Note: Calling function has to free allocated memory! + * + * \return Pointer to matrix array. + */ + virtual real_t * full() const; + + /** Prints matrix to screen. + * \return SUCCESSFUL_RETURN */ + virtual returnValue print(const char * name = 0 /** Name of matrix. */ + ) const; + + /** Write matrix to file. + * \return SUCCESSFUL_RETURN */ + virtual returnValue writeToFile(FILE * output_file, const char * prefix) const; + +protected: + int_t nRows; /**< Number of rows. */ + int_t nCols; /**< Number of columns. */ + sparse_int_t * jr; /**< Indices to first entry of row (nRows+1). */ + sparse_int_t * ic; /**< Column indices (length). */ + sparse_int_t * jd; /**< Indices to first entry of upper triangle (including diagonal) (nRows). */ + real_t * val; /**< Vector of entries (length). */ +}; + +/** + * \brief Interfaces matrix-vector operations tailored to symmetric sparse matrices. + * + * Symmetric sparse matrix class (column compressed format). + * + * \author Andreas Potschka, Christian Kirches, Hans Joachim Ferreau + * \version 3.2 + * \date 2011-2017 + */ +class SymSparseMat +: public SymmetricMatrix +, public SparseMatrix +{ +public: + /** Default constructor. */ + SymSparseMat() : SparseMatrix(){}; + + /** Constructor with arguments. */ + SymSparseMat(int_t nr, /**< Number of rows. */ + int_t nc, /**< Number of columns. */ + sparse_int_t * r, /**< Row indices (length). */ + sparse_int_t * c, /**< Indices to first entry of columns (nCols+1). */ + real_t * v /**< Vector of entries (length). */ + ) + : SparseMatrix(nr, nc, r, c, v){}; + + /** Constructor from dense matrix. */ + SymSparseMat(int_t nr, /**< Number of rows. */ + int_t nc, /**< Number of columns. */ + int_t ld, /**< Leading dimension. */ + const real_t * const v /**< Row major stored matrix elements. */ + ) + : SparseMatrix(nr, nc, ld, v){}; + + /** Destructor. */ + virtual ~SymSparseMat(){}; + + /** Returns a deep-copy of the Matrix object. + * \return Deep-copy of Matrix object */ + virtual Matrix * duplicate() const; + + /** Returns a deep-copy of the SymmetricMatrix object. + * \return Deep-copy of SymmetricMatrix object */ + virtual SymmetricMatrix * duplicateSym() const; + + /** Compute bilinear form y = x'*H*x using submatrix given by index list. + * \return SUCCESSFUL_RETURN */ + virtual returnValue bilinear(const Indexlist * const icols, /**< Index list specifying columns of x. */ + int_t xN, /**< Number of vectors to multiply. */ + const real_t * x, /**< Input vector to be multiplied (uncompressed). */ + int_t xLD, /**< Leading dimension of input x. */ + real_t * y, /**< Output vector of results (compressed). */ + int_t yLD /**< Leading dimension of output y. */ + ) const; +}; + +END_NAMESPACE_QPOASES + +#endif /* QPOASES_MATRICES_HPP */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/MessageHandling.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/MessageHandling.hpp new file mode 100644 index 0000000..ff41be5 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/MessageHandling.hpp @@ -0,0 +1,475 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/MessageHandling.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches (thanks to Leonard Wirsching) + * \version 3.2 + * \date 2007-2017 + * + * Declaration of the MessageHandling class including global return values. + */ + +#ifndef QPOASES_MESSAGEHANDLING_HPP +#define QPOASES_MESSAGEHANDLING_HPP + +#include +#include + +#ifdef __DEBUG__ +#include +#endif + +#include + +BEGIN_NAMESPACE_QPOASES + +/** Default file to display messages. */ +extern FILE * stdFile; + +/** + * \brief Defines all symbols for global return values. + * + * The enumeration returnValueType defines all symbols for global return values. + * Important: All return values are assumed to be nonnegative! + * + * \author Hans Joachim Ferreau + */ +enum returnValue +{ + TERMINAL_LIST_ELEMENT = -1, /**< Terminal list element, internal usage only! */ + /* miscellaneous */ + SUCCESSFUL_RETURN = 0, /**< Successful return. */ + RET_DIV_BY_ZERO, /**< Division by zero. */ + RET_INDEX_OUT_OF_BOUNDS, /**< Index out of bounds. */ + RET_INVALID_ARGUMENTS, /**< At least one of the arguments is invalid. */ + RET_ERROR_UNDEFINED, /**< Error number undefined. */ + RET_WARNING_UNDEFINED, /**< Warning number undefined. */ + RET_INFO_UNDEFINED, /**< Info number undefined. */ + RET_EWI_UNDEFINED, /**< Error/warning/info number undefined. */ + RET_AVAILABLE_WITH_LINUX_ONLY, /**< This function is available under Linux only. */ + RET_UNKNOWN_BUG, /**< The error occurred is not yet known. */ + RET_PRINTLEVEL_CHANGED, /**< Print level changed. (10) */ + RET_NOT_YET_IMPLEMENTED, /**< Requested function is not yet implemented in this version of qpOASES. */ + /* Indexlist */ + RET_INDEXLIST_MUST_BE_REORDERD, /**< Index list has to be reordered. */ + RET_INDEXLIST_EXCEEDS_MAX_LENGTH, /**< Index list exceeds its maximal physical length. */ + RET_INDEXLIST_CORRUPTED, /**< Index list corrupted. */ + RET_INDEXLIST_OUTOFBOUNDS, /**< Physical index is out of bounds. */ + RET_INDEXLIST_ADD_FAILED, /**< Adding indices from another index set failed. */ + RET_INDEXLIST_INTERSECT_FAILED, /**< Intersection with another index set failed. */ + /* SubjectTo / Bounds / Constraints */ + RET_INDEX_ALREADY_OF_DESIRED_STATUS, /**< Index is already of desired status. (18) */ + RET_ADDINDEX_FAILED, /**< Adding index to index set failed. */ + RET_REMOVEINDEX_FAILED, /**< Removing index from index set failed. (20) */ + RET_SWAPINDEX_FAILED, /**< Cannot swap between different indexsets. */ + RET_NOTHING_TO_DO, /**< Nothing to do. */ + RET_SETUP_BOUND_FAILED, /**< Setting up bound index failed. */ + RET_SETUP_CONSTRAINT_FAILED, /**< Setting up constraint index failed. */ + RET_MOVING_BOUND_FAILED, /**< Moving bound between index sets failed. */ + RET_MOVING_CONSTRAINT_FAILED, /**< Moving constraint between index sets failed. */ + RET_SHIFTING_FAILED, /**< Shifting of bounds/constraints failed. */ + RET_ROTATING_FAILED, /**< Rotating of bounds/constraints failed. */ + /* QProblem */ + RET_QPOBJECT_NOT_SETUP, /**< The QP object has not been setup correctly, use another constructor. */ + RET_QP_ALREADY_INITIALISED, /**< QProblem has already been initialised. (30) */ + RET_NO_INIT_WITH_STANDARD_SOLVER, /**< Initialisation via extern QP solver is not yet implemented. */ + RET_RESET_FAILED, /**< Reset failed. */ + RET_INIT_FAILED, /**< Initialisation failed. */ + RET_INIT_FAILED_TQ, /**< Initialisation failed due to TQ factorisation. */ + RET_INIT_FAILED_CHOLESKY, /**< Initialisation failed due to Cholesky decomposition. */ + RET_INIT_FAILED_HOTSTART, /**< Initialisation failed! QP could not be solved! */ + RET_INIT_FAILED_INFEASIBILITY, /**< Initial QP could not be solved due to infeasibility! */ + RET_INIT_FAILED_UNBOUNDEDNESS, /**< Initial QP could not be solved due to unboundedness! */ + RET_INIT_FAILED_REGULARISATION, /**< Initialisation failed as Hessian matrix could not be regularised. */ + RET_INIT_SUCCESSFUL, /**< Initialisation done. (40) */ + RET_OBTAINING_WORKINGSET_FAILED, /**< Failed to obtain working set for auxiliary QP. */ + RET_SETUP_WORKINGSET_FAILED, /**< Failed to setup working set for auxiliary QP. */ + RET_SETUP_AUXILIARYQP_FAILED, /**< Failed to setup auxiliary QP for initialised homotopy. */ + RET_NO_CHOLESKY_WITH_INITIAL_GUESS, /**< Externally computed Cholesky factor cannot be combined with an + initial guess. */ + RET_NO_EXTERN_SOLVER, /**< No extern QP solver available. */ + RET_QP_UNBOUNDED, /**< QP is unbounded. */ + RET_QP_INFEASIBLE, /**< QP is infeasible. */ + RET_QP_NOT_SOLVED, /**< Problems occurred while solving QP with standard solver. */ + RET_QP_SOLVED, /**< QP successfully solved. */ + RET_UNABLE_TO_SOLVE_QP, /**< Problems occurred while solving QP. (50) */ + RET_INITIALISATION_STARTED, /**< Starting problem initialisation... */ + RET_HOTSTART_FAILED, /**< Unable to perform homotopy due to internal error. */ + RET_HOTSTART_FAILED_TO_INIT, /**< Unable to initialise problem. */ + RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED, /**< Unable to perform homotopy as previous QP is not solved. + */ + RET_ITERATION_STARTED, /**< Iteration... */ + RET_SHIFT_DETERMINATION_FAILED, /**< Determination of shift of the QP data failed. */ + RET_STEPDIRECTION_DETERMINATION_FAILED, /**< Determination of step direction failed. */ + RET_STEPLENGTH_DETERMINATION_FAILED, /**< Determination of step direction failed. */ + RET_OPTIMAL_SOLUTION_FOUND, /**< Optimal solution of neighbouring QP found. */ + RET_HOMOTOPY_STEP_FAILED, /**< Unable to perform homotopy step. (60) */ + RET_HOTSTART_STOPPED_INFEASIBILITY, /**< Premature homotopy termination because QP is infeasible. */ + RET_HOTSTART_STOPPED_UNBOUNDEDNESS, /**< Premature homotopy termination because QP is unbounded. */ + RET_WORKINGSET_UPDATE_FAILED, /**< Unable to update working sets according to initial guesses. */ + RET_MAX_NWSR_REACHED, /**< Maximum number of working set recalculations performed. */ + RET_CONSTRAINTS_NOT_SPECIFIED, /**< Problem does comprise constraints! You also have to specify new + constraints' bounds. */ + RET_INVALID_FACTORISATION_FLAG, /**< Invalid factorisation flag. */ + RET_UNABLE_TO_SAVE_QPDATA, /**< Unable to save QP data. */ + RET_STEPDIRECTION_FAILED_TQ, /**< Abnormal termination due to TQ factorisation. */ + RET_STEPDIRECTION_FAILED_CHOLESKY, /**< Abnormal termination due to Cholesky factorisation. */ + RET_CYCLING_DETECTED, /**< Cycling detected. (70) */ + RET_CYCLING_NOT_RESOLVED, /**< Cycling cannot be resolved, QP probably infeasible. */ + RET_CYCLING_RESOLVED, /**< Cycling probably resolved. */ + RET_STEPSIZE, /**< For displaying performed stepsize. */ + RET_STEPSIZE_NONPOSITIVE, /**< For displaying non-positive stepsize. */ + RET_SETUPSUBJECTTOTYPE_FAILED, /**< Setup of SubjectToTypes failed. */ + RET_ADDCONSTRAINT_FAILED, /**< Addition of constraint to working set failed. */ + RET_ADDCONSTRAINT_FAILED_INFEASIBILITY, /**< Addition of constraint to working set failed (due to QP + infeasibility). */ + RET_ADDBOUND_FAILED, /**< Addition of bound to working set failed. */ + RET_ADDBOUND_FAILED_INFEASIBILITY, /**< Addition of bound to working set failed (due to QP infeasibility). + */ + RET_REMOVECONSTRAINT_FAILED, /**< Removal of constraint from working set failed. (80) */ + RET_REMOVEBOUND_FAILED, /**< Removal of bound from working set failed. */ + RET_REMOVE_FROM_ACTIVESET, /**< Removing from active set... */ + RET_ADD_TO_ACTIVESET, /**< Adding to active set... */ + RET_REMOVE_FROM_ACTIVESET_FAILED, /**< Removing from active set failed. */ + RET_ADD_TO_ACTIVESET_FAILED, /**< Adding to active set failed. */ + RET_CONSTRAINT_ALREADY_ACTIVE, /**< Constraint is already active. */ + RET_ALL_CONSTRAINTS_ACTIVE, /**< All constraints are active, no further constraint can be added. */ + RET_LINEARLY_DEPENDENT, /**< New bound/constraint is linearly dependent. */ + RET_LINEARLY_INDEPENDENT, /**< New bound/constraint is linearly independent. */ + RET_LI_RESOLVED, /**< Linear independence of active constraint matrix successfully resolved. (90) */ + RET_ENSURELI_FAILED, /**< Failed to ensure linear independence of active constraint matrix. */ + RET_ENSURELI_FAILED_TQ, /**< Abnormal termination due to TQ factorisation. */ + RET_ENSURELI_FAILED_NOINDEX, /**< QP is infeasible. */ + RET_ENSURELI_FAILED_CYCLING, /**< QP is infeasible. */ + RET_BOUND_ALREADY_ACTIVE, /**< Bound is already active. */ + RET_ALL_BOUNDS_ACTIVE, /**< All bounds are active, no further bound can be added. */ + RET_CONSTRAINT_NOT_ACTIVE, /**< Constraint is not active. */ + RET_BOUND_NOT_ACTIVE, /**< Bound is not active. */ + RET_HESSIAN_NOT_SPD, /**< Projected Hessian matrix not positive definite. */ + RET_HESSIAN_INDEFINITE, /**< Hessian matrix is indefinite. (100) */ + RET_MATRIX_SHIFT_FAILED, /**< Unable to update matrices or to transform vectors. */ + RET_MATRIX_FACTORISATION_FAILED, /**< Unable to calculate new matrix factorisations. */ + RET_PRINT_ITERATION_FAILED, /**< Unable to print information on current iteration. */ + RET_NO_GLOBAL_MESSAGE_OUTPUTFILE, /**< No global message output file initialised. */ + RET_DISABLECONSTRAINTS_FAILED, /**< Unable to disbable constraints. */ + RET_ENABLECONSTRAINTS_FAILED, /**< Unable to enbable constraints. */ + RET_ALREADY_ENABLED, /**< Bound or constraint is already enabled. */ + RET_ALREADY_DISABLED, /**< Bound or constraint is already disabled. */ + RET_NO_HESSIAN_SPECIFIED, /**< No Hessian matrix has been specified. */ + RET_USING_REGULARISATION, /**< Using regularisation as Hessian matrix is not positive definite. (110) */ + RET_EPS_MUST_BE_POSITVE, /**< Eps for regularisation must be sufficiently positive. */ + RET_REGSTEPS_MUST_BE_POSITVE, /**< Maximum number of regularisation steps must be non-negative. */ + RET_HESSIAN_ALREADY_REGULARISED, /**< Hessian has been already regularised. */ + RET_CANNOT_REGULARISE_IDENTITY, /**< Identity Hessian matrix cannot be regularised. */ + RET_CANNOT_REGULARISE_SPARSE, /**< Sparse matrix cannot be regularised as diagonal entry is missing. */ + RET_NO_REGSTEP_NWSR, /**< No additional regularisation step could be performed due to limits. */ + RET_FEWER_REGSTEPS_NWSR, /**< Fewer additional regularisation steps have been performed due to limits. */ + RET_CHOLESKY_OF_ZERO_HESSIAN, /**< Cholesky decomposition of (unregularised) zero Hessian matrix. */ + RET_ZERO_HESSIAN_ASSUMED, /**< Zero Hessian matrix assumed as null pointer passed without specifying + hessianType. */ + RET_CONSTRAINTS_ARE_NOT_SCALED, /**< (no longer in use) (120) */ + RET_INITIAL_BOUNDS_STATUS_NYI, /**< (no longer in use) */ + RET_ERROR_IN_CONSTRAINTPRODUCT, /**< Error in user-defined constraint product function. */ + RET_FIX_BOUNDS_FOR_LP, /**< All initial bounds must be fixed when solving an (unregularised) LP. */ + RET_USE_REGULARISATION_FOR_LP, /**< Set options.enableRegularisation=BT_TRUE for solving LPs. */ + /* SQProblem */ + RET_UPDATEMATRICES_FAILED, /**< Unable to update QP matrices. */ + RET_UPDATEMATRICES_FAILED_AS_QP_NOT_SOLVED, /**< Unable to update matrices as previous QP is not solved. + */ + /* Utils */ + RET_UNABLE_TO_OPEN_FILE, /**< Unable to open file. */ + RET_UNABLE_TO_WRITE_FILE, /**< Unable to write into file. */ + RET_UNABLE_TO_READ_FILE, /**< Unable to read from file. */ + RET_FILEDATA_INCONSISTENT, /**< File contains inconsistent data. (130) */ + /* Options */ + RET_OPTIONS_ADJUSTED, /**< Options needed to be adjusted for consistency reasons. */ + /* SolutionAnalysis */ + RET_UNABLE_TO_ANALYSE_QPROBLEM, /**< Unable to analyse (S)QProblem(B) object. */ + /* Benchmark */ + RET_NWSR_SET_TO_ONE, /**< Maximum number of working set changes was set to 1. */ + RET_UNABLE_TO_READ_BENCHMARK, /**< Unable to read benchmark data. */ + RET_BENCHMARK_ABORTED, /**< Benchmark aborted. */ + RET_INITIAL_QP_SOLVED, /**< Initial QP solved. */ + RET_QP_SOLUTION_STARTED, /**< Solving QP... */ + RET_BENCHMARK_SUCCESSFUL, /**< Benchmark terminated successfully. */ + /* Sparse matrices */ + RET_NO_DIAGONAL_AVAILABLE, /**< Sparse matrix does not have entries on full diagonal. */ + RET_DIAGONAL_NOT_INITIALISED, /**< Diagonal data of sparse matrix has not been initialised. (140) */ + /* Dropping of infeasible constraints */ + RET_ENSURELI_DROPPED, /**< Linear independence resolved by dropping blocking constraint. */ + /* Schur complement computations */ + RET_KKT_MATRIX_SINGULAR, /**< KKT matrix is singular. */ + RET_QR_FACTORISATION_FAILED, /**< QR factorization of Schur complement failed. */ + RET_INERTIA_CORRECTION_FAILED, /**< Inertia correction failed after KKT matrix had too many negative + eigenvalues. */ + RET_NO_SPARSE_SOLVER, /**< No factorization routine for the KKT matrix installed. */ + /* Simple exitflags */ + RET_SIMPLE_STATUS_P1, /**< QP problem could not be solved within given number of iterations. */ + RET_SIMPLE_STATUS_P0, /**< QP problem solved. */ + RET_SIMPLE_STATUS_M1, /**< QP problem could not be solved due to an internal error. */ + RET_SIMPLE_STATUS_M2, /**< QP problem is infeasible (and thus could not be solved). */ + RET_SIMPLE_STATUS_M3 /**< QP problem is unbounded (and thus could not be solved). (150) */ +}; + +/** + * \brief Handles all kind of error messages, warnings and other information. + * + * This class handles all kinds of messages (errors, warnings, infos) initiated + * by qpOASES modules and stores the corresponding global preferences. + * + * \author Hans Joachim Ferreau (thanks to Leonard Wirsching) + * \version 3.2 + * \date 2007-2017 + */ +class MessageHandling +{ + /* + * INTERNAL DATA STRUCTURES + */ +public: + /** + * \brief Data structure for entries in global message list. + * + * Data structure for entries in global message list. + * + * \author Hans Joachim Ferreau + */ + typedef struct + { + returnValue key; /**< Global return value. */ + const char * data; /**< Corresponding message. */ + VisibilityStatus + globalVisibilityStatus; /**< Determines if message can be printed. + * If this value is set to VS_HIDDEN, no message is printed! */ + } ReturnValueList; + + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + MessageHandling(); + + /** Constructor which takes the desired output file. */ + MessageHandling(FILE * _outputFile /**< Output file. */ + ); + + /** Constructor which takes the desired visibility states. */ + MessageHandling(VisibilityStatus _errorVisibility, /**< Visibility status for error messages. */ + VisibilityStatus _warningVisibility, /**< Visibility status for warning messages. */ + VisibilityStatus _infoVisibility /**< Visibility status for info messages. */ + ); + + /** Constructor which takes the desired output file and desired visibility states. */ + MessageHandling(FILE * _outputFile, /**< Output file. */ + VisibilityStatus _errorVisibility, /**< Visibility status for error messages. */ + VisibilityStatus _warningVisibility, /**< Visibility status for warning messages. */ + VisibilityStatus _infoVisibility /**< Visibility status for info messages. */ + ); + + /** Copy constructor (deep copy). */ + MessageHandling(const MessageHandling & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + ~MessageHandling(); + + /** Assignment operator (deep copy). */ + MessageHandling & operator=(const MessageHandling & rhs /**< Rhs object. */ + ); + + /** Prints an error message(a simplified macro THROWERROR is also provided). \n + * Errors are defined as abnormal events which cause an immediate termination of the current (sub) + * function. Errors of a sub function should be commented by the calling function by means of a warning + * message (if this error does not cause an error of the calling function, either)! \return Error number + * returned by sub function call + */ + returnValue throwError(returnValue Enumber, /**< Error number returned by sub function call. */ + const char * additionaltext, /**< Additional error text (0, if none). */ + const char * functionname, /**< Name of function which caused the error. */ + const char * filename, /**< Name of file which caused the error. */ + const unsigned long linenumber, /**< Number of line which caused the error.incompatible binary file */ + VisibilityStatus localVisibilityStatus /**< Determines (locally) if error message can be printed to + * stdFile. If GLOBAL visibility status of the message is set to + * VS_HIDDEN, no message is printed, anyway! */ + ); + + /** Prints a warning message (a simplified macro THROWWARNING is also provided). + * Warnings are definied as abnormal events which does NOT cause an immediate termination of the current + * (sub) function. \return Warning number returned by sub function call + */ + returnValue throwWarning(returnValue Wnumber, /**< Warning number returned by sub function call. */ + const char * additionaltext, /**< Additional warning text (0, if none). */ + const char * functionname, /**< Name of function which caused the warning. */ + const char * filename, /**< Name of file which caused the warning. */ + const unsigned long linenumber, /**< Number of line which caused the warning. */ + VisibilityStatus localVisibilityStatus /**< Determines (locally) if warning message can be printed to + * stdFile. If GLOBAL visibility status of the message is set to + * VS_HIDDEN, no message is printed, anyway! */ + ); + + /** Prints a info message (a simplified macro THROWINFO is also provided). + * \return Info number returned by sub function call + */ + returnValue throwInfo(returnValue Inumber, /**< Info number returned by sub function call. */ + const char * additionaltext, /**< Additional warning text (0, if none). */ + const char * functionname, /**< Name of function which submitted the info. */ + const char * filename, /**< Name of file which submitted the info. */ + const unsigned long linenumber, /**< Number of line which submitted the info. */ + VisibilityStatus localVisibilityStatus /**< Determines (locally) if info message can be printed to + * stdFile. If GLOBAL visibility status of the message is set to + * VS_HIDDEN, no message is printed, anyway! */ + ); + + /** Resets all preferences to default values. + * \return SUCCESSFUL_RETURN */ + returnValue reset(); + + /** Prints a complete list of all messages to output file. + * \return SUCCESSFUL_RETURN */ + returnValue listAllMessages(); + + /** Returns visibility status for error messages. + * \return Visibility status for error messages. */ + inline VisibilityStatus getErrorVisibilityStatus() const; + + /** Returns visibility status for warning messages. + * \return Visibility status for warning messages. */ + inline VisibilityStatus getWarningVisibilityStatus() const; + + /** Returns visibility status for info messages. + * \return Visibility status for info messages. */ + inline VisibilityStatus getInfoVisibilityStatus() const; + + /** Returns pointer to output file. + * \return Pointer to output file. */ + inline FILE * getOutputFile() const; + + /** Returns error count value. + * \return Error count value. */ + inline int_t getErrorCount() const; + + /** Changes visibility status for error messages. */ + inline void setErrorVisibilityStatus( + VisibilityStatus _errorVisibility /**< New visibility status for error messages. */ + ); + + /** Changes visibility status for warning messages. */ + inline void setWarningVisibilityStatus( + VisibilityStatus _warningVisibility /**< New visibility status for warning messages. */ + ); + + /** Changes visibility status for info messages. */ + inline void setInfoVisibilityStatus( + VisibilityStatus _infoVisibility /**< New visibility status for info messages. */ + ); + + /** Changes output file for messages. */ + inline void setOutputFile(FILE * _outputFile /**< New output file for messages. */ + ); + + /** Changes error count. + * \return SUCCESSFUL_RETURN \n + * RET_INVALID_ARGUMENT */ + inline returnValue setErrorCount(int_t _errorCount /**< New error count value. */ + ); + + /** Provides message text corresponding to given \a returnValue. + * \return String containing message text. */ + static const char * getErrorCodeMessage(const returnValue _returnValue); + + /* + * PROTECTED MEMBER FUNCTIONS + */ +protected: + /** Prints a info message to stdFile (auxiliary function). + * \return Error/warning/info number returned by sub function call + */ + returnValue throwMessage( + returnValue RETnumber, /**< Error/warning/info number returned by sub function call. */ + const char * additionaltext, /**< Additional warning text (0, if none). */ + const char * functionname, /**< Name of function which caused the error/warning/info. */ + const char * filename, /**< Name of file which caused the error/warning/info. */ + const unsigned long linenumber, /**< Number of line which caused the error/warning/info. */ + VisibilityStatus localVisibilityStatus, /**< Determines (locally) if info message can be printed to + * stdFile. If GLOBAL visibility status of the message is set to + * VS_HIDDEN, no message is printed, anyway! */ + const char * RETstring /**< Leading string of error/warning/info message. */ + ); + + /* + * PROTECTED MEMBER VARIABLES + */ +protected: + VisibilityStatus errorVisibility; /**< Error messages visible? */ + VisibilityStatus warningVisibility; /**< Warning messages visible? */ + VisibilityStatus infoVisibility; /**< Info messages visible? */ + + FILE * outputFile; /**< Output file for messages. */ + + int_t errorCount; /**< Counts number of errors (for nicer output only). */ +}; + +#ifndef __FILE__ +/** Ensures that __FILE__ macro is defined. */ +#define __FILE__ 0 +#endif + +#ifndef __LINE__ +/** Ensures that __LINE__ macro is defined. */ +#define __LINE__ 0 +#endif + +/** Define __FUNC__ macro providing current function for debugging. */ +/*#define __FUNC__ 0*/ +#define __FUNC__ ("(no function name provided)") +/*#define __FUNC__ __func__*/ +/*#define __FUNC__ __FUNCTION__*/ + +/** Short version of throwError with default values, only returnValue is needed */ +#define THROWERROR(retval) \ +(getGlobalMessageHandler()->throwError((retval), 0, __FUNC__, __FILE__, __LINE__, VS_VISIBLE)) + +/** Short version of throwWarning with default values, only returnValue is needed */ +#define THROWWARNING(retval) \ +(getGlobalMessageHandler()->throwWarning((retval), 0, __FUNC__, __FILE__, __LINE__, VS_VISIBLE)) + +/** Short version of throwInfo with default values, only returnValue is needed */ +#define THROWINFO(retval) \ +(getGlobalMessageHandler()->throwInfo((retval), 0, __FUNC__, __FILE__, __LINE__, VS_VISIBLE)) + +/** Returns a pointer to global message handler. + * \return Pointer to global message handler. + */ +MessageHandling * getGlobalMessageHandler(); + +END_NAMESPACE_QPOASES + +#include + +#endif /* QPOASES_MESSAGEHANDLING_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/MessageHandling.ipp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/MessageHandling.ipp new file mode 100755 index 0000000..7ddb936 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/MessageHandling.ipp @@ -0,0 +1,144 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file include/qpOASES/MessageHandling.ipp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of inlined member functions of the MessageHandling class. + */ + + +BEGIN_NAMESPACE_QPOASES + + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + + +/* + * g e t E r r o r V i s i b i l i t y S t a t u s + */ +inline VisibilityStatus MessageHandling::getErrorVisibilityStatus( ) const +{ + return errorVisibility; +} + + +/* + * g e t W a r n i n g V i s i b i l i t y S t a t u s + */ +inline VisibilityStatus MessageHandling::getWarningVisibilityStatus( ) const +{ + return warningVisibility; +} + + +/* + * g e t I n f o V i s i b i l i t y S t a t u s + */ +inline VisibilityStatus MessageHandling::getInfoVisibilityStatus( ) const +{ + return infoVisibility; +} + + +/* + * g e t O u t p u t F i l e + */ +inline FILE* MessageHandling::getOutputFile( ) const +{ + return outputFile; +} + + +/* + * g e t E r r o r C o u n t + */ +inline int_t MessageHandling::getErrorCount( ) const +{ + return errorCount; +} + + +/* + * s e t E r r o r V i s i b i l i t y S t a t u s + */ +inline void MessageHandling::setErrorVisibilityStatus( VisibilityStatus _errorVisibility ) +{ + errorVisibility = _errorVisibility; +} + + +/* + * s e t W a r n i n g V i s i b i l i t y S t a t u s + */ +inline void MessageHandling::setWarningVisibilityStatus( VisibilityStatus _warningVisibility ) +{ + warningVisibility = _warningVisibility; +} + + +/* + * s e t I n f o V i s i b i l i t y S t a t u s + */ +inline void MessageHandling::setInfoVisibilityStatus( VisibilityStatus _infoVisibility ) +{ + infoVisibility = _infoVisibility; +} + + +/* + * s e t O u t p u t F i l e + */ +inline void MessageHandling::setOutputFile( FILE* _outputFile ) +{ + outputFile = _outputFile; +} + + +/* + * s e t E r r o r C o u n t + */ +inline returnValue MessageHandling::setErrorCount( int_t _errorCount ) +{ + if ( _errorCount >= -1 ) + { + errorCount = _errorCount; + return SUCCESSFUL_RETURN; + } + else + return RET_INVALID_ARGUMENTS; +} + + +END_NAMESPACE_QPOASES + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Options.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Options.hpp new file mode 100644 index 0000000..bf1a61b --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Options.hpp @@ -0,0 +1,166 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/Options.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Declaration of the Options class designed to manage user-specified + * options for solving a QProblem. + */ + +#ifndef QPOASES_OPTIONS_HPP +#define QPOASES_OPTIONS_HPP + +#include + +BEGIN_NAMESPACE_QPOASES + +/** + * \brief Manages all user-specified options for solving QPs. + * + * This class manages all user-specified options used for solving + * quadratic programs. + * + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + */ +class Options +{ + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + Options(); + + /** Copy constructor (deep copy). */ + Options(const Options & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + ~Options(); + + /** Assignment operator (deep copy). */ + Options & operator=(const Options & rhs /**< Rhs object. */ + ); + + /** Sets all options to default values. + * \return SUCCESSFUL_RETURN */ + returnValue setToDefault(); + + /** Sets all options to values resulting in maximum reliabilty. + * \return SUCCESSFUL_RETURN */ + returnValue setToReliable(); + + /** Sets all options to values resulting in minimum solution time. + * \return SUCCESSFUL_RETURN */ + returnValue setToMPC(); + + /** Same as setToMPC( ), for ensuring backwards compatibility. + * \return SUCCESSFUL_RETURN */ + returnValue setToFast(); + + /** Ensures that all options have consistent values by automatically + * adjusting inconsistent ones. + * Note: This routine cannot (and does not try to) ensure that values + * are set to reasonable values that make the QP solution work! + * \return SUCCESSFUL_RETURN \n + * RET_OPTIONS_ADJUSTED */ + returnValue ensureConsistency(); + + /** Prints values of all options. + * \return SUCCESSFUL_RETURN */ + returnValue print() const; + + /* + * PROTECTED MEMBER FUNCTIONS + */ +protected: + /** Copies all members from given rhs object. + * \return SUCCESSFUL_RETURN */ + returnValue copy(const Options & rhs /**< Rhs object. */ + ); + + /* + * PUBLIC MEMBER VARIABLES + */ +public: + PrintLevel printLevel; /**< Print level. */ + + BooleanType enableRamping; /**< Specifies whether ramping shall be enabled or not. */ + BooleanType enableFarBounds; /**< Specifies whether far bounds shall be used or not. */ + BooleanType enableFlippingBounds; /**< Specifies whether flipping bounds shall be used or not. */ + BooleanType enableRegularisation; /**< Specifies whether Hessian matrix shall be regularised in case + semi-definiteness is detected. */ + BooleanType enableFullLITests; /**< Specifies whether condition-hardened LI test shall be used or not. */ + BooleanType enableNZCTests; /**< Specifies whether nonzero curvature tests shall be used. */ + int_t enableDriftCorrection; /**< Specifies the frequency of drift corrections (0 = off). */ + int_t enableCholeskyRefactorisation; /**< Specifies the frequency of full refactorisation of proj. Hessian + (otherwise updates). */ + BooleanType + enableEqualities; /**< Specifies whether equalities shall be always treated as active constraints. */ + + real_t terminationTolerance; /**< Termination tolerance. */ + real_t boundTolerance; /**< Lower/upper (constraints') bound tolerance (an inequality constraint whose + lower and upper bounds differ by less is regarded to be an equality constraint). */ + real_t boundRelaxation; /**< Offset for relaxing (constraints') bounds at beginning of an initial + homotopy. It is also as initial value for far bounds. */ + real_t epsNum; /**< Numerator tolerance for ratio tests. */ + real_t epsDen; /**< Denominator tolerance for ratio tests. */ + real_t maxPrimalJump; /**< Maximum allowed jump in primal variables in nonzero curvature tests. */ + real_t maxDualJump; /**< Maximum allowed jump in dual variables in linear independence tests. */ + + real_t initialRamping; /**< Start value for Ramping Strategy. */ + real_t finalRamping; /**< Final value for Ramping Strategy. */ + real_t initialFarBounds; /**< Initial size of Far Bounds. */ + real_t growFarBounds; /**< Factor to grow Far Bounds. */ + SubjectToStatus initialStatusBounds; /**< Initial status of bounds at first iteration. */ + real_t epsFlipping; /**< Tolerance of squared Cholesky diagonal factor which triggers flipping bound. */ + int_t numRegularisationSteps; /**< Maximum number of successive regularisation steps. */ + real_t epsRegularisation; /**< Scaling factor of identity matrix used for Hessian regularisation. */ + int_t numRefinementSteps; /**< Maximum number of iterative refinement steps. */ + real_t epsIterRef; /**< Early termination tolerance for iterative refinement. */ + real_t epsLITests; /**< Tolerance for linear independence tests. */ + real_t epsNZCTests; /**< Tolerance for nonzero curvature tests. */ + + real_t rcondSMin; /**< Minimum reciprocal condition number of S before refactorization is triggered */ + BooleanType enableInertiaCorrection; /**< Specifies whether the working set should be repaired when + negative curvature is discovered during hotstart. */ + + BooleanType enableDropInfeasibles; /**< ... */ + int_t dropBoundPriority; /**< ... */ + int_t dropEqConPriority; /**< ... */ + int_t dropIneqConPriority; /**< ... */ +}; + +END_NAMESPACE_QPOASES + +#endif /* QPOASES_OPTIONS_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/QProblem.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/QProblem.hpp new file mode 100644 index 0000000..0935b31 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/QProblem.hpp @@ -0,0 +1,1080 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/QProblem.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Declaration of the QProblem class which is able to use the newly + * developed online active set strategy for parametric quadratic programming. + */ + +#ifndef QPOASES_QPROBLEM_HPP +#define QPOASES_QPROBLEM_HPP + +#include +#include +#include +#include + +BEGIN_NAMESPACE_QPOASES + +/** + * \brief Implements the online active set strategy for QPs with general constraints. + * + * A class for setting up and solving quadratic programs. The main feature is + * the possibily to use the newly developed online active set strategy for + * parametric quadratic programming. + * + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + */ +class QProblem : public QProblemB +{ + /* allow SolutionAnalysis class to access private members */ + friend class SolutionAnalysis; + + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + QProblem(); + + /** Constructor which takes the QP dimension and Hessian type + * information. If the Hessian is the zero (i.e. HST_ZERO) or the + * identity matrix (i.e. HST_IDENTITY), respectively, no memory + * is allocated for it and a NULL pointer can be passed for it + * to the init() functions. */ + QProblem(int_t _nV, /**< Number of variables. */ + int_t _nC, /**< Number of constraints. */ + HessianType _hessianType = HST_UNKNOWN, /**< Type of Hessian matrix. */ + BooleanType allocDenseMats = BT_TRUE /**< Enable allocation of dense matrices. */ + ); + + /** Copy constructor (deep copy). */ + QProblem(const QProblem & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + virtual ~QProblem(); + + /** Assignment operator (deep copy). */ + virtual QProblem & operator=(const QProblem & rhs /**< Rhs object. */ + ); + + /** Clears all data structures of QProblemB except for QP data. + * \return SUCCESSFUL_RETURN \n + RET_RESET_FAILED */ + virtual returnValue reset(); + + /** Initialises a QP problem with given QP data and tries to solve it + * using at most nWSR iterations. Depending on the parameter constellation it: \n + * 1. 0, 0, 0 : starts with xOpt = 0, yOpt = 0 and gB/gC empty (or all implicit equality bounds), + \n * 2. xOpt, 0, 0 : starts with xOpt, yOpt = 0 and obtain gB/gC by "clipping", \n * 3. 0, yOpt, 0 + : starts with xOpt = 0, yOpt and obtain gB/gC from yOpt != 0, \n * 4. 0, 0, gB/gC: starts with xOpt + = 0, yOpt = 0 and gB/gC, \n * 5. xOpt, yOpt, 0 : starts with xOpt, yOpt and obtain gB/gC from yOpt != + 0, \n * 6. xOpt, 0, gB/gC: starts with xOpt, yOpt = 0 and gB/gC, \n * 7. xOpt, yOpt, gB/gC: starts + with xOpt, yOpt and gB/gC (assume them to be consistent!) + * + * Note: This function internally calls solveInitialQP for initialisation! + * + * \return SUCCESSFUL_RETURN \n + RET_INIT_FAILED \n + RET_INIT_FAILED_CHOLESKY \n + RET_INIT_FAILED_TQ \n + RET_INIT_FAILED_HOTSTART \n + RET_INIT_FAILED_INFEASIBILITY \n + RET_INIT_FAILED_UNBOUNDEDNESS \n + RET_MAX_NWSR_REACHED \n + RET_INVALID_ARGUMENTS */ + returnValue init(SymmetricMatrix * _H, /**< Hessian matrix (a shallow copy is made). */ + const real_t * const _g, /**< Gradient vector. */ + Matrix * _A, /**< Constraint matrix (a shallow copy is made). */ + const real_t * const _lb, /**< Lower bound vector (on variables). \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const _ub, /**< Upper bound vector (on variables). \n + If no upper bounds exist, a NULL pointer can be passed. */ + const real_t * const _lbA, /**< Lower constraints' bound vector. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const real_t * const _ubA, /**< Upper constraints' bound vector. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations when using initial homotopy. + Output: Number of performed working set recalculations. */ + real_t * const cputime = 0, /**< Input: Maximum CPU time allowed for QP initialisation. \n + Output: CPU time spent for QP initialisation (if pointer passed). */ + const real_t * const xOpt = 0, /**< Optimal primal solution vector. \n + (If a null pointer is passed, the old primal solution is kept!) */ + const real_t * const yOpt = 0, /**< Optimal dual solution vector. \n + (If a null pointer is passed, the old dual solution is kept!) */ + const Bounds * const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n + (If a null pointer is passed, all bounds are assumed inactive!) */ + const Constraints * const guessedConstraints = + 0, /**< Optimal working set of constraints for solution (xOpt,yOpt). \n + (If a null pointer is passed, all constraints are assumed inactive!) */ + const real_t * const _R = 0 /**< Pre-computed (upper triangular) Cholesky factor of Hessian matrix. + The Cholesky factor must be stored in a real_t array of size nV*nV + in row-major format. Note: Only used if xOpt/yOpt and gB are NULL! \n + (If a null pointer is passed, Cholesky decomposition is computed internally!) */ + ); + + /** Initialises a QP problem with given QP data and tries to solve it + * using at most nWSR iterations. Depending on the parameter constellation it: \n + * 1. 0, 0, 0 : starts with xOpt = 0, yOpt = 0 and gB/gC empty (or all implicit equality bounds), + \n * 2. xOpt, 0, 0 : starts with xOpt, yOpt = 0 and obtain gB/gC by "clipping", \n * 3. 0, yOpt, 0 + : starts with xOpt = 0, yOpt and obtain gB/gC from yOpt != 0, \n * 4. 0, 0, gB/gC: starts with xOpt + = 0, yOpt = 0 and gB/gC, \n * 5. xOpt, yOpt, 0 : starts with xOpt, yOpt and obtain gB/gC from yOpt != + 0, \n * 6. xOpt, 0, gB/gC: starts with xOpt, yOpt = 0 and gB/gC, \n * 7. xOpt, yOpt, gB/gC: starts + with xOpt, yOpt and gB/gC (assume them to be consistent!) + * + * Note: This function internally calls solveInitialQP for initialisation! + * + * \return SUCCESSFUL_RETURN \n + RET_INIT_FAILED \n + RET_INIT_FAILED_CHOLESKY \n + RET_INIT_FAILED_TQ \n + RET_INIT_FAILED_HOTSTART \n + RET_INIT_FAILED_INFEASIBILITY \n + RET_INIT_FAILED_UNBOUNDEDNESS \n + RET_MAX_NWSR_REACHED \n + RET_INVALID_ARGUMENTS */ + returnValue init(const real_t * const _H, /**< Hessian matrix (a shallow copy is made). \n + If Hessian matrix is trivial, a NULL pointer can be passed. */ + const real_t * const _g, /**< Gradient vector. */ + const real_t * const _A, /**< Constraint matrix (a shallow copy is made). */ + const real_t * const _lb, /**< Lower bound vector (on variables). \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const _ub, /**< Upper bound vector (on variables). \n + If no upper bounds exist, a NULL pointer can be passed. */ + const real_t * const _lbA, /**< Lower constraints' bound vector. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const real_t * const _ubA, /**< Upper constraints' bound vector. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations when using initial homotopy. + Output: Number of performed working set recalculations. */ + real_t * const cputime = 0, /**< Input: Maximum CPU time allowed for QP initialisation. \n + Output: CPU time spent for QP initialisation (if pointer passed). */ + const real_t * const xOpt = 0, /**< Optimal primal solution vector. \n + (If a null pointer is passed, the old primal solution is kept!) */ + const real_t * const yOpt = 0, /**< Optimal dual solution vector. \n + (If a null pointer is passed, the old dual solution is kept!) */ + const Bounds * const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n + (If a null pointer is passed, all bounds are assumed inactive!) */ + const Constraints * const guessedConstraints = + 0, /**< Optimal working set of constraints for solution (xOpt,yOpt). \n + (If a null pointer is passed, all constraints are assumed inactive!) */ + const real_t * const _R = 0 /**< Pre-computed (upper triangular) Cholesky factor of Hessian matrix. + The Cholesky factor must be stored in a real_t array of size nV*nV + in row-major format. Note: Only used if xOpt/yOpt and gB are NULL! \n + (If a null pointer is passed, Cholesky decomposition is computed internally!) */ + ); + + /** Initialises a QP problem with given data to be read from files and solves it + * using at most nWSR iterations. Depending on the parameter constellation it: \n + * 1. 0, 0, 0 : starts with xOpt = 0, yOpt = 0 and gB/gC empty (or all implicit equality bounds), + \n * 2. xOpt, 0, 0 : starts with xOpt, yOpt = 0 and obtain gB/gC by "clipping", \n * 3. 0, yOpt, 0 + : starts with xOpt = 0, yOpt and obtain gB/gC from yOpt != 0, \n * 4. 0, 0, gB/gC: starts with xOpt + = 0, yOpt = 0 and gB/gC, \n * 5. xOpt, yOpt, 0 : starts with xOpt, yOpt and obtain gB/gC from yOpt != + 0, \n * 6. xOpt, 0, gB/gC: starts with xOpt, yOpt = 0 and gB/gC, \n * 7. xOpt, yOpt, gB/gC: starts + with xOpt, yOpt and gB/gC (assume them to be consistent!) + * + * Note: This function internally calls solveInitialQP for initialisation! + * + * \return SUCCESSFUL_RETURN \n + RET_INIT_FAILED \n + RET_INIT_FAILED_CHOLESKY \n + RET_INIT_FAILED_TQ \n + RET_INIT_FAILED_HOTSTART \n + RET_INIT_FAILED_INFEASIBILITY \n + RET_INIT_FAILED_UNBOUNDEDNESS \n + RET_MAX_NWSR_REACHED \n + RET_UNABLE_TO_READ_FILE \n + RET_INVALID_ARGUMENTS */ + returnValue init(const char * const H_file, /**< Name of file where Hessian matrix is stored. \n + If Hessian matrix is trivial, a NULL pointer can be passed. */ + const char * const g_file, /**< Name of file where gradient vector is stored. */ + const char * const A_file, /**< Name of file where constraint matrix is stored. */ + const char * const lb_file, /**< Name of file where lower bound vector. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const char * const ub_file, /**< Name of file where upper bound vector. \n + If no upper bounds exist, a NULL pointer can be passed. */ + const char * const lbA_file, /**< Name of file where lower constraints' bound vector. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const char * const ubA_file, /**< Name of file where upper constraints' bound vector. \n + If no upper constraints' bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations when using initial homotopy. + Output: Number of performed working set recalculations. */ + real_t * const cputime = 0, /**< Input: Maximum CPU time allowed for QP initialisation. \n + Output: CPU time spent for QP initialisation (if pointer passed). */ + const real_t * const xOpt = 0, /**< Optimal primal solution vector. \n + (If a null pointer is passed, the old primal solution is kept!) */ + const real_t * const yOpt = 0, /**< Optimal dual solution vector. \n + (If a null pointer is passed, the old dual solution is kept!) */ + const Bounds * const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n + (If a null pointer is passed, all bounds are assumed inactive!) */ + const Constraints * const guessedConstraints = + 0, /**< Optimal working set of constraints for solution (xOpt,yOpt). \n +(If a null pointer is passed, all constraints are assumed inactive!) */ + const char * const R_file = + 0 /**< Name of the file where a pre-computed (upper triangular) Cholesky factor +of the Hessian matrix is stored. \n +(If a null pointer is passed, Cholesky decomposition is computed internally!) */ + ); + + /** Solves an initialised QP sequence using the online active set strategy. + * By default, QP solution is started from previous solution. If a guess + * for the working set is provided, an initialised homotopy is performed. + * + * Note: This function internally calls solveQP/solveRegularisedQP + * for solving an initialised QP! + * + * \return SUCCESSFUL_RETURN \n + RET_MAX_NWSR_REACHED \n + RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n + RET_HOTSTART_FAILED \n + RET_SHIFT_DETERMINATION_FAILED \n + RET_STEPDIRECTION_DETERMINATION_FAILED \n + RET_STEPLENGTH_DETERMINATION_FAILED \n + RET_HOMOTOPY_STEP_FAILED \n + RET_HOTSTART_STOPPED_INFEASIBILITY \n + RET_HOTSTART_STOPPED_UNBOUNDEDNESS */ + returnValue hotstart(const real_t * const g_new, /**< Gradient of neighbouring QP to be solved. */ + const real_t * const lb_new, /**< Lower bounds of neighbouring QP to be solved. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const ub_new, /**< Upper bounds of neighbouring QP to be solved. \n + If no upper bounds exist, a NULL pointer can be passed. */ + const real_t * const lbA_new, /**< Lower constraints' bounds of neighbouring QP to be solved. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const real_t * const ubA_new, /**< Upper constraints' bounds of neighbouring QP to be solved. \n + If no upper constraints' bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Number of performed working set recalculations. */ + real_t * const cputime = 0, /**< Input: Maximum CPU time allowed for QP solution. \n + Output: CPU time spent for QP solution (or to perform nWSR iterations). */ + const Bounds * const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n + (If a null pointer is passed, the previous working set of bounds is kept!) */ + const Constraints * const guessedConstraints = + 0 /**< Optimal working set of constraints for solution (xOpt,yOpt). \n +(If a null pointer is passed, the previous working set of constraints is kept!) */ + ); + + /** Solves an initialised QP sequence using the online active set strategy, + * where QP data is read from files. + * By default, QP solution is started from previous solution. If a guess + * for the working set is provided, an initialised homotopy is performed. + * + * Note: This function internally calls solveQP/solveRegularisedQP + * for solving an initialised QP! + * + * \return SUCCESSFUL_RETURN \n + RET_MAX_NWSR_REACHED \n + RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n + RET_HOTSTART_FAILED \n + RET_SHIFT_DETERMINATION_FAILED \n + RET_STEPDIRECTION_DETERMINATION_FAILED \n + RET_STEPLENGTH_DETERMINATION_FAILED \n + RET_HOMOTOPY_STEP_FAILED \n + RET_HOTSTART_STOPPED_INFEASIBILITY \n + RET_HOTSTART_STOPPED_UNBOUNDEDNESS \n + RET_UNABLE_TO_READ_FILE \n + RET_INVALID_ARGUMENTS */ + returnValue hotstart( + const char * const + g_file, /**< Name of file where gradient, of neighbouring QP to be solved, is stored. */ + const char * const lb_file, /**< Name of file where lower bounds, of neighbouring QP to be solved, is + stored. \n If no lower bounds exist, a NULL pointer can be passed. */ + const char * const ub_file, /**< Name of file where upper bounds, of neighbouring QP to be solved, is + stored. \n If no upper bounds exist, a NULL pointer can be passed. */ + const char * const + lbA_file, /**< Name of file where lower constraints' bounds, of neighbouring QP to be solved, is + stored. \n If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const char * const + ubA_file, /**< Name of file where upper constraints' bounds, of neighbouring QP to be solved, is + stored. \n If no upper constraints' bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Number of performed working set recalculations. */ + real_t * const cputime = 0, /**< Input: Maximum CPU time allowed for QP solution. \n + Output: CPU time spent for QP solution (or to perform nWSR iterations). */ + const Bounds * const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n + (If a null pointer is passed, the previous working set of bounds is kept!) */ + const Constraints * const guessedConstraints = + 0 /**< Optimal working set of constraints for solution (xOpt,yOpt). \n +(If a null pointer is passed, the previous working set of constraints is kept!) */ + ); + + /** Solves an equality-constrained QP problem resulting from the current working set. + * \return SUCCESSFUL_RETURN \n + * RET_STEPDIRECTION_FAILED_TQ \n + * RET_STEPDIRECTION_FAILED_CHOLESKY \n + * RET_INVALID_ARGUMENTS */ + returnValue solveCurrentEQP(const int_t n_rhs, /**< Number of consecutive right hand sides */ + const real_t * g_in, /**< Gradient of neighbouring QP to be solved. */ + const real_t * lb_in, /**< Lower bounds of neighbouring QP to be solved. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * ub_in, /**< Upper bounds of neighbouring QP to be solved. \n + If no upper bounds exist, a NULL pointer can be passed. */ + const real_t * lbA_in, /**< Lower constraints' bounds of neighbouring QP to be solved. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const real_t * ubA_in, /**< Upper constraints' bounds of neighbouring QP to be solved. \n */ + real_t * x_out, /**< Output: Primal solution */ + real_t * y_out /**< Output: Dual solution */ + ); + + /** Writes a vector with the state of the working set + * \return SUCCESSFUL_RETURN \n + * RET_INVALID_ARGUMENTS */ + virtual returnValue getWorkingSet( + real_t * workingSet /** Output: array containing state of the working set. */ + ); + + /** Writes a vector with the state of the working set of bounds + * \return SUCCESSFUL_RETURN \n + * RET_INVALID_ARGUMENTS */ + virtual returnValue getWorkingSetBounds( + real_t * workingSetB /** Output: array containing state of the working set of bounds. */ + ); + + /** Writes a vector with the state of the working set of constraints + * \return SUCCESSFUL_RETURN \n + * RET_INVALID_ARGUMENTS */ + virtual returnValue getWorkingSetConstraints( + real_t * workingSetC /** Output: array containing state of the working set of constraints. */ + ); + + /** Returns current constraints object of the QP (deep copy). + * \return SUCCESSFUL_RETURN \n + RET_QPOBJECT_NOT_SETUP */ + inline returnValue getConstraints(Constraints & _constraints /** Output: Constraints object. */ + ) const; + + /** Returns the number of constraints. + * \return Number of constraints. */ + inline int_t getNC() const; + + /** Returns the number of (implicitly defined) equality constraints. + * \return Number of (implicitly defined) equality constraints. */ + inline int_t getNEC() const; + + /** Returns the number of active constraints. + * \return Number of active constraints. */ + inline int_t getNAC() const; + + /** Returns the number of inactive constraints. + * \return Number of inactive constraints. */ + inline int_t getNIAC() const; + + /** Returns the dimension of null space. + * \return Dimension of null space. */ + virtual int_t getNZ() const; + + /** Returns the dual solution vector (deep copy). + * \return SUCCESSFUL_RETURN \n + RET_QP_NOT_SOLVED */ + virtual returnValue getDualSolution( + real_t * const yOpt /**< Output: Dual solution vector (if QP has been solved). */ + ) const; + + /** Defines user-defined routine for calculating the constraint product A*x + * \return SUCCESSFUL_RETURN \n */ + returnValue setConstraintProduct(ConstraintProduct * const _constraintProduct); + + /** Prints concise list of properties of the current QP. + * \return SUCCESSFUL_RETURN \n */ + virtual returnValue printProperties(); + + /** Set the incoming array to true for each variable entry that is + in the set of free variables */ + returnValue getFreeVariablesFlags(BooleanType * varIsFree); + + /* + * PROTECTED MEMBER FUNCTIONS + */ +protected: + /** Frees all allocated memory. + * \return SUCCESSFUL_RETURN */ + returnValue clear(); + + /** Copies all members from given rhs object. + * \return SUCCESSFUL_RETURN */ + returnValue copy(const QProblem & rhs /**< Rhs object. */ + ); + + /** Solves a QProblem whose QP data is assumed to be stored in the member variables. + * A guess for its primal/dual optimal solution vectors and the corresponding + * working sets of bounds and constraints can be provided. + * Note: This function is internally called by all init functions! + * \return SUCCESSFUL_RETURN \n + RET_INIT_FAILED \n + RET_INIT_FAILED_CHOLESKY \n + RET_INIT_FAILED_TQ \n + RET_INIT_FAILED_HOTSTART \n + RET_INIT_FAILED_INFEASIBILITY \n + RET_INIT_FAILED_UNBOUNDEDNESS \n + RET_MAX_NWSR_REACHED */ + returnValue solveInitialQP(const real_t * const xOpt, /**< Optimal primal solution vector.*/ + const real_t * const yOpt, /**< Optimal dual solution vector. */ + const Bounds * const guessedBounds, /**< Optimal working set of bounds for solution (xOpt,yOpt). */ + const Constraints * const + guessedConstraints, /**< Optimal working set of constraints for solution (xOpt,yOpt). */ + const real_t * const _R, /**< Pre-computed (upper triangular) Cholesky factor of Hessian matrix. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Number of performed working set recalculations. */ + real_t * const cputime /**< Input: Maximum CPU time allowed for QP solution. \n + Output: CPU time spent for QP solution (or to perform nWSR iterations). */ + ); + + /** Solves QProblem using online active set strategy. + * Note: This function is internally called by all hotstart functions! + * \return SUCCESSFUL_RETURN \n + RET_MAX_NWSR_REACHED \n + RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n + RET_HOTSTART_FAILED \n + RET_SHIFT_DETERMINATION_FAILED \n + RET_STEPDIRECTION_DETERMINATION_FAILED \n + RET_STEPLENGTH_DETERMINATION_FAILED \n + RET_HOMOTOPY_STEP_FAILED \n + RET_HOTSTART_STOPPED_INFEASIBILITY \n + RET_HOTSTART_STOPPED_UNBOUNDEDNESS */ + returnValue solveQP(const real_t * const g_new, /**< Gradient of neighbouring QP to be solved. */ + const real_t * const lb_new, /**< Lower bounds of neighbouring QP to be solved. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const ub_new, /**< Upper bounds of neighbouring QP to be solved. \n + If no upper bounds exist, a NULL pointer can be passed. */ + const real_t * const lbA_new, /**< Lower constraints' bounds of neighbouring QP to be solved. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const real_t * const ubA_new, /**< Upper constraints' bounds of neighbouring QP to be solved. \n + If no upper constraints' bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Number of performed working set recalculations. */ + real_t * const cputime, /**< Input: Maximum CPU time allowed for QP solution. \n + Output: CPU time spent for QP solution (or to perform nWSR iterations). */ + int_t nWSRperformed = 0, /**< Number of working set recalculations already performed to solve + this QP within previous solveQP() calls. This number is + always zero, except for successive calls from solveRegularisedQP() + or when using the far bound strategy. */ + BooleanType isFirstCall = BT_TRUE /**< Indicating whether this is the first call for current QP. */ + ); + + /** Solves QProblem using online active set strategy. + * Note: This function is internally called by all hotstart functions! + * \return SUCCESSFUL_RETURN \n + RET_MAX_NWSR_REACHED \n + RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n + RET_HOTSTART_FAILED \n + RET_SHIFT_DETERMINATION_FAILED \n + RET_STEPDIRECTION_DETERMINATION_FAILED \n + RET_STEPLENGTH_DETERMINATION_FAILED \n + RET_HOMOTOPY_STEP_FAILED \n + RET_HOTSTART_STOPPED_INFEASIBILITY \n + RET_HOTSTART_STOPPED_UNBOUNDEDNESS */ + returnValue solveRegularisedQP( + const real_t * const g_new, /**< Gradient of neighbouring QP to be solved. */ + const real_t * const lb_new, /**< Lower bounds of neighbouring QP to be solved. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const ub_new, /**< Upper bounds of neighbouring QP to be solved. \n + If no upper bounds exist, a NULL pointer can be passed. */ + const real_t * const lbA_new, /**< Lower constraints' bounds of neighbouring QP to be solved. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const real_t * const ubA_new, /**< Upper constraints' bounds of neighbouring QP to be solved. \n + If no upper constraints' bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Number of performed working set recalculations. */ + real_t * const cputime, /**< Input: Maximum CPU time allowed for QP solution. \n + Output: CPU time spent for QP solution (or to perform nWSR iterations). */ + int_t nWSRperformed = 0, /**< Number of working set recalculations already performed to solve + this QP within previous solveRegularisedQP() calls. This number is + always zero, except for successive calls when using the far bound strategy. */ + BooleanType isFirstCall = BT_TRUE /**< Indicating whether this is the first call for current QP. */ + ); + + /** Update activities in a hot start if some of the bounds have + become infinity or if variables have become fixed. */ + /* \return SUCCESSFUL_RETURN \n + RET_HOTSTART_FAILED */ + virtual returnValue updateActivitiesForHotstart(const real_t * const lb_new, /**< New lower bounds. */ + const real_t * const ub_new, /**< New upper bounds. */ + const real_t * const lbA_new, /**< New lower constraints' bounds. */ + const real_t * const ubA_new /**< New upper constraints' bounds. */ + ); + + /** Determines type of existing constraints and bounds (i.e. implicitly fixed, unbounded etc.). + * \return SUCCESSFUL_RETURN \n + RET_SETUPSUBJECTTOTYPE_FAILED */ + virtual returnValue setupSubjectToType(); + + /** Determines type of new constraints and bounds (i.e. implicitly fixed, unbounded etc.). + * \return SUCCESSFUL_RETURN \n + RET_SETUPSUBJECTTOTYPE_FAILED */ + using QProblemB::setupSubjectToType; + virtual returnValue setupSubjectToType(const real_t * const lb_new, /**< New lower bounds. */ + const real_t * const ub_new, /**< New upper bounds. */ + const real_t * const lbA_new, /**< New lower constraints' bounds. */ + const real_t * const ubA_new /**< New upper constraints' bounds. */ + ); + + /** Computes the Cholesky decomposition of the projected Hessian (i.e. R^T*R = Z^T*H*Z). + * Note: If Hessian turns out not to be positive definite, the Hessian type + * is set to HST_SEMIDEF accordingly. + * \return SUCCESSFUL_RETURN \n + * RET_HESSIAN_NOT_SPD \n + * RET_INDEXLIST_CORRUPTED */ + virtual returnValue computeProjectedCholesky(); + + /** Computes initial Cholesky decomposition of the projected Hessian making + * use of the function computeCholesky() or computeProjectedCholesky(). + * \return SUCCESSFUL_RETURN \n + * RET_HESSIAN_NOT_SPD \n + * RET_INDEXLIST_CORRUPTED */ + virtual returnValue setupInitialCholesky(); + + /** Initialises TQ factorisation of A (i.e. A*Q = [0 T]) if NO constraint is active. + * \return SUCCESSFUL_RETURN \n + RET_INDEXLIST_CORRUPTED */ + virtual returnValue setupTQfactorisation(); + + /** Obtains the desired working set for the auxiliary initial QP in + * accordance with the user specifications + * (assumes that member AX has already been initialised!) + * \return SUCCESSFUL_RETURN \n + RET_OBTAINING_WORKINGSET_FAILED \n + RET_INVALID_ARGUMENTS */ + returnValue obtainAuxiliaryWorkingSet( + const real_t * const xOpt, /**< Optimal primal solution vector. + * If a NULL pointer is passed, all entries are assumed to be zero. */ + const real_t * const yOpt, /**< Optimal dual solution vector. + * If a NULL pointer is passed, all entries are assumed to be zero. */ + const Bounds * const guessedBounds, /**< Guessed working set of bounds for solution (xOpt,yOpt). */ + const Constraints * const guessedConstraints, /**< Guessed working set for solution (xOpt,yOpt). */ + Bounds * auxiliaryBounds, /**< Input: Allocated bound object. \n + * Ouput: Working set of constraints for auxiliary QP. */ + Constraints * auxiliaryConstraints /**< Input: Allocated bound object. \n + * Ouput: Working set for auxiliary QP. */ + ) const; + + /** Sets up bound and constraints data structures according to auxiliaryBounds/Constraints. + * (If the working set shall be setup afresh, make sure that + * bounds and constraints data structure have been resetted + * and the TQ factorisation has been initialised!) + * \return SUCCESSFUL_RETURN \n + RET_SETUP_WORKINGSET_FAILED \n + RET_INVALID_ARGUMENTS \n + RET_UNKNOWN_BUG */ + virtual returnValue setupAuxiliaryWorkingSet( + const Bounds * const auxiliaryBounds, /**< Working set of bounds for auxiliary QP. */ + const Constraints * const auxiliaryConstraints, /**< Working set of constraints for auxiliary QP. */ + BooleanType setupAfresh /**< Flag indicating if given working set shall be + * setup afresh or by updating the current one. */ + ); + + /** Sets up the optimal primal/dual solution of the auxiliary initial QP. + * \return SUCCESSFUL_RETURN */ + returnValue setupAuxiliaryQPsolution( + const real_t * const xOpt, /**< Optimal primal solution vector. + * If a NULL pointer is passed, all entries are set to zero. */ + const real_t * const yOpt /**< Optimal dual solution vector. + * If a NULL pointer is passed, all entries are set to zero. */ + ); + + /** Sets up gradient of the auxiliary initial QP for given + * optimal primal/dual solution and given initial working set + * (assumes that members X, Y and BOUNDS, CONSTRAINTS have already been initialised!). + * \return SUCCESSFUL_RETURN */ + returnValue setupAuxiliaryQPgradient(); + + /** Sets up (constraints') bounds of the auxiliary initial QP for given + * optimal primal/dual solution and given initial working set + * (assumes that members X, Y and BOUNDS, CONSTRAINTS have already been initialised!). + * \return SUCCESSFUL_RETURN \n + RET_UNKNOWN_BUG */ + returnValue setupAuxiliaryQPbounds( + const Bounds * const auxiliaryBounds, /**< Working set of bounds for auxiliary QP. */ + const Constraints * const auxiliaryConstraints, /**< Working set of constraints for auxiliary QP. */ + BooleanType useRelaxation /**< Flag indicating if inactive (constraints') bounds shall be relaxed. */ + ); + + /** Adds a constraint to active set. + * \return SUCCESSFUL_RETURN \n + RET_ADDCONSTRAINT_FAILED \n + RET_ADDCONSTRAINT_FAILED_INFEASIBILITY \n + RET_ENSURELI_FAILED */ + virtual returnValue addConstraint(int_t number, /**< Number of constraint to be added to active set. */ + SubjectToStatus C_status, /**< Status of new active constraint. */ + BooleanType updateCholesky, /**< Flag indicating if Cholesky decomposition shall be updated. */ + BooleanType ensureLI = BT_TRUE /**< Ensure linear independence by exchange rules by default. */ + ); + + /** Checks if new active constraint to be added is linearly dependent from + * from row of the active constraints matrix. + * \return RET_LINEARLY_DEPENDENT \n + RET_LINEARLY_INDEPENDENT \n + RET_INDEXLIST_CORRUPTED */ + virtual returnValue addConstraint_checkLI( + int_t number /**< Number of constraint to be added to active set. */ + ); + + /** Ensures linear independence of constraint matrix when a new constraint is added. + * To this end a bound or constraint is removed simultaneously if necessary. + * \return SUCCESSFUL_RETURN \n + RET_LI_RESOLVED \n + RET_ENSURELI_FAILED \n + RET_ENSURELI_FAILED_TQ \n + RET_ENSURELI_FAILED_NOINDEX \n + RET_REMOVE_FROM_ACTIVESET */ + virtual returnValue addConstraint_ensureLI( + int_t number, /**< Number of constraint to be added to active set. */ + SubjectToStatus C_status /**< Status of new active bound. */ + ); + + /** Adds a bound to active set. + * \return SUCCESSFUL_RETURN \n + RET_ADDBOUND_FAILED \n + RET_ADDBOUND_FAILED_INFEASIBILITY \n + RET_ENSURELI_FAILED */ + virtual returnValue addBound(int_t number, /**< Number of bound to be added to active set. */ + SubjectToStatus B_status, /**< Status of new active bound. */ + BooleanType updateCholesky, /**< Flag indicating if Cholesky decomposition shall be updated. */ + BooleanType ensureLI = BT_TRUE /**< Ensure linear independence by exchange rules by default. */ + ); + + /** Checks if new active bound to be added is linearly dependent from + * from row of the active constraints matrix. + * \return RET_LINEARLY_DEPENDENT \n + RET_LINEARLY_INDEPENDENT */ + virtual returnValue addBound_checkLI(int_t number /**< Number of bound to be added to active set. */ + ); + + /** Ensures linear independence of constraint matrix when a new bound is added. + * To this end a bound or constraint is removed simultaneously if necessary. + * \return SUCCESSFUL_RETURN \n + RET_LI_RESOLVED \n + RET_ENSURELI_FAILED \n + RET_ENSURELI_FAILED_TQ \n + RET_ENSURELI_FAILED_NOINDEX \n + RET_REMOVE_FROM_ACTIVESET */ + virtual returnValue addBound_ensureLI(int_t number, /**< Number of bound to be added to active set. */ + SubjectToStatus B_status /**< Status of new active bound. */ + ); + + /** Removes a constraint from active set. + * \return SUCCESSFUL_RETURN \n + RET_CONSTRAINT_NOT_ACTIVE \n + RET_REMOVECONSTRAINT_FAILED \n + RET_HESSIAN_NOT_SPD */ + virtual returnValue removeConstraint( + int_t number, /**< Number of constraint to be removed from active set. */ + BooleanType updateCholesky, /**< Flag indicating if Cholesky decomposition shall be updated. */ + BooleanType allowFlipping = BT_FALSE, /**< Flag indicating if flipping bounds are allowed. */ + BooleanType ensureNZC = + BT_FALSE /**< Flag indicating if non-zero curvature is ensured by exchange rules. */ + ); + + /** Removes a bounds from active set. + * \return SUCCESSFUL_RETURN \n + RET_BOUND_NOT_ACTIVE \n + RET_HESSIAN_NOT_SPD \n + RET_REMOVEBOUND_FAILED */ + virtual returnValue removeBound(int_t number, /**< Number of bound to be removed from active set. */ + BooleanType updateCholesky, /**< Flag indicating if Cholesky decomposition shall be updated. */ + BooleanType allowFlipping = BT_FALSE, /**< Flag indicating if flipping bounds are allowed. */ + BooleanType ensureNZC = + BT_FALSE /**< Flag indicating if non-zero curvature is ensured by exchange rules. */ + ); + + /** Performs robustified ratio test yield the maximum possible step length + * along the homotopy path. + * \return SUCCESSFUL_RETURN */ + returnValue performPlainRatioTest(int_t nIdx, /**< Number of ratios to be checked. */ + const int_t * const idxList, /**< Array containing the indices of all ratios to be checked. */ + const real_t * const num, /**< Array containing all numerators for performing the ratio test. */ + const real_t * const den, /**< Array containing all denominators for performing the ratio test. */ + real_t epsNum, /**< Numerator tolerance. */ + real_t epsDen, /**< Denominator tolerance. */ + real_t & t, /**< Output: Maximum possible step length along the homotopy path. */ + int_t & BC_idx /**< Output: Index of blocking constraint. */ + ) const; + + /** Ensure non-zero curvature by primal jump. + * \return SUCCESSFUL_RETURN \n + * RET_HOTSTART_STOPPED_UNBOUNDEDNESS */ + returnValue ensureNonzeroCurvature( + BooleanType removeBoundNotConstraint, /**< SubjectTo to be removed is a bound. */ + int_t remIdx, /**< Index of bound/constraint to be removed. */ + BooleanType & exchangeHappened, /**< Output: Exchange was necessary to ensure. */ + BooleanType & addBoundNotConstraint, /**< SubjectTo to be added is a bound. */ + int_t & addIdx, /**< Index of bound/constraint to be added. */ + SubjectToStatus & addStatus /**< Status of bound/constraint to be added. */ + ); + + /** Solves the system Ta = b or T^Ta = b where T is a reverse upper triangular matrix. + * \return SUCCESSFUL_RETURN \n + RET_DIV_BY_ZERO */ + virtual returnValue backsolveT(const real_t * const b, /**< Right hand side vector. */ + BooleanType transposed, /**< Indicates if the transposed system shall be solved. */ + real_t * const a /**< Output: Solution vector */ + ) const; + + /** Determines step direction of the shift of the QP data. + * \return SUCCESSFUL_RETURN */ + returnValue determineDataShift(const real_t * const g_new, /**< New gradient vector. */ + const real_t * const lbA_new, /**< New lower constraints' bounds. */ + const real_t * const ubA_new, /**< New upper constraints' bounds. */ + const real_t * const lb_new, /**< New lower bounds. */ + const real_t * const ub_new, /**< New upper bounds. */ + real_t * const delta_g, /**< Output: Step direction of gradient vector. */ + real_t * const delta_lbA, /**< Output: Step direction of lower constraints' bounds. */ + real_t * const delta_ubA, /**< Output: Step direction of upper constraints' bounds. */ + real_t * const delta_lb, /**< Output: Step direction of lower bounds. */ + real_t * const delta_ub, /**< Output: Step direction of upper bounds. */ + BooleanType & + Delta_bC_isZero, /**< Output: Indicates if active constraints' bounds are to be shifted. */ + BooleanType & Delta_bB_isZero /**< Output: Indicates if active bounds are to be shifted. */ + ); + + /** Determines step direction of the homotopy path. + * \return SUCCESSFUL_RETURN \n + RET_STEPDIRECTION_FAILED_TQ \n + RET_STEPDIRECTION_FAILED_CHOLESKY */ + virtual returnValue determineStepDirection( + const real_t * const delta_g, /**< Step direction of gradient vector. */ + const real_t * const delta_lbA, /**< Step direction of lower constraints' bounds. */ + const real_t * const delta_ubA, /**< Step direction of upper constraints' bounds. */ + const real_t * const delta_lb, /**< Step direction of lower bounds. */ + const real_t * const delta_ub, /**< Step direction of upper bounds. */ + BooleanType Delta_bC_isZero, /**< Indicates if active constraints' bounds are to be shifted. */ + BooleanType Delta_bB_isZero, /**< Indicates if active bounds are to be shifted. */ + real_t * const delta_xFX, /**< Output: Primal homotopy step direction of fixed variables. */ + real_t * const delta_xFR, /**< Output: Primal homotopy step direction of free variables. */ + real_t * const + delta_yAC, /**< Output: Dual homotopy step direction of active constraints' multiplier. */ + real_t * const delta_yFX /**< Output: Dual homotopy step direction of fixed variables' multiplier. */ + ); + + /** Determines the maximum possible step length along the homotopy path + * and performs this step (without changing working set). + * \return SUCCESSFUL_RETURN \n + * RET_ERROR_IN_CONSTRAINTPRODUCT \n + * RET_QP_INFEASIBLE */ + returnValue performStep(const real_t * const delta_g, /**< Step direction of gradient. */ + const real_t * const delta_lbA, /**< Step direction of lower constraints' bounds. */ + const real_t * const delta_ubA, /**< Step direction of upper constraints' bounds. */ + const real_t * const delta_lb, /**< Step direction of lower bounds. */ + const real_t * const delta_ub, /**< Step direction of upper bounds. */ + const real_t * const delta_xFX, /**< Primal homotopy step direction of fixed variables. */ + const real_t * const delta_xFR, /**< Primal homotopy step direction of free variables. */ + const real_t * const delta_yAC, /**< Dual homotopy step direction of active constraints' multiplier. */ + const real_t * const delta_yFX, /**< Dual homotopy step direction of fixed variables' multiplier. */ + int_t & BC_idx, /**< Output: Index of blocking constraint. */ + SubjectToStatus & BC_status, /**< Output: Status of blocking constraint. */ + BooleanType & BC_isBound /**< Output: Indicates if blocking constraint is a bound. */ + ); + + /** Updates the active set. + * \return SUCCESSFUL_RETURN \n + RET_REMOVE_FROM_ACTIVESET_FAILED \n + RET_ADD_TO_ACTIVESET_FAILED */ + returnValue changeActiveSet(int_t BC_idx, /**< Index of blocking constraint. */ + SubjectToStatus BC_status, /**< Status of blocking constraint. */ + BooleanType BC_isBound /**< Indicates if blocking constraint is a bound. */ + ); + + /** Compute relative length of homotopy in data space for termination + * criterion. + * \return Relative length in data space. */ + real_t getRelativeHomotopyLength(const real_t * const g_new, /**< Final gradient. */ + const real_t * const lb_new, /**< Final lower variable bounds. */ + const real_t * const ub_new, /**< Final upper variable bounds. */ + const real_t * const lbA_new, /**< Final lower constraint bounds. */ + const real_t * const ubA_new /**< Final upper constraint bounds. */ + ); + + /** Ramping Strategy to avoid ties. Modifies homotopy start without + * changing current active set. + * \return SUCCESSFUL_RETURN */ + virtual returnValue performRamping(); + + /** ... */ + returnValue updateFarBounds(real_t curFarBound, /**< ... */ + int_t nRamp, /**< ... */ + const real_t * const lb_new, /**< ... */ + real_t * const lb_new_far, /**< ... */ + const real_t * const ub_new, /**< ... */ + real_t * const ub_new_far, /**< ... */ + const real_t * const lbA_new, /**< ... */ + real_t * const lbA_new_far, /**< ... */ + const real_t * const ubA_new, /**< ... */ + real_t * const ubA_new_far /**< ... */ + ) const; + + /** Drift correction at end of each active set iteration + * \return SUCCESSFUL_RETURN */ + virtual returnValue performDriftCorrection(); + + /** Updates QP vectors, working sets and internal data structures in order to + start from an optimal solution corresponding to initial guesses of the working + set for bounds and constraints. + * \return SUCCESSFUL_RETURN \n + * RET_SETUP_AUXILIARYQP_FAILED \n + RET_INVALID_ARGUMENTS */ + using QProblemB::setupAuxiliaryQP; + virtual returnValue setupAuxiliaryQP( + const Bounds * const guessedBounds, /**< Initial guess for working set of bounds. */ + const Constraints * const guessedConstraints /**< Initial guess for working set of constraints. */ + ); + + /** Determines if it is more efficient to refactorise the matrices when + * hotstarting or not (i.e. better to update the existing factorisations). + * \return BT_TRUE iff matrices shall be refactorised afresh + */ + BooleanType shallRefactorise( + const Bounds * const guessedBounds, /**< Guessed new working set of bounds. */ + const Constraints * const guessedConstraints /**< Guessed new working set of constraints. */ + ) const; + + /** Sets up internal QP data. + * \return SUCCESSFUL_RETURN \n + RET_INVALID_ARGUMENTS \n + RET_UNKNONW_BUG */ + returnValue setupQPdata(SymmetricMatrix * _H, /**< Hessian matrix. \n + If Hessian matrix is trivial,a NULL pointer can be passed. */ + const real_t * const _g, /**< Gradient vector. */ + Matrix * _A, /**< Constraint matrix. */ + const real_t * const _lb, /**< Lower bound vector (on variables). \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const _ub, /**< Upper bound vector (on variables). \n + If no upper bounds exist, a NULL pointer can be passed. */ + const real_t * const _lbA, /**< Lower constraints' bound vector. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const real_t * const _ubA /**< Upper constraints' bound vector. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + ); + + /** Sets up dense internal QP data. If the current Hessian is trivial + * (i.e. HST_ZERO or HST_IDENTITY) but a non-trivial one is given, + * memory for Hessian is allocated and it is set to the given one. + * \return SUCCESSFUL_RETURN \n + RET_INVALID_ARGUMENTS \n + RET_UNKNONW_BUG */ + returnValue setupQPdata(const real_t * const _H, /**< Hessian matrix. \n + If Hessian matrix is trivial,a NULL pointer can be passed. */ + const real_t * const _g, /**< Gradient vector. */ + const real_t * const _A, /**< Constraint matrix. */ + const real_t * const _lb, /**< Lower bound vector (on variables). \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const _ub, /**< Upper bound vector (on variables). \n + If no upper bounds exist, a NULL pointer can be passed. */ + const real_t * const _lbA, /**< Lower constraints' bound vector. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const real_t * const _ubA /**< Upper constraints' bound vector. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + ); + + /** Sets up internal QP data by loading it from files. If the current Hessian + * is trivial (i.e. HST_ZERO or HST_IDENTITY) but a non-trivial one is given, + * memory for Hessian is allocated and it is set to the given one. + * \return SUCCESSFUL_RETURN \n + RET_UNABLE_TO_OPEN_FILE \n + RET_UNABLE_TO_READ_FILE \n + RET_INVALID_ARGUMENTS \n + RET_UNKNONW_BUG */ + returnValue setupQPdataFromFile( + const char * const H_file, /**< Name of file where Hessian matrix, of neighbouring QP to be solved, is + stored. \n If Hessian matrix is trivial,a NULL pointer can be passed. */ + const char * const + g_file, /**< Name of file where gradient, of neighbouring QP to be solved, is stored. */ + const char * const + A_file, /**< Name of file where constraint matrix, of neighbouring QP to be solved, is stored. */ + const char * const lb_file, /**< Name of file where lower bounds, of neighbouring QP to be solved, is + stored. \n If no lower bounds exist, a NULL pointer can be passed. */ + const char * const ub_file, /**< Name of file where upper bounds, of neighbouring QP to be solved, is + stored. \n If no upper bounds exist, a NULL pointer can be passed. */ + const char * const + lbA_file, /**< Name of file where lower constraints' bounds, of neighbouring QP to be solved, is + stored. \n If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const char * const + ubA_file /**< Name of file where upper constraints' bounds, of neighbouring QP to be solved, is + stored. \n If no upper constraints' bounds exist, a NULL pointer can be passed. */ + ); + + /** Loads new QP vectors from files (internal members are not affected!). + * \return SUCCESSFUL_RETURN \n + RET_UNABLE_TO_OPEN_FILE \n + RET_UNABLE_TO_READ_FILE \n + RET_INVALID_ARGUMENTS */ + returnValue loadQPvectorsFromFile( + const char * const + g_file, /**< Name of file where gradient, of neighbouring QP to be solved, is stored. */ + const char * const lb_file, /**< Name of file where lower bounds, of neighbouring QP to be solved, is + stored. \n If no lower bounds exist, a NULL pointer can be passed. */ + const char * const ub_file, /**< Name of file where upper bounds, of neighbouring QP to be solved, is + stored. \n If no upper bounds exist, a NULL pointer can be passed. */ + const char * const + lbA_file, /**< Name of file where lower constraints' bounds, of neighbouring QP to be solved, is + stored. \n If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const char * const + ubA_file, /**< Name of file where upper constraints' bounds, of neighbouring QP to be solved, is + stored. \n If no upper constraints' bounds exist, a NULL pointer can be passed. */ + real_t * const g_new, /**< Output: Gradient of neighbouring QP to be solved. */ + real_t * const lb_new, /**< Output: Lower bounds of neighbouring QP to be solved */ + real_t * const ub_new, /**< Output: Upper bounds of neighbouring QP to be solved */ + real_t * const lbA_new, /**< Output: Lower constraints' bounds of neighbouring QP to be solved */ + real_t * const ubA_new /**< Output: Upper constraints' bounds of neighbouring QP to be solved */ + ) const; + + /** Prints concise information on the current iteration. + * \return SUCCESSFUL_RETURN \n */ + returnValue printIteration(int_t iter, /**< Number of current iteration. */ + int_t BC_idx, /**< Index of blocking constraint. */ + SubjectToStatus BC_status, /**< Status of blocking constraint. */ + BooleanType BC_isBound, /**< Indicates if blocking constraint is a bound. */ + real_t homotopyLength, /**< Current homotopy distance. */ + BooleanType isFirstCall = BT_TRUE /**< Indicating whether this is the first call for current QP. */ + ); + + /** Sets constraint matrix of the QP. \n + Note: Also internal vector Ax is recomputed! + * \return SUCCESSFUL_RETURN \n + * RET_INVALID_ARGUMENTS */ + inline returnValue setA(Matrix * A_new /**< New constraint matrix (a shallow copy is made). */ + ); + + /** Sets dense constraint matrix of the QP. \n + Note: Also internal vector Ax is recomputed! + * \return SUCCESSFUL_RETURN \n + * RET_INVALID_ARGUMENTS */ + inline returnValue setA(const real_t * const + A_new /**< New dense constraint matrix (with correct dimension!), a shallow copy is made. */ + ); + + /** Sets constraints' lower bound vector of the QP. + * \return SUCCESSFUL_RETURN \n + * RET_QPOBJECT_NOT_SETUP */ + inline returnValue setLBA( + const real_t * const lbA_new /**< New constraints' lower bound vector (with correct dimension!). */ + ); + + /** Changes single entry of lower constraints' bound vector of the QP. + * \return SUCCESSFUL_RETURN \n + * RET_QPOBJECT_NOT_SETUP \n + * RET_INDEX_OUT_OF_BOUNDS */ + inline returnValue setLBA(int_t number, /**< Number of entry to be changed. */ + real_t value /**< New value for entry of lower constraints' bound vector (with correct dimension!). */ + ); + + /** Sets constraints' upper bound vector of the QP. + * \return SUCCESSFUL_RETURN \n + * RET_QPOBJECT_NOT_SETUP */ + inline returnValue setUBA( + const real_t * const ubA_new /**< New constraints' upper bound vector (with correct dimension!). */ + ); + + /** Changes single entry of upper constraints' bound vector of the QP. + * \return SUCCESSFUL_RETURN \n + * RET_QPOBJECT_NOT_SETUP \n + * RET_INDEX_OUT_OF_BOUNDS */ + inline returnValue setUBA(int_t number, /**< Number of entry to be changed. */ + real_t value /**< New value for entry of upper constraints' bound vector (with correct dimension!). */ + ); + + /** Drops the blocking bound/constraint that led to infeasibility, or finds another + * bound/constraint to drop according to drop priorities. + * \return SUCCESSFUL_RETURN \n + */ + returnValue dropInfeasibles(int_t BC_number, /**< Number of the bound or constraint to be added. */ + SubjectToStatus BC_status, /**< New status of the bound or constraint to be added. */ + BooleanType BC_isBound, /**< Whether a bound or a constraint is to be added. */ + real_t * xiB, /**< (not yet documented) */ + real_t * xiC /**< (not yet documented) */ + ); + + /** Decides if lower bounds are smaller than upper bounds + * + * \return SUCCESSFUL_RETURN \n + * RET_QP_INFEASIBLE */ + + returnValue areBoundsConsistent(const real_t * const lb, /**< Vector of lower bounds*/ + const real_t * const ub, /**< Vector of upper bounds*/ + const real_t * const lbA, /**< Vector of lower constraints*/ + const real_t * const ubA /**< Vector of upper constraints*/ + ) const; + +public: + /** ... + * \return SUCCESSFUL_RETURN \n + RET_UNABLE_TO_OPEN_FILE */ + returnValue writeQpDataIntoMatFile(const char * const filename /**< Mat file name. */ + ) const; + + /** ... + * \return SUCCESSFUL_RETURN \n + RET_UNABLE_TO_OPEN_FILE */ + returnValue writeQpWorkspaceIntoMatFile(const char * const filename /**< Mat file name. */ + ); + + /* + * PROTECTED MEMBER VARIABLES + */ +protected: + BooleanType + freeConstraintMatrix; /**< Flag indicating whether the constraint matrix needs to be de-allocated. */ + Matrix * A; /**< Constraint matrix. */ + + real_t * lbA; /**< Lower constraints' bound vector. */ + real_t * ubA; /**< Upper constraints' bound vector. */ + + Constraints constraints; /**< Data structure for problem's constraints. */ + + real_t * T; /**< Reverse triangular matrix, A = [0 T]*Q'. */ + real_t * Q; /**< Orthonormal quadratic matrix, A = [0 T]*Q'. */ + int_t sizeT; /**< Matrix T is stored in a (sizeT x sizeT) array. */ + + real_t * Ax; /**< Stores the current A*x \n + * (for increased efficiency only). */ + real_t * Ax_l; /**< Stores the current distance to lower constraints' bounds A*x-lbA \n + * (for increased efficiency only). */ + real_t * Ax_u; /**< Stores the current distance to lower constraints' bounds ubA-A*x \n + * (for increased efficiency only). */ + + ConstraintProduct * constraintProduct; /**< Pointer to user-defined constraint product function. */ + + real_t * tempA; /**< Temporary for determineStepDirection. */ + real_t * tempB; /**< Temporary for determineStepDirection. */ + real_t * ZFR_delta_xFRz; /**< Temporary for determineStepDirection. */ + real_t * delta_xFRy; /**< Temporary for determineStepDirection. */ + real_t * delta_xFRz; /**< Temporary for determineStepDirection. */ + real_t * delta_yAC_TMP; /**< Temporary for determineStepDirection. */ + + real_t * tempC; /**< Temporary for constraint types. */ +}; + +END_NAMESPACE_QPOASES + +#include + +#endif /* QPOASES_QPROBLEM_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/QProblem.ipp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/QProblem.ipp new file mode 100755 index 0000000..611fa31 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/QProblem.ipp @@ -0,0 +1,284 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file include/qpOASES/QProblem.ipp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of inlined member functions of the QProblem class which + * is able to use the newly developed online active set strategy for + * parametric quadratic programming. + */ + + +BEGIN_NAMESPACE_QPOASES + + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + + +/* + * g e t C o n s t r a i n t s + */ +inline returnValue QProblem::getConstraints( Constraints& _constraints ) const +{ + int_t nV = getNV( ); + + if ( nV == 0 ) + return THROWERROR( RET_QPOBJECT_NOT_SETUP ); + + _constraints = constraints; + + return SUCCESSFUL_RETURN; +} + + + +/* + * g e t N C + */ +inline int_t QProblem::getNC( ) const +{ + return constraints.getNC( ); +} + + +/* + * g e t N E C + */ +inline int_t QProblem::getNEC( ) const +{ + return constraints.getNEC( ); +} + + +/* + * g e t N A C + */ +inline int_t QProblem::getNAC( ) const +{ + return constraints.getNAC( ); +} + + +/* + * g e t N I A C + */ +inline int_t QProblem::getNIAC( ) const +{ + return constraints.getNIAC( ); +} + + + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + + +/* + * s e t A + */ +inline returnValue QProblem::setA( Matrix *A_new ) +{ + int_t j; + int_t nV = getNV( ); + int_t nC = getNC( ); + + if ( nV == 0 ) + return THROWERROR( RET_QPOBJECT_NOT_SETUP ); + + if ( A_new == 0 ) + return THROWERROR( RET_INVALID_ARGUMENTS ); + + /* Set constraint matrix AND update member AX. */ + if ( ( freeConstraintMatrix == BT_TRUE ) && ( A != 0 ) ) + { + delete A; + A = 0; + } + A = A_new; + freeConstraintMatrix = BT_FALSE; + + A->times(1, 1.0, x, nV, 0.0, Ax, nC); + + A->getRowNorm(tempC); + + for( j=0; jtimes(1, 1.0, x, nV, 0.0, Ax, nC); + + for( j=0; j= 0 ) && ( number < nC ) ) + { + lbA[number] = value; + return SUCCESSFUL_RETURN; + } + else + return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); +} + + +/* + * s e t U B A + */ +inline returnValue QProblem::setUBA( const real_t* const ubA_new ) +{ + uint_t i; + uint_t nV = (uint_t)getNV( ); + uint_t nC = (uint_t)getNC( ); + + if ( nV == 0 ) + return THROWERROR( RET_QPOBJECT_NOT_SETUP ); + + if ( ubA_new != 0 ) + { + memcpy( ubA,ubA_new,nC*sizeof(real_t) ); + } + else + { + /* if no upper constraints' bounds are specified, set them to infinity */ + for( i=0; i= 0 ) && ( number < nC ) ) + { + ubA[number] = value; + return SUCCESSFUL_RETURN; + } + else + return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); +} + + +END_NAMESPACE_QPOASES + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/QProblemB.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/QProblemB.hpp new file mode 100644 index 0000000..b938567 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/QProblemB.hpp @@ -0,0 +1,1005 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/QProblemB.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Declaration of the QProblemB class which is able to use the newly + * developed online active set strategy for parametric quadratic programming + * for problems with (simple) bounds only. + */ + +#ifndef QPOASES_QPROBLEMB_HPP +#define QPOASES_QPROBLEMB_HPP + +#include +#include +#include + +BEGIN_NAMESPACE_QPOASES + +class SolutionAnalysis; + +/** + * \brief Implements the online active set strategy for box-constrained QPs. + * + * Class for setting up and solving quadratic programs with bounds (= box constraints) only. + * The main feature is the possibily to use the newly developed online active set strategy + * for parametric quadratic programming. + * + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + */ +class QProblemB +{ + /* allow SolutionAnalysis class to access private members */ + friend class SolutionAnalysis; + + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + QProblemB(); + + /** Constructor which takes the QP dimension and Hessian type + * information. If the Hessian is the zero (i.e. HST_ZERO) or the + * identity matrix (i.e. HST_IDENTITY), respectively, no memory + * is allocated for it and a NULL pointer can be passed for it + * to the init() functions. */ + QProblemB(int_t _nV, /**< Number of variables. */ + HessianType _hessianType = HST_UNKNOWN, /**< Type of Hessian matrix. */ + BooleanType allocDenseMats = BT_TRUE /**< Enable allocation of dense matrices. */ + ); + + /** Copy constructor (deep copy). */ + QProblemB(const QProblemB & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + virtual ~QProblemB(); + + /** Assignment operator (deep copy). */ + virtual QProblemB & operator=(const QProblemB & rhs /**< Rhs object. */ + ); + + /** Clears all data structures of QProblemB except for QP data. + * \return SUCCESSFUL_RETURN \n + RET_RESET_FAILED */ + virtual returnValue reset(); + + /** Initialises a simply bounded QP problem with given QP data and tries to solve it + * using at most nWSR iterations. Depending on the parameter constellation it: \n + * 1. 0, 0, 0 : starts with xOpt = 0, yOpt = 0 and gB empty (or all implicit equality bounds), \n + * 2. xOpt, 0, 0 : starts with xOpt, yOpt = 0 and obtain gB by "clipping", \n + * 3. 0, yOpt, 0 : starts with xOpt = 0, yOpt and obtain gB from yOpt != 0, \n + * 4. 0, 0, gB: starts with xOpt = 0, yOpt = 0 and gB, \n + * 5. xOpt, yOpt, 0 : starts with xOpt, yOpt and obtain gB from yOpt != 0, \n + * 6. xOpt, 0, gB: starts with xOpt, yOpt = 0 and gB, \n + * 7. xOpt, yOpt, gB: starts with xOpt, yOpt and gB (assume them to be consistent!) + * + * Note: This function internally calls solveInitialQP for initialisation! + * + * \return SUCCESSFUL_RETURN \n + RET_INIT_FAILED \n + RET_INIT_FAILED_CHOLESKY \n + RET_INIT_FAILED_HOTSTART \n + RET_INIT_FAILED_INFEASIBILITY \n + RET_INIT_FAILED_UNBOUNDEDNESS \n + RET_MAX_NWSR_REACHED \n + RET_INVALID_ARGUMENTS */ + returnValue init(SymmetricMatrix * _H, /**< Hessian matrix (a shallow copy is made). */ + const real_t * const _g, /**< Gradient vector. */ + const real_t * const _lb, /**< Lower bounds (on variables). \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const _ub, /**< Upper bounds (on variables). \n + If no upper bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations when using initial homotopy. \n + Output: Number of performed working set recalculations. */ + real_t * const cputime = 0, /**< Input: Maximum CPU time allowed for QP initialisation. \n + Output: CPU time spent for QP initialisation (if pointer passed). */ + const real_t * const xOpt = 0, /**< Optimal primal solution vector. A NULL pointer can be passed. \n + (If a null pointer is passed, the old primal solution is kept!) */ + const real_t * const yOpt = 0, /**< Optimal dual solution vector. A NULL pointer can be passed. \n + (If a null pointer is passed, the old dual solution is kept!) */ + const Bounds * const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n + (If a null pointer is passed, all bounds are assumed inactive!) */ + const real_t * const _R = 0 /**< Pre-computed (upper triangular) Cholesky factor of Hessian matrix. + The Cholesky factor must be stored in a real_t array of size nV*nV + in row-major format. Note: Only used if xOpt/yOpt and gB are NULL! \n + (If a null pointer is passed, Cholesky decomposition is computed internally!) */ + ); + + /** Initialises a simply bounded QP problem with given QP data and tries to solve it + * using at most nWSR iterations. Depending on the parameter constellation it: \n + * 1. 0, 0, 0 : starts with xOpt = 0, yOpt = 0 and gB empty (or all implicit equality bounds), \n + * 2. xOpt, 0, 0 : starts with xOpt, yOpt = 0 and obtain gB by "clipping", \n + * 3. 0, yOpt, 0 : starts with xOpt = 0, yOpt and obtain gB from yOpt != 0, \n + * 4. 0, 0, gB: starts with xOpt = 0, yOpt = 0 and gB, \n + * 5. xOpt, yOpt, 0 : starts with xOpt, yOpt and obtain gB from yOpt != 0, \n + * 6. xOpt, 0, gB: starts with xOpt, yOpt = 0 and gB, \n + * 7. xOpt, yOpt, gB: starts with xOpt, yOpt and gB (assume them to be consistent!) + * + * Note: This function internally calls solveInitialQP for initialisation! + * + * \return SUCCESSFUL_RETURN \n + RET_INIT_FAILED \n + RET_INIT_FAILED_CHOLESKY \n + RET_INIT_FAILED_HOTSTART \n + RET_INIT_FAILED_INFEASIBILITY \n + RET_INIT_FAILED_UNBOUNDEDNESS \n + RET_MAX_NWSR_REACHED \n + RET_INVALID_ARGUMENTS */ + returnValue init(const real_t * const _H, /**< Hessian matrix (a shallow copy is made). \n + If Hessian matrix is trivial, a NULL pointer can be passed. */ + const real_t * const _g, /**< Gradient vector. */ + const real_t * const _lb, /**< Lower bounds (on variables). \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const _ub, /**< Upper bounds (on variables). \n + If no upper bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations when using initial homotopy. \n + Output: Number of performed working set recalculations. */ + real_t * const cputime = 0, /**< Input: Maximum CPU time allowed for QP initialisation. \n + Output: CPU time spent for QP initialisation (if pointer passed). */ + const real_t * const xOpt = 0, /**< Optimal primal solution vector. A NULL pointer can be passed. \n + (If a null pointer is passed, the old primal solution is kept!) */ + const real_t * const yOpt = 0, /**< Optimal dual solution vector. A NULL pointer can be passed. \n + (If a null pointer is passed, the old dual solution is kept!) */ + const Bounds * const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n + (If a null pointer is passed, all bounds are assumed inactive!) */ + const real_t * const _R = 0 /**< Pre-computed (upper triangular) Cholesky factor of Hessian matrix. + The Cholesky factor must be stored in a real_t array of size nV*nV + in row-major format. Note: Only used if xOpt/yOpt and gB are NULL! \n + (If a null pointer is passed, Cholesky decomposition is computed internally!) */ + ); + + /** Initialises a simply bounded QP problem with given QP data to be read from files and solves it + * using at most nWSR iterations. Depending on the parameter constellation it: \n + * 1. 0, 0, 0 : starts with xOpt = 0, yOpt = 0 and gB empty (or all implicit equality bounds), \n + * 2. xOpt, 0, 0 : starts with xOpt, yOpt = 0 and obtain gB by "clipping", \n + * 3. 0, yOpt, 0 : starts with xOpt = 0, yOpt and obtain gB from yOpt != 0, \n + * 4. 0, 0, gB: starts with xOpt = 0, yOpt = 0 and gB, \n + * 5. xOpt, yOpt, 0 : starts with xOpt, yOpt and obtain gB from yOpt != 0, \n + * 6. xOpt, 0, gB: starts with xOpt, yOpt = 0 and gB, \n + * 7. xOpt, yOpt, gB: starts with xOpt, yOpt and gB (assume them to be consistent!) + * + * Note: This function internally calls solveInitialQP for initialisation! + * + * \return SUCCESSFUL_RETURN \n + RET_INIT_FAILED \n + RET_INIT_FAILED_CHOLESKY \n + RET_INIT_FAILED_HOTSTART \n + RET_INIT_FAILED_INFEASIBILITY \n + RET_INIT_FAILED_UNBOUNDEDNESS \n + RET_MAX_NWSR_REACHED \n + RET_UNABLE_TO_READ_FILE */ + returnValue init(const char * const H_file, /**< Name of file where Hessian matrix is stored. \n + If Hessian matrix is trivial, a NULL pointer can be passed. */ + const char * const g_file, /**< Name of file where gradient vector is stored. */ + const char * const lb_file, /**< Name of file where lower bound vector. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const char * const ub_file, /**< Name of file where upper bound vector. \n + If no upper bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations when using initial homotopy. \n + Output: Number of performed working set recalculations. */ + real_t * const cputime = 0, /**< Input: Maximum CPU time allowed for QP initialisation. \n + Output: CPU time spent for QP initialisation (if pointer passed). */ + const real_t * const xOpt = 0, /**< Optimal primal solution vector. A NULL pointer can be passed. \n + (If a null pointer is passed, the old primal solution is kept!) */ + const real_t * const yOpt = 0, /**< Optimal dual solution vector. A NULL pointer can be passed. \n + (If a null pointer is passed, the old dual solution is kept!) */ + const Bounds * const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n + (If a null pointer is passed, all bounds are assumed inactive!) */ + const char * const R_file = + 0 /**< Name of the file where a pre-computed (upper triangular) Cholesky factor +of the Hessian matrix is stored. \n +(If a null pointer is passed, Cholesky decomposition is computed internally!) */ + ); + + /** Solves an initialised QP sequence using the online active set strategy. + * By default, QP solution is started from previous solution. If a guess + * for the working set is provided, an initialised homotopy is performed. + * + * Note: This function internally calls solveQP/solveRegularisedQP + * for solving an initialised QP! + * + * \return SUCCESSFUL_RETURN \n + RET_MAX_NWSR_REACHED \n + RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n + RET_HOTSTART_FAILED \n + RET_SHIFT_DETERMINATION_FAILED \n + RET_STEPDIRECTION_DETERMINATION_FAILED \n + RET_STEPLENGTH_DETERMINATION_FAILED \n + RET_HOMOTOPY_STEP_FAILED \n + RET_HOTSTART_STOPPED_INFEASIBILITY \n + RET_HOTSTART_STOPPED_UNBOUNDEDNESS \n + RET_SETUP_AUXILIARYQP_FAILED */ + returnValue hotstart(const real_t * const g_new, /**< Gradient of neighbouring QP to be solved. */ + const real_t * const lb_new, /**< Lower bounds of neighbouring QP to be solved. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const ub_new, /**< Upper bounds of neighbouring QP to be solved. \n + If no upper bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Number of performed working set recalculations. */ + real_t * const cputime = 0, /**< Input: Maximum CPU time allowed for QP solution. \n + Output: CPU time spent for QP solution (or to perform nWSR iterations). */ + const Bounds * const guessedBounds = 0 /**< Optimal working set of bounds for solution (xOpt,yOpt). \n + (If a null pointer is passed, the previous working set is kept!) */ + ); + + /** Solves an initialised QP sequence using the online active set strategy, + * where QP data is read from files. + * By default, QP solution is started from previous solution. If a guess + * for the working set is provided, an initialised homotopy is performed. + * + * Note: This function internally calls solveQP/solveRegularisedQP + * for solving an initialised QP! + * + * \return SUCCESSFUL_RETURN \n + RET_MAX_NWSR_REACHED \n + RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n + RET_HOTSTART_FAILED \n + RET_SHIFT_DETERMINATION_FAILED \n + RET_STEPDIRECTION_DETERMINATION_FAILED \n + RET_STEPLENGTH_DETERMINATION_FAILED \n + RET_HOMOTOPY_STEP_FAILED \n + RET_HOTSTART_STOPPED_INFEASIBILITY \n + RET_HOTSTART_STOPPED_UNBOUNDEDNESS \n + RET_UNABLE_TO_READ_FILE \n + RET_SETUP_AUXILIARYQP_FAILED \n + RET_INVALID_ARGUMENTS */ + returnValue hotstart( + const char * const + g_file, /**< Name of file where gradient, of neighbouring QP to be solved, is stored. */ + const char * const lb_file, /**< Name of file where lower bounds, of neighbouring QP to be solved, is + stored. \n If no lower bounds exist, a NULL pointer can be passed. */ + const char * const ub_file, /**< Name of file where upper bounds, of neighbouring QP to be solved, is + stored. \n If no upper bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Number of performed working set recalculations. */ + real_t * const cputime = 0, /**< Input: Maximum CPU time allowed for QP solution. \n + Output: CPU time spent for QP solution (or to perform nWSR iterations). */ + const Bounds * const guessedBounds = 0 /**< Optimal working set of bounds for solution (xOpt,yOpt). \n + (If a null pointer is passed, the previous working set is kept!) */ + ); + + /** Writes a vector with the state of the working set + * \return SUCCESSFUL_RETURN \n + * RET_INVALID_ARGUMENTS */ + virtual returnValue getWorkingSet( + real_t * workingSet /** Output: array containing state of the working set. */ + ); + + /** Writes a vector with the state of the working set of bounds + * \return SUCCESSFUL_RETURN \n + * RET_INVALID_ARGUMENTS */ + virtual returnValue getWorkingSetBounds( + real_t * workingSetB /** Output: array containing state of the working set of bounds. */ + ); + + /** Writes a vector with the state of the working set of constraints + * \return SUCCESSFUL_RETURN \n + * RET_INVALID_ARGUMENTS */ + virtual returnValue getWorkingSetConstraints( + real_t * workingSetC /** Output: array containing state of the working set of constraints. */ + ); + + /** Returns current bounds object of the QP (deep copy). + * \return SUCCESSFUL_RETURN \n + RET_QPOBJECT_NOT_SETUP */ + inline returnValue getBounds(Bounds & _bounds /** Output: Bounds object. */ + ) const; + + /** Returns the number of variables. + * \return Number of variables. */ + inline int_t getNV() const; + + /** Returns the number of free variables. + * \return Number of free variables. */ + inline int_t getNFR() const; + + /** Returns the number of fixed variables. + * \return Number of fixed variables. */ + inline int_t getNFX() const; + + /** Returns the number of implicitly fixed variables. + * \return Number of implicitly fixed variables. */ + inline int_t getNFV() const; + + /** Returns the dimension of null space. + * \return Dimension of null space. */ + virtual int_t getNZ() const; + + /** Returns the optimal objective function value. + * \return finite value: Optimal objective function value (QP was solved) \n + +infinity: QP was not yet solved */ + real_t getObjVal() const; + + /** Returns the objective function value at an arbitrary point x. + * \return Objective function value at point x */ + real_t getObjVal(const real_t * const _x /**< Point at which the objective function shall be evaluated. */ + ) const; + + /** Returns the primal solution vector. + * \return SUCCESSFUL_RETURN \n + RET_QP_NOT_SOLVED */ + returnValue getPrimalSolution( + real_t * const xOpt /**< Output: Primal solution vector (if QP has been solved). */ + ) const; + + /** Returns the dual solution vector. + * \return SUCCESSFUL_RETURN \n + RET_QP_NOT_SOLVED */ + virtual returnValue getDualSolution( + real_t * const yOpt /**< Output: Dual solution vector (if QP has been solved). */ + ) const; + + /** Returns status of the solution process. + * \return Status of solution process. */ + inline QProblemStatus getStatus() const; + + /** Returns if the QProblem object is initialised. + * \return BT_TRUE: QProblemB initialised \n + BT_FALSE: QProblemB not initialised */ + inline BooleanType isInitialised() const; + + /** Returns if the QP has been solved. + * \return BT_TRUE: QProblemB solved \n + BT_FALSE: QProblemB not solved */ + inline BooleanType isSolved() const; + + /** Returns if the QP is infeasible. + * \return BT_TRUE: QP infeasible \n + BT_FALSE: QP feasible (or not known to be infeasible!) */ + inline BooleanType isInfeasible() const; + + /** Returns if the QP is unbounded. + * \return BT_TRUE: QP unbounded \n + BT_FALSE: QP unbounded (or not known to be unbounded!) */ + inline BooleanType isUnbounded() const; + + /** Returns Hessian type flag (type is not determined due to this call!). + * \return Hessian type. */ + inline HessianType getHessianType() const; + + /** Changes the print level. + * \return SUCCESSFUL_RETURN */ + inline returnValue setHessianType(HessianType _hessianType /**< New Hessian type. */ + ); + + /** Returns if the QP has been internally regularised. + * \return BT_TRUE: Hessian is internally regularised for QP solution \n + BT_FALSE: No internal Hessian regularisation is used for QP solution */ + inline BooleanType usingRegularisation() const; + + /** Returns current options struct. + * \return Current options struct. */ + inline Options getOptions() const; + + /** Overrides current options with given ones. + * \return SUCCESSFUL_RETURN */ + inline returnValue setOptions(const Options & _options /**< New options. */ + ); + + /** Returns the print level. + * \return Print level. */ + inline PrintLevel getPrintLevel() const; + + /** Changes the print level. + * \return SUCCESSFUL_RETURN */ + returnValue setPrintLevel(PrintLevel _printlevel /**< New print level. */ + ); + + /** Returns the current number of QP problems solved. + * \return Number of QP problems solved. */ + inline uint_t getCount() const; + + /** Resets QP problem counter (to zero). + * \return SUCCESSFUL_RETURN. */ + inline returnValue resetCounter(); + + /** Prints concise list of properties of the current QP. + * \return SUCCESSFUL_RETURN \n */ + virtual returnValue printProperties(); + + /** Prints a list of all options and their current values. + * \return SUCCESSFUL_RETURN \n */ + returnValue printOptions() const; + + /* + * PROTECTED MEMBER FUNCTIONS + */ +protected: + /** Frees all allocated memory. + * \return SUCCESSFUL_RETURN */ + returnValue clear(); + + /** Copies all members from given rhs object. + * \return SUCCESSFUL_RETURN */ + returnValue copy(const QProblemB & rhs /**< Rhs object. */ + ); + + /** If Hessian type has been set by the user, nothing is done. + * Otherwise the Hessian type is set to HST_IDENTITY, HST_ZERO, or + * HST_POSDEF (default), respectively. + * \return SUCCESSFUL_RETURN \n + RET_HESSIAN_INDEFINITE */ + returnValue determineHessianType(); + + /** Determines type of existing constraints and bounds (i.e. implicitly fixed, unbounded etc.). + * \return SUCCESSFUL_RETURN \n + RET_SETUPSUBJECTTOTYPE_FAILED */ + virtual returnValue setupSubjectToType(); + + /** Determines type of new constraints and bounds (i.e. implicitly fixed, unbounded etc.). + * \return SUCCESSFUL_RETURN \n + RET_SETUPSUBJECTTOTYPE_FAILED */ + virtual returnValue setupSubjectToType(const real_t * const lb_new, /**< New lower bounds. */ + const real_t * const ub_new /**< New upper bounds. */ + ); + + /** Computes the Cholesky decomposition of the (simply projected) Hessian + * (i.e. R^T*R = Z^T*H*Z). It only works in the case where Z is a simple + * projection matrix! + * Note: If Hessian turns out not to be positive definite, the Hessian type + * is set to HST_SEMIDEF accordingly. + * \return SUCCESSFUL_RETURN \n + * RET_HESSIAN_NOT_SPD \n + * RET_INDEXLIST_CORRUPTED */ + virtual returnValue computeCholesky(); + + /** Computes initial Cholesky decomposition of the (simply projected) Hessian + * making use of the function computeCholesky(). + * \return SUCCESSFUL_RETURN \n + * RET_HESSIAN_NOT_SPD \n + * RET_INDEXLIST_CORRUPTED */ + virtual returnValue setupInitialCholesky(); + + /** Obtains the desired working set for the auxiliary initial QP in + * accordance with the user specifications + * \return SUCCESSFUL_RETURN \n + RET_OBTAINING_WORKINGSET_FAILED \n + RET_INVALID_ARGUMENTS */ + returnValue obtainAuxiliaryWorkingSet( + const real_t * const xOpt, /**< Optimal primal solution vector. + * If a NULL pointer is passed, all entries are assumed to be zero. */ + const real_t * const yOpt, /**< Optimal dual solution vector. + * If a NULL pointer is passed, all entries are assumed to be zero. */ + const Bounds * const guessedBounds, /**< Guessed working set for solution (xOpt,yOpt). */ + Bounds * auxiliaryBounds /**< Input: Allocated bound object. \n + * Output: Working set for auxiliary QP. */ + ) const; + + /** Decides if lower bounds are smaller than upper bounds + * + * \return SUCCESSFUL_RETURN \n + * RET_QP_INFEASIBLE */ + + returnValue areBoundsConsistent(const real_t * const lb, /**< Vector of lower bounds*/ + const real_t * const ub /**< Vector of upper bounds*/ + ) const; + + /** Solves the system Ra = b or R^Ta = b where R is an upper triangular matrix. + * \return SUCCESSFUL_RETURN \n + RET_DIV_BY_ZERO */ + virtual returnValue backsolveR(const real_t * const b, /**< Right hand side vector. */ + BooleanType transposed, /**< Indicates if the transposed system shall be solved. */ + real_t * const a /**< Output: Solution vector */ + ) const; + + /** Solves the system Ra = b or R^Ta = b where R is an upper triangular matrix. \n + * Special variant for the case that this function is called from within "removeBound()". + * \return SUCCESSFUL_RETURN \n + RET_DIV_BY_ZERO */ + virtual returnValue backsolveR(const real_t * const b, /**< Right hand side vector. */ + BooleanType transposed, /**< Indicates if the transposed system shall be solved. */ + BooleanType removingBound, /**< Indicates if function is called from "removeBound()". */ + real_t * const a /**< Output: Solution vector */ + ) const; + + /** Determines step direction of the shift of the QP data. + * \return SUCCESSFUL_RETURN */ + returnValue determineDataShift(const real_t * const g_new, /**< New gradient vector. */ + const real_t * const lb_new, /**< New lower bounds. */ + const real_t * const ub_new, /**< New upper bounds. */ + real_t * const delta_g, /**< Output: Step direction of gradient vector. */ + real_t * const delta_lb, /**< Output: Step direction of lower bounds. */ + real_t * const delta_ub, /**< Output: Step direction of upper bounds. */ + BooleanType & Delta_bB_isZero /**< Output: Indicates if active bounds are to be shifted. */ + ); + + /** Sets up internal QP data. + * \return SUCCESSFUL_RETURN \n + RET_INVALID_ARGUMENTS */ + returnValue setupQPdata(SymmetricMatrix * _H, /**< Hessian matrix.*/ + const real_t * const _g, /**< Gradient vector. */ + const real_t * const _lb, /**< Lower bounds (on variables). \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const _ub /**< Upper bounds (on variables). \n + If no upper bounds exist, a NULL pointer can be passed. */ + ); + + /** Sets up internal QP data. If the current Hessian is trivial + * (i.e. HST_ZERO or HST_IDENTITY) but a non-trivial one is given, + * memory for Hessian is allocated and it is set to the given one. + * \return SUCCESSFUL_RETURN \n + RET_INVALID_ARGUMENTS \n + RET_NO_HESSIAN_SPECIFIED */ + returnValue setupQPdata(const real_t * const _H, /**< Hessian matrix. \n + If Hessian matrix is trivial,a NULL pointer can be passed. */ + const real_t * const _g, /**< Gradient vector. */ + const real_t * const _lb, /**< Lower bounds (on variables). \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const _ub /**< Upper bounds (on variables). \n + If no upper bounds exist, a NULL pointer can be passed. */ + ); + + /** Sets up internal QP data by loading it from files. If the current Hessian + * is trivial (i.e. HST_ZERO or HST_IDENTITY) but a non-trivial one is given, + * memory for Hessian is allocated and it is set to the given one. + * \return SUCCESSFUL_RETURN \n + RET_UNABLE_TO_OPEN_FILE \n + RET_UNABLE_TO_READ_FILE \n + RET_INVALID_ARGUMENTS \n + RET_NO_HESSIAN_SPECIFIED */ + returnValue setupQPdataFromFile( + const char * const H_file, /**< Name of file where Hessian matrix, of neighbouring QP to be solved, is + stored. \n If Hessian matrix is trivial,a NULL pointer can be passed. */ + const char * const + g_file, /**< Name of file where gradient, of neighbouring QP to be solved, is stored. */ + const char * const lb_file, /**< Name of file where lower bounds, of neighbouring QP to be solved, is + stored. \n If no lower bounds exist, a NULL pointer can be passed. */ + const char * const ub_file /**< Name of file where upper bounds, of neighbouring QP to be solved, is + stored. \n If no upper bounds exist, a NULL pointer can be passed. */ + ); + + /** Loads new QP vectors from files (internal members are not affected!). + * \return SUCCESSFUL_RETURN \n + RET_UNABLE_TO_OPEN_FILE \n + RET_UNABLE_TO_READ_FILE \n + RET_INVALID_ARGUMENTS */ + returnValue loadQPvectorsFromFile( + const char * const + g_file, /**< Name of file where gradient, of neighbouring QP to be solved, is stored. */ + const char * const lb_file, /**< Name of file where lower bounds, of neighbouring QP to be solved, is + stored. \n If no lower bounds exist, a NULL pointer can be passed. */ + const char * const ub_file, /**< Name of file where upper bounds, of neighbouring QP to be solved, is + stored. \n If no upper bounds exist, a NULL pointer can be passed. */ + real_t * const g_new, /**< Output: Gradient of neighbouring QP to be solved. */ + real_t * const lb_new, /**< Output: Lower bounds of neighbouring QP to be solved */ + real_t * const ub_new /**< Output: Upper bounds of neighbouring QP to be solved */ + ) const; + + /** Sets internal infeasibility flag and throws given error in case the far bound + * strategy is not enabled (as QP might actually not be infeasible in this case). + * \return RET_HOTSTART_STOPPED_INFEASIBILITY \n + RET_ENSURELI_FAILED_CYCLING \n + RET_ENSURELI_FAILED_NOINDEX */ + returnValue setInfeasibilityFlag(returnValue returnvalue, /**< Returnvalue to be tunneled. */ + BooleanType doThrowError = BT_FALSE /**< Flag forcing to throw an error. */ + ); + + /** Determines if next QP iteration can be performed within given CPU time limit. + * \return BT_TRUE: CPU time limit is exceeded, stop QP solution. \n + BT_FALSE: Sufficient CPU time for next QP iteration. */ + BooleanType isCPUtimeLimitExceeded( + const real_t * const cputime, /**< Maximum CPU time allowed for QP solution. */ + real_t starttime, /**< Start time of current QP solution. */ + int_t nWSR /**< Number of working set recalculations performed so far. */ + ) const; + + /** Regularise Hessian matrix by adding a scaled identity matrix to it. + * \return SUCCESSFUL_RETURN \n + RET_HESSIAN_ALREADY_REGULARISED */ + returnValue regulariseHessian(); + + /** Sets Hessian matrix of the QP. + * \return SUCCESSFUL_RETURN */ + inline returnValue setH(SymmetricMatrix * H_new /**< New Hessian matrix (a shallow copy is made). */ + ); + + /** Sets dense Hessian matrix of the QP. + * If a null pointer is passed and + * a) hessianType is HST_IDENTITY, nothing is done, + * b) hessianType is not HST_IDENTITY, Hessian matrix is set to zero. + * \return SUCCESSFUL_RETURN */ + inline returnValue setH(const real_t * const + H_new /**< New dense Hessian matrix (with correct dimension!), a shallow copy is made. */ + ); + + /** Changes gradient vector of the QP. + * \return SUCCESSFUL_RETURN \n + * RET_INVALID_ARGUMENTS */ + inline returnValue setG(const real_t * const g_new /**< New gradient vector (with correct dimension!). */ + ); + + /** Changes lower bound vector of the QP. + * \return SUCCESSFUL_RETURN \n + * RET_QPOBJECT_NOT_SETUP */ + inline returnValue setLB( + const real_t * const lb_new /**< New lower bound vector (with correct dimension!). */ + ); + + /** Changes single entry of lower bound vector of the QP. + * \return SUCCESSFUL_RETURN \n + * RET_QPOBJECT_NOT_SETUP \n + * RET_INDEX_OUT_OF_BOUNDS */ + inline returnValue setLB(int_t number, /**< Number of entry to be changed. */ + real_t value /**< New value for entry of lower bound vector. */ + ); + + /** Changes upper bound vector of the QP. + * \return SUCCESSFUL_RETURN \n + * RET_QPOBJECT_NOT_SETUP */ + inline returnValue setUB( + const real_t * const ub_new /**< New upper bound vector (with correct dimension!). */ + ); + + /** Changes single entry of upper bound vector of the QP. + * \return SUCCESSFUL_RETURN \n + * RET_QPOBJECT_NOT_SETUP \n + * RET_INDEX_OUT_OF_BOUNDS */ + inline returnValue setUB(int_t number, /**< Number of entry to be changed. */ + real_t value /**< New value for entry of upper bound vector. */ + ); + + /** Computes parameters for the Givens matrix G for which [x,y]*G = [z,0] + * \return SUCCESSFUL_RETURN */ + inline void computeGivens(real_t xold, /**< Matrix entry to be normalised. */ + real_t yold, /**< Matrix entry to be annihilated. */ + real_t & xnew, /**< Output: Normalised matrix entry. */ + real_t & ynew, /**< Output: Annihilated matrix entry. */ + real_t & c, /**< Output: Cosine entry of Givens matrix. */ + real_t & s /**< Output: Sine entry of Givens matrix. */ + ) const; + + /** Applies Givens matrix determined by c and s (cf. computeGivens). + * \return SUCCESSFUL_RETURN */ + inline void applyGivens(real_t c, /**< Cosine entry of Givens matrix. */ + real_t s, /**< Sine entry of Givens matrix. */ + real_t nu, /**< Further factor: s/(1+c). */ + real_t xold, /**< Matrix entry to be transformed corresponding to + * the normalised entry of the original matrix. */ + real_t yold, /**< Matrix entry to be transformed corresponding to + * the annihilated entry of the original matrix. */ + real_t & xnew, /**< Output: Transformed matrix entry corresponding to + * the normalised entry of the original matrix. */ + real_t & ynew /**< Output: Transformed matrix entry corresponding to + * the annihilated entry of the original matrix. */ + ) const; + + /** Compute relative length of homotopy in data space for termination + * criterion. + * \return Relative length in data space. */ + real_t getRelativeHomotopyLength(const real_t * const g_new, /**< Final gradient. */ + const real_t * const lb_new, /**< Final lower variable bounds. */ + const real_t * const ub_new /**< Final upper variable bounds. */ + ); + + /** Ramping Strategy to avoid ties. Modifies homotopy start without + * changing current active set. + * \return SUCCESSFUL_RETURN */ + virtual returnValue performRamping(); + + /** ... */ + returnValue updateFarBounds(real_t curFarBound, /**< ... */ + int_t nRamp, /**< ... */ + const real_t * const lb_new, /**< ... */ + real_t * const lb_new_far, /**< ... */ + const real_t * const ub_new, /**< ... */ + real_t * const ub_new_far /**< ... */ + ) const; + + /** Performs robustified ratio test yield the maximum possible step length + * along the homotopy path. + * \return SUCCESSFUL_RETURN */ + returnValue performRatioTest(int_t nIdx, /**< Number of ratios to be checked. */ + const int_t * const idxList, /**< Array containing the indices of all ratios to be checked. */ + const SubjectTo * const + subjectTo, /**< Bound/Constraint object corresponding to ratios to be checked. */ + const real_t * const num, /**< Array containing all numerators for performing the ratio test. */ + const real_t * const den, /**< Array containing all denominators for performing the ratio test. */ + real_t epsNum, /**< Numerator tolerance. */ + real_t epsDen, /**< Denominator tolerance. */ + real_t & t, /**< Output: Maximum possible step length along the homotopy path. */ + int_t & BC_idx /**< Output: Index of blocking constraint. */ + ) const; + + /** Checks whether given ratio is blocking, i.e. limits the maximum step length + * along the homotopy path to a value lower than given one. + * \return SUCCESSFUL_RETURN */ + inline BooleanType isBlocking(real_t num, /**< Numerator for performing the ratio test. */ + real_t den, /**< Denominator for performing the ratio test. */ + real_t epsNum, /**< Numerator tolerance. */ + real_t epsDen, /**< Denominator tolerance. */ + real_t & t /**< Input: Current maximum step length along the homotopy path, + * Output: Updated maximum possible step length along the homotopy path. */ + ) const; + + /** Creates a sparse diagonal (square-)matrix which is a given + * multiple of the identity matrix. + * \return Diagonal matrix \n + */ + SymSparseMat * createDiagSparseMat(int_t n, /**< Row/column dimension of matrix to be created. */ + real_t diagVal = 1.0 /**< Value of all diagonal entries. */ + ); + + /* + * PRIVATE MEMBER FUNCTIONS + */ +private: + /** Solves a QProblemB whose QP data is assumed to be stored in the member variables. + * A guess for its primal/dual optimal solution vectors and the corresponding + * optimal working set can be provided. + * Note: This function is internally called by all init functions! + * \return SUCCESSFUL_RETURN \n + RET_INIT_FAILED \n + RET_INIT_FAILED_CHOLESKY \n + RET_INIT_FAILED_HOTSTART \n + RET_INIT_FAILED_INFEASIBILITY \n + RET_INIT_FAILED_UNBOUNDEDNESS \n + RET_MAX_NWSR_REACHED */ + returnValue solveInitialQP(const real_t * const xOpt, /**< Optimal primal solution vector.*/ + const real_t * const yOpt, /**< Optimal dual solution vector. */ + const Bounds * const guessedBounds, /**< Optimal working set of bounds for solution (xOpt,yOpt). */ + const real_t * const _R, /**< Pre-computed (upper triangular) Cholesky factor of Hessian matrix. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + * Output: Number of performed working set recalculations. */ + real_t * const cputime /**< Input: Maximum CPU time allowed for QP solution. \n + Output: CPU time spent for QP solution (or to perform nWSR iterations). */ + ); + + /** Solves an initialised QProblemB using online active set strategy. + * Note: This function is internally called by all hotstart functions! + * \return SUCCESSFUL_RETURN \n + RET_MAX_NWSR_REACHED \n + RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n + RET_HOTSTART_FAILED \n + RET_SHIFT_DETERMINATION_FAILED \n + RET_STEPDIRECTION_DETERMINATION_FAILED \n + RET_STEPLENGTH_DETERMINATION_FAILED \n + RET_HOMOTOPY_STEP_FAILED \n + RET_HOTSTART_STOPPED_INFEASIBILITY \n + RET_HOTSTART_STOPPED_UNBOUNDEDNESS */ + returnValue solveQP(const real_t * const g_new, /**< Gradient of neighbouring QP to be solved. */ + const real_t * const lb_new, /**< Lower bounds of neighbouring QP to be solved. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const ub_new, /**< Upper bounds of neighbouring QP to be solved. \n + If no upper bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Number of performed working set recalculations. */ + real_t * const cputime, /**< Input: Maximum CPU time allowed for QP solution. \n + Output: CPU time spent for QP solution (or to perform nWSR iterations). */ + int_t nWSRperformed = 0, /**< Number of working set recalculations already performed to solve + this QP within previous solveQP() calls. This number is + always zero, except for successive calls from solveRegularisedQP() + or when using the far bound strategy. */ + BooleanType isFirstCall = BT_TRUE /**< Indicating whether this is the first call for current QP. */ + ); + + /** Solves an initialised QProblemB using online active set strategy. + * Note: This function is internally called by all hotstart functions! + * \return SUCCESSFUL_RETURN \n + RET_MAX_NWSR_REACHED \n + RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n + RET_HOTSTART_FAILED \n + RET_SHIFT_DETERMINATION_FAILED \n + RET_STEPDIRECTION_DETERMINATION_FAILED \n + RET_STEPLENGTH_DETERMINATION_FAILED \n + RET_HOMOTOPY_STEP_FAILED \n + RET_HOTSTART_STOPPED_INFEASIBILITY \n + RET_HOTSTART_STOPPED_UNBOUNDEDNESS */ + returnValue solveRegularisedQP( + const real_t * const g_new, /**< Gradient of neighbouring QP to be solved. */ + const real_t * const lb_new, /**< Lower bounds of neighbouring QP to be solved. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const ub_new, /**< Upper bounds of neighbouring QP to be solved. \n + If no upper bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Number of performed working set recalculations. */ + real_t * const cputime, /**< Input: Maximum CPU time allowed for QP solution. \n + Output: CPU time spent for QP solution (or to perform nWSR iterations). */ + int_t nWSRperformed = 0, /**< Number of working set recalculations already performed to solve + this QP within previous solveRegularisedQP() calls. This number is + always zero, except for successive calls when using the far bound strategy. */ + BooleanType isFirstCall = BT_TRUE /**< Indicating whether this is the first call for current QP. */ + ); + + /** Sets up bound data structure according to auxiliaryBounds. + * (If the working set shall be setup afresh, make sure that + * bounds data structure has been resetted!) + * \return SUCCESSFUL_RETURN \n + RET_SETUP_WORKINGSET_FAILED \n + RET_INVALID_ARGUMENTS \n + RET_UNKNOWN_BUG */ + returnValue setupAuxiliaryWorkingSet( + const Bounds * const auxiliaryBounds, /**< Working set for auxiliary QP. */ + BooleanType setupAfresh /**< Flag indicating if given working set shall be + * setup afresh or by updating the current one. */ + ); + + /** Sets up the optimal primal/dual solution of the auxiliary initial QP. + * \return SUCCESSFUL_RETURN */ + returnValue setupAuxiliaryQPsolution( + const real_t * const xOpt, /**< Optimal primal solution vector. + * If a NULL pointer is passed, all entries are set to zero. */ + const real_t * const yOpt /**< Optimal dual solution vector. + * If a NULL pointer is passed, all entries are set to zero. */ + ); + + /** Sets up gradient of the auxiliary initial QP for given + * optimal primal/dual solution and given initial working set + * (assumes that members X, Y and BOUNDS have already been initialised!). + * \return SUCCESSFUL_RETURN */ + returnValue setupAuxiliaryQPgradient(); + + /** Sets up bounds of the auxiliary initial QP for given + * optimal primal/dual solution and given initial working set + * (assumes that members X, Y and BOUNDS have already been initialised!). + * \return SUCCESSFUL_RETURN \n + RET_UNKNOWN_BUG */ + returnValue setupAuxiliaryQPbounds( + BooleanType useRelaxation /**< Flag indicating if inactive bounds shall be relaxed. */ + ); + +protected: + /** Updates QP vectors, working sets and internal data structures in order to + start from an optimal solution corresponding to initial guesses of the working + set for bounds + * \return SUCCESSFUL_RETURN \n + * RET_SETUP_AUXILIARYQP_FAILED */ + virtual returnValue setupAuxiliaryQP( + const Bounds * const guessedBounds /**< Initial guess for working set of bounds. */ + ); + +private: + /** Determines step direction of the homotopy path. + * \return SUCCESSFUL_RETURN \n + RET_STEPDIRECTION_FAILED_CHOLESKY */ + returnValue determineStepDirection( + const real_t * const delta_g, /**< Step direction of gradient vector. */ + const real_t * const delta_lb, /**< Step direction of lower bounds. */ + const real_t * const delta_ub, /**< Step direction of upper bounds. */ + BooleanType Delta_bB_isZero, /**< Indicates if active bounds are to be shifted. */ + real_t * const delta_xFX, /**< Output: Primal homotopy step direction of fixed variables. */ + real_t * const delta_xFR, /**< Output: Primal homotopy step direction of free variables. */ + real_t * const delta_yFX /**< Output: Dual homotopy step direction of fixed variables' multiplier. */ + ); + + /** Determines the maximum possible step length along the homotopy path + * and performs this step (without changing working set). + * \return SUCCESSFUL_RETURN \n + * RET_QP_INFEASIBLE \n + */ + returnValue performStep(const real_t * const delta_g, /**< Step direction of gradient. */ + const real_t * const delta_lb, /**< Step direction of lower bounds. */ + const real_t * const delta_ub, /**< Step direction of upper bounds. */ + const real_t * const delta_xFX, /**< Primal homotopy step direction of fixed variables. */ + const real_t * const delta_xFR, /**< Primal homotopy step direction of free variables. */ + const real_t * const delta_yFX, /**< Dual homotopy step direction of fixed variables' multiplier. */ + int_t & BC_idx, /**< Output: Index of blocking constraint. */ + SubjectToStatus & BC_status /**< Output: Status of blocking constraint. */ + ); + + /** Updates active set. + * \return SUCCESSFUL_RETURN \n + RET_REMOVE_FROM_ACTIVESET_FAILED \n + RET_ADD_TO_ACTIVESET_FAILED */ + returnValue changeActiveSet(int_t BC_idx, /**< Index of blocking constraint. */ + SubjectToStatus BC_status /**< Status of blocking constraint. */ + ); + + /** Drift correction at end of each active set iteration + * \return SUCCESSFUL_RETURN */ + virtual returnValue performDriftCorrection(); + + /** Determines if it is more efficient to refactorise the matrices when + * hotstarting or not (i.e. better to update the existing factorisations). + * \return BT_TRUE iff matrices shall be refactorised afresh + */ + BooleanType shallRefactorise(const Bounds * const guessedBounds /**< Guessed new working set. */ + ) const; + + /** Adds a bound to active set (specialised version for the case where no constraints exist). + * \return SUCCESSFUL_RETURN \n + RET_ADDBOUND_FAILED */ + returnValue addBound(int_t number, /**< Number of bound to be added to active set. */ + SubjectToStatus B_status, /**< Status of new active bound. */ + BooleanType updateCholesky /**< Flag indicating if Cholesky decomposition shall be updated. */ + ); + + /** Removes a bounds from active set (specialised version for the case where no constraints exist). + * \return SUCCESSFUL_RETURN \n + RET_HESSIAN_NOT_SPD \n + RET_REMOVEBOUND_FAILED */ + returnValue removeBound(int_t number, /**< Number of bound to be removed from active set. */ + BooleanType updateCholesky /**< Flag indicating if Cholesky decomposition shall be updated. */ + ); + + /** Prints concise information on the current iteration. + * \return SUCCESSFUL_RETURN \n */ + returnValue printIteration(int_t iter, /**< Number of current iteration. */ + int_t BC_idx, /**< Index of blocking bound. */ + SubjectToStatus BC_status, /**< Status of blocking bound. */ + real_t homotopyLength, /**< Current homotopy distance. */ + BooleanType isFirstCall = BT_TRUE /**< Indicating whether this is the first call for current QP. */ + ); + + /* + * PROTECTED MEMBER VARIABLES + */ +protected: + BooleanType freeHessian; /**< Flag indicating whether the Hessian matrix needs to be de-allocated. */ + SymmetricMatrix * H; /**< Hessian matrix. */ + + real_t * g; /**< Gradient. */ + real_t * lb; /**< Lower bound vector (on variables). */ + real_t * ub; /**< Upper bound vector (on variables). */ + + Bounds bounds; /**< Data structure for problem's bounds. */ + + real_t * R; /**< Cholesky factor of H (i.e. H = R^T*R). */ + BooleanType haveCholesky; /**< Flag indicating whether Cholesky decomposition has already been setup. */ + + real_t * x; /**< Primal solution vector. */ + real_t * y; /**< Dual solution vector. */ + + real_t tau; /**< Last homotopy step length. */ + + QProblemStatus status; /**< Current status of the solution process. */ + + BooleanType infeasible; /**< QP infeasible? */ + BooleanType unbounded; /**< QP unbounded? */ + + HessianType hessianType; /**< Type of Hessian matrix. */ + real_t regVal; /**< Holds the offset used to regularise Hessian matrix (zero by default). */ + + uint_t count; /**< Counts the number of hotstart function calls. */ + + real_t * delta_xFR_TMP; /**< Temporary for determineStepDirection */ + + real_t ramp0; /**< Start value for Ramping Strategy. */ + real_t ramp1; /**< Final value for Ramping Strategy. */ + int_t rampOffset; /**< Offset index for Ramping. */ + + Options options; /**< Struct containing all user-defined options for solving QPs. */ + + Flipper flipper; /**< Struct for making a temporary copy of the matrix factorisations. */ + + TabularOutput + tabularOutput; /**< Struct storing information for tabular output (printLevel == PL_TABULAR). */ +}; + +END_NAMESPACE_QPOASES + +#include + +#endif /* QPOASES_QPROBLEMB_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/QProblemB.ipp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/QProblemB.ipp new file mode 100755 index 0000000..6831374 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/QProblemB.ipp @@ -0,0 +1,496 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file include/qpOASES/QProblemB.ipp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of inlined member functions of the QProblemB class which + * is able to use the newly developed online active set strategy for + * parametric quadratic programming. + */ + + + +BEGIN_NAMESPACE_QPOASES + + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +/* + * g e t B o u n d s + */ +inline returnValue QProblemB::getBounds( Bounds& _bounds ) const +{ + int_t nV = getNV( ); + + if ( nV == 0 ) + return THROWERROR( RET_QPOBJECT_NOT_SETUP ); + + _bounds = bounds; + + return SUCCESSFUL_RETURN; +} + + +/* + * g e t N V + */ +inline int_t QProblemB::getNV( ) const +{ + return bounds.getNV( ); +} + + +/* + * g e t N F R + */ +inline int_t QProblemB::getNFR( ) const +{ + return bounds.getNFR( ); +} + + +/* + * g e t N F X + */ +inline int_t QProblemB::getNFX( ) const +{ + return bounds.getNFX( ); +} + + +/* + * g e t N F V + */ +inline int_t QProblemB::getNFV( ) const +{ + return bounds.getNFV( ); +} + + +/* + * g e t S t a t u s + */ +inline QProblemStatus QProblemB::getStatus( ) const +{ + return status; +} + + +/* + * i s I n i t i a l i s e d + */ +inline BooleanType QProblemB::isInitialised( ) const +{ + if ( status == QPS_NOTINITIALISED ) + return BT_FALSE; + else + return BT_TRUE; +} + + +/* + * i s S o l v e d + */ +inline BooleanType QProblemB::isSolved( ) const +{ + if ( status == QPS_SOLVED ) + return BT_TRUE; + else + return BT_FALSE; +} + + +/* + * i s I n f e a s i b l e + */ +inline BooleanType QProblemB::isInfeasible( ) const +{ + return infeasible; +} + + +/* + * i s U n b o u n d e d + */ +inline BooleanType QProblemB::isUnbounded( ) const +{ + return unbounded; +} + + +/* + * g e t H e s s i a n T y p e + */ +inline HessianType QProblemB::getHessianType( ) const +{ + return hessianType; +} + + +/* + * s e t H e s s i a n T y p e + */ +inline returnValue QProblemB::setHessianType( HessianType _hessianType ) +{ + hessianType = _hessianType; + return SUCCESSFUL_RETURN; +} + + +/* + * u s i n g R e g u l a r i s a t i o n + */ +inline BooleanType QProblemB::usingRegularisation( ) const +{ + if ( regVal > ZERO ) + return BT_TRUE; + else + return BT_FALSE; +} + + +/* + * g e t O p t i o n s + */ +inline Options QProblemB::getOptions( ) const +{ + return options; +} + + +/* + * s e t O p t i o n s + */ +inline returnValue QProblemB::setOptions( const Options& _options + ) +{ + options = _options; + options.ensureConsistency( ); + + setPrintLevel( options.printLevel ); + + return SUCCESSFUL_RETURN; +} + + +/* + * g e t P r i n t L e v e l + */ +inline PrintLevel QProblemB::getPrintLevel( ) const +{ + return options.printLevel; +} + + + +/* + * g e t C o u n t + */ +inline uint_t QProblemB::getCount( ) const +{ + return count; +} + + +/* + * r e s e t C o u n t e r + */ +inline returnValue QProblemB::resetCounter( ) +{ + count = 0; + return SUCCESSFUL_RETURN; +} + + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + +/* + * s e t H + */ +inline returnValue QProblemB::setH( SymmetricMatrix* H_new ) +{ + if ( ( freeHessian == BT_TRUE ) && ( H != 0 ) ) + { + delete H; + H = 0; + } + + H = H_new; + freeHessian = BT_FALSE; + + return SUCCESSFUL_RETURN; +} + + +/* + * s e t H + */ +inline returnValue QProblemB::setH( const real_t* const H_new ) +{ + int_t nV = getNV(); + SymDenseMat* dH; + + /* if null pointer is passed, Hessian is set to zero matrix + * (or stays identity matrix) */ + if ( H_new == 0 ) + { + if ( hessianType == HST_IDENTITY ) + return SUCCESSFUL_RETURN; + + hessianType = HST_ZERO; + + if ( ( freeHessian == BT_TRUE ) && ( H != 0 ) ) + delete H; + + H = 0; + freeHessian = BT_FALSE; + } + else + { + if ( ( freeHessian == BT_TRUE ) && ( H != 0 ) ) + delete H; + + H = dH = new SymDenseMat( nV, nV, nV, (real_t*) H_new ); + freeHessian = BT_TRUE; + } + + return SUCCESSFUL_RETURN; +} + + +/* + * s e t G + */ +inline returnValue QProblemB::setG( const real_t* const g_new ) +{ + uint_t nV = (uint_t)getNV( ); + + if ( nV == 0 ) + return THROWERROR( RET_QPOBJECT_NOT_SETUP ); + + if ( g_new == 0 ) + return THROWERROR( RET_INVALID_ARGUMENTS ); + + memcpy( g,g_new,nV*sizeof(real_t) ); + + return SUCCESSFUL_RETURN; +} + + +/* + * s e t L B + */ +inline returnValue QProblemB::setLB( const real_t* const lb_new ) +{ + uint_t i; + uint_t nV = (uint_t)getNV( ); + + if ( nV == 0 ) + return THROWERROR( RET_QPOBJECT_NOT_SETUP ); + + if ( lb_new != 0 ) + { + memcpy( lb,lb_new,nV*sizeof(real_t) ); + } + else + { + /* if no lower bounds are specified, set them to -infinity */ + for( i=0; i= 0 ) && ( number < nV ) ) + { + lb[number] = value; + return SUCCESSFUL_RETURN; + } + else + { + return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); + } +} + + +/* + * s e t U B + */ +inline returnValue QProblemB::setUB( const real_t* const ub_new ) +{ + uint_t i; + uint_t nV = (uint_t)getNV( ); + + if ( nV == 0 ) + return THROWERROR( RET_QPOBJECT_NOT_SETUP ); + + if ( ub_new != 0 ) + { + memcpy( ub,ub_new,nV*sizeof(real_t) ); + } + else + { + /* if no upper bounds are specified, set them to infinity */ + for( i=0; i= 0 ) && ( number < nV ) ) + { + ub[number] = value; + + return SUCCESSFUL_RETURN; + } + else + { + return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); + } +} + + +/* + * c o m p u t e G i v e n s + */ +inline void QProblemB::computeGivens( real_t xold, real_t yold, real_t& xnew, real_t& ynew, + real_t& c, real_t& s + ) const +{ + real_t t, mu; + + if ( isZero( yold ) == BT_TRUE ) + { + c = 1.0; + s = 0.0; + + xnew = xold; + ynew = yold; + } + else + { + mu = getAbs( xold ); + if ( getAbs( yold ) > mu ) + mu = getAbs( yold ); + + t = mu * getSqrt( (xold/mu)*(xold/mu) + (yold/mu)*(yold/mu) ); + + if ( xold < 0.0 ) + t = -t; + + c = xold/t; + s = yold/t; + xnew = t; + ynew = 0.0; + } + + return; +} + + +/* + * a p p l y G i v e n s + */ +inline void QProblemB::applyGivens( real_t c, real_t s, real_t nu, real_t xold, real_t yold, + real_t& xnew, real_t& ynew + ) const +{ + #ifdef __USE_THREE_MULTS_GIVENS__ + + /* Givens plane rotation requiring only three multiplications, + * cf. Hammarling, S.: A note on modifications to the givens plane rotation. + * J. Inst. Maths Applics, 13:215-218, 1974. */ + xnew = xold*c + yold*s; + ynew = (xnew+xold)*nu - yold; + + #else + + /* Usual Givens plane rotation requiring four multiplications. */ + xnew = c*xold + s*yold; + ynew = -s*xold + c*yold; + + #endif + + return; +} + + +/* + * i s B l o c k i n g + */ +inline BooleanType QProblemB::isBlocking( real_t num, + real_t den, + real_t epsNum, + real_t epsDen, + real_t& t + ) const +{ + if ( ( den >= epsDen ) && ( num >= epsNum ) ) + { + if ( num < t*den ) + return BT_TRUE; + } + + return BT_FALSE; +} + + +END_NAMESPACE_QPOASES + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SQProblem.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SQProblem.hpp new file mode 100644 index 0000000..fe0283e --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SQProblem.hpp @@ -0,0 +1,359 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/SQProblem.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Declaration of the SQProblem class which is able to use the newly + * developed online active set strategy for parametric quadratic programming + * with varying matrices. + */ + +#ifndef QPOASES_SQPROBLEM_HPP +#define QPOASES_SQPROBLEM_HPP + +#include + +BEGIN_NAMESPACE_QPOASES + +/** + * \brief Implements the online active set strategy for QPs with varying matrices. + * + * A class for setting up and solving quadratic programs with varying QP matrices. + * The main feature is the possibily to use the newly developed online active set strategy + * for parametric quadratic programming. + * + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + */ +class SQProblem : public QProblem +{ + /* allow SolutionAnalysis class to access private members */ + friend class SolutionAnalysis; + + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + SQProblem(); + + /** Constructor which takes the QP dimension and Hessian type + * information. If the Hessian is the zero (i.e. HST_ZERO) or the + * identity matrix (i.e. HST_IDENTITY), respectively, no memory + * is allocated for it and a NULL pointer can be passed for it + * to the init() functions. */ + SQProblem(int_t _nV, /**< Number of variables. */ + int_t _nC, /**< Number of constraints. */ + HessianType _hessianType = HST_UNKNOWN, /**< Type of Hessian matrix. */ + BooleanType allocDenseMats = BT_TRUE /**< Enable allocation of dense matrices. */ + ); + + /** Copy constructor (deep copy). */ + SQProblem(const SQProblem & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + virtual ~SQProblem(); + + /** Assignment operator (deep copy). */ + virtual SQProblem & operator=(const SQProblem & rhs /**< Rhs object. */ + ); + + /** Solves an initialised QP sequence with matrix shift using + * the online active set strategy. + * \return SUCCESSFUL_RETURN \n + RET_MAX_NWSR_REACHED \n + RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n + RET_HOTSTART_FAILED \n + RET_MATRIX_SHIFT_FAILED \n + RET_SHIFT_DETERMINATION_FAILED \n + RET_STEPDIRECTION_DETERMINATION_FAILED \n + RET_STEPLENGTH_DETERMINATION_FAILED \n + RET_HOMOTOPY_STEP_FAILED \n + RET_HOTSTART_STOPPED_INFEASIBILITY \n + RET_HOTSTART_STOPPED_UNBOUNDEDNESS \n + RET_SETUP_AUXILIARYQP_FAILED */ + returnValue hotstart( + SymmetricMatrix * H_new, /**< Hessian matrix of neighbouring QP to be solved (a shallow copy is made). + \n If Hessian matrix is trivial, a NULL pointer can be passed. */ + const real_t * const g_new, /**< Gradient of neighbouring QP to be solved. */ + Matrix * A_new, /**< Constraint matrix of neighbouring QP to be solved (a shallow copy is made). \n + If QP sequence does not involve constraints, a NULL pointer can be passed. */ + const real_t * const lb_new, /**< Lower bounds of neighbouring QP to be solved. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const ub_new, /**< Upper bounds of neighbouring QP to be solved. \n + If no upper bounds exist, a NULL pointer can be passed. */ + const real_t * const lbA_new, /**< Lower constraints' bounds of neighbouring QP to be solved. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const real_t * const ubA_new, /**< Upper constraints' bounds of neighbouring QP to be solved. \n + If no upper constraints' bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Number of performed working set recalculations. */ + real_t * const cputime = 0, /**< Input: Maximum CPU time allowed for QP solution. \n + Output: CPU time spen for QP solution (or to perform nWSR iterations). */ + const Bounds * const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n + (If a null pointer is passed, the previous working set of bounds is kept!) */ + const Constraints * const guessedConstraints = + 0 /**< Optimal working set of constraints for solution (xOpt,yOpt). \n +(If a null pointer is passed, the previous working set of constraints is kept!) */ + ); + + /** Solves an initialised QP sequence with matrix shift using + * the online active set strategy. + * \return SUCCESSFUL_RETURN \n + RET_MAX_NWSR_REACHED \n + RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n + RET_HOTSTART_FAILED \n + RET_MATRIX_SHIFT_FAILED \n + RET_SHIFT_DETERMINATION_FAILED \n + RET_STEPDIRECTION_DETERMINATION_FAILED \n + RET_STEPLENGTH_DETERMINATION_FAILED \n + RET_HOMOTOPY_STEP_FAILED \n + RET_HOTSTART_STOPPED_INFEASIBILITY \n + RET_HOTSTART_STOPPED_UNBOUNDEDNESS \n + RET_SETUP_AUXILIARYQP_FAILED */ + returnValue hotstart( + const real_t * const H_new, /**< Hessian matrix of neighbouring QP to be solved (a shallow copy is + made). \n If Hessian matrix is trivial, a NULL pointer can be passed. */ + const real_t * const g_new, /**< Gradient of neighbouring QP to be solved. */ + const real_t * const A_new, /**< Constraint matrix of neighbouring QP to be solved (a shallow copy is + made). \n If QP sequence does not involve constraints, a NULL pointer can be passed. */ + const real_t * const lb_new, /**< Lower bounds of neighbouring QP to be solved. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const ub_new, /**< Upper bounds of neighbouring QP to be solved. \n + If no upper bounds exist, a NULL pointer can be passed. */ + const real_t * const lbA_new, /**< Lower constraints' bounds of neighbouring QP to be solved. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const real_t * const ubA_new, /**< Upper constraints' bounds of neighbouring QP to be solved. \n + If no upper constraints' bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Number of performed working set recalculations. */ + real_t * const cputime = 0, /**< Input: Maximum CPU time allowed for QP solution. \n + Output: CPU time spent for QP solution (or to perform nWSR iterations). */ + const Bounds * const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n + (If a null pointer is passed, the previous working set of bounds is kept!) */ + const Constraints * const guessedConstraints = + 0 /**< Optimal working set of constraints for solution (xOpt,yOpt). \n +(If a null pointer is passed, the previous working set of constraints is kept!) */ + ); + + /** Solves an initialised QP sequence with matrix shift using + * the online active set strategy, where QP data is read from files. + * \return SUCCESSFUL_RETURN \n + RET_MAX_NWSR_REACHED \n + RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n + RET_HOTSTART_FAILED \n + RET_MATRIX_SHIFT_FAILED \n + RET_SHIFT_DETERMINATION_FAILED \n + RET_STEPDIRECTION_DETERMINATION_FAILED \n + RET_STEPLENGTH_DETERMINATION_FAILED \n + RET_HOMOTOPY_STEP_FAILED \n + RET_HOTSTART_STOPPED_INFEASIBILITY \n + RET_HOTSTART_STOPPED_UNBOUNDEDNESS \n + RET_SETUP_AUXILIARYQP_FAILED \n + RET_UNABLE_TO_READ_FILE \n + RET_INVALID_ARGUMENTS */ + returnValue hotstart(const char * const H_file, /**< Name of file where Hessian matrix is stored. \n + If Hessian matrix is trivial, a NULL pointer can be passed. */ + const char * const + g_file, /**< Name of file where gradient, of neighbouring QP to be solved, is stored. */ + const char * const A_file, /**< Name of file where constraint matrix is stored. \n + If QP sequence does not involve constraints, a NULL pointer can be passed. */ + const char * const lb_file, /**< Name of file where lower bounds, of neighbouring QP to be solved, is + stored. \n If no lower bounds exist, a NULL pointer can be passed. */ + const char * const ub_file, /**< Name of file where upper bounds, of neighbouring QP to be solved, is + stored. \n If no upper bounds exist, a NULL pointer can be passed. */ + const char * const + lbA_file, /**< Name of file where lower constraints' bounds, of neighbouring QP to be solved, is + stored. \n If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const char * const + ubA_file, /**< Name of file where upper constraints' bounds, of neighbouring QP to be solved, is + stored. \n If no upper constraints' bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Number of performed working set recalculations. */ + real_t * const cputime = 0, /**< Input: Maximum CPU time allowed for QP solution. \n + Output: CPU time spent for QP solution (or to perform nWSR iterations). */ + const Bounds * const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n + (If a null pointer is passed, the previous working set of bounds is kept!) */ + const Constraints * const guessedConstraints = + 0 /**< Optimal working set of constraints for solution (xOpt,yOpt). \n +(If a null pointer is passed, the previous working set of constraints is kept!) */ + ); + + /** Solves an initialised QP sequence (without matrix shift) using + * the online active set strategy. + * By default, QP solution is started from previous solution. If a guess + * for the working set is provided, an initialised homotopy is performed. + * + * Note: This functions just forwards to the corresponding + * QProblem::hotstart member function. + * + * \return SUCCESSFUL_RETURN \n + RET_MAX_NWSR_REACHED \n + RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n + RET_HOTSTART_FAILED \n + RET_SHIFT_DETERMINATION_FAILED \n + RET_STEPDIRECTION_DETERMINATION_FAILED \n + RET_STEPLENGTH_DETERMINATION_FAILED \n + RET_HOMOTOPY_STEP_FAILED \n + RET_HOTSTART_STOPPED_INFEASIBILITY \n + RET_HOTSTART_STOPPED_UNBOUNDEDNESS */ + returnValue hotstart(const real_t * const g_new, /**< Gradient of neighbouring QP to be solved. */ + const real_t * const lb_new, /**< Lower bounds of neighbouring QP to be solved. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * const ub_new, /**< Upper bounds of neighbouring QP to be solved. \n + If no upper bounds exist, a NULL pointer can be passed. */ + const real_t * const lbA_new, /**< Lower constraints' bounds of neighbouring QP to be solved. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const real_t * const ubA_new, /**< Upper constraints' bounds of neighbouring QP to be solved. \n + If no upper constraints' bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Number of performed working set recalculations. */ + real_t * const cputime = 0, /**< Input: Maximum CPU time allowed for QP solution. \n + Output: CPU time spent for QP solution (or to perform nWSR iterations). */ + const Bounds * const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n + (If a null pointer is passed, the previous working set of bounds is kept!) */ + const Constraints * const guessedConstraints = + 0 /**< Optimal working set of constraints for solution (xOpt,yOpt). \n +(If a null pointer is passed, the previous working set of constraints is kept!) */ + ); + + /** Solves an initialised QP sequence (without matrix shift) using + * the online active set strategy, where QP data is read from files. + * By default, QP solution is started from previous solution. If a guess + * for the working set is provided, an initialised homotopy is performed. + * + * Note: This functions just forwards to the corresponding + * QProblem::hotstart member function. + * + * \return SUCCESSFUL_RETURN \n + RET_MAX_NWSR_REACHED \n + RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED \n + RET_HOTSTART_FAILED \n + RET_SHIFT_DETERMINATION_FAILED \n + RET_STEPDIRECTION_DETERMINATION_FAILED \n + RET_STEPLENGTH_DETERMINATION_FAILED \n + RET_HOMOTOPY_STEP_FAILED \n + RET_HOTSTART_STOPPED_INFEASIBILITY \n + RET_HOTSTART_STOPPED_UNBOUNDEDNESS \n + RET_UNABLE_TO_READ_FILE \n + RET_INVALID_ARGUMENTS */ + returnValue hotstart( + const char * const + g_file, /**< Name of file where gradient, of neighbouring QP to be solved, is stored. */ + const char * const lb_file, /**< Name of file where lower bounds, of neighbouring QP to be solved, is + stored. \n If no lower bounds exist, a NULL pointer can be passed. */ + const char * const ub_file, /**< Name of file where upper bounds, of neighbouring QP to be solved, is + stored. \n If no upper bounds exist, a NULL pointer can be passed. */ + const char * const + lbA_file, /**< Name of file where lower constraints' bounds, of neighbouring QP to be solved, is + stored. \n If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const char * const + ubA_file, /**< Name of file where upper constraints' bounds, of neighbouring QP to be solved, is + stored. \n If no upper constraints' bounds exist, a NULL pointer can be passed. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Number of performed working set recalculations. */ + real_t * const cputime = 0, /**< Input: Maximum CPU time allowed for QP solution. \n + Output: CPU time spent for QP solution (or to perform nWSR iterations). */ + const Bounds * const guessedBounds = 0, /**< Optimal working set of bounds for solution (xOpt,yOpt). \n + (If a null pointer is passed, the previous working set of bounds is kept!) */ + const Constraints * const guessedConstraints = + 0 /**< Optimal working set of constraints for solution (xOpt,yOpt). \n +(If a null pointer is passed, the previous working set of constraints is kept!) */ + ); + +#ifdef __MATLAB__ + /** Sets pointer of Hessian and constraint matrix to zero. + * QUICK HACK FOR MAKING THE MATLAB INTERFACE RUN! TO BE REMOVED! + * \return SUCCESSFUL_RETURN */ + returnValue resetMatrixPointers(); +#endif + + /* + * PROTECTED MEMBER FUNCTIONS + */ +protected: + /** Sets new matrices and calculates their factorisations. If the + * current Hessian is trivial (i.e. HST_ZERO or HST_IDENTITY) but a + * non-trivial one is given, memory for Hessian is allocated and + * it is set to the given one. Afterwards, all QP vectors are + * transformed in order to start from an optimal solution. + * \return SUCCESSFUL_RETURN \n + * RET_MATRIX_FACTORISATION_FAILED \n + * RET_NO_HESSIAN_SPECIFIED */ + virtual returnValue setupNewAuxiliaryQP(SymmetricMatrix * H_new, /**< New Hessian matrix. \n + If Hessian matrix is trivial, a NULL pointer can be passed. */ + Matrix * A_new, /**< New constraint matrix. \n + If QP sequence does not involve constraints, a NULL pointer can be passed. */ + const real_t * lb_new, /**< New lower bounds. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * ub_new, /**< New upper bounds. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * lbA_new, /**< New lower constraints' bounds. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const real_t * ubA_new /**< New lower constraints' bounds. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + ); + + /** Sets new matrices and calculates their factorisations. If the + * current Hessian is trivial (i.e. HST_ZERO or HST_IDENTITY) but a + * non-trivial one is given, memory for Hessian is allocated and + * it is set to the given one. Afterwards, all QP vectors are + * transformed in order to start from an optimal solution. + * \return SUCCESSFUL_RETURN \n + * RET_MATRIX_FACTORISATION_FAILED \n + * RET_NO_HESSIAN_SPECIFIED */ + virtual returnValue setupNewAuxiliaryQP(const real_t * const H_new, /**< New Hessian matrix. \n + If Hessian matrix is trivial, a NULL pointer can be passed. */ + const real_t * const A_new, /**< New constraint matrix. \n + If QP sequence does not involve constraints, a NULL pointer can be passed. */ + const real_t * lb_new, /**< New lower bounds. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * ub_new, /**< New upper bounds. \n + If no lower bounds exist, a NULL pointer can be passed. */ + const real_t * lbA_new, /**< New lower constraints' bounds. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + const real_t * ubA_new /**< New lower constraints' bounds. \n + If no lower constraints' bounds exist, a NULL pointer can be passed. */ + ); + + /* + * PROTECTED MEMBER VARIABLES + */ +protected: +}; + +END_NAMESPACE_QPOASES + +#include + +#endif /* QPOASES_SQPROBLEM_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SQProblem.ipp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SQProblem.ipp new file mode 100755 index 0000000..518bfc6 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SQProblem.ipp @@ -0,0 +1,51 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file include/qpOASES/SQProblem.ipp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of inlined member functions of the SQProblem class which + * is able to use the newly developed online active set strategy for + * parametric quadratic programming with varying matrices. + */ + + + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + + +BEGIN_NAMESPACE_QPOASES + + +END_NAMESPACE_QPOASES + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SQProblemSchur.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SQProblemSchur.hpp new file mode 100644 index 0000000..ec4038a --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SQProblemSchur.hpp @@ -0,0 +1,487 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2014 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/SQProblemSchur.hpp + * \author Andreas Waechter and Dennis Janka, based on QProblem.hpp by Hans Joachim Ferreau, Andreas + *Potschka, Christian Kirches \version 3.2 \date 2012-2017 + * + * Declaration of the SQProblemSchur class which is able to use the newly + * developed online active set strategy for parametric quadratic programming + * with varying matrices and uses a Schur Complement approach to solve + * the linear systems. + */ + +#ifndef QPOASES_SQPROBLEMSCHUR_HPP +#define QPOASES_SQPROBLEMSCHUR_HPP + +#include +#include + +BEGIN_NAMESPACE_QPOASES + +/** + * \brief Implements the online active set strategy for QPs with varying, sparse matrices. + * + * A class for setting up and solving quadratic programs with varying, + * sparse QP matrices. Here, sparsity is exploited by means of a + * Schur complement approach to solve the linear systems. + * + * \author Andreas Waechter, Dennis Janka + * \version 3.2 + * \date 2012-2017 + */ +class SQProblemSchur : public SQProblem +{ + /* allow SolutionAnalysis class to access private members */ + friend class SolutionAnalysis; + + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + SQProblemSchur(); + + /** Constructor which takes the QP dimension and Hessian type + * information. If the Hessian is the zero (i.e. HST_ZERO) or the + * identity matrix (i.e. HST_IDENTITY), respectively, no memory + * is allocated for it and a NULL pointer can be passed for it + * to the init() functions. */ + SQProblemSchur(int_t _nV, /**< Number of variables. */ + int_t _nC, /**< Number of constraints. */ + HessianType _hessianType = HST_UNKNOWN, /**< Type of Hessian matrix. */ + int_t maxSchurUpdates = 75 /**< Maximal number of Schur updates */ + ); + + /** Copy constructor (deep copy). */ + SQProblemSchur(const SQProblemSchur & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + virtual ~SQProblemSchur(); + + /** Assignment operator (deep copy). */ + virtual SQProblemSchur & operator=(const SQProblemSchur & rhs /**< Rhs object. */ + ); + + /** Clears all data structures of QProblem except for QP data. + * \return SUCCESSFUL_RETURN \n + RET_RESET_FAILED */ + virtual returnValue reset(); + + /** Resets Schur complement. This sets up the KKT matrix for the + current activities, copies the activities, etc. TODO: Return values */ + returnValue resetSchurComplement(BooleanType allowInertiaCorrection); + + /** Return the total number of sparse matrix factorizations performed so far. */ + inline int_t getNumFactorizations() const; + + /* + * PROTECTED MEMBER FUNCTIONS + */ +protected: + /** Frees all allocated memory. + * \return SUCCESSFUL_RETURN */ + returnValue clear(); + + /** Copies all members from given rhs object. + * \return SUCCESSFUL_RETURN */ + returnValue copy(const SQProblemSchur & rhs /**< Rhs object. */ + ); + + /** Computes the Cholesky decomposition of the projected Hessian (i.e. R^T*R = Z^T*H*Z). + * For the Schur complement version, this function only returns SUCCESSFUL_RETURN. */ + virtual returnValue computeProjectedCholesky(); + + /** Computes initial Cholesky decomposition of the projected Hessian making + * use of the function setupCholeskyDecomposition() or setupCholeskyDecompositionProjected(). + * For the Schur complement version, this function only returns SUCCESSFUL_RETURN. */ + virtual returnValue computeInitialCholesky(); + + /** Initialises TQ factorisation of A (i.e. A*Q = [0 T]) if NO constraint is active. + * For the Schur complement version, this function only returns SUCCESSFUL_RETURN. */ + virtual returnValue setupTQfactorisation(); + + /** This method is overloaded from SQProblem. + * Sets new matrices and calculates their factorisations. If the + * current Hessian is trivial (i.e. HST_ZERO or HST_IDENTITY) but a + * non-trivial one is given, memory for Hessian is allocated and + * it is set to the given one. Afterwards, all QP vectors are + * transformed in order to start from an optimal solution. + * \return SUCCESSFUL_RETURN \n + * RET_MATRIX_FACTORISATION_FAILED \n + * RET_NO_HESSIAN_SPECIFIED */ + virtual returnValue setupAuxiliaryQP(SymmetricMatrix * H_new, /**< New Hessian matrix. \n + If Hessian matrix is trivial, a NULL pointer can be passed. */ + Matrix * A_new, /**< New constraint matrix. \n + If QP sequence does not involve constraints, a NULL pointer can be passed. */ + const real_t * lb_new, + const real_t * ub_new, + const real_t * lbA_new, + const real_t * ubA_new); + + /** Setup bounds and constraints data structures according to auxiliaryBounds/Constraints. + * Calls the sparse solver to obtain the factorization for the initial active set. + * \return SUCCESSFUL_RETURN \n + RET_SETUP_WORKINGSET_FAILED \n + RET_INVALID_ARGUMENTS \n + RET_UNKNOWN_BUG */ + virtual returnValue setupAuxiliaryWorkingSet(const Bounds * const auxiliaryBounds, + const Constraints * const auxiliaryConstraints, + BooleanType setupAfresh); + + /** Adds a constraint to active set. + * \return SUCCESSFUL_RETURN \n + RET_ADDCONSTRAINT_FAILED \n + RET_ADDCONSTRAINT_FAILED_INFEASIBILITY \n + RET_ENSURELI_FAILED */ + virtual returnValue addConstraint(int_t number, /**< Number of constraint to be added to active set. */ + SubjectToStatus C_status, /**< Status of new active constraint. */ + BooleanType updateCholesky, /**< Flag indicating if Cholesky decomposition shall be updated. */ + BooleanType ensureLI = BT_TRUE /**< Ensure linear independence by exchange rules by default. */ + ); + + /** Checks if new active constraint to be added is linearly dependent from + * from row of the active constraints matrix. + * \return RET_LINEARLY_DEPENDENT \n + RET_LINEARLY_INDEPENDENT \n + RET_INDEXLIST_CORRUPTED */ + virtual returnValue addConstraint_checkLI( + int_t number /**< Number of constraint to be added to active set. */ + ); + + /** Ensures linear independence of constraint matrix when a new constraint is added. + * To this end a bound or constraint is removed simultaneously if necessary. + * \return SUCCESSFUL_RETURN \n + RET_LI_RESOLVED \n + RET_ENSURELI_FAILED \n + RET_ENSURELI_FAILED_TQ \n + RET_ENSURELI_FAILED_NOINDEX \n + RET_REMOVE_FROM_ACTIVESET */ + virtual returnValue addConstraint_ensureLI( + int_t number, /**< Number of constraint to be added to active set. */ + SubjectToStatus C_status /**< Status of new active bound. */ + ); + + /** Adds a bound to active set. + * \return SUCCESSFUL_RETURN \n + RET_ADDBOUND_FAILED \n + RET_ADDBOUND_FAILED_INFEASIBILITY \n + RET_ENSURELI_FAILED */ + virtual returnValue addBound(int_t number, /**< Number of bound to be added to active set. */ + SubjectToStatus B_status, /**< Status of new active bound. */ + BooleanType updateCholesky, /**< Flag indicating if Cholesky decomposition shall be updated. */ + BooleanType ensureLI = BT_TRUE /**< Ensure linear independence by exchange rules by default. */ + ); + + /** Checks if new active bound to be added is linearly dependent from + * from row of the active constraints matrix. + * \return RET_LINEARLY_DEPENDENT \n + RET_LINEARLY_INDEPENDENT */ + virtual returnValue addBound_checkLI(int_t number /**< Number of bound to be added to active set. */ + ); + + /** Ensures linear independence of constraint matrix when a new bound is added. + * To this end a bound or constraint is removed simultaneously if necessary. + * \return SUCCESSFUL_RETURN \n + RET_LI_RESOLVED \n + RET_ENSURELI_FAILED \n + RET_ENSURELI_FAILED_TQ \n + RET_ENSURELI_FAILED_NOINDEX \n + RET_REMOVE_FROM_ACTIVESET */ + virtual returnValue addBound_ensureLI(int_t number, /**< Number of bound to be added to active set. */ + SubjectToStatus B_status /**< Status of new active bound. */ + ); + + /** Removes a constraint from active set. + * \return SUCCESSFUL_RETURN \n + RET_CONSTRAINT_NOT_ACTIVE \n + RET_REMOVECONSTRAINT_FAILED \n + RET_HESSIAN_NOT_SPD */ + virtual returnValue removeConstraint( + int_t number, /**< Number of constraint to be removed from active set. */ + BooleanType updateCholesky, /**< Flag indicating if Cholesky decomposition shall be updated. */ + BooleanType allowFlipping = BT_FALSE, /**< Flag indicating if flipping bounds are allowed. */ + BooleanType ensureNZC = + BT_FALSE /**< Flag indicating if non-zero curvature is ensured by exchange rules. */ + ); + + /** Removes a bounds from active set. + * \return SUCCESSFUL_RETURN \n + RET_BOUND_NOT_ACTIVE \n + RET_HESSIAN_NOT_SPD \n + RET_REMOVEBOUND_FAILED */ + virtual returnValue removeBound(int_t number, /**< Number of bound to be removed from active set. */ + BooleanType updateCholesky, /**< Flag indicating if Cholesky decomposition shall be updated. */ + BooleanType allowFlipping = BT_FALSE, /**< Flag indicating if flipping bounds are allowed. */ + BooleanType ensureNZC = + BT_FALSE /**< Flag indicating if non-zero curvature is ensured by exchange rules. */ + ); + + /** Solves the system Ta = b or T^Ta = b where T is a reverse upper triangular matrix. + * This must not be called for the Schur complement version. */ + virtual returnValue backsolveT(const real_t * const b, /**< Right hand side vector. */ + BooleanType transposed, /**< Indicates if the transposed system shall be solved. */ + real_t * const a /**< Output: Solution vector */ + ) const; + + /** Solves the system Ra = b or R^Ta = b where R is an upper triangular matrix. + * This must not be called for the Schur complement version. */ + virtual returnValue backsolveR(const real_t * const b, /**< Right hand side vector. */ + BooleanType transposed, /**< Indicates if the transposed system shall be solved. */ + real_t * const a /**< Output: Solution vector */ + ) const; + + /** Solves the system Ra = b or R^Ta = b where R is an upper triangular matrix. \n + * This must not be called for the Schur complement version. */ + virtual returnValue backsolveR(const real_t * const b, /**< Right hand side vector. */ + BooleanType transposed, /**< Indicates if the transposed system shall be solved. */ + BooleanType removingBound, /**< Indicates if function is called from "removeBound()". */ + real_t * const a /**< Output: Solution vector */ + ) const; + + /** Determines step direction of the homotopy path. + * \return SUCCESSFUL_RETURN \n + RET_STEPDIRECTION_FAILED_TQ \n + RET_STEPDIRECTION_FAILED_CHOLESKY */ + virtual returnValue determineStepDirection( + const real_t * const delta_g, /**< Step direction of gradient vector. */ + const real_t * const delta_lbA, /**< Step direction of lower constraints' bounds. */ + const real_t * const delta_ubA, /**< Step direction of upper constraints' bounds. */ + const real_t * const delta_lb, /**< Step direction of lower bounds. */ + const real_t * const delta_ub, /**< Step direction of upper bounds. */ + BooleanType Delta_bC_isZero, /**< Indicates if active constraints' bounds are to be shifted. */ + BooleanType Delta_bB_isZero, /**< Indicates if active bounds are to be shifted. */ + real_t * const delta_xFX, /**< Output: Primal homotopy step direction of fixed variables. */ + real_t * const delta_xFR, /**< Output: Primal homotopy step direction of free variables. */ + real_t * const + delta_yAC, /**< Output: Dual homotopy step direction of active constraints' multiplier. */ + real_t * const delta_yFX /**< Output: Dual homotopy step direction of fixed variables' multiplier. */ + ); + + virtual returnValue determineStepDirection2( + const real_t * const delta_g, /**< Step direction of gradient vector. */ + const real_t * const delta_lbA, /**< Step direction of lower constraints' bounds. */ + const real_t * const delta_ubA, /**< Step direction of upper constraints' bounds. */ + const real_t * const delta_lb, /**< Step direction of lower bounds. */ + const real_t * const delta_ub, /**< Step direction of upper bounds. */ + BooleanType Delta_bC_isZero, /**< Indicates if active constraints' bounds are to be shifted. */ + BooleanType Delta_bB_isZero, /**< Indicates if active bounds are to be shifted. */ + real_t * const delta_xFX, /**< Output: Primal homotopy step direction of fixed variables. */ + real_t * const delta_xFR, /**< Output: Primal homotopy step direction of free variables. */ + real_t * const + delta_yAC, /**< Output: Dual homotopy step direction of active constraints' multiplier. */ + real_t * const delta_yFX /**< Output: Dual homotopy step direction of fixed variables' multiplier. */ + ); + + /* + * PRIVATE MEMBER FUNCTION + */ +private: + /** Checks if new active bound to be added is linearly dependent from + * from row of the active constraints matrix. This version computes + * the multipliers in the (full) test. + * \return RET_LINEARLY_DEPENDENT \n + RET_LINEARLY_INDEPENDENT */ + returnValue addBound_checkLISchur(int_t number, /**< Number of bound to be added to active set. */ + real_t * const xiC, /**< Output: Multipliers in linear independence test for active constraints. */ + real_t * const xiX /**< Output: Multipliers in linear independence test for fixed variables. */ + ); + + /** Checks if new active bound to be added is linearly dependent from + * from row of the active constraints matrix. This version computes + * the multipliers in the (full) test. + * \return RET_LINEARLY_DEPENDENT \n + RET_LINEARLY_INDEPENDENT */ + returnValue addConstraint_checkLISchur(int_t number, /**< Number of bound to be added to active set. */ + real_t * const xiC, /**< Output: Multipliers in linear independence test for active constraints. */ + real_t * const xiX /**< Output: Multipliers in linear independence test for fixed variables. */ + ); + + /** Compute product of "M" matrix (additional columns in KKT + matrix) with vector. y = alpha * M * x + beta * y */ + returnValue computeMTimes(real_t alpha, const real_t * const x, real_t beta, real_t * const y); + + /** Compute product of transpose of "M" matrix (additional columns in KKT + matrix) with vector. y = alpha * M^T * x + beta * y */ + returnValue computeMTransTimes(real_t alpha, const real_t * const x, real_t beta, real_t * const y); + + /** Add a row/column to the Schur complement. */ + returnValue addToSchurComplement(int_t number, + SchurUpdateType update, + int_t numNonzerosM, + const sparse_int_t * M_pos, + const real_t * const M_vals, + int_t numNonzerosN, + const sparse_int_t * Npos, + const real_t * const Nvals, + real_t N_diag); + + /** Remove a row/column from the Schur complement. */ + returnValue deleteFromSchurComplement(int_t idx, BooleanType allowUndo = BT_FALSE); + + /** Undo the last deletion from the Schur complement by moving the nS+1th row/column to position idx. */ + returnValue undoDeleteFromSchurComplement(int_t idx); + + /** Compute determinant of new nS*nS Schur complement from old factorization */ + real_t calcDetSchur(int_t idxDel); + + /** Update QR factorization and determinant of Schur complement after a row and column have been added or + * removed */ + returnValue updateSchurQR(int_t idxDel); + + /** Compute the solution to QRx = rhs and store it in sol */ + returnValue backsolveSchurQR(int_t dimS, const real_t * const rhs, int_t dimRhs, real_t * const sol); + + /** If negative curvature is discovered in the reduced Hessian, add bounds until all eigenvalues are + * positive */ + returnValue correctInertia(); + + /** If the KKT matrix is declared singular during refactorization, remove linearly dependent constraints + * or add bounds */ + returnValue repairSingularWorkingSet(); + + returnValue stepCalcRhs(int_t nFR, + int_t nFX, + int_t nAC, + int_t * FR_idx, + int_t * FX_idx, + int_t * AC_idx, + real_t & rhs_max, + const real_t * const delta_g, + const real_t * const delta_lbA, + const real_t * const delta_ubA, + const real_t * const delta_lb, + const real_t * const delta_ub, + BooleanType Delta_bC_isZero, + BooleanType Delta_bB_isZero, + real_t * const delta_xFX, + real_t * const delta_xFR, + real_t * const delta_yAC, + real_t * const delta_yFX); + + returnValue stepCalcReorder(int_t nFR, + int_t nAC, + int_t * FR_idx, + int_t * AC_idx, + int_t nFRStart, + int_t nACStart, + int_t * FR_idxStart, + int_t * AC_idxStart, + int_t * FR_iSort, + int_t * FR_iSortStart, + int_t * AC_iSort, + int_t * AC_iSortStart, + real_t * rhs); + + returnValue stepCalcBacksolveSchur(int_t nFR, + int_t nFX, + int_t nAC, + int_t * FR_idx, + int_t * FX_idx, + int_t * AC_idx, + int_t dim, + real_t * rhs, + real_t * sol); + + returnValue stepCalcReorder2(int_t nFR, + int_t nAC, + int_t * FR_idx, + int_t * AC_idx, + int_t nFRStart, + int_t nACStart, + int_t * FR_idxStart, + int_t * AC_idxStart, + int_t * FR_iSort, + int_t * FR_iSortStart, + int_t * AC_iSort, + int_t * AC_iSortStart, + real_t * sol, + real_t * const delta_xFR, + real_t * const delta_yAC); + + returnValue stepCalcResid(int_t nFR, + int_t nFX, + int_t nAC, + int_t * FR_idx, + int_t * FX_idx, + int_t * AC_idx, + BooleanType Delta_bC_isZero, + real_t * const delta_xFX, + real_t * const delta_xFR, + real_t * const delta_yAC, + const real_t * const delta_g, + const real_t * const delta_lbA, + const real_t * const delta_ubA, + real_t & rnrm); + + returnValue stepCalcDeltayFx(int_t nFR, + int_t nFX, + int_t nAC, + int_t * FX_idx, + const real_t * const delta_g, + real_t * const delta_xFX, + real_t * const delta_xFR, + real_t * const delta_yAC, + real_t * const delta_yFX); + + /* + * PROTECTED MEMBER VARIABLES + */ +protected: + SparseSolver * sparseSolver; /**< Interface to the sparse linear solver. */ + + real_t * S; /**< Schur complement matrix. (This is actually the negative of the Schur complement!) */ + int_t nS; /**< Current size of Schur complement matrix. -1 means that the Schur complement has not yet + been initialized. */ + int_t nSmax; /**< Maximum size of Schur complement matrix. */ + + real_t * Q_; /**< QR factorization of S: orthogonal matrix Q */ + real_t * R_; /**< QR factorization of S: upper triangular matrix R */ + real_t detS; /**< Determinant of Schur complement */ + real_t rcondS; /**< Reciprocal of condition number of S (estimate) */ + int_t numFactorizations; /**< Total number of factorizations performed */ + + int_t * schurUpdateIndex; /**< Indices of variables or constraints for each update in Schur complement. */ + SchurUpdateType * schurUpdate; /**< Type of update for each update in Schur complement. */ + + int_t M_physicallength; /**< Allocated size of the M_vals and M_ir arrays. */ + real_t * M_vals; /**< Values of the sparse M matrix containing the vectors with the additional rows + defining the Schur complement (length). */ + sparse_int_t * M_ir; /**< Row indices (length). */ + sparse_int_t * M_jc; /**< Indices in M to first entry of columns (nS+1). */ + + Indexlist boundsFreeStart; /**< Index list for free bounds when major iteration started. */ + Indexlist constraintsActiveStart; /**< Index list for active constraints when major iteration started. */ +}; + +END_NAMESPACE_QPOASES + +#include + +#endif /* QPOASES_QPROBLEMSCHUR_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SQProblemSchur.ipp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SQProblemSchur.ipp new file mode 100755 index 0000000..cda165a --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SQProblemSchur.ipp @@ -0,0 +1,57 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2013 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file include/qpOASES/SQProblemSchur.ipp + * \author Andreas Waechter, Dennis Janka + * \version 3.2 + * \date 2012-2017 + * + * Implementation of inlined member functions of the SQProblemSchur class which + * is able to use the newly developed online active set strategy for + * parametric quadratic programming. + */ + + +BEGIN_NAMESPACE_QPOASES + + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +/* + * g e t N u m F a c t o r i z a t i o n s + */ +inline int_t SQProblemSchur::getNumFactorizations( ) const +{ + return numFactorizations; +} + +END_NAMESPACE_QPOASES + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SparseSolver.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SparseSolver.hpp new file mode 100644 index 0000000..dc5ba11 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SparseSolver.hpp @@ -0,0 +1,562 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/SparseSolver.hpp + * \author Andreas Waechter, Dennis Janka + * \version 3.2 + * \date 2012-2017 + * + * Interfaces to sparse linear solvers that are used in a Schur-complement + * implementation in qpOASES. + */ + +#ifndef QPOASES_SPARSESOLVER_HPP +#define QPOASES_SPARSESOLVER_HPP +#include +#include + +#include + +BEGIN_NAMESPACE_QPOASES + +/** + * \brief Base class for linear solvers that are used in a Schur-complement + * implementation in qpOASES. + * + * \author Andreas Waechter, Dennis Janka + * \version 3.2 + * \date 2012-2017 + */ +class SparseSolver +{ + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + SparseSolver(); + + /** Copy constructor (deep copy). */ + SparseSolver(const SparseSolver & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + virtual ~SparseSolver(); + + /** Assignment operator (deep copy). */ + virtual SparseSolver & operator=(const SparseSolver & rhs /**< Rhs object. */ + ); + + /** Set new matrix data. The matrix is to be provided + in the Harwell-Boeing format. Only the lower + triangular part should be set. */ + virtual returnValue setMatrixData(int_t dim, /**< Dimension of the linear system. */ + int_t numNonzeros, /**< Number of nonzeros in the matrix. */ + const int_t * const airn, /**< Row indices for each matrix entry. */ + const int_t * const acjn, /**< Column indices for each matrix entry. */ + const real_t * const avals /**< Values for each matrix entry. */ + ) = 0; + + /** Compute factorization of current matrix. This method must be called before solve.*/ + virtual returnValue factorize() = 0; + + /** Solve linear system with most recently set matrix data. */ + virtual returnValue solve(int_t dim, /**< Dimension of the linear system. */ + const real_t * const rhs, /**< Values for the right hand side. */ + real_t * const sol /**< Solution of the linear system. */ + ) = 0; + + /** Clears all data structures. */ + virtual returnValue reset(); + + /** Return the number of negative eigenvalues. */ + virtual int_t getNegativeEigenvalues(); + + /** Return the rank after a factorization */ + virtual int_t getRank(); + + /** Returns the zero pivots in case the matrix is rank deficient */ + virtual returnValue getZeroPivots(int_t *& zeroPivots); + + /* + * PROTECTED MEMBER FUNCTIONS + */ +protected: + /** Frees all allocated memory. + * \return SUCCESSFUL_RETURN */ + returnValue clear(); + + /** Copies all members from given rhs object. + * \return SUCCESSFUL_RETURN */ + returnValue copy(const SparseSolver & rhs /**< Rhs object. */ + ); + + /* + * PROTECTED MEMBER VARIABLES + */ +protected: +}; + +#ifdef SOLVER_MA27 + +/** + * \brief Implementation of the linear solver interface using Harwell's MA27. + * + * \author Andreas Waechter, Dennis Janka + * \version 3.2 + * \date 2012-2017 + */ +class Ma27SparseSolver : public SparseSolver +{ + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + Ma27SparseSolver(); + + /** Copy constructor (deep copy). */ + Ma27SparseSolver(const Ma27SparseSolver & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + virtual ~Ma27SparseSolver(); + + /** Assignment operator (deep copy). */ + virtual Ma27SparseSolver & operator=(const SparseSolver & rhs /**< Rhs object. */ + ); + + /** Set new matrix data. The matrix is to be provided + in the Harwell-Boeing format. Only the lower + triangular part should be set. */ + virtual returnValue setMatrixData(int_t dim, /**< Dimension of the linear system. */ + int_t numNonzeros, /**< Number of nonzeros in the matrix. */ + const int_t * const airn, /**< Row indices for each matrix entry. */ + const int_t * const acjn, /**< Column indices for each matrix entry. */ + const real_t * const avals /**< Values for each matrix entry. */ + ); + + /** Compute factorization of current matrix. This method must be called before solve.*/ + virtual returnValue factorize(); + + /** Solve linear system with most recently set matrix data. */ + virtual returnValue solve(int_t dim, /**< Dimension of the linear system. */ + const real_t * const rhs, /**< Values for the right hand side. */ + real_t * const sol /**< Solution of the linear system. */ + ); + + /** Clears all data structures. */ + virtual returnValue reset(); + + /** Return the number of negative eigenvalues. */ + virtual int_t getNegativeEigenvalues(); + + /** Return the rank after a factorization */ + virtual int getRank(); + + /* + * PROTECTED MEMBER FUNCTIONS + */ +protected: + /** Frees all allocated memory. + * \return SUCCESSFUL_RETURN */ + returnValue clear(); + + /** Copies all members from given rhs object. + * \return SUCCESSFUL_RETURN */ + returnValue copy(const Ma27SparseSolver & rhs /**< Rhs object. */ + ); + + /* + * PRIVATE MEMBER FUNCTIONS + */ +private: + /* + * PRIVATE MEMBER VARIABLES + */ +private: + fint_t dim; /**< Dimension of the current linear system. */ + + fint_t numNonzeros; /**< Number of nonzeros in the current linear system. */ + + fint_t la_ma27; /**< size of a_ma27 (LA in MA27) */ + + double * + a_ma27; /**< matrix/factor for MA27 (A in MA27). If have_factorization is false, it contains the matrix + entries (and has length numNonzeros), otherwise the factor (and has length la_ma27). */ + + fint_t * irn_ma27; /**< Row entries of matrix (IRN in MA27) */ + + fint_t * jcn_ma27; /**< Column entries of matrix (JCN in MA27) */ + + fint_t icntl_ma27[30]; /**< integer control values (ICNRL in MA27) */ + + double cntl_ma27[5]; /**< real control values (CNRL in MA27) */ + + fint_t liw_ma27; /**< length of integer work space (LIW in MA27) */ + + fint_t * iw_ma27; /**< integer work space (IW in MA27) */ + + fint_t * ikeep_ma27; /**< IKEEP in MA27 */ + + fint_t nsteps_ma27; /**< NSTEPS in MA27 */ + + fint_t maxfrt_ma27; /**< MAXFRT in MA27 */ + + bool have_factorization; /**< flag indicating whether factorization for current matrix has already been + computed */ + + fint_t neig; /**< number of negative eigenvalues */ + + fint_t rank; /**< rank of matrix */ +}; + +#endif /* SOLVER_MA27 */ + +#ifdef SOLVER_MA57 + +/** + * \brief Implementation of the linear solver interface using Harwell's MA57. + * + * \author Andreas Waechter, Dennis Janka + * \version 3.2 + * \date 2013-2017 + */ +class Ma57SparseSolver : public SparseSolver +{ + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + Ma57SparseSolver(); + + /** Copy constructor (deep copy). */ + Ma57SparseSolver(const Ma57SparseSolver & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + virtual ~Ma57SparseSolver(); + + /** Assignment operator (deep copy). */ + virtual Ma57SparseSolver & operator=(const SparseSolver & rhs /**< Rhs object. */ + ); + + /** Set new matrix data. The matrix is to be provided + in the Harwell-Boeing format. Only the lower + triangular part should be set. */ + virtual returnValue setMatrixData(int_t dim, /**< Dimension of the linear system. */ + int_t numNonzeros, /**< Number of nonzeros in the matrix. */ + const int_t * const airn, /**< Row indices for each matrix entry. */ + const int_t * const acjn, /**< Column indices for each matrix entry. */ + const real_t * const avals /**< Values for each matrix entry. */ + ); + + /** Compute factorization of current matrix. This method must be called before solve.*/ + virtual returnValue factorize(); + + /** Solve linear system with most recently set matrix data. */ + virtual returnValue solve(int_t dim, /**< Dimension of the linear system. */ + const real_t * const rhs, /**< Values for the right hand side. */ + real_t * const sol /**< Solution of the linear system. */ + ); + + /** Clears all data structures. */ + virtual returnValue reset(); + + /** Return the number of negative eigenvalues. */ + virtual int_t getNegativeEigenvalues(); + + /** Return the rank after a factorization */ + virtual int_t getRank(); + + /** Returns the zero pivots in case the matrix is rank deficient */ + virtual returnValue getZeroPivots(int_t *& zeroPivots /**< ... */ + ); + /* + * PROTECTED MEMBER FUNCTIONS + */ +protected: + /** Frees all allocated memory. + * \return SUCCESSFUL_RETURN */ + returnValue clear(); + + /** Copies all members from given rhs object. + * \return SUCCESSFUL_RETURN */ + returnValue copy(const Ma57SparseSolver & rhs /**< Rhs object. */ + ); + + /* + * PRIVATE MEMBER FUNCTIONS + */ +private: + /* + * PRIVATE MEMBER VARIABLES + */ +private: + fint_t dim; /**< Dimension of the current linear system. */ + + fint_t numNonzeros; /**< Number of nonzeros in the current linear system. */ + + double * a_ma57; /**< matrix for MA57 (A in MA57) */ + + fint_t * irn_ma57; /**< Row entries of matrix (IRN in MA57) */ + + fint_t * jcn_ma57; /**< Column entries of matrix (JCN in MA57) */ + + fint_t icntl_ma57[30]; /**< integer control values (ICNRL in MA57) */ + + double cntl_ma57[5]; /**< real control values (CNRL in MA57) */ + + double * fact_ma57; /**< array for storing the factors */ + + fint_t lfact_ma57; /**< length of fact_ma57 */ + + fint_t * ifact_ma57; /**< indexing information about the factors */ + + fint_t lifact_ma57; /**< length of ifact_ma57 */ + + bool have_factorization; /**< flag indicating whether factorization for current matrix has already been + computed */ + + fint_t neig; /**< number of negative eigenvalues */ + + fint_t rank; /**< rank of matrix */ + + fint_t * pivots; /**< sequence of pivots used in factorization */ +}; + +#endif /* SOLVER_MA57 */ + +#ifdef SOLVER_MUMPS + +/** + * \brief Implementation of the linear solver interface using MUMPS. + * + * \author Andrea Zanelli + * \version 3.2 + * \date 2022 + */ +class MumpsSparseSolver : public SparseSolver +{ + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + MumpsSparseSolver(); + + /** Copy constructor (deep copy). */ + MumpsSparseSolver(const MumpsSparseSolver & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + virtual ~MumpsSparseSolver(); + + /** Assignment operator (deep copy). */ + virtual MumpsSparseSolver & operator=(const SparseSolver & rhs /**< Rhs object. */ + ); + + /** Set new matrix data. The matrix is to be provided + in the Harwell-Boeing format. Only the lower + triangular part should be set. */ + virtual returnValue setMatrixData(int_t dim, /**< Dimension of the linear system. */ + int_t numNonzeros, /**< Number of nonzeros in the matrix. */ + const int_t * const airn, /**< Row indices for each matrix entry. */ + const int_t * const acjn, /**< Column indices for each matrix entry. */ + const real_t * const avals /**< Values for each matrix entry. */ + ); + + /** Compute factorization of current matrix. This method must be called before solve.*/ + virtual returnValue factorize(); + + /** Solve linear system with most recently set matrix data. */ + virtual returnValue solve(int_t dim, /**< Dimension of the linear system. */ + const real_t * const rhs, /**< Values for the right hand side. */ + real_t * const sol /**< Solution of the linear system. */ + ); + + /** Clears all data structures. */ + virtual returnValue reset(); + + /** Return the number of negative eigenvalues. */ + virtual int_t getNegativeEigenvalues(); + + /** Return the rank after a factorization */ + virtual int_t getRank(); + + /** Returns the zero pivots in case the matrix is rank deficient */ + virtual returnValue getZeroPivots(int_t *& zeroPivots /**< ... */ + ); + /* + * PROTECTED MEMBER FUNCTIONS + */ +protected: + /** Frees all allocated memory. + * \return SUCCESSFUL_RETURN */ + returnValue clear(); + + /** Copies all members from given rhs object. + * \return SUCCESSFUL_RETURN */ + returnValue copy(const MumpsSparseSolver & rhs /**< Rhs object. */ + ); + + /* + * PRIVATE MEMBER FUNCTIONS + */ +private: + /* + * PRIVATE MEMBER VARIABLES + */ +private: + void * mumps_ptr_; /** Primary MUMPS data structure */ + + int dim; /**< Dimension of the current linear system. */ + + int numNonzeros; /**< Number of nonzeros in the current linear system. */ + + double * a_mumps; /**< matrix for MUMPS (A in MUMPS) */ + + int * irn_mumps; /**< Row entries of matrix (IRN in MUMPS) */ + + int * jcn_mumps; /**< Column entries of matrix (JCN in MUMPS) */ + + bool have_factorization; /**< flag indicating whether factorization for current matrix has already been + computed */ + + int negevals_; /**< number of negative eigenvalues */ + + int mumps_pivot_order_; /* pivot order*/ + + bool initialized_; + /** Flag indicating if the matrix has to be refactorized because + * the pivot tolerance has been changed. + */ + bool pivtol_changed_; + /** Flag that is true if we just requested the values of the + * matrix again (SYMSOLVER_CALL_AGAIN) and have to factorize + * again. + */ + bool refactorize_; + ///@} + + /** @name Solver specific data/options */ + ///@{ + /** Pivot tolerance */ + double pivtol_; + + /** Maximal pivot tolerance */ + double pivtolmax_; + + /** Percent increase in memory */ + int mem_percent_; + + /** Permutation and scaling method in MUMPS */ + int mumps_permuting_scaling_; + + /** Scaling in MUMPS */ + int mumps_scaling_; + + /** Threshold in MUMPS to state that a constraint is linearly dependent */ + double mumps_dep_tol_; + + /** Flag indicating whether the TNLP with identical structure has + * already been solved before. + */ + bool warm_start_same_structure_; + ///@} + + /** Flag indicating if symbolic factorization has already been called */ + bool have_symbolic_factorization_; +}; + +template +inline void ComputeMemIncrease(T & len, ///< current length on input, new length on output + double recommended, ///< recommended size + T min, ///< minimal size that should ensured + const char * + context ///< context from where this function is called - used to setup message for exception +) +{ + if (recommended >= std::numeric_limits::max()) { + // increase len to the maximum possible, if that is still an increase + if (len < std::numeric_limits::max()) { + len = std::numeric_limits::max(); + } else { + std::stringstream what; + what << "Cannot allocate more than " << std::numeric_limits::max() * sizeof(T) << " bytes for " + << context << " due to limitation on integer type"; + throw std::overflow_error(what.str()); + } + } else { + len = std::max(min, (T)recommended); + } +} + +#endif /* SOLVER_MUMPS */ + +#ifdef SOLVER_NONE + +/** + * \brief Implementation of a dummy sparse solver. An error is thrown if a factorization is attempted. + * + * \author Dennis Janka + * \version 3.2 + * \date 2015-2017 + */ +class DummySparseSolver : public SparseSolver +{ + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Set new matrix data. The matrix is to be provided + in the Harwell-Boeing format. Only the lower + triangular part should be set. */ + virtual returnValue setMatrixData(int_t dim, /**< Dimension of the linear system. */ + int_t numNonzeros, /**< Number of nonzeros in the matrix. */ + const int_t * const airn, /**< Row indices for each matrix entry. */ + const int_t * const acjn, /**< Column indices for each matrix entry. */ + const real_t * const avals /**< Values for each matrix entry. */ + ); + + /** Compute factorization of current matrix. This method must be called before solve.*/ + virtual returnValue factorize(); + + /** Solve linear system with most recently set matrix data. */ + virtual returnValue solve(int_t dim, /**< Dimension of the linear system. */ + const real_t * const rhs, /**< Values for the right hand side. */ + real_t * const sol /**< Solution of the linear system. */ + ); +}; + +#endif /* SOLVER_NONE */ + +END_NAMESPACE_QPOASES + +#endif /* QPOASES_SPARSESOLVER_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SubjectTo.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SubjectTo.hpp new file mode 100644 index 0000000..1430efd --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SubjectTo.hpp @@ -0,0 +1,216 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/SubjectTo.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Declaration of the SubjectTo class designed to manage working sets of + * constraints and bounds within a QProblem. + */ + +#ifndef QPOASES_SUBJECTTO_HPP +#define QPOASES_SUBJECTTO_HPP + +#include + +BEGIN_NAMESPACE_QPOASES + +/** + * \brief Base class for managing working sets of bounds and constraints. + * + * This class manages working sets of bounds and constraints by storing + * index sets and other status information. + * + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + */ +class SubjectTo +{ + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + SubjectTo(); + + /** Constructor which takes the number of constraints or bounds. */ + SubjectTo(int_t _n /**< Number of constraints or bounds. */ + ); + + /** Copy constructor (deep copy). */ + SubjectTo(const SubjectTo & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + virtual ~SubjectTo(); + + /** Assignment operator (deep copy). */ + SubjectTo & operator=(const SubjectTo & rhs /**< Rhs object. */ + ); + + /** Initialises object with given number of constraints or bounds. + * \return SUCCESSFUL_RETURN \n + RET_INVALID_ARGUMENTS */ + returnValue init(int_t _n = 0 /**< Number of constraints or bounds. */ + ); + + /** Returns number of constraints/bounds with given SubjectTo type. + * \return Number of constraints/bounds with given type. */ + inline int_t getNumberOfType(SubjectToType _type /**< Type of (constraints') bound. */ + ) const; + + /** Returns type of (constraints') bound. + * \return Type of (constraints') bound \n + RET_INDEX_OUT_OF_BOUNDS */ + inline SubjectToType getType(int_t i /**< Number of (constraints') bound. */ + ) const; + + /** Returns status of (constraints') bound. + * \return Status of (constraints') bound \n + ST_UNDEFINED */ + inline SubjectToStatus getStatus(int_t i /**< Number of (constraints') bound. */ + ) const; + + /** Sets type of (constraints') bound. + * \return SUCCESSFUL_RETURN \n + RET_INDEX_OUT_OF_BOUNDS */ + inline returnValue setType(int_t i, /**< Number of (constraints') bound. */ + SubjectToType value /**< Type of (constraints') bound. */ + ); + + /** Sets status of (constraints') bound. + * \return SUCCESSFUL_RETURN \n + RET_INDEX_OUT_OF_BOUNDS */ + inline returnValue setStatus(int_t i, /**< Number of (constraints') bound. */ + SubjectToStatus value /**< Status of (constraints') bound. */ + ); + + /** Sets status of lower (constraints') bounds. */ + inline void setNoLower(BooleanType _status /**< Status of lower (constraints') bounds. */ + ); + + /** Sets status of upper (constraints') bounds. */ + inline void setNoUpper(BooleanType _status /**< Status of upper (constraints') bounds. */ + ); + + /** Returns status of lower (constraints') bounds. + * \return BT_TRUE if there is no lower (constraints') bound on any variable. */ + inline BooleanType hasNoLower() const; + + /** Returns status of upper bounds. + * \return BT_TRUE if there is no upper (constraints') bound on any variable. */ + inline BooleanType hasNoUpper() const; + + /** Shifts forward type and status of all constraints/bounds by a given + * offset. This offset has to lie within the range [0,n/2] and has to + * be an integer divisor of the total number of constraints/bounds n. + * Type and status of the first \ constraints/bounds is thrown away, + * type and status of the last \ constraints/bounds is doubled, + * e.g. for offset = 2: \n + * shift( {c/b1,c/b2,c/b3,c/b4,c/b5,c/b6} ) = {c/b3,c/b4,c/b5,c/b6,c/b5,c/b6} + * \return SUCCESSFUL_RETURN \n + RET_INDEX_OUT_OF_BOUNDS \n + RET_INVALID_ARGUMENTS \n + RET_SHIFTING_FAILED */ + virtual returnValue shift( + int_t offset /**< Shift offset within the range [0,n/2] and integer divisor of n. */ + ) = 0; + + /** Rotates forward type and status of all constraints/bounds by a given + * offset. This offset has to lie within the range [0,n]. + * Example for offset = 2: \n + * rotate( {c/b1,c/b2,c/b3,c/b4,c/b5,c/b6} ) = {c/b3,c/b4,c/b5,c/b6,c/b1,c/b2} + * \return SUCCESSFUL_RETURN \n + RET_INDEX_OUT_OF_BOUNDS \n + RET_ROTATING_FAILED */ + virtual returnValue rotate(int_t offset /**< Rotation offset within the range [0,n]. */ + ) = 0; + + /* + * PROTECTED MEMBER FUNCTIONS + */ +protected: + /** Frees all allocated memory. + * \return SUCCESSFUL_RETURN */ + returnValue clear(); + + /** Copies all members from given rhs object. + * \return SUCCESSFUL_RETURN */ + returnValue copy(const SubjectTo & rhs /**< Rhs object. */ + ); + + /** Adds the index of a new constraint or bound to index set. + * \return SUCCESSFUL_RETURN \n + RET_ADDINDEX_FAILED \n + RET_INVALID_ARGUMENTS */ + returnValue addIndex( + Indexlist * const indexlist, /**< Index list to which the new index shall be added. */ + int_t newnumber, /**< Number of new constraint or bound. */ + SubjectToStatus newstatus /**< Status of new constraint or bound. */ + ); + + /** Removes the index of a constraint or bound from index set. + * \return SUCCESSFUL_RETURN \n + RET_REMOVEINDEX_FAILED \n + RET_INVALID_ARGUMENTS */ + returnValue removeIndex( + Indexlist * const indexlist, /**< Index list from which the new index shall be removed. */ + int_t removenumber /**< Number of constraint or bound to be removed. */ + ); + + /** Swaps the indices of two constraints or bounds within the index set. + * \return SUCCESSFUL_RETURN \n + RET_SWAPINDEX_FAILED \n + RET_INVALID_ARGUMENTS */ + returnValue swapIndex( + Indexlist * const indexlist, /**< Index list in which the indices shold be swapped. */ + int_t number1, /**< Number of first constraint or bound. */ + int_t number2 /**< Number of second constraint or bound. */ + ); + + /* + * PROTECTED MEMBER VARIABLES + */ +protected: + int_t n; /**< Total number of constraints/bounds. */ + + SubjectToType * type; /**< Type of constraints/bounds. */ + SubjectToStatus * status; /**< Status of constraints/bounds. */ + + BooleanType noLower; /**< This flag indicates if there is no lower bound on any variable. */ + BooleanType noUpper; /**< This flag indicates if there is no upper bound on any variable. */ +}; + +END_NAMESPACE_QPOASES + +#include + +#endif /* QPOASES_SUBJECTTO_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SubjectTo.ipp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SubjectTo.ipp new file mode 100755 index 0000000..b409b38 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/SubjectTo.ipp @@ -0,0 +1,158 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file include/qpOASES/SubjectTo.ipp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of the inlined member functions of the SubjectTo class + * designed to manage working sets of constraints and bounds within a QProblem. + */ + + +BEGIN_NAMESPACE_QPOASES + + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + + +/* + * g e t N u m b e r O f T y p e + */ +inline int_t SubjectTo::getNumberOfType( SubjectToType _type ) const +{ + int_t i; + int_t numberOfType = 0; + + if ( type != 0 ) + { + for( i=0; i= 0 ) && ( i < n ) ) + return type[i]; + + return ST_UNKNOWN; +} + + +/* + * g e t S t a t u s + */ +inline SubjectToStatus SubjectTo::getStatus( int_t i ) const +{ + if ( ( i >= 0 ) && ( i < n ) ) + return status[i]; + + return ST_UNDEFINED; +} + + +/* + * s e t T y p e + */ +inline returnValue SubjectTo::setType( int_t i, SubjectToType value ) +{ + if ( ( i >= 0 ) && ( i < n ) ) + { + type[i] = value; + return SUCCESSFUL_RETURN; + } + else + return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); +} + + +/* + * s e t S t a t u s + */ +inline returnValue SubjectTo::setStatus( int_t i, SubjectToStatus value ) +{ + if ( ( i >= 0 ) && ( i < n ) ) + { + status[i] = value; + return SUCCESSFUL_RETURN; + } + else + return THROWERROR( RET_INDEX_OUT_OF_BOUNDS ); +} + + +/* + * s e t N o L o w e r + */ +inline void SubjectTo::setNoLower( BooleanType _status ) +{ + noLower = _status; +} + + +/* + * s e t N o U p p e r + */ +inline void SubjectTo::setNoUpper( BooleanType _status ) +{ + noUpper = _status; +} + + +/* + * h a s N o L o w e r + */ +inline BooleanType SubjectTo::hasNoLower( ) const +{ + return noLower; +} + + +/* + * h a s N o U p p p e r + */ +inline BooleanType SubjectTo::hasNoUpper( ) const +{ + return noUpper; +} + + +END_NAMESPACE_QPOASES + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Types.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Types.hpp new file mode 100644 index 0000000..58186a5 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Types.hpp @@ -0,0 +1,318 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/Types.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Declaration of all non-built-in types (except for classes). + */ + +#ifndef QPOASES_TYPES_HPP +#define QPOASES_TYPES_HPP + +/* If your compiler does not support the snprintf() function, + * uncomment the following line and try to compile again. */ +/* #define __NO_SNPRINTF__ */ + +/* Uncomment the following line for setting the __DSPACE__ flag. */ +/* #define __DSPACE__ */ + +/* Uncomment the following line for setting the __XPCTARGET__ flag. */ +/* #define __XPCTARGET__ */ + +/* Uncomment the following line for setting the __NO_FMATH__ flag. */ +/* #define __NO_FMATH__ */ + +/* Uncomment the following line to enable debug information. */ +/* #define __DEBUG__ */ + +/* Uncomment the following line to enable suppress any kind of console output. */ +/* #define __SUPPRESSANYOUTPUT__ */ + +/** Forces to always include all implicitly fixed bounds and all equality constraints + * into the initial working set when setting up an auxiliary QP. */ +#define __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ + +/* Uncomment the following line to activate the use of an alternative Givens + * plane rotation requiring only three multiplications. */ +/* #define __USE_THREE_MULTS_GIVENS__ */ + +/* Uncomment the following line to activate the use of single precision arithmetic. */ +/* #define __USE_SINGLE_PRECISION__ */ + +/* Work-around for Borland BCC 5.5 compiler. */ +#ifdef __BORLANDC__ +#if __BORLANDC__ < 0x0561 +#define __STDC__ 1 +#endif +#endif + +/* Work-around for Microsoft compilers. */ +#ifdef _MSC_VER +#define __NO_SNPRINTF__ +#pragma warning(disable : 4061 4100 4250 4514 4996) +#endif + +#ifdef __DSPACE__ + +/** Macro for switching on/off the beginning of the qpOASES namespace definition. */ +#define BEGIN_NAMESPACE_QPOASES + +/** Macro for switching on/off the end of the qpOASES namespace definition. */ +#define END_NAMESPACE_QPOASES + +/** Macro for switching on/off the use of the qpOASES namespace. */ +#define USING_NAMESPACE_QPOASES + +/** Macro for switching on/off references to the qpOASES namespace. */ +#define REFER_NAMESPACE_QPOASES :: + +#else + +/** Macro for switching on/off the beginning of the qpOASES namespace definition. */ +#define BEGIN_NAMESPACE_QPOASES namespace qpOASES { +/** Macro for switching on/off the end of the qpOASES namespace definition. */ +#define END_NAMESPACE_QPOASES } + +/** Macro for switching on/off the use of the qpOASES namespace. */ +#define USING_NAMESPACE_QPOASES using namespace qpOASES; + +/** Macro for switching on/off references to the qpOASES namespace. */ +#define REFER_NAMESPACE_QPOASES qpOASES:: + +#endif + +/* Avoid any printing on embedded platforms. */ +#if defined(__DSPACE__) || defined(__XPCTARGET__) +#define __SUPPRESSANYOUTPUT__ +#define __NO_SNPRINTF__ +#endif + +#ifdef __NO_SNPRINTF__ +#if (!defined(_MSC_VER)) || defined(__DSPACE__) || defined(__XPCTARGET__) +/* If snprintf is not available, provide an empty implementation... */ +int snprintf(char * s, size_t n, const char * format, ...); +#else +/* ... or substitute snprintf by _snprintf for Microsoft compilers. */ +#define snprintf _snprintf +#endif +#endif /* __NO_SNPRINTF__ */ + +/** Macro for accessing the Cholesky factor R. */ +#define RR(I, J) R[(I) + nV * (J)] + +/** Macro for accessing the orthonormal matrix Q of the QT factorisation. */ +#define QQ(I, J) Q[(I) + nV * (J)] + +/** Macro for accessing the triangular matrix T of the QT factorisation. */ +#define TT(I, J) T[(I)*sizeT + (J)] + +/* If neither MA57 nor MA27 nor MUMPS are selected, activate the dummy solver */ +#if !defined(SOLVER_MA27) && !defined(SOLVER_MA57) && !defined(SOLVER_MUMPS) && !defined(SOLVER_NONE) +#define SOLVER_NONE +#endif + +/** + * Defined integer type for calling BLAS/LAPACK. Should usually be + * "(unsigned) int", currently set to "(unsigned) long" for backwards + * compatibility. This will change in a future release. + */ +typedef long la_int_t; +typedef unsigned long la_uint_t; + +BEGIN_NAMESPACE_QPOASES + +/** Defines real_t for facilitating switching between double and float. */ +#ifdef __USE_SINGLE_PRECISION__ +typedef float real_t; +#else +typedef double real_t; +#endif /* __USE_SINGLE_PRECISION__ */ + +/** Defines int_t for facilitating switching between int and long int. */ +#ifdef __USE_LONG_INTEGERS__ +typedef long int_t; +typedef unsigned long uint_t; +#else +typedef int int_t; +typedef unsigned int uint_t; +#endif /* __USE_LONG_INTEGERS__ */ + +/** Defines FORTRAN integer type. Might be platform dependent! */ +#ifdef __USE_LONG_FINTS__ +typedef long fint_t; +#else +typedef int fint_t; +#endif /* __USE_LONG_FINTS__ */ + +/** + * Integer type for sparse matrix row/column entries. Make this "int" + * for 32 bit entries, and "long" for 64-bit entries on x86_64 platform. + * + * Most sparse codes still assume 32-bit entries here (HSL, BQPD, ...) + */ +typedef int_t sparse_int_t; + +/** Summarises all possible logical values. */ +enum BooleanType +{ + BT_FALSE, /**< Logical value for "false". */ + BT_TRUE /**< Logical value for "true". */ +}; + +/** Summarises all possible print levels. Print levels are used to describe + * the desired amount of output during runtime of qpOASES. */ +enum PrintLevel +{ + PL_DEBUG_ITER = -2, /**< Full tabular debugging output. */ + PL_TABULAR, /**< Normal tabular output. */ + PL_NONE, /**< No output. */ + PL_LOW, /**< Print error messages only. */ + PL_MEDIUM, /**< Print error and warning messages as well as concise info messages. */ + PL_HIGH /**< Print all messages with full details. */ +}; + +/** Defines visibility status of a message. */ +enum VisibilityStatus +{ + VS_HIDDEN, /**< Message not visible. */ + VS_VISIBLE /**< Message visible. */ +}; + +/** Summarises all possible states of the (S)QProblem(B) object during the +solution process of a QP sequence. */ +enum QProblemStatus +{ + QPS_NOTINITIALISED, /**< QProblem object is freshly instantiated or reset. */ + QPS_PREPARINGAUXILIARYQP, /**< An auxiliary problem is currently setup, either at the very beginning + * via an initial homotopy or after changing the QP matrices. */ + QPS_AUXILIARYQPSOLVED, /**< An auxilary problem was solved, either at the very beginning + * via an initial homotopy or after changing the QP matrices. */ + QPS_PERFORMINGHOMOTOPY, /**< A homotopy according to the main idea of the online active + * set strategy is performed. */ + QPS_HOMOTOPYQPSOLVED, /**< An intermediate QP along the homotopy path was solved. */ + QPS_SOLVED /**< The solution of the actual QP was found. */ +}; + +/** Summarises all possible types of the QP's Hessian matrix. */ +enum HessianType +{ + HST_ZERO, /**< Hessian is zero matrix (i.e. LP formulation). */ + HST_IDENTITY, /**< Hessian is identity matrix. */ + HST_POSDEF, /**< Hessian is (strictly) positive definite. */ + HST_POSDEF_NULLSPACE, /**< Hessian is positive definite on null space of active bounds/constraints. */ + HST_SEMIDEF, /**< Hessian is positive semi-definite. */ + HST_INDEF, /**< Hessian is indefinite. */ + HST_UNKNOWN /**< Hessian type is unknown. */ +}; + +/** Summarises all possible types of bounds and constraints. */ +enum SubjectToType +{ + ST_UNBOUNDED, /**< Bound/constraint is unbounded. */ + ST_BOUNDED, /**< Bound/constraint is bounded but not fixed. */ + ST_EQUALITY, /**< Bound/constraint is fixed (implicit equality bound/constraint). */ + ST_DISABLED, /**< Bound/constraint is disabled (i.e. ignored when solving QP). */ + ST_UNKNOWN /**< Type of bound/constraint unknown. */ +}; + +/** Summarises all possible states of bounds and constraints. */ +enum SubjectToStatus +{ + ST_LOWER = -1, /**< Bound/constraint is at its lower bound. */ + ST_INACTIVE, /**< Bound/constraint is inactive. */ + ST_UPPER, /**< Bound/constraint is at its upper bound. */ + ST_INFEASIBLE_LOWER, /**< (to be documented) */ + ST_INFEASIBLE_UPPER, /**< (to be documented) */ + ST_UNDEFINED /**< Status of bound/constraint undefined. */ +}; + +/** Flag indicating which type of update generated column in Schur complement. */ +enum SchurUpdateType +{ + SUT_VarFixed, /**< Free variable gets fixed. */ + SUT_VarFreed, /**< Fixed variable gets freed. */ + SUT_ConAdded, /**< Constraint becomes active. */ + SUT_ConRemoved, /**< Constraint becomes inactive. */ + SUT_UNDEFINED /**< Type of Schur update is undefined. */ +}; + +/** + * \brief Stores internal information for tabular (debugging) output. + * + * Struct storing internal information for tabular (debugging) output + * when using the (S)QProblem(B) objects. + * + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2013-2017 + */ +struct TabularOutput +{ + int_t idxAddB; /**< Index of bound that has been added to working set. */ + int_t idxRemB; /**< Index of bound that has been removed from working set. */ + int_t idxAddC; /**< Index of constraint that has been added to working set. */ + int_t idxRemC; /**< Index of constraint that has been removed from working set. */ + int_t excAddB; /**< Flag indicating whether a bound has been added to working set to keep a regular + projected Hessian. */ + int_t excRemB; /**< Flag indicating whether a bound has been removed from working set to keep a regular + projected Hessian. */ + int_t excAddC; /**< Flag indicating whether a constraint has been added to working set to keep a regular + projected Hessian. */ + int_t excRemC; /**< Flag indicating whether a constraint has been removed from working set to keep a + regular projected Hessian. */ +}; + +/** + * \brief Struct containing the variable header for mat file. + * + * Struct storing the header of a variable to be stored in + * Matlab's binary format (using the outdated Level 4 variant + * for simplictiy). + * + * Note, this code snippet has been inspired from the document + * "Matlab(R) MAT-file Format, R2013b" by MathWorks + * + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2013-2017 + */ +typedef struct +{ + long numericFormat; /**< Flag indicating numerical format. */ + long nRows; /**< Number of rows. */ + long nCols; /**< Number of rows. */ + long imaginaryPart; /**< (to be documented) */ + long nCharName; /**< Number of character in name. */ +} MatMatrixHeader; + +END_NAMESPACE_QPOASES + +#endif /* QPOASES_TYPES_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/UnitTesting.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/UnitTesting.hpp new file mode 100644 index 0000000..678fcc7 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/UnitTesting.hpp @@ -0,0 +1,83 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/UnitTesting.hpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2014-2017 + * + * Definition of auxiliary functions/macros for unit testing. + */ + +#ifndef QPOASES_UNIT_TESTING_HPP +#define QPOASES_UNIT_TESTING_HPP + +#ifndef TEST_TOL_FACTOR +#define TEST_TOL_FACTOR 1 +#endif + +/** Return value for tests that passed. */ +#define TEST_PASSED 0 + +/** Return value for tests that failed. */ +#define TEST_FAILED 1 + +/** Return value for tests that could not run due to missing external data. */ +#define TEST_DATA_NOT_FOUND 99 + +/** Macro verifying that two numerical values are equal in order to pass unit test. */ +#define QPOASES_TEST_FOR_EQUAL(x, y) \ +if (REFER_NAMESPACE_QPOASES isEqual((x), (y)) == BT_FALSE) { \ +return TEST_FAILED; \ +} + +/** Macro verifying that two numerical values are close to each other in order to pass unit test. */ +#define QPOASES_TEST_FOR_NEAR(x, y) \ +if (REFER_NAMESPACE_QPOASES getAbs((x) - (y)) / \ + REFER_NAMESPACE_QPOASES getMax(1.0, REFER_NAMESPACE_QPOASES getAbs(x)) >= \ + 1e-10) { \ +return TEST_FAILED; \ +} + +/** Macro verifying that first quantity is lower or equal than second one in order to pass unit test. */ +#define QPOASES_TEST_FOR_TOL(x, tol) \ +if ((x) > (tol) * (TEST_TOL_FACTOR)) { \ +return TEST_FAILED; \ +} + +/** Macro verifying that a logical expression holds in order to pass unit test. */ +#define QPOASES_TEST_FOR_TRUE(x) \ +if ((x) == false) { \ +return TEST_FAILED; \ +} + +BEGIN_NAMESPACE_QPOASES + +END_NAMESPACE_QPOASES + +#endif /* QPOASES_UNIT_TESTING_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Utils.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Utils.hpp new file mode 100644 index 0000000..153d6e9 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Utils.hpp @@ -0,0 +1,347 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/Utils.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Declaration of some utility functions for working with qpOASES. + */ + +#ifndef QPOASES_UTILS_HPP +#define QPOASES_UTILS_HPP + +#include + +BEGIN_NAMESPACE_QPOASES + +/** Prints a (possibly named) vector. + * \return SUCCESSFUL_RETURN */ +returnValue print(const real_t * const v, /**< Vector to be printed. */ + int_t n, /**< Length of vector. */ + const char * name = 0 /**< Name of vector. */ +); + +/** Prints a (possibly named) permuted vector. + * \return SUCCESSFUL_RETURN */ +returnValue print(const real_t * const v, /**< Vector to be printed. */ + int_t n, /**< Length of vector. */ + const int_t * const V_idx, /**< Pemutation vector. */ + const char * name = 0 /**< Name of vector. */ +); + +/** Prints a (possibly named) matrix. + * \return SUCCESSFUL_RETURN */ +returnValue print(const real_t * const M, /**< Matrix to be printed. */ + int_t nrow, /**< Row number of matrix. */ + int_t ncol, /**< Column number of matrix. */ + const char * name = 0 /**< Name of matrix. */ +); + +/** Prints a (possibly named) permuted matrix. + * \return SUCCESSFUL_RETURN */ +returnValue print(const real_t * const M, /**< Matrix to be printed. */ + int_t nrow, /**< Row number of matrix. */ + int_t ncol, /**< Column number of matrix. */ + const int_t * const ROW_idx, /**< Row pemutation vector. */ + const int_t * const COL_idx, /**< Column pemutation vector. */ + const char * name = 0 /**< Name of matrix. */ +); + +/** Prints a (possibly named) index array. + * \return SUCCESSFUL_RETURN */ +returnValue print(const int_t * const index, /**< Index array to be printed. */ + int_t n, /**< Length of index array. */ + const char * name = 0 /**< Name of index array. */ +); + +/** Prints a string to desired output target (useful also for MATLAB output!). + * \return SUCCESSFUL_RETURN */ +returnValue myPrintf(const char * s /**< String to be written. */ +); + +/** Prints qpOASES copyright notice. + * \return SUCCESSFUL_RETURN */ +returnValue printCopyrightNotice(); + +/** Reads a real_t matrix from file. + * \return SUCCESSFUL_RETURN \n + RET_UNABLE_TO_OPEN_FILE \n + RET_UNABLE_TO_READ_FILE */ +returnValue readFromFile(real_t * data, /**< Matrix to be read from file. */ + int_t nrow, /**< Row number of matrix. */ + int_t ncol, /**< Column number of matrix. */ + const char * datafilename /**< Data file name. */ +); + +/** Reads a real_t vector from file. + * \return SUCCESSFUL_RETURN \n + RET_UNABLE_TO_OPEN_FILE \n + RET_UNABLE_TO_READ_FILE */ +returnValue readFromFile(real_t * data, /**< Vector to be read from file. */ + int_t n, /**< Length of vector. */ + const char * datafilename /**< Data file name. */ +); + +/** Reads an integer (column) vector from file. + * \return SUCCESSFUL_RETURN \n + RET_UNABLE_TO_OPEN_FILE \n + RET_UNABLE_TO_READ_FILE */ +returnValue readFromFile(int_t * data, /**< Vector to be read from file. */ + int_t n, /**< Length of vector. */ + const char * datafilename /**< Data file name. */ +); + +/** Writes a real_t matrix into a file. + * \return SUCCESSFUL_RETURN \n + RET_UNABLE_TO_OPEN_FILE */ +returnValue writeIntoFile(const real_t * const data, /**< Matrix to be written into file. */ + int_t nrow, /**< Row number of matrix. */ + int_t ncol, /**< Column number of matrix. */ + const char * datafilename, /**< Data file name. */ + BooleanType append = BT_FALSE /**< Indicates if data shall be appended if the file already exists + (otherwise it is overwritten). */ +); + +/** Writes a real_t vector into a file. + * \return SUCCESSFUL_RETURN \n + RET_UNABLE_TO_OPEN_FILE */ +returnValue writeIntoFile(const real_t * const data, /**< Vector to be written into file. */ + int_t n, /**< Length of vector. */ + const char * datafilename, /**< Data file name. */ + BooleanType append = BT_FALSE /**< Indicates if data shall be appended if the file already exists + (otherwise it is overwritten). */ +); + +/** Writes an integer (column) vector into a file. + * \return SUCCESSFUL_RETURN \n + RET_UNABLE_TO_OPEN_FILE */ +returnValue writeIntoFile(const int_t * const integer, /**< Integer vector to be written into file. */ + int_t n, /**< Length of vector. */ + const char * datafilename, /**< Data file name. */ + BooleanType append = BT_FALSE /**< Indicates if integer shall be appended if the file already exists + (otherwise it is overwritten). */ +); + +/** Writes a real_t matrix/vector into a Matlab binary file. + * \return SUCCESSFUL_RETURN \n + RET_INVALID_ARGUMENTS + RET_UNABLE_TO_WRITE_FILE */ +returnValue writeIntoMatFile(FILE * const matFile, /**< Pointer to Matlab binary file. */ + const real_t * const data, /**< Data to be written into file. */ + int_t nRows, /**< Row number of matrix. */ + int_t nCols, /**< Column number of matrix. */ + const char * name /**< Matlab name of matrix/vector to be stored. */ +); + +/** Writes in integer matrix/vector into a Matlab binary file. + * \return SUCCESSFUL_RETURN \n + RET_INVALID_ARGUMENTS + RET_UNABLE_TO_WRITE_FILE */ +returnValue writeIntoMatFile(FILE * const matFile, /**< Pointer to Matlab binary file. */ + const int_t * const data, /**< Data to be written into file. */ + int_t nRows, /**< Row number of matrix. */ + int_t nCols, /**< Column number of matrix. */ + const char * name /**< Matlab name of matrix/vector to be stored. */ +); + +/** Returns the current system time. + * \return current system time */ +real_t getCPUtime(); + +/** Returns the N-norm of a vector. + * \return >= 0.0: successful */ +real_t getNorm(const real_t * const v, /**< Vector. */ + int_t n, /**< Vector's dimension. */ + int_t type = 2 /**< Norm type, 1: one-norm, 2: Euclidean norm. */ +); + +/** Tests whether two real_t-valued arguments are (numerically) equal. + * \return BT_TRUE: arguments differ not more than TOL \n + BT_FALSE: arguments differ more than TOL */ +inline BooleanType isEqual(real_t x, /**< First real number. */ + real_t y, /**< Second real number. */ + real_t TOL = ZERO /**< Tolerance for comparison. */ +); + +/** Tests whether a real-valued argument is (numerically) zero. + * \return BT_TRUE: argument differs from 0.0 not more than TOL \n + BT_FALSE: argument differs from 0.0 more than TOL */ +inline BooleanType isZero(real_t x, /**< Real number. */ + real_t TOL = ZERO /**< Tolerance for comparison. */ +); + +/** Returns sign of a real-valued argument. + * \return 1.0: argument is non-negative \n + -1.0: argument is negative */ +inline real_t getSign(real_t arg /**< real-valued argument whose sign is to be determined. */ +); + +/** Returns maximum of two integers. + * \return Maximum of two integers */ +inline int_t getMax(int_t x, /**< First integer. */ + int_t y /**< Second integer. */ +); + +/** Returns minimum of two integers. + * \return Minimum of two integers */ +inline int_t getMin(int_t x, /**< First integer. */ + int_t y /**< Second integer. */ +); + +/** Returns maximum of two reals. + * \return Maximum of two reals */ +inline real_t getMax(real_t x, /**< First real number. */ + real_t y /**< Second real number. */ +); + +/** Returns minimum of two reals. + * \return Minimum of two reals */ +inline real_t getMin(real_t x, /**< First real number. */ + real_t y /**< Second real number. */ +); + +/** Returns the absolute value of a real number. + * \return Absolute value of a real number */ +inline real_t getAbs(real_t x /**< Real number. */ +); + +/** Returns the square-root of a real number. + * \return Square-root of a real number */ +inline real_t getSqrt(real_t x /**< Non-negative real number. */ +); + +/** Computes the maximum violation of the KKT optimality conditions + * of given iterate for given QP data. */ +returnValue getKktViolation(int_t nV, /**< Number of variables. */ + int_t nC, /**< Number of constraints. */ + const real_t * const H, /**< Hessian matrix (may be NULL if Hessian is zero or identity matrix). */ + const real_t * const g, /**< Gradient vector. */ + const real_t * const A, /**< Constraint matrix. */ + const real_t * const lb, /**< Lower bound vector (on variables). */ + const real_t * const ub, /**< Upper bound vector (on variables). */ + const real_t * const lbA, /**< Lower constraints' bound vector. */ + const real_t * const ubA, /**< Upper constraints' bound vector. */ + const real_t * const x, /**< Primal trial vector. */ + const real_t * const y, /**< Dual trial vector. */ + real_t & stat, /**< Output: maximum value of stationarity condition residual. */ + real_t & feas, /**< Output: maximum value of primal feasibility violation. */ + real_t & cmpl, /**< Output: maximum value of complementarity residual. */ + const real_t * const workingSetB = 0, /**< Working set of bounds (used to determine active bounds). */ + const real_t * const workingSetC = + 0, /**< Working set of constraints (used to determine active constraints). */ + BooleanType hasIdentityHessian = + BT_FALSE /**< Indicating whether Hessian matrix is identity matrix or not if NULL pointer is passed. */ +); + +/** Computes the maximum violation of the KKT optimality conditions + * of given iterate for given QP data. */ +returnValue getKktViolation(int_t nV, /**< Number of variables. */ + const real_t * const H, /**< Hessian matrix (may be NULL if Hessian is zero or identity matrix). */ + const real_t * const g, /**< Gradient vector. */ + const real_t * const lb, /**< Lower bound vector (on variables). */ + const real_t * const ub, /**< Upper bound vector (on variables). */ + const real_t * const x, /**< Primal trial vector. */ + const real_t * const y, /**< Dual trial vector. */ + real_t & stat, /**< Output: maximum value of stationarity condition residual. */ + real_t & feas, /**< Output: maximum value of primal feasibility violation. */ + real_t & cmpl, /**< Output: maximum value of complementarity residual. */ + const real_t * const workingSetB = 0, /**< Working set of bounds (used to determine active bounds). */ + BooleanType hasIdentityHessian = + BT_FALSE /**< Indicating whether Hessian matrix is identity matrix or not if NULL pointer is passed */ +); + +/** Writes a value of BooleanType into a string. + * \return SUCCESSFUL_RETURN */ +returnValue convertBooleanTypeToString(BooleanType value, /**< Value to be written. */ + char * const string /**< Input: String of sufficient size, \n + Output: String containing value. */ +); + +/** Writes a value of SubjectToStatus into a string. + * \return SUCCESSFUL_RETURN */ +returnValue convertSubjectToStatusToString(SubjectToStatus value, /**< Value to be written. */ + char * const string /**< Input: String of sufficient size, \n + Output: String containing value. */ +); + +/** Writes a value of PrintLevel into a string. + * \return SUCCESSFUL_RETURN */ +returnValue convertPrintLevelToString(PrintLevel value, /**< Value to be written. */ + char * const string /**< Input: String of sufficient size, \n + Output: String containing value. */ +); + +/** Converts a returnValue from an (S)QProblem(B) object into a more + * simple status flag. + * + * \return 0: QP problem solved + * 1: QP could not be solved within given number of iterations + * -1: QP could not be solved due to an internal error + * -2: QP is infeasible (and thus could not be solved) + * -3: QP is unbounded (and thus could not be solved) + */ +int_t getSimpleStatus(returnValue returnvalue, /**< ReturnValue to be analysed. */ + BooleanType doPrintStatus = + BT_FALSE /**< Flag indicating whether simple status shall be printed to screen. */ +); + +/** Normalises QP constraints. + * \return SUCCESSFUL_RETURN \n + * RET_INVALID_ARGUMENTS */ +returnValue normaliseConstraints(int_t nV, /**< Number of variables. */ + int_t nC, /**< Number of constraints. */ + real_t * A, /**< Input: Constraint matrix, \n + Output: Normalised constraint matrix. */ + real_t * lbA, /**< Input: Constraints' lower bound vector, \n + Output: Normalised constraints' lower bound vector. */ + real_t * ubA, /**< Input: Constraints' upper bound vector, \n + Output: Normalised constraints' upper bound vector. */ + int_t type = 1 /**< Norm type, 1: one-norm, 2: Euclidean norm. */ +); + +#ifdef __DEBUG__ +/** Writes matrix with given dimension into specified file. */ +extern "C" void gdb_printmat(const char * fname, /**< File name. */ + real_t * M, /**< Matrix to be written. */ + int_t n, /**< Number of rows. */ + int_t m, /**< Number of columns. */ + int_t ldim /**< Leading dimension. */ +); +#endif /* __DEBUG__ */ + +#if defined(__DSPACE__) || defined(__XPCTARGET__) || defined(__C_WRAPPER__) +extern "C" void __cxa_pure_virtual(void); +#endif /* __DSPACE__ || __XPCTARGET__*/ + +END_NAMESPACE_QPOASES + +#include + +#endif /* QPOASES_UTILS_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Utils.ipp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Utils.ipp new file mode 100755 index 0000000..3f8bdc3 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/Utils.ipp @@ -0,0 +1,174 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + + +/** + * \file include/qpOASES/Utils.ipp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of some inlined utilities for working with the different QProblem classes. + */ + + +#include + + +BEGIN_NAMESPACE_QPOASES + + +/* + * i s E q u a l + */ +inline BooleanType isEqual( real_t x, + real_t y, + real_t TOL + ) +{ + if ( getAbs(x-y) <= TOL ) + return BT_TRUE; + else + return BT_FALSE; +} + + +/* + * i s Z e r o + */ +inline BooleanType isZero( real_t x, + real_t TOL + ) +{ + if ( getAbs(x) <= TOL ) + return BT_TRUE; + else + return BT_FALSE; +} + + +/* + * g e t S i g n + */ +inline real_t getSign( real_t arg + ) +{ + if ( arg >= 0.0 ) + return 1.0; + else + return -1.0; +} + + + +/* + * g e t M a x + */ +inline int_t getMax( int_t x, + int_t y + ) +{ + return (yx) ? x : y; +} + + + +/* + * g e t M a x + */ +inline real_t getMax( real_t x, + real_t y + ) +{ + #ifdef __NO_FMATH__ + return (yx) ? x : y; + #else + return (y>x) ? x : y; + //return fmin(x,y); /* seems to be slower */ + #endif +} + + +/* + * g e t A b s + */ +inline real_t getAbs( real_t x + ) +{ + #ifdef __NO_FMATH__ + return (x>=0.0) ? x : -x; + #else + return fabs(x); + #endif +} + + +/* + * g e t S q r t + */ +inline real_t getSqrt( real_t x + ) +{ + #ifdef __NO_FMATH__ + return sqrt(x); /* put your custom sqrt-replacement here */ + #else + return sqrt(x); + #endif +} + + + +END_NAMESPACE_QPOASES + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/extras/OQPinterface.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/extras/OQPinterface.hpp new file mode 100644 index 0000000..163308c --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/extras/OQPinterface.hpp @@ -0,0 +1,242 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/extras/OQPinterface.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Declaration of an interface comprising several utility functions + * for solving test problems from the Online QP Benchmark Collection + * (This collection is no longer maintained, see + * http://www.qpOASES.org/onlineQP for a backup). + */ + +#ifndef QPOASES_OQPINTERFACE_HPP +#define QPOASES_OQPINTERFACE_HPP + +#include + +BEGIN_NAMESPACE_QPOASES + +/** Reads dimensions of an Online QP Benchmark problem from file. + * + * \return SUCCESSFUL_RETURN \n + RET_UNABLE_TO_READ_FILE \n + RET_FILEDATA_INCONSISTENT */ +returnValue readOqpDimensions( + const char * path, /**< Full path of the data files (without trailing slash!). */ + int_t & nQP, /**< Output: Number of QPs. */ + int_t & nV, /**< Output: Number of variables. */ + int_t & nC, /**< Output: Number of constraints. */ + int_t & nEC /**< Output: Number of equality constraints. */ +); + +/** Reads data of an Online QP Benchmark problem from file. + * This function allocates the required memory for all data; after successfully calling it, + * you have to free this memory yourself! + * + * \return SUCCESSFUL_RETURN \n + RET_INVALID_ARGUMENTS \n + RET_UNABLE_TO_READ_FILE \n + RET_FILEDATA_INCONSISTENT */ +returnValue readOqpData(const char * path, /**< Full path of the data files (without trailing slash!). */ + int_t & nQP, /**< Output: Number of QPs. */ + int_t & nV, /**< Output: Number of variables. */ + int_t & nC, /**< Output: Number of constraints. */ + int_t & nEC, /**< Output: Number of equality constraints. */ + real_t ** H, /**< Output: Hessian matrix. */ + real_t ** g, /**< Output: Sequence of gradient vectors. */ + real_t ** A, /**< Output: Constraint matrix. */ + real_t ** lb, /**< Output: Sequence of lower bound vectors (on variables). */ + real_t ** ub, /**< Output: Sequence of upper bound vectors (on variables). */ + real_t ** lbA, /**< Output: Sequence of lower constraints' bound vectors. */ + real_t ** ubA, /**< Output: Sequence of upper constraints' bound vectors. */ + real_t ** xOpt, /**< Output: Sequence of primal solution vectors + * (not read if a null pointer is passed). */ + real_t ** yOpt, /**< Output: Sequence of dual solution vectors + * (not read if a null pointer is passed). */ + real_t ** objOpt /**< Output: Sequence of optimal objective function values + * (not read if a null pointer is passed). */ +); + +/** Solves an Online QP Benchmark problem as specified by the arguments. + * The maximum deviations from the given optimal solution as well as the + * maximum CPU time to solve each QP are determined. + * + * Note: This variant is outdated and only kept to ensure + * backwards-compatibility! + * + * \return SUCCESSFUL_RETURN \n + RET_BENCHMARK_ABORTED */ +returnValue solveOqpBenchmark(int_t nQP, /**< Number of QPs. */ + int_t nV, /**< Number of variables. */ + int_t nC, /**< Number of constraints. */ + int_t nEC, /**< Number of equality constraints. */ + const real_t * const _H, /**< Hessian matrix. */ + const real_t * const g, /**< Sequence of gradient vectors. */ + const real_t * const _A, /**< Constraint matrix. */ + const real_t * const lb, /**< Sequence of lower bound vectors (on variables). */ + const real_t * const ub, /**< Sequence of upper bound vectors (on variables). */ + const real_t * const lbA, /**< Sequence of lower constraints' bound vectors. */ + const real_t * const ubA, /**< Sequence of upper constraints' bound vectors. */ + BooleanType isSparse, /**< Shall convert matrices to sparse format before solution? */ + const Options & options, /**< QP solver options to be used while solving benchmark problems. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Maximum number of performed working set recalculations. */ + real_t & maxCPUtime, /**< Output: Maximum CPU time required for solving each QP. */ + real_t & maxStationarity, /**< Output: Maximum residual of stationarity condition. */ + real_t & maxFeasibility, /**< Output: Maximum residual of primal feasibility condition. */ + real_t & maxComplementarity /**< Output: Maximum residual of complementarity condition. */ +); + +/** Solves an Online QP Benchmark problem as specified by the arguments. + * The maximum deviations from the given optimal solution as well as the + * maximum CPU time to solve each QP are determined. + * + * \return SUCCESSFUL_RETURN \n + RET_BENCHMARK_ABORTED */ +returnValue solveOqpBenchmark(int_t nQP, /**< Number of QPs. */ + int_t nV, /**< Number of variables. */ + int_t nC, /**< Number of constraints. */ + int_t nEC, /**< Number of equality constraints. */ + const real_t * const _H, /**< Hessian matrix. */ + const real_t * const g, /**< Sequence of gradient vectors. */ + const real_t * const _A, /**< Constraint matrix. */ + const real_t * const lb, /**< Sequence of lower bound vectors (on variables). */ + const real_t * const ub, /**< Sequence of upper bound vectors (on variables). */ + const real_t * const lbA, /**< Sequence of lower constraints' bound vectors. */ + const real_t * const ubA, /**< Sequence of upper constraints' bound vectors. */ + BooleanType isSparse, /**< Shall convert matrices to sparse format before solution? */ + BooleanType useHotstarts, /**< Shall QP solution be hotstarted? */ + const Options & options, /**< QP solver options to be used while solving benchmark problems. */ + int_t maxAllowedNWSR, /**< Maximum number of working set recalculations to be performed. */ + real_t & maxNWSR, /**< Output: Maximum number of performed working set recalculations. */ + real_t & avgNWSR, /**< Output: Average number of performed working set recalculations. */ + real_t & maxCPUtime, /**< Output: Maximum CPU time required for solving each QP. */ + real_t & avgCPUtime, /**< Output: Average CPU time required for solving each QP. */ + real_t & maxStationarity, /**< Output: Maximum residual of stationarity condition. */ + real_t & maxFeasibility, /**< Output: Maximum residual of primal feasibility condition. */ + real_t & maxComplementarity /**< Output: Maximum residual of complementarity condition. */ +); + +/** Solves an Online QP Benchmark problem (without constraints) as specified + * by the arguments. The maximum deviations from the given optimal solution + * as well as the maximum CPU time to solve each QP are determined. + * + * Note: This variant is outdated and only kept to ensure + * backwards-compatibility! + * + * \return SUCCESSFUL_RETURN \n + RET_BENCHMARK_ABORTED */ +returnValue solveOqpBenchmark(int_t nQP, /**< Number of QPs. */ + int_t nV, /**< Number of variables. */ + const real_t * const _H, /**< Hessian matrix. */ + const real_t * const g, /**< Sequence of gradient vectors. */ + const real_t * const lb, /**< Sequence of lower bound vectors (on variables). */ + const real_t * const ub, /**< Sequence of upper bound vectors (on variables). */ + BooleanType isSparse, /**< Shall convert matrices to sparse format before solution? */ + const Options & options, /**< QP solver options to be used while solving benchmark problems. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Maximum number of performed working set recalculations. */ + real_t & maxCPUtime, /**< Output: Maximum CPU time required for solving each QP. */ + real_t & maxStationarity, /**< Output: Maximum residual of stationarity condition. */ + real_t & maxFeasibility, /**< Output: Maximum residual of primal feasibility condition. */ + real_t & maxComplementarity /**< Output: Maximum residual of complementarity condition. */ +); + +/** Solves an Online QP Benchmark problem (without constraints) as specified + * by the arguments. The maximum deviations from the given optimal solution + * as well as the maximum CPU time to solve each QP are determined. + * + * \return SUCCESSFUL_RETURN \n + RET_BENCHMARK_ABORTED */ +returnValue solveOqpBenchmark(int_t nQP, /**< Number of QPs. */ + int_t nV, /**< Number of variables. */ + const real_t * const _H, /**< Hessian matrix. */ + const real_t * const g, /**< Sequence of gradient vectors. */ + const real_t * const lb, /**< Sequence of lower bound vectors (on variables). */ + const real_t * const ub, /**< Sequence of upper bound vectors (on variables). */ + BooleanType isSparse, /**< Shall convert matrices to sparse format before solution? */ + BooleanType useHotstarts, /**< Shall QP solution be hotstarted? */ + const Options & options, /**< QP solver options to be used while solving benchmark problems. */ + int_t maxAllowedNWSR, /**< Maximum number of working set recalculations to be performed. */ + real_t & maxNWSR, /**< Output: Maximum number of performed working set recalculations. */ + real_t & avgNWSR, /**< Output: Average number of performed working set recalculations. */ + real_t & maxCPUtime, /**< Output: Maximum CPU time required for solving each QP. */ + real_t & avgCPUtime, /**< Output: Average CPU time required for solving each QP. */ + real_t & maxStationarity, /**< Output: Maximum residual of stationarity condition. */ + real_t & maxFeasibility, /**< Output: Maximum residual of primal feasibility condition. */ + real_t & maxComplementarity /**< Output: Maximum residual of complementarity condition. */ +); + +/** Runs an Online QP Benchmark problem and determines the maximum + * violation of the KKT optimality conditions as well as the + * maximum CPU time to solve each QP. + * + * \return SUCCESSFUL_RETURN \n + RET_UNABLE_TO_READ_BENCHMARK \n + RET_BENCHMARK_ABORTED */ +returnValue runOqpBenchmark( + const char * path, /**< Full path of the benchmark files (without trailing slash!). */ + BooleanType isSparse, /**< Shall convert matrices to sparse format before solution? */ + const Options & options, /**< QP solver options to be used while solving benchmark problems. */ + int_t & nWSR, /**< Input: Maximum number of working set recalculations; \n + Output: Maximum number of performed working set recalculations. */ + real_t & maxCPUtime, /**< Output: Maximum CPU time required for solving each QP. */ + real_t & maxStationarity, /**< Output: Maximum residual of stationarity condition. */ + real_t & maxFeasibility, /**< Output: Maximum residual of primal feasibility condition. */ + real_t & maxComplementarity /**< Output: Maximum residual of complementarity condition. */ +); + +/** Runs an Online QP Benchmark problem and determines the maximum + * violation of the KKT optimality conditions as well as the + * maximum and average number of iterations and CPU time to solve + * each QP. + * + * \return SUCCESSFUL_RETURN \n + RET_UNABLE_TO_READ_BENCHMARK \n + RET_BENCHMARK_ABORTED */ +returnValue runOqpBenchmark( + const char * path, /**< Full path of the benchmark files (without trailing slash!). */ + BooleanType isSparse, /**< Shall convert matrices to sparse format before solution? */ + BooleanType useHotstarts, /**< Shall QP solution be hotstarted? */ + const Options & options, /**< QP solver options to be used while solving benchmark problems. */ + int_t maxAllowedNWSR, /**< Maximum number of working set recalculations to be performed. */ + real_t & maxNWSR, /**< Output: Maximum number of performed working set recalculations. */ + real_t & avgNWSR, /**< Output: Average number of performed working set recalculations. */ + real_t & maxCPUtime, /**< Output: Maximum CPU time required for solving each QP. */ + real_t & avgCPUtime, /**< Output: Average CPU time required for solving each QP. */ + real_t & maxStationarity, /**< Output: Maximum residual of stationarity condition. */ + real_t & maxFeasibility, /**< Output: Maximum residual of primal feasibility condition. */ + real_t & maxComplementarity /**< Output: Maximum residual of complementarity condition. */ +); + +END_NAMESPACE_QPOASES + +#endif /* QPOASES_OQPINTERFACE_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/extras/SolutionAnalysis.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/extras/SolutionAnalysis.hpp new file mode 100644 index 0000000..70d8ff3 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/extras/SolutionAnalysis.hpp @@ -0,0 +1,159 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file include/qpOASES/extras/SolutionAnalysis.hpp + * \author Hans Joachim Ferreau (thanks to Boris Houska) + * \version 3.2 + * \date 2008-2017 + * + * Declaration of the SolutionAnalysis class designed to perform + * additional analysis after solving a QP with qpOASES. + */ + +#ifndef QPOASES_SOLUTIONANALYSIS_HPP +#define QPOASES_SOLUTIONANALYSIS_HPP + +#include +#include + +BEGIN_NAMESPACE_QPOASES + +/** + * \brief Provides additional tools for analysing QP solutions. + * + * This class is intended to provide additional tools for analysing + * a QP solution obtained with qpOASES. + * + * \author Hans Joachim Ferreau (thanks to Boris Houska) + * \version 3.2 + * \date 2008-2017 + */ +class SolutionAnalysis +{ + /* + * PUBLIC MEMBER FUNCTIONS + */ +public: + /** Default constructor. */ + SolutionAnalysis(); + + /** Copy constructor (deep copy). */ + SolutionAnalysis(const SolutionAnalysis & rhs /**< Rhs object. */ + ); + + /** Destructor. */ + ~SolutionAnalysis(); + + /** Assignment operator (deep copy). */ + SolutionAnalysis & operator=(const SolutionAnalysis & rhs /**< Rhs object. */ + ); + + /** Computes the maximum violation of the KKT optimality conditions + * of the current iterate within the QProblemB object. + * \return Maximum violation of the KKT conditions (or INFTY on error). */ + real_t getKktViolation(QProblemB * const qp, /**< QProblemB to be analysed. */ + real_t * const maxStat = 0, /**< Output: maximum value of stationarity condition residual. */ + real_t * const maxFeas = 0, /**< Output: maximum value of primal feasibility violation. */ + real_t * const maxCmpl = 0 /**< Output: maximum value of complementarity residual. */ + ) const; + + /** Computes the maximum violation of the KKT optimality conditions + * of the current iterate within the QProblem object. + * \return Maximum violation of the KKT conditions (or INFTY on error). */ + real_t getKktViolation(QProblem * const qp, /**< QProblem to be analysed. */ + real_t * const maxStat = 0, /**< Output: maximum value of stationarity condition residual. */ + real_t * const maxFeas = 0, /**< Output: maximum value of primal feasibility violation. */ + real_t * const maxCmpl = 0 /**< Output: maximum value of complementarity residual. */ + ) const; + + /** Computes the maximum violation of the KKT optimality conditions + * of the current iterate within the SQProblem object. + * \return Maximum violation of the KKT conditions (or INFTY on error). */ + real_t getKktViolation(SQProblem * const qp, /**< SQProblem to be analysed. */ + real_t * const maxStat = 0, /**< Output: maximum value of stationarity condition residual. */ + real_t * const maxFeas = 0, /**< Output: maximum value of primal feasibility violation. */ + real_t * const maxCmpl = 0 /**< Output: maximum value of complementarity residual. */ + ) const; + + /** Computes the variance-covariance matrix of the QP output for uncertain + inputs. + * \return SUCCESSFUL_RETURN \n + RET_HOTSTART_FAILED \n + RET_STEPDIRECTION_FAILED_TQ \n + RET_STEPDIRECTION_FAILED_CHOLESKY */ + returnValue getVarianceCovariance(QProblemB * const qp, /**< QProblemB to be analysed. */ + const real_t * const g_b_bA_VAR, /**< Input: Variance-covariance of g, the bounds lb and ub, + * and lbA and ubA respectively. Dimension: 2nV x 2nV */ + real_t * const Primal_Dual_VAR /**< Output: The result for the variance-covariance of the primal + * and dual variables. Dimension: 2nV x 2nV */ + ) const; + + /** Computes the variance-covariance matrix of the QP output for uncertain + inputs. + * \return SUCCESSFUL_RETURN \n + RET_HOTSTART_FAILED \n + RET_STEPDIRECTION_FAILED_TQ \n + RET_STEPDIRECTION_FAILED_CHOLESKY */ + returnValue getVarianceCovariance(QProblem * const qp, /**< QProblem to be analysed. */ + const real_t * const + g_b_bA_VAR, /**< Input: Variance-covariance of g, the bounds lb and ub, + * and lbA and ubA respectively. Dimension: (2nV+nC) x (2nV+nC) */ + real_t * const Primal_Dual_VAR /**< Output: The result for the variance-covariance of the primal + * and dual variables. Dimension: (2nV+nC) x (2nV+nC) */ + ) const; + + /** Computes the variance-covariance matrix of the QP output for uncertain + inputs. + * \return SUCCESSFUL_RETURN \n + RET_HOTSTART_FAILED \n + RET_STEPDIRECTION_FAILED_TQ \n + RET_STEPDIRECTION_FAILED_CHOLESKY */ + returnValue getVarianceCovariance(SQProblem * const qp, /**< SQProblem to be analysed. */ + const real_t * const + g_b_bA_VAR, /**< Input: Variance-covariance of g, the bounds lb and ub, + * and lbA and ubA respectively. Dimension: (2nV+nC) x (2nV+nC) */ + real_t * const Primal_Dual_VAR /**< Output: The result for the variance-covariance of the primal + * and dual variables. Dimension: (2nV+nC) x (2nV+nC) */ + ) const; + + /** Checks if a direction of negative curvature shows up if we remove all bounds that just recently became + * active */ + returnValue checkCurvatureOnStronglyActiveConstraints(SQProblemSchur * qp); + returnValue checkCurvatureOnStronglyActiveConstraints(SQProblem * qp); + + /* + * PROTECTED MEMBER VARIABLES + */ +protected: +}; + +END_NAMESPACE_QPOASES + +#include + +#endif /* QPOASES_SOLUTIONANALYSIS_HPP */ + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/extras/SolutionAnalysis.ipp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/extras/SolutionAnalysis.ipp new file mode 100755 index 0000000..cd89776 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/include/qpOASES/extras/SolutionAnalysis.ipp @@ -0,0 +1,51 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file include/qpOASES/extras/SolutionAnalysis.ipp + * \author Hans Joachim Ferreau (thanks to Boris Houska) + * \version 3.2 + * \date 2008-2017 + * + * Implementation of inlined member functions of the SolutionAnalysis class + * designed to perform additional analysis after solving a QP with qpOASES. + * + */ + + + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + + +BEGIN_NAMESPACE_QPOASES + + +END_NAMESPACE_QPOASES + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/CUTEst/Makefile b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/CUTEst/Makefile new file mode 100755 index 0000000..e1fbef0 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/CUTEst/Makefile @@ -0,0 +1,79 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: cutestDriver/Makefile +## Author: Dennis Janka +## Version: 3.2 +## Date: 2015-2017 +## + +# include directories, relative +IDIR = ../../include +SRCDIR = ../../src +BINDIR = ../../bin +CUTESTLIBPATH = ${CUTEST}/objects/${MYARCH}/double + +# don't change that (for now) ... +PROBLEMPATH = ./prob + +# file extensions +CPP = g++ +CPPFLAGS = -Wall -pedantic -Wshadow -O0 -finline-functions -fPIC -DLINUX -g +FF = gfortran +FFLAGS = + +#link against CUTEst library, qpOASES library and compiled test problem +LINKOPTS = -L${CUTESTLIBPATH} -L${PROBLEMPATH} -Wl,-rpath=${PROBLEMPATH} \ + -L${BINDIR} -Wl,-rpath=${BINDIR} -lqpOASES \ + -lcutest -llapack -lm -lgfortran -lprob + +IFLAGS = -I${IDIR} \ + -I${CUTEST}/include + +QPOASES_EXES = \ + qpoasesCutest + +## +## targets +## + +all: ${QPOASES_EXES} + +qpoasesCutest: qpoasesCutest.o + @echo "Creating" $@ + ${CPP} -o $@ ${CPPFLAGS} $< ${LINKOPTS} + +clean: + rm -f *.o ${QPOASES_EXES} + +clobber: clean + +%.o: %.cpp + @echo "Creating" $@ + @${CPP} -c ${IFLAGS} ${CPPFLAGS} $< -o $@ + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/CUTEst/makeprob b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/CUTEst/makeprob new file mode 100755 index 0000000..237a895 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/CUTEst/makeprob @@ -0,0 +1,28 @@ +#!/bin/bash + +if [ -z "$1" ]; then + echo Usage: $0 problemname + exit +fi + +PROBLEMPATH="./prob" +mkdir -p $PROBLEMPATH +cd $PROBLEMPATH + +# Call sifdecoder (additional parameter for problem size can be passed) +if [ -z "$2" ]; then + sifdecoder $MASTSIF/$1 +else + sifdecoder -param N=$2 $MASTSIF/$1 +fi + +# Compile objects +gfortran -c RANGE.f -fPIC -o RANGE.o +gfortran -c ELFUN.f -fPIC -o ELFUN.o +gfortran -c GROUP.f -fPIC -o GROUP.o + +# Build shared library +gfortran -shared -o libprob.so RANGE.o ELFUN.o GROUP.o + +cd ../ + diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/CUTEst/qpoasesCutest.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/CUTEst/qpoasesCutest.cpp new file mode 100644 index 0000000..d1d568f --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/CUTEst/qpoasesCutest.cpp @@ -0,0 +1,504 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file interfaces/CUTEst/qpoasesCutest.cpp + * \author Dennis Janka + * \version 3.2 + * \date 2015-2017 + * + * Solve the CUTEst problem in prob/ subdirectory + */ + +/* Choose one or more methods to solve the QP */ +#define SOLVE_DENSE 0 /* Standard qpOASES, matrices passed dense */ +#define SOLVE_SPARSE 0 /* Standard qpOASES, matrices passed sparse */ +#define SOLVE_SCHUR 1 /* Schur complement qpOASES */ + +#include +#include + +extern "C" +{ /* To prevent C++ compilers from mangling symbols */ +#include +} + +int convertTripletToHbf(int m, + int n, + int nnz, + double * vals, + int * iRow, + int * jCol, + double * vals_hbf, + int * iRow_hbf, + int * jCol_hbf) +{ + int i, ii, j, k; + + /* Initialize output arrays */ + for (k = 0; k < n + 1; k++) + jCol_hbf[k] = 0; + for (k = 0; k < nnz; k++) { + iRow_hbf[k] = 0; + vals_hbf[k] = 0.0; + } + + /* Count elements for each column */ + for (k = 0; k < nnz; k++) { + j = jCol[k] - 1; // Convert Fortran to C indices! + jCol_hbf[j]++; + } + + /* Set the column pointers */ + jCol_hbf[n] = nnz; + for (k = n - 1; k > -1; k--) + jCol_hbf[k] = jCol_hbf[k + 1] - jCol_hbf[k]; + + /* Put row indices and values at the right places, use jCol_hbf[j] to track elements of the jth column */ + for (k = 0; k < nnz; k++) { + i = iRow[k] - 1; // Convert Fortran to C indices! + j = jCol[k] - 1; + ii = jCol_hbf[j]; + + vals_hbf[ii] = vals[k]; + iRow_hbf[ii] = i; + jCol_hbf[j] = ii + 1; + } + + /* Shift all column pointers back again */ + for (k = n - 1; k > 0; k--) + jCol_hbf[k] = jCol_hbf[k - 1]; + jCol_hbf[0] = 0; + + return 0; +} + +int main() +{ + /* + * PART I: Extract CUTEst problemdata: + * + * - problem dimension + * - variable and constraint bounds + * - objective gradient + * - sparse and dense Jacobian + * - sparse and dense Hessian + * - initial values for x and y + */ + + /* From CUTEst generic c package */ + char * fname = "prob/OUTSDIF.d"; /* CUTEst data file */ + int funit = 42; /* FORTRAN unit number for OUTSDIF.d */ + int iout = 6; /* FORTRAN unit number for error output */ + int io_buffer = 11; /* FORTRAN unit internal input/output */ + int ierr; /* Exit flag from OPEN and CLOSE */ + int status; /* Exit flag from CUTEst tools */ + int e_order = 0, l_order = 0, v_order = 0; + + /* Problem description: the following variables will be set for qpOASES call */ + int nVar; /* number of variables */ + int nCon; /* number of constraints */ + double *lb, *ub; /* lower and upper bounds for variables */ + double *lbA, *ubA; /* lower and upper bounds for constraints */ + double * g; /* objective gradient */ +#if SOLVE_DENSE + double *hesDense, *jacDense; /* dense Hessian and Jacobian */ +#endif +#if SOLVE_SCHUR || SOLVE_SPARSE + /* Sparse Hessian and Jacobian in Harwell-Boeing format: */ + int nnzj, nnzh; /* number of nonzero elements in Jacobian and Hessian */ + double *hesVal, *jacVal; /* nonzero elements of Hessian and Jacobian */ + int *hesIndCol, *hesIndRow; /* column and row indices of Hessian */ + int *jacIndCol, *jacIndRow; /* column and row indices of Jacobian */ +#endif + + /* Additional problem description: these variables are set and may also be used by qpOASES */ + double obj; /* constant objective offset */ + double * xInit; /* initial values for primal variables */ + double * yInit; /* initial values for dual variables */ + logical * isEq; /* logical array to mark equality constraints */ + + /* Open problem description file OUTSDIF.d */ + ierr = 0; + FORTRAN_open(&funit, fname, &ierr); + if (ierr) { + printf("Error opening file OUTSDIF.d.\nAborting.\n"); + exit(1); + } + + /* Determine problem size */ + CUTEST_cdimen(&status, &funit, &nVar, &nCon); + if (status) { + printf("** CUTEst error, status = %d, aborting\n", status); + exit(status); + } + + /* Reserve memory for variables, bounds, and multipliers */ + /* and call appropriate initialization routine for CUTEst */ + logical * isLinear; + xInit = new double[nVar]; + yInit = new double[nCon]; + lb = new double[nVar]; + ub = new double[nVar]; + lbA = new double[nCon]; + ubA = new double[nCon]; + isEq = new logical[nCon]; + isLinear = new logical[nCon]; + + CUTEST_csetup(&status, + &funit, + &iout, + &io_buffer, + &nVar, + &nCon, + xInit, + lb, + ub, + yInit, + lbA, + ubA, + isEq, + isLinear, + &e_order, + &l_order, + &v_order); + if (status) { + printf("** CUTEst_csetup: error, status = %d, aborting\n", status); + exit(status); + } + + /* Evaluate gradient and objective at x=0 to get g */ + logical grad = 1; + g = new double[nVar]; + double * xZero = new double[nVar]; + for (int k = 0; k < nVar; k++) + xZero[k] = 0.0; + CUTEST_cofg(&status, &nVar, xZero, &obj, g, &grad); + if (status) { + printf("** CUTEst_cofg: error, status = %d, aborting\n", status); + exit(status); + } + + double * cVal = new double[nCon]; +#if SOLVE_SPARSE || SOLVE_SCHUR + /* Evaluate sparse Jacobian in triplet format */ + int lj = nCon * nVar; // overestimate + double * J_val = new double[lj]; + int * J_var = new int[lj]; + int * J_fun = new int[lj]; + + if (nCon > 0) { + /* Evaluate sparse constraints at x=0 to get the rhs of equality constraints (they are not set by + * csetup!) */ + CUTEST_ccfsg(&status, &nVar, &nCon, xZero, cVal, &nnzj, &lj, J_val, J_var, J_fun, &grad); + if (status) { + printf("** CUTEst_ccfsg: error, status = %d, aborting\n", status); + exit(status); + } + + for (int k = 0; k < nCon; k++) + if (isEq[k]) + lbA[k] = ubA[k] = -cVal[k]; + + jacIndCol = new int[nVar + 1]; + jacIndRow = new int[nnzj]; + jacVal = new double[nnzj]; + convertTripletToHbf(nCon, nVar, nnzj, J_val, J_fun, J_var, jacVal, jacIndRow, jacIndCol); + } + delete[] J_val; + delete[] J_fun; + delete[] J_var; + + /* Evaluate sparse Hessian in triplet format */ + int lh = nVar * nVar; // overestimate + double * H_val = new double[lh]; + int * H_col = new int[lh]; + int * H_row = new int[lh]; + CUTEST_csh(&status, &nVar, &nCon, xInit, yInit, &nnzh, &lh, H_val, H_row, H_col); + if (status) { + printf("** CUTEst_csh: error, status = %d, aborting\n", status); + exit(status); + } + /* Only upper triangular matrix is returned by CUTEst, to be safe, set H to be the full matrix */ + int count = 0; + for (int k = 0; k < nnzh; k++) + if (H_row[k] != H_col[k]) { + H_val[nnzh + count] = H_val[k]; + H_col[nnzh + count] = H_row[k]; + H_row[nnzh + count] = H_col[k]; + count++; + } + nnzh = nnzh + count; + + hesIndCol = new int[nVar + 1]; + hesIndRow = new int[nnzh]; + hesVal = new double[nnzh]; + convertTripletToHbf(nVar, nVar, nnzh, H_val, H_row, H_col, hesVal, hesIndRow, hesIndCol); + + delete[] H_val; + delete[] H_row; + delete[] H_col; +#endif + +#if SOLVE_DENSE + if (nCon > 0) { + /* Evaluate dense constraints at x=0 to get the rhs of equality constraints (they are not set by + * csetup!) */ + logical trans = 1; + jacDense = new double[nCon * nVar]; + CUTEST_ccfg(&status, &nVar, &nCon, xZero, cVal, &trans, &nVar, &nCon, jacDense, &grad); + } + + /* Evaluate dense Hessian */ + hesDense = new double[nVar * nVar]; + CUTEST_cdh(&status, &nVar, &nCon, xInit, yInit, &nVar, hesDense); + if (status) { + printf("** CUTEst_cdh: error, status = %d, aborting\n", status); + exit(status); + } +#endif + delete[] xZero; + + /* + * End of CUTEst stuff + */ + + /* + * PART II: qpOASES + */ + + USING_NAMESPACE_QPOASES + + Options opts; +#if SOLVE_DENSE + SymDenseMat * H_d; + DenseMatrix * A_d; +#endif +#if SOLVE_SCHUR || SOLVE_SPARSE + SymSparseMat * H_s; + SparseMatrix * A_s; +#endif + Bounds bInit(nVar); + Constraints cInit(nCon); + double * xOpt = new double[nVar]; + double * yOpt = new double[nVar + nCon]; + Bounds bOpt(nVar); + Constraints cOpt(nCon); + +#if SOLVE_DENSE + A_d = new DenseMatrix(nCon, nVar, nVar, jacDense); + H_d = new SymDenseMat(nVar, nVar, nVar, hesDense); +#endif +#if SOLVE_SCHUR || SOLVE_SPARSE + A_s = new SparseMatrix(nCon, nVar, jacIndRow, jacIndCol, jacVal); + H_s = new SymSparseMat(nVar, nVar, hesIndRow, hesIndCol, hesVal); + H_s->createDiagInfo(); +#endif + + /* Set initial working set depending on initial values for x and y */ + /// \todo I have not tested this + double eps = 2.0e-16; + for (int k = 0; k < nVar; k++) { + if (getAbs(xInit[k] - lb[k]) < eps) + bInit.setStatus(k, ST_LOWER); + else if (getAbs(xInit[k] - ub[k]) < eps) + bInit.setStatus(k, ST_UPPER); + else + bInit.setStatus(k, ST_INACTIVE); + + bInit.setType(k, ST_UNKNOWN); + } + /// \todo should do this based on yInit (take care of signs of lambda) + for (int k = 0; k < nCon; k++) { + if (getAbs(cVal[k] - lbA[k]) < eps) + cInit.setStatus(k, ST_LOWER); + else if (getAbs(cVal[k] - ubA[k]) < eps) + cInit.setStatus(k, ST_UPPER); + else + cInit.setStatus(k, ST_INACTIVE); + + if (isEq[k]) + cInit.setType(k, ST_EQUALITY); + else + cInit.setType(k, ST_UNKNOWN); + } + delete[] cVal; + + /* Set up QProblem object(s). */ +#if SOLVE_SCHUR + SQProblemSchur qpSchur(nVar, nCon, HST_UNKNOWN, 75); +#endif +#if SOLVE_DENSE + SQProblem qpDense(nVar, nCon, HST_UNKNOWN); +#endif +#if SOLVE_SPARSE + SQProblem qpSparse(nVar, nCon, HST_UNKNOWN); +#endif + + /* Set options */ + returnValue ret; + int maxIt = 10000; + double maxTime = 100000; + + // opts.setToReliable(); + opts.setToDefault(); + + // opts.printLevel = PL_HIGH; + // opts.enableRamping = BT_TRUE; + // opts.enableFarBounds = BT_TRUE; + // opts.enableFlippingBounds = BT_TRUE; + // opts.enableRegularisation = BT_FALSE; + // opts.enableFullLITests = BT_TRUE; + // opts.enableNZCTests = BT_TRUE; + // opts.enableDriftCorrection = 1; + // opts.enableCholeskyRefactorisation = 1; + opts.enableEqualities = BT_TRUE; + // opts.terminationTolerance = 2.2204e-09; + // opts.boundTolerance = 2.2204e-10; + // opts.boundRelaxation = 10000; + // opts.epsNum = -2.2204e-13; + // opts.epsDen = 2.2204e-13; + // opts.maxPrimalJump = 100000000; + // opts.maxDualJump = 100000000; + // opts.initialRamping = 0.50000; + // opts.finalRamping = 1; + // opts.initialFarBounds = 1000000; + // opts.growFarBounds = 1000; + opts.initialStatusBounds = ST_INACTIVE; + // opts.epsFlipping = 2.2204e-13; + // opts.numRegularisationSteps = 4; + // opts.epsRegularisation = 2.2204e-13; + opts.numRefinementSteps = 3; + // opts.epsIterRef = 2.2204e-14; + // opts.epsLITests = 2.2204e-09; + // opts.epsNZCTests = 6.6613e-13; + opts.enableInertiaCorrection = BT_TRUE; + opts.rcondSMin = 1.0e-14; + + /* Solve QPs. */ + int nWSR; + double time; + struct timeval startTime; + struct timeval endTime; + int elapsedTime; + gettimeofday(&startTime, NULL); +#if SOLVE_DENSE + printf("\n----------Begin Standard version with dense matrices----------\n"); + qpDense.setOptions(opts); + nWSR = maxIt; + time = maxTime; + + for (int k = 0; k < nVar; k++) { + xOpt[k] = xInit[k]; + yOpt[k] = 0.0; + } + for (int k = 0; k < nCon; k++) + yOpt[k + nVar] = yInit[k]; // what about lambda for bound constraints? + bOpt = Bounds(bInit); + cOpt = Constraints(cInit); + ret = qpDense.init(H_d, g, A_d, lb, ub, lbA, ubA, nWSR, &time, xOpt, yOpt, &bOpt, &cOpt); + + if (ret == SUCCESSFUL_RETURN) + printf("Obj. = %23.16e\n", qpDense.getObjVal() + obj); + printf("\n-----------End Standard version with dense matrices-----------\n"); +#endif + +#if SOLVE_SCHUR + printf("\n----------Begin Schur complement version----------\n"); + qpSchur.setOptions(opts); + nWSR = maxIt; + time = maxTime; + + for (int k = 0; k < nVar; k++) { + xOpt[k] = xInit[k]; + yOpt[k] = 0.0; + } + for (int k = 0; k < nCon; k++) + yOpt[k + nVar] = yInit[k]; // what about lambda for bound constraints? + bOpt = Bounds(bInit); + cOpt = Constraints(cInit); + // ret = qpSchur.init( H_s, g, A_s, lb, ub, lbA, ubA, nWSR, &time, xOpt, yOpt, &bOpt, &cOpt ); + ret = qpSchur.init(H_s, g, A_s, lb, ub, lbA, ubA, nWSR, &time); + + if (ret == SUCCESSFUL_RETURN) + printf("Obj. = %23.16e\n", qpSchur.getObjVal() + obj); + printf("\n\n-----------End Schur complement version-----------\n"); +#endif + +#if SOLVE_SPARSE + printf("\n----------Begin Standard version with sparse matrices----------\n"); + qpSparse.setOptions(opts); + nWSR = maxIt; + time = maxTime; + + for (int k = 0; k < nVar; k++) { + xOpt[k] = xInit[k]; + yOpt[k] = 0.0; + } + for (int k = 0; k < nCon; k++) + yOpt[k + nVar] = yInit[k]; // what about lambda for bound constraints? + bOpt = Bounds(bInit); + cOpt = Constraints(cInit); + ret = qpSparse.init(H_s, g, A_s, lb, ub, lbA, ubA, nWSR, &time, xOpt, yOpt, &bOpt, &cOpt); + + if (ret == SUCCESSFUL_RETURN) + printf("Obj. = %23.16e\n", qpSparse.getObjVal() + obj); + printf("\n-----------End Standard version with sparse matrices-----------\n"); +#endif + gettimeofday(&endTime, NULL); + + elapsedTime = + (endTime.tv_sec * 1000000 + (endTime.tv_usec)) - (startTime.tv_sec * 1000000 + (startTime.tv_usec)); + printf("Took %g seconds.\n", elapsedTime / 1000000.0); + + /* Clean up */ + delete[] g; + delete[] lb; + delete[] ub; + delete[] lbA; + delete[] ubA; + delete[] isEq; + delete[] isLinear; + delete[] xOpt; + delete[] yOpt; + delete[] xInit; + delete[] yInit; + +#if SOLVE_SCHUR || SOLVE_SPARSE + delete[] hesVal; + delete[] hesIndRow; + delete[] hesIndCol; + if (nCon > 0) { + delete[] jacVal; + delete[] jacIndRow; + delete[] jacIndCol; + } +#endif +#if SOLVE_DENSE + delete[] hesDense; + if (nCon > 0) + delete[] jacDense; +#endif + + return ret; +} diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/CUTEst/readme.txt b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/CUTEst/readme.txt new file mode 100755 index 0000000..2983489 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/CUTEst/readme.txt @@ -0,0 +1,39 @@ +CUTEst interface for qpOASES +by Dennis Janka + +==================================================== + +0.) Files included: + + - qpoasesCutest.cpp + - Makefile + - makeprob + - readme.txt + +1.) Download and install CUTEst from + + http://ccpforge.cse.rl.ac.uk/gf/project/cutest/wiki/ + + Make sure all environment variables are set as instructed. + (in particular $CUTEST, $MYARCH and $MASTSIF) + +2.) To decode and compile a problem, type: + + ./makeprob + + For problems that come in different sizes (e.g. NCVXQP[1-9]) the size + parameter ( N= ) may be passed as a second argument: + + ./makeprob + + This calls "sifdecoder" to decode the .sif file and creates a shared + library libprob.so in prob/ that will be linked against the + qpOASES CUTEst interface. + +3.) Finally, call "make" to compile and link qpoasesCutest. + You may have to set the correct paths for the qpOASES library and + header files in the makefile. + +4.) The command ./qpoasesCutest runs qpOASES with the latest compiled + .sif problem. For solving further problems, only the appropriate + "./makeprob" call is required. diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/Makefile b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/Makefile new file mode 100755 index 0000000..f7774a1 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/Makefile @@ -0,0 +1,129 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: interfaces/c/Makefile +## Author: Hans Joachim Ferreau +## Version: 3.2 +## Date: 2014-2017 +## + + +include ../../make.mk + +## +## flags +## + +IFLAGS = -I. \ + -I${IDIR} \ + -I${SRCDIR} + +QPOASES_WRAPPER_OBJECTS = \ + ${SRCDIR}/SQProblem.${OBJEXT} \ + ${SRCDIR}/QProblem.${OBJEXT} \ + ${SRCDIR}/QProblemB.${OBJEXT} \ + ${SRCDIR}/Bounds.${OBJEXT} \ + ${SRCDIR}/Constraints.${OBJEXT} \ + ${SRCDIR}/SubjectTo.${OBJEXT} \ + ${SRCDIR}/Indexlist.${OBJEXT} \ + ${SRCDIR}/Flipper.${OBJEXT} \ + ${SRCDIR}/Utils.${OBJEXT} \ + ${SRCDIR}/Options.${OBJEXT} \ + ${SRCDIR}/Matrices.${OBJEXT} \ + ${SRCDIR}/MessageHandling.${OBJEXT} \ + qpOASES_wrapper.${OBJEXT} + +QPOASES_DEPENDS = \ + ${IDIR}/qpOASES.hpp \ + ${IDIR}/qpOASES/LapackBlasReplacement.hpp \ + ${IDIR}/qpOASES/SQProblem.hpp \ + ${IDIR}/qpOASES/QProblem.hpp \ + ${IDIR}/qpOASES/Flipper.hpp \ + ${IDIR}/qpOASES/QProblemB.hpp \ + ${IDIR}/qpOASES/Bounds.hpp \ + ${IDIR}/qpOASES/Constraints.hpp \ + ${IDIR}/qpOASES/SubjectTo.hpp \ + ${IDIR}/qpOASES/Indexlist.hpp \ + ${IDIR}/qpOASES/Utils.hpp \ + ${IDIR}/qpOASES/Constants.hpp \ + ${IDIR}/qpOASES/Types.hpp \ + ${IDIR}/qpOASES/Options.hpp \ + ${IDIR}/qpOASES/Matrices.hpp \ + ${IDIR}/qpOASES/MessageHandling.hpp \ + qpOASES_wrapper.h + +QPOASES_C_EXAMPLES = \ + ${BINDIR}/c_example1${EXE} \ + ${BINDIR}/c_example1a${EXE} \ + ${BINDIR}/c_example1b${EXE} + + +## +## targets +## + +all: ${LINK_DEPENDS_WRAPPER} ${QPOASES_C_EXAMPLES} + + +${BINDIR}/libqpOASES_wrapper.${LIBEXT}: ${QPOASES_WRAPPER_OBJECTS} + @${ECHO} "Creating" $@ + @${AR} r $@ qpOASES_wrapper.${OBJEXT} + +${BINDIR}/libqpOASES_wrapper.${DLLEXT}: ${QPOASES_WRAPPER_OBJECTS} + @${ECHO} "Creating" $@ + ${CC} ${SHARED} ${DEF_TARGET} qpOASES_wrapper.${OBJEXT} ${LINK_LIBRARIES_WRAPPER} + +clean: + @${ECHO} "Cleaning up (interfaces/c)" + @${RM} -f *.${OBJEXT} ${BINDIR}/*.${LIBEXT} ${BINDIR}/*.${DLLEXT} ${BINDIR}/c_example*${EXE} + +clobber: clean + + +%.${OBJEXT}: %.cpp ${QPOASES_DEPENDS} + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} -c ${IFLAGS} ${CPPFLAGS} -D__C_WRAPPER__ $< + +c_example1.${OBJEXT}: c_example1.c ${LINK_DEPENDS_WRAPPER} + @${ECHO} "Creating" $@ + @${CC} ${DEF_TARGET} -c ${IFLAGS} ${CPPFLAGS} $< + +c_example1a.${OBJEXT}: c_example1a.c ${LINK_DEPENDS_WRAPPER} + @${ECHO} "Creating" $@ + @${CC} ${DEF_TARGET} -c ${IFLAGS} ${CPPFLAGS} $< + +c_example1b.${OBJEXT}: c_example1b.c ${LINK_DEPENDS_WRAPPER} + @${ECHO} "Creating" $@ + @${CC} ${DEF_TARGET} -c ${IFLAGS} ${CPPFLAGS} $< + + +${BINDIR}/%${EXE}: %.${OBJEXT} ${LINK_DEPENDS_WRAPPER} + @${ECHO} "Creating" $@ + ${CC} ${DEF_TARGET} ${IFLAGS} ${CPPFLAGS} $< ${QPOASES_LINK_WRAPPER} ${LINK_LIBRARIES_WRAPPER} + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/c_example1.c b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/c_example1.c new file mode 100755 index 0000000..9a917ee --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/c_example1.c @@ -0,0 +1,104 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file interfaces/c/c_example1.c + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2014-2017 + * + * Very simple example for testing qpOASES (using QProblem class through C interface). + */ + +#include + +#include + + +/** Example for qpOASES main function using the QProblem class. */ +int main( ) +{ + /* Setup data of first QP. */ + real_t H[2*2] = { 1.0, 0.0, 0.0, 0.5 }; + real_t A[1*2] = { 1.0, 1.0 }; + real_t g[2] = { 1.5, 1.0 }; + real_t lb[2] = { 0.5, -2.0 }; + real_t ub[2] = { 5.0, 2.0 }; + real_t lbA[1] = { -1.0 }; + real_t ubA[1] = { 2.0 }; + + /* Setup data of second QP. */ + real_t g_new[2] = { 1.0, 1.5 }; + real_t lb_new[2] = { 0.0, -1.0 }; + real_t ub_new[2] = { 5.0, -0.5 }; + real_t lbA_new[1] = { -2.0 }; + real_t ubA_new[1] = { 1.0 }; + + int nWSR; + qpOASES_Options options; + + real_t xOpt[2]; + real_t yOpt[2+1]; + real_t obj; + int status; + + qpOASES_Options_init( &options,0 ); + options.printLevel = PL_MEDIUM; + + + QProblem_setup( 2,1,HST_UNKNOWN ); + + /* Solve first QP. */ + nWSR = 10; + QProblem_init( H,g,A,lb,ub,lbA,ubA, + (int_t* const)&nWSR,0,&options, + xOpt,yOpt,&obj,(int_t* const)&status + ); + + /* Print solution of first QP. */ + printf( "\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", + xOpt[0],xOpt[1],yOpt[0],yOpt[1],yOpt[2], obj ); + + + /* Solve second QP. */ + nWSR = 10; + QProblem_hotstart( g_new,lb_new,ub_new,lbA_new,ubA_new, + (int_t* const)&nWSR,0, + xOpt,yOpt,&obj,(int_t* const)&status + ); + + /* Print solution of first QP. */ + printf( "\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", + xOpt[0],xOpt[1],yOpt[0],yOpt[1],yOpt[2], obj ); + + + QProblem_cleanup(); + + return 0; +} + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/c_example1a.c b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/c_example1a.c new file mode 100755 index 0000000..f341837 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/c_example1a.c @@ -0,0 +1,105 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file interfaces/c/c_example1a.c + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2014-2017 + * + * Very simple example for testing qpOASES (using SQProblem class through C interface). + */ + +#include + +#include + + +/** Example for qpOASES main function using the QProblem class. */ +int main( ) +{ + /* Setup data of first QP. */ + real_t H[2*2] = { 1.0, 0.0, 0.0, 0.5 }; + real_t A[1*2] = { 1.0, 1.0 }; + real_t g[2] = { 1.5, 1.0 }; + real_t lb[2] = { 0.5, -2.0 }; + real_t ub[2] = { 5.0, 2.0 }; + real_t lbA[1] = { -1.0 }; + real_t ubA[1] = { 2.0 }; + + /* Setup data of second QP. */ + real_t H_new[2*2] = { 1.0, 0.5, 0.5, 0.5 }; + real_t A_new[1*2] = { 1.0, 5.0 }; + real_t g_new[2] = { 1.0, 1.5 }; + real_t lb_new[2] = { 0.0, -1.0 }; + real_t ub_new[2] = { 5.0, -0.5 }; + real_t lbA_new[1] = { -2.0 }; + real_t ubA_new[1] = { 1.0 }; + + int nWSR; + + real_t xOpt[2]; + real_t yOpt[2+1]; + real_t obj; + int status; + + qpOASES_Options options; + qpOASES_Options_init( &options,0 ); + + + SQProblem_setup( 2,1,HST_UNKNOWN ); + + /* Solve first QP. */ + nWSR = 10; + SQProblem_init( H,g,A,lb,ub,lbA,ubA, + (int_t* const)&nWSR,0,&options, + xOpt,yOpt,&obj,(int_t* const)&status + ); + + /* Print solution of first QP. */ + printf( "\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", + xOpt[0],xOpt[1],yOpt[0],yOpt[1],yOpt[2], obj ); + + + /* Solve second QP. */ + nWSR = 10; + SQProblem_hotstart( H_new,g_new,A_new,lb_new,ub_new,lbA_new,ubA_new, + (int_t* const)&nWSR,0, + xOpt,yOpt,&obj,(int_t* const)&status + ); + + /* Print solution of first QP. */ + printf( "\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", + xOpt[0],xOpt[1],yOpt[0],yOpt[1],yOpt[2], obj ); + + + SQProblem_cleanup(); + + return 0; +} + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/c_example1b.c b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/c_example1b.c new file mode 100755 index 0000000..701c7e5 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/c_example1b.c @@ -0,0 +1,102 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file interfaces/c/example1b.c + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2014-2017 + * + * Very simple example for testing qpOASES (using QProblemB class through C interface). + */ + +#include + +#include + + +/** Example for qpOASES main function using the QProblem class. */ +int main( ) +{ + /* Setup data of first QP. */ + real_t H[2*2] = { 1.0, 0.0, 0.0, 0.5 }; + real_t g[2] = { 1.5, 1.0 }; + real_t lb[2] = { 0.5, -2.0 }; + real_t ub[2] = { 5.0, 2.0 }; + + /* Setup data of second QP. */ + real_t g_new[2] = { 1.0, 1.5 }; + real_t lb_new[2] = { 0.0, -1.0 }; + real_t ub_new[2] = { 5.0, -0.5 }; + + int nWSR; + qpOASES_Options options; + + real_t xOpt[2]; + real_t yOpt[2]; + real_t obj; + int status; + + qpOASES_Options_init( &options,0 ); + /*options.enableFlippingBounds = 0; */ + options.initialStatusBounds = ST_INACTIVE; + options.numRefinementSteps = 1; + options.enableCholeskyRefactorisation = 1; + + + QProblemB_setup( 2,HST_UNKNOWN ); + + /* Solve first QP. */ + nWSR = 10; + QProblemB_init( H,g,lb,ub, + (int_t* const)&nWSR,0,&options, + xOpt,yOpt,&obj,(int_t* const)&status + ); + + /* Print solution of first QP. */ + printf( "\nxOpt = [ %e, %e ]; yOpt = [ %e, %e ]; objVal = %e\n\n", + xOpt[0],xOpt[1],yOpt[0],yOpt[1], obj ); + + + /* Solve second QP. */ + nWSR = 10; + QProblemB_hotstart( g_new,lb_new,ub_new, + (int_t* const)&nWSR,0, + xOpt,yOpt,&obj,(int_t* const)&status + ); + + /* Print solution of first QP. */ + printf( "\nxOpt = [ %e, %e ]; yOpt = [ %e, %e ]; objVal = %e\n\n", + xOpt[0],xOpt[1],yOpt[0],yOpt[1], obj ); + + + QProblemB_cleanup(); + + return 0; +} + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/qpOASES_wrapper.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/qpOASES_wrapper.cpp new file mode 100644 index 0000000..cd1e189 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/qpOASES_wrapper.cpp @@ -0,0 +1,521 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file interfaces/c/qpOASES_wrapper.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2014-2017 + * + * Interface that enables to call qpOASES from plain C. + * + */ + +#include + +USING_NAMESPACE_QPOASES + +extern "C" +{ +#include "qpOASES_wrapper.h" +} + +/* + * q p O A S E S _ O p t i o n s _ i n i t + */ +int_t qpOASES_Options_init(qpOASES_Options * const options, int_t mode) +{ + if ((mode < 0) || (mode > 2)) + return -1; + + if (options == 0) + return -1; + + /* setup default */ + options->printLevel = PL_MEDIUM; +#ifdef __DEBUG__ + options->printLevel = PL_HIGH; +#endif +#ifdef __SUPPRESSANYOUTPUT__ + options->printLevel = PL_NONE; +#endif + + options->enableRamping = BT_TRUE; + options->enableFarBounds = BT_TRUE; + options->enableFlippingBounds = BT_TRUE; + options->enableRegularisation = BT_FALSE; + options->enableFullLITests = BT_FALSE; + options->enableNZCTests = BT_TRUE; + options->enableDriftCorrection = 1; + options->enableCholeskyRefactorisation = 0; + options->enableEqualities = BT_FALSE; + +#ifdef __USE_SINGLE_PRECISION__ + options->terminationTolerance = 1.0e2 * EPS; + options->boundTolerance = 1.0e2 * EPS; +#else + options->terminationTolerance = 5.0e6 * EPS; + options->boundTolerance = 1.0e6 * EPS; +#endif + options->boundRelaxation = 1.0e4; +#ifdef __USE_SINGLE_PRECISION__ + options->epsNum = -1.0e2 * EPS; + options->epsDen = 1.0e2 * EPS; +#else + options->epsNum = -1.0e3 * EPS; + options->epsDen = 1.0e3 * EPS; +#endif + options->maxPrimalJump = 1.0e8; + options->maxDualJump = 1.0e8; + + options->initialRamping = 0.5; + options->finalRamping = 1.0; + options->initialFarBounds = 1.0e6; + options->growFarBounds = 1.0e3; + options->initialStatusBounds = ST_LOWER; +#ifdef __USE_SINGLE_PRECISION__ + options->epsFlipping = 5.0e1 * EPS; +#else + options->epsFlipping = 1.0e3 * EPS; +#endif + options->numRegularisationSteps = 0; +#ifdef __USE_SINGLE_PRECISION__ + options->epsRegularisation = 2.0e1 * EPS; + options->numRefinementSteps = 2; +#else + options->epsRegularisation = 1.0e3 * EPS; + options->numRefinementSteps = 1; +#endif + options->epsIterRef = 1.0e2 * EPS; +#ifdef __USE_SINGLE_PRECISION__ + options->epsLITests = 5.0e1 * EPS; + options->epsNZCTests = 1.0e2 * EPS; +#else + options->epsLITests = 1.0e5 * EPS; + options->epsNZCTests = 3.0e3 * EPS; +#endif + + options->enableDropInfeasibles = BT_FALSE; + options->dropBoundPriority = 1; + options->dropEqConPriority = 1; + options->dropIneqConPriority = 1; + + switch (mode) { + case 0: + /* default, already set */ + break; + + case 1: + /* reliable */ + options->enableFullLITests = BT_TRUE; + options->enableCholeskyRefactorisation = 1; + +#ifdef __USE_SINGLE_PRECISION__ + options->numRefinementSteps = 3; +#else + options->numRefinementSteps = 2; +#endif + + case 2: + /* MPC */ + options->enableRamping = BT_FALSE; + options->enableFarBounds = BT_TRUE; + options->enableFlippingBounds = BT_FALSE; + options->enableRegularisation = BT_TRUE; + options->enableNZCTests = BT_FALSE; + options->enableDriftCorrection = 0; + options->enableEqualities = BT_TRUE; + +#ifdef __USE_SINGLE_PRECISION__ + options->terminationTolerance = 1.0e3 * EPS; +#else + options->terminationTolerance = 1.0e9 * EPS; +#endif + + options->initialStatusBounds = ST_INACTIVE; + options->numRegularisationSteps = 1; +#ifdef __USE_SINGLE_PRECISION__ + options->numRefinementSteps = 2; +#else + options->numRefinementSteps = 0; +#endif + } + + return 0; +} + +/* + * q p O A S E S _ O p t i o n s _ c o p y + */ +int_t qpOASES_Options_copy(const qpOASES_Options * const from, Options * const to) +{ + if ((from == 0) || (to == 0)) + return -1; + + to->printLevel = (PrintLevel)(from->printLevel); + + to->enableRamping = (BooleanType)(from->enableRamping); + to->enableFarBounds = (BooleanType)(from->enableFarBounds); + to->enableFlippingBounds = (BooleanType)(from->enableFlippingBounds); + to->enableRegularisation = (BooleanType)(from->enableRegularisation); + to->enableFullLITests = (BooleanType)(from->enableFullLITests); + to->enableNZCTests = (BooleanType)(from->enableNZCTests); + to->enableDriftCorrection = from->enableDriftCorrection; + to->enableCholeskyRefactorisation = from->enableCholeskyRefactorisation; + to->enableEqualities = (BooleanType)(from->enableEqualities); + + to->terminationTolerance = from->terminationTolerance; + to->boundTolerance = from->boundTolerance; + to->boundRelaxation = from->boundRelaxation; + to->epsNum = from->epsNum; + to->epsDen = from->epsDen; + to->maxPrimalJump = from->maxPrimalJump; + to->maxDualJump = from->maxDualJump; + + to->initialRamping = from->initialRamping; + to->finalRamping = from->finalRamping; + to->initialFarBounds = from->initialFarBounds; + to->growFarBounds = from->growFarBounds; + to->initialStatusBounds = (SubjectToStatus)(from->initialStatusBounds); + to->epsFlipping = from->epsFlipping; + to->numRegularisationSteps = from->numRegularisationSteps; + to->epsRegularisation = from->epsRegularisation; + to->numRefinementSteps = from->numRefinementSteps; + to->epsIterRef = from->epsIterRef; + to->epsLITests = from->epsLITests; + to->epsNZCTests = from->epsNZCTests; + + to->enableDropInfeasibles = (BooleanType)(from->enableDropInfeasibles); + to->dropBoundPriority = from->dropBoundPriority; + to->dropEqConPriority = from->dropEqConPriority; + to->dropIneqConPriority = from->dropIneqConPriority; + + return 0; +} + +/* + * q p O A S E S _ o b t a i n O u t p u t s + */ +int_t qpOASES_obtainOutputs(const QProblemB * const globalQpObject, + returnValue returnvalue, + real_t * const x, + real_t * const y, + real_t * const obj, + int_t * const status) +{ + if (globalQpObject == 0) + return -1; + + globalQpObject->getPrimalSolution(x); + globalQpObject->getDualSolution(y); + *obj = globalQpObject->getObjVal(); + *status = getSimpleStatus(returnvalue); + + return 0; +} + +/* + * Q P r o b l e m _ s e t u p + */ +int_t QProblem_setup(int_t nV, int_t nC, int_t hessianType) +{ + if ((nV < 1) || (nC < 0)) + return -1; + + if ((hessianType < 0) || (hessianType > 6)) + return -1; + + if (QProblem_cleanup() != 0) + return -1; + + globalQProblemObject = new QProblem(nV, nC, (HessianType)hessianType); + + return 0; +} + +/* + * Q P r o b l e m _ i n i t + */ +int_t QProblem_init(const real_t * const H, + const real_t * const g, + const real_t * const A, + const real_t * const lb, + const real_t * const ub, + const real_t * const lbA, + const real_t * const ubA, + int_t * const nWSR, + real_t * const cputime, + const qpOASES_Options * const options, + real_t * const x, + real_t * const y, + real_t * const obj, + int_t * const status) +{ + /* abort if QProblem_setup has not been called */ + if (globalQProblemObject == 0) + return -1; + + /* adjust options if provided */ + if (options != 0) { + qpOASES_Options_copy(options, &globalOptionsObject); + globalQProblemObject->setOptions(globalOptionsObject); + } + + /* actually call solver */ + returnValue returnvalue = globalQProblemObject->init(H, g, A, lb, ub, lbA, ubA, *nWSR, cputime); + + /* assign lhs arguments */ + return qpOASES_obtainOutputs(globalQProblemObject, returnvalue, x, y, obj, status); +} + +/* + * Q P r o b l e m _ h o t s t a r t + */ +int_t QProblem_hotstart(const real_t * const g, + const real_t * const lb, + const real_t * const ub, + const real_t * const lbA, + const real_t * const ubA, + int_t * const nWSR, + real_t * const cputime, + real_t * const x, + real_t * const y, + real_t * const obj, + int_t * const status) +{ + /* abort if QProblem_setup has not been called */ + if (globalQProblemObject == 0) + return -1; + + /* actually call solver */ + returnValue returnvalue = globalQProblemObject->hotstart(g, lb, ub, lbA, ubA, *nWSR, cputime); + + /* assign lhs arguments */ + return qpOASES_obtainOutputs(globalQProblemObject, returnvalue, x, y, obj, status); + + return 0; +} + +/* + * Q P r o b l e m _ c l e a n u p + */ +int_t QProblem_cleanup() +{ + if (globalQProblemObject != 0) { + delete globalQProblemObject; + globalQProblemObject = 0; + } + + return 0; +} + +/* + * Q P r o b l e m B _ s e t u p + */ +int_t QProblemB_setup(int_t nV, int_t hessianType) +{ + if (nV < 1) + return -1; + + if ((hessianType < 0) || (hessianType > 6)) + return -1; + + if (QProblemB_cleanup() != 0) + return -1; + + globalQProblemBObject = new QProblemB(nV, (HessianType)hessianType); + + return 0; +} + +/* + * Q P r o b l e m B _ i n i t + */ +int_t QProblemB_init(const real_t * const H, + const real_t * const g, + const real_t * const lb, + const real_t * const ub, + int_t * const nWSR, + real_t * const cputime, + const qpOASES_Options * const options, + real_t * const x, + real_t * const y, + real_t * const obj, + int_t * const status) +{ + /* abort if QProblemB_setup has not been called */ + if (globalQProblemBObject == 0) + return -1; + + /* adjust options if provided */ + if (options != 0) { + qpOASES_Options_copy(options, &globalOptionsObject); + globalQProblemBObject->setOptions(globalOptionsObject); + } + + /* actually call solver */ + returnValue returnvalue = globalQProblemBObject->init(H, g, lb, ub, *nWSR, cputime); + + /* assign lhs arguments */ + return qpOASES_obtainOutputs(globalQProblemBObject, returnvalue, x, y, obj, status); +} + +/* + * Q P r o b l e m B _ h o t s t a r t + */ +int_t QProblemB_hotstart(const real_t * const g, + const real_t * const lb, + const real_t * const ub, + int_t * const nWSR, + real_t * const cputime, + real_t * const x, + real_t * const y, + real_t * const obj, + int_t * const status) +{ + /* abort if QProblemB_setup has not been called */ + if (globalQProblemBObject == 0) + return -1; + + /* actually call solver */ + returnValue returnvalue = globalQProblemBObject->hotstart(g, lb, ub, *nWSR, cputime); + + /* assign lhs arguments */ + return qpOASES_obtainOutputs(globalQProblemBObject, returnvalue, x, y, obj, status); + + return 0; +} + +/* + * Q P r o b l e m B _ c l e a n u p + */ +int_t QProblemB_cleanup() +{ + if (globalQProblemBObject != 0) { + delete globalQProblemBObject; + globalQProblemBObject = 0; + } + + return 0; +} + +/* + * S Q P r o b l e m _ s e t u p + */ +int_t SQProblem_setup(int_t nV, int_t nC, int_t hessianType) +{ + if ((nV < 1) || (nC < 0)) + return -1; + + if ((hessianType < 0) || (hessianType > 6)) + return -1; + + if (SQProblem_cleanup() != 0) + return -1; + + globalSQProblemObject = new SQProblem(nV, nC, (HessianType)hessianType); + + return 0; +} + +/* + * S Q P r o b l e m _ i n i t + */ +int_t SQProblem_init(const real_t * const H, + const real_t * const g, + const real_t * const A, + const real_t * const lb, + const real_t * const ub, + const real_t * const lbA, + const real_t * const ubA, + int_t * const nWSR, + real_t * const cputime, + const qpOASES_Options * const options, + real_t * const x, + real_t * const y, + real_t * const obj, + int_t * const status) +{ + /* abort if SQProblem_setup has not been called */ + if (globalSQProblemObject == 0) + return -1; + + /* adjust options if provided */ + if (options != 0) { + qpOASES_Options_copy(options, &globalOptionsObject); + globalSQProblemObject->setOptions(globalOptionsObject); + } + + /* actually call solver */ + returnValue returnvalue = globalSQProblemObject->init(H, g, A, lb, ub, lbA, ubA, *nWSR, cputime); + + /* assign lhs arguments */ + return qpOASES_obtainOutputs(globalSQProblemObject, returnvalue, x, y, obj, status); +} + +/* + * S Q P r o b l e m _ h o t s t a r t + */ +int_t SQProblem_hotstart(const real_t * const H, + const real_t * const g, + const real_t * const A, + const real_t * const lb, + const real_t * const ub, + const real_t * const lbA, + const real_t * const ubA, + int_t * const nWSR, + real_t * const cputime, + real_t * const x, + real_t * const y, + real_t * const obj, + int_t * const status) +{ + /* abort if SQProblem_setup has not been called */ + if (globalSQProblemObject == 0) + return -1; + + /* actually call solver */ + returnValue returnvalue = globalSQProblemObject->hotstart(H, g, A, lb, ub, lbA, ubA, *nWSR, cputime); + + /* assign lhs arguments */ + return qpOASES_obtainOutputs(globalSQProblemObject, returnvalue, x, y, obj, status); + + return 0; +} + +/* + * S Q P r o b l e m _ c l e a n u p + */ +int_t SQProblem_cleanup() +{ + if (globalSQProblemObject != 0) { + delete globalSQProblemObject; + globalSQProblemObject = 0; + } + + return 0; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/qpOASES_wrapper.h b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/qpOASES_wrapper.h new file mode 100755 index 0000000..e975523 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/c/qpOASES_wrapper.h @@ -0,0 +1,316 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file interfaces/c/qpOASES_wrapper.h + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2014-2017 + * + * Interface that enables to call qpOASES from plain C. + * + */ + + +#ifndef QPOASES_WRAPPER_H +#define QPOASES_WRAPPER_H + + +#ifndef QPOASES_TYPES_HPP + + /** + * Defined integer type for calling BLAS/LAPACK. Should usually be + * "(unsigned) int", currently set to "(unsigned) long" for backwards + * compatibility. This will change in a future release. + */ + typedef long la_int_t; + typedef unsigned long la_uint_t; + + /** Defines real_t for facilitating switching between double and float. */ + #ifdef __USE_SINGLE_PRECISION__ + typedef float real_t; + #else + typedef double real_t; + #endif /* __USE_SINGLE_PRECISION__ */ + + /** Defines int_t for facilitating switching between int and long int. */ + #ifdef __USE_LONG_INTEGERS__ + typedef long int_t; + typedef unsigned long uint_t; + #else + typedef int int_t; + typedef unsigned int uint_t; + #endif /* __USE_LONG_INTEGERS__ */ + + /** Defines FORTRAN integer type. Might be platform dependent! */ + #ifdef __USE_LONG_FINTS__ + typedef long fint_t; + #else + typedef int fint_t; + #endif /* __USE_LONG_FINTS__ */ + + /** + * Integer type for sparse matrix row/column entries. Make this "int" + * for 32 bit entries, and "long" for 64-bit entries on x86_64 platform. + * + * Most sparse codes still assume 32-bit entries here (HSL, BQPD, ...) + */ + typedef int_t sparse_int_t; + + /* dummy definitions, not used when calling from C */ + #define QProblemBClass int_t + #define OptionsClass int_t + #define returnValue int_t + + /* HessianType */ + #define HST_ZERO 0 + #define HST_IDENTITY 1 + #define HST_POSDEF 2 + #define HST_POSDEF_NULLSPACE 3 + #define HST_SEMIDEF 4 + #define HST_INDEF 5 + #define HST_UNKNOWN 6 + + /* SubjectToStatus */ + #define ST_LOWER -1 + #define ST_INACTIVE 0 + #define ST_UPPER 1 + #define ST_INFEASIBLE_LOWER 2 + #define ST_INFEASIBLE_UPPER 3 + #define ST_UNDEFINED 4 + + /* PrintLevel */ + #define PL_DEBUG_ITER -2 + #define PL_TABULAR -1 + #define PL_NONE 0 + #define PL_LOW 1 + #define PL_MEDIUM 2 + #define PL_HIGH 3 + +#else + + #define QProblemBClass QProblemB + #define OptionsClass REFER_NAMESPACE_QPOASES Options + + /* only declare when compiling C++ library */ + static QProblem* globalQProblemObject = 0; + static QProblemB* globalQProblemBObject = 0; + static SQProblem* globalSQProblemObject = 0; + static Options globalOptionsObject; + +#endif /* QPOASES_TYPES_HPP */ + + + +/** + * \brief Manages all user-specified options for solving QPs. + * + * This struct manages all user-specified options used for solving + * quadratic programs. + * + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2014-2017 + */ +typedef struct +{ + int_t printLevel; /**< Print level. */ + + int_t enableRamping; /**< Specifies whether ramping shall be enabled or not. */ + int_t enableFarBounds; /**< Specifies whether far bounds shall be used or not. */ + int_t enableFlippingBounds; /**< Specifies whether flipping bounds shall be used or not. */ + int_t enableRegularisation; /**< Specifies whether Hessian matrix shall be regularised in case semi-definiteness is detected. */ + int_t enableFullLITests; /**< Specifies whether condition-hardened LI test shall be used or not. */ + int_t enableNZCTests; /**< Specifies whether nonzero curvature tests shall be used. */ + int_t enableDriftCorrection; /**< Specifies the frequency of drift corrections (0 = off). */ + int_t enableCholeskyRefactorisation; /**< Specifies the frequency of full refactorisation of proj. Hessian (otherwise updates). */ + int_t enableEqualities; /**< Specifies whether equalities shall be always treated as active constraints. */ + + real_t terminationTolerance; /**< Termination tolerance. */ + real_t boundTolerance; /**< Lower/upper (constraints') bound tolerance (an inequality constraint whose lower and + upper bounds differ by less is regarded to be an equality constraint). */ + real_t boundRelaxation; /**< Offset for relaxing (constraints') bounds at beginning of an initial homotopy. It is also as initial value for far bounds. */ + real_t epsNum; /**< Numerator tolerance for ratio tests. */ + real_t epsDen; /**< Denominator tolerance for ratio tests. */ + real_t maxPrimalJump; /**< Maximum allowed jump in primal variables in nonzero curvature tests. */ + real_t maxDualJump; /**< Maximum allowed jump in dual variables in linear independence tests. */ + + real_t initialRamping; /**< Start value for Ramping Strategy. */ + real_t finalRamping; /**< Final value for Ramping Strategy. */ + real_t initialFarBounds; /**< Initial size of Far Bounds. */ + real_t growFarBounds; /**< Factor to grow Far Bounds. */ + int_t initialStatusBounds; /**< Initial status of bounds at first iteration. */ + real_t epsFlipping; /**< Tolerance of squared Cholesky diagonal factor which triggers flipping bound. */ + int_t numRegularisationSteps; /**< Maximum number of successive regularisation steps. */ + real_t epsRegularisation; /**< Scaling factor of identity matrix used for Hessian regularisation. */ + int_t numRefinementSteps; /**< Maximum number of iterative refinement steps. */ + real_t epsIterRef; /**< Early termination tolerance for iterative refinement. */ + real_t epsLITests; /**< Tolerance for linear independence tests. */ + real_t epsNZCTests; /**< Tolerance for nonzero curvature tests. */ + + real_t rcondSMin; /**< Minimum reciprocal condition number of S before refactorization is triggered */ + int_t enableInertiaCorrection; /**< Specifies whether the working set should be repaired when negative curvature is discovered during hotstart. */ + + int_t enableDropInfeasibles; /**< ... */ + int_t dropBoundPriority; /**< ... */ + int_t dropEqConPriority; /**< ... */ + int_t dropIneqConPriority; /**< ... */ + int_t printResiduals; /**< If true, it will print the internal qpOASES residuals and other information per iteration */ + +} qpOASES_Options; + + +int_t qpOASES_Options_init( qpOASES_Options* const options, + int_t mode + ); + +int_t qpOASES_Options_copy( const qpOASES_Options* const from, + OptionsClass* const to + ); + + +int_t qpOASES_obtainOutputs( const QProblemBClass* const globalQpObject, + returnValue returnvalue, + real_t* const x, + real_t* const y, + real_t* const obj, + int_t* const status + ); + + +int_t QProblem_setup( int_t nV, + int_t nC, + int_t hessianType + ); + +int_t QProblem_init( const real_t* const H, + const real_t* const g, + const real_t* const A, + const real_t* const lb, + const real_t* const ub, + const real_t* const lbA, + const real_t* const ubA, + int_t* const nWSR, + real_t* const cputime, + const qpOASES_Options* const options, + real_t* const x, + real_t* const y, + real_t* const obj, + int_t* const status + ); + +int_t QProblem_hotstart( const real_t* const g, + const real_t* const lb, + const real_t* const ub, + const real_t* const lbA, + const real_t* const ubA, + int_t* const nWSR, + real_t* const cputime, + real_t* const x, + real_t* const y, + real_t* const obj, + int_t* const status + ); + +int_t QProblem_cleanup( ); + + + +int_t QProblemB_setup( int_t nV, + int_t hessianType + ); + +int_t QProblemB_init( const real_t* const H, + const real_t* const g, + const real_t* const lb, + const real_t* const ub, + int_t* const nWSR, + real_t* const cputime, + const qpOASES_Options* const options, + real_t* const x, + real_t* const y, + real_t* const obj, + int_t* const status + ); + +int_t QProblemB_hotstart( const real_t* const g, + const real_t* const lb, + const real_t* const ub, + int_t* const nWSR, + real_t* const cputime, + real_t* const x, + real_t* const y, + real_t* const obj, + int_t* const status + ); + +int_t QProblemB_cleanup( ); + + + +int_t SQProblem_setup( int_t nV, + int_t nC, + int_t hessianType + ); + +int_t SQProblem_init( const real_t* const H, + const real_t* const g, + const real_t* const A, + const real_t* const lb, + const real_t* const ub, + const real_t* const lbA, + const real_t* const ubA, + int_t* const nWSR, + real_t* const cputime, + const qpOASES_Options* const options, + real_t* const x, + real_t* const y, + real_t* const obj, + int_t* const status + ); + +int_t SQProblem_hotstart( const real_t* const H, + const real_t* const g, + const real_t* const A, + const real_t* const lb, + const real_t* const ub, + const real_t* const lbA, + const real_t* const ubA, + int_t* const nWSR, + real_t* const cputime, + real_t* const x, + real_t* const y, + real_t* const obj, + int_t* const status + ); + +int_t SQProblem_cleanup( ); + + +#endif /* QPOASES_WRAPPER_H */ + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/Makefile b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/Makefile new file mode 100755 index 0000000..9371ab0 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/Makefile @@ -0,0 +1,85 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: src/interfaces/matlab/Makefile +## Author: Christian Kirches, Hans Joachim Ferreau, Andreas Potschka +## Version: 3.2 +## Date: 2007-2017 +## + +include ../../make.mk + +## +## flags +## + +IDIR = ../../include + +IFLAGS = -I. \ + -I${IDIR} \ + -I${MATLAB_IDIR} + +LINK_MATLAB_LIBS = -L${MATLAB_LIBDIR} -lmex -lmat -lmx + +EXTRAFLAGS = -largeArrayDims -O -D__cpluplus -D__MATLAB__ -fexceptions + +QPOASES_OBJECT = qpOASES.${OBJEXT} +QPOASES_SEQUENCE_OBJECT = qpOASES_sequence.${OBJEXT} + +## +## targets +## + +all: ${BINDIR}/qpOASES.${MEXEXT} ${BINDIR}/qpOASES_sequence.${MEXEXT} copyMs + +${BINDIR}/qpOASES.${MEXEXT}: ${QPOASES_OBJECT} + @${ECHO} "Creating" $@ + @${CPP} -shared -o $@ $? ${QPOASES_LINK} ${LINK_LIBRARIES} ${LINK_MATLAB_LIBS} + +${BINDIR}/qpOASES_sequence.${MEXEXT}: ${QPOASES_SEQUENCE_OBJECT} + @${ECHO} "Creating" $@ + @${CPP} -shared -o $@ $? ${QPOASES_LINK} ${LINK_LIBRARIES} ${LINK_MATLAB_LIBS} + +copyMs: + @${ECHO} "Copying M files ..." + @${CP} qpOASES.m ${BINDIR} + @${CP} qpOASES_options.m ${BINDIR} + @${CP} qpOASES_sequence.m ${BINDIR} + +#@${CP} qpOASES_sequenceVM.m ${BINDIR} + +clean: + @${RM} -f *.${OBJEXT} *.mex* + +clobber: clean + +%.${OBJEXT}: %.cpp + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} -c ${IFLAGS} ${EXTRAFLAGS} ${CPPFLAGS} $< + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/example1.mat b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/example1.mat new file mode 100755 index 0000000..c0bd0d2 Binary files /dev/null and b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/example1.mat differ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/example1a.mat b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/example1a.mat new file mode 100755 index 0000000..48c784f Binary files /dev/null and b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/example1a.mat differ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/example1b.mat b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/example1b.mat new file mode 100755 index 0000000..b45b4f7 Binary files /dev/null and b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/example1b.mat differ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/make.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/make.m new file mode 100755 index 0000000..37c02c2 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/make.m @@ -0,0 +1,254 @@ +function [] = make( varargin ) +%MAKE Compiles the Matlab interface of qpOASES. +% +%Type make to compile all interfaces that +% have been modified, +%type make clean to delete all compiled interfaces, +%type make clean all to first delete and then compile +% all interfaces, +%type make 'name' to compile only the interface with +% the given name (if it has been modified), +%type make 'opt' to compile all interfaces using the +% given compiler options. +% +%Copyright (C) 2013-2017 by Hans Joachim Ferreau, Andreas Potschka, +%Christian Kirches et al. All rights reserved. + +%% +%% This file is part of qpOASES. +%% +%% qpOASES -- An Implementation of the Online Active Set Strategy. +%% Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +%% Christian Kirches et al. All rights reserved. +%% +%% qpOASES is free software; you can redistribute it and/or +%% modify it under the terms of the GNU Lesser General Public +%% License as published by the Free Software Foundation; either +%% version 2.1 of the License, or (at your option) any later version. +%% +%% qpOASES is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +%% See the GNU Lesser General Public License for more details. +%% +%% You should have received a copy of the GNU Lesser General Public +%% License along with qpOASES; if not, write to the Free Software +%% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +%% + +%% +%% Filename: interfaces/matlab/make.m +%% Author: Hans Joachim Ferreau, Andreas Potschka, Christian Kirches +%% Version: 3.2 +%% Date: 2007-2017 +%% + + + %% consistency check + if ( exist( [pwd, '/make.m'],'file' ) == 0 ) + error( ['ERROR (',mfilename '.m): Run this make script directly within the directory ', ... + '/interfaces/matlab, please.'] ); + end + + + if ( nargin > 2 ) + error( ['ERROR (',mfilename '.m): At most two make arguments supported!'] ); + else + [ doClean,fcnNames,userFlags ] = analyseMakeArguments( nargin,varargin ); + end + + + %% define compiler settings + QPOASESPATH = '../../'; + + DEBUGFLAGS = ' '; + %DEBUGFLAGS = ' -v -g CXXDEBUGFLAGS=''$CXXDEBUGFLAGS -Wall -pedantic -Wshadow'' '; + + IFLAGS = [ '-I. -I',QPOASESPATH,'include',' -I',QPOASESPATH,'src',' ' ]; + CPPFLAGS = [ IFLAGS, DEBUGFLAGS, '-largeArrayDims -D__cpluplus -D__MATLAB__ -D__AVOID_LA_NAMING_CONFLICTS__ -D__SINGLE_OBJECT__',' ' ]; + defaultFlags = '-O -D__NO_COPYRIGHT__ '; %% -D__SUPPRESSANYOUTPUT__ + + if ( ispc() == 0 ) + CPPFLAGS = [ CPPFLAGS, '-DLINUX -lmwblas',' ' ]; + else + CPPFLAGS = [ CPPFLAGS, '-DWIN32',' ' ]; + end + + if ( isempty(userFlags) > 0 ) + CPPFLAGS = [ CPPFLAGS, defaultFlags,' ' ]; + else + CPPFLAGS = [ CPPFLAGS, userFlags,' ' ]; + end + + %% determine if MA57 is available for sparse linear algebra + isoctave = exist('OCTAVE_VERSION', 'builtin') ~= 0; + if isoctave + warning('Sparse linear algebra is currently not available for qpOASES in Octave. Passing sparse matrices works but will likely be slow.') + SPARSEFLAGS = ''; + elseif verLessThan('matlab', '7.8') + warning('Sparse linear algebra is currently available for qpOASES only for Matlab versions 7.8 and later. Passing sparse matrices works but will likely be slow.') + SPARSEFLAGS = ''; + else + if ( ispc() == 0 ) + SPARSEFLAGS = '-largeArrayDims -D__USE_LONG_INTEGERS__ -D__USE_LONG_FINTS__ -DSOLVER_MA57 -lmwma57 '; + else + SPARSEFLAGS = '-largeArrayDims -D__USE_LONG_INTEGERS__ -D__USE_LONG_FINTS__ '; + end + end + + mexExt = eval('mexext'); + + + %% ensure copyright notice is displayed + if ~isempty( strfind( CPPFLAGS,'-D__NO_COPYRIGHT__' ) ) + printCopyrightNotice( ); + end + + + %% clean if desired + if ( doClean > 0 ) + + eval( 'delete *.o;' ); + eval( ['delete *.',mexExt,'*;'] ); + disp( [ 'INFO (',mfilename '.m): Cleaned all compiled files.'] ); + pause( 0.2 ); + + end + + + if ( ~isempty(userFlags) ) + disp( [ 'INFO (',mfilename '.m): Compiling all files with user-defined compiler flags (''',userFlags,''')...'] ); + end + + + %% call mex compiler + for ii=1:length(fcnNames) + + cmd = [ 'mex -output ', fcnNames{ii}, ' ', CPPFLAGS, SPARSEFLAGS, [fcnNames{ii},'.cpp'] ]; + + if ( exist( [fcnNames{ii},'.',mexExt],'file' ) == 0 ) + + eval( cmd ); + disp( [ 'INFO (',mfilename '.m): ', fcnNames{ii},'.',mexExt, ' successfully created.'] ); + + else + + % check modification time of source/Make files and compiled mex file + cppFile = dir( [pwd,'/',fcnNames{ii},'.cpp'] ); + cppFileTimestamp = getTimestamp( cppFile ); + + utilsFile = dir( [pwd,'/qpOASES_matlab_utils.cpp'] ); + utilsFileTimestamp = getTimestamp( utilsFile ); + + makeFile = dir( [pwd,'/make.m'] ); + makeFileTimestamp = getTimestamp( makeFile ); + + mexFile = dir( [pwd,'/',fcnNames{ii},'.',mexExt] ); + if ( isempty(mexFile) == 0 ) + mexFileTimestamp = getTimestamp( mexFile ); + else + mexFileTimestamp = 0; + end + + if ( ( cppFileTimestamp >= mexFileTimestamp ) || ... + ( utilsFileTimestamp >= mexFileTimestamp ) || ... + ( makeFileTimestamp >= mexFileTimestamp ) ) + eval( cmd ); + disp( [ 'INFO (',mfilename '.m): ', fcnNames{ii},'.',mexExt, ' successfully created.'] ); + else + disp( [ 'INFO (',mfilename '.m): ', fcnNames{ii},'.',mexExt, ' already exists.'] ); + end + + end + + end + + %% add qpOASES directory to path + path( path,pwd ); + +end + + +function [ doClean,fcnNames,userIFlags ] = analyseMakeArguments( nArgs,args ) + + doClean = 0; + fcnNames = []; + userIFlags = []; + + switch ( nArgs ) + + case 1 + if ( strcmp( args{1},'all' ) > 0 ) + fcnNames = { 'qpOASES','qpOASES_sequence' }; + elseif ( strcmp( args{1},'qpOASES' ) > 0 ) + fcnNames = { 'qpOASES' }; + elseif ( strcmp( args{1},'qpOASES_sequence' ) > 0 ) + fcnNames = { 'qpOASES_sequence' }; + elseif ( strcmp( args{1},'clean' ) > 0 ) + doClean = 1; + elseif ( strcmp( args{1}(1),'-' ) > 0 ) + % make clean all with user-specified compiler flags + userIFlags = args{1}; + doClean = 1; + fcnNames = { 'qpOASES','qpOASES_sequence' }; + else + error( ['ERROR (',mfilename '.m): Invalid first argument (''',args{1},''')!'] ); + end + + case 2 + if ( strcmp( args{1},'clean' ) > 0 ) + doClean = 1; + else + error( ['ERROR (',mfilename '.m): First argument must be ''clean'' if two arguments are provided!'] ); + end + + if ( strcmp( args{2},'all' ) > 0 ) + fcnNames = { 'qpOASES','qpOASES_sequence' }; + elseif ( strcmp( args{2},'qpOASES' ) > 0 ) + fcnNames = { 'qpOASES' }; + elseif ( strcmp( args{2},'qpOASES_sequence' ) > 0 ) + fcnNames = { 'qpOASES_sequence' }; + else + error( ['ERROR (',mfilename '.m): Invalid second argument (''',args{2},''')!'] ); + end + + otherwise + fcnNames = { 'qpOASES','qpOASES_sequence' }; + + end + +end + + +function [ timestamp ] = getTimestamp( dateString ) + + try + timestamp = dateString.datenum; + catch + timestamp = Inf; + end + +end + + +function [ ] = printCopyrightNotice( ) + + disp( ' ' ); + disp( 'qpOASES -- An Implementation of the Online Active Set Strategy.' ); + disp( 'Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka,' ); + disp( 'Christian Kirches et al. All rights reserved.' ); + disp( ' ' ); + disp( 'qpOASES is distributed under the terms of the' ); + disp( 'GNU Lesser General Public License 2.1 in the hope that it will be' ); + disp( 'useful, but WITHOUT ANY WARRANTY; without even the implied warranty' ); + disp( 'of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.' ); + disp( 'See the GNU Lesser General Public License for more details.' ); + disp( ' ' ); + disp( ' ' ); + +end + + +%% +%% end of file +%% diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES.cpp new file mode 100644 index 0000000..5dcbd46 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES.cpp @@ -0,0 +1,598 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file interfaces/matlab/qpOASES.cpp + * \author Hans Joachim Ferreau, Alexander Buchner (thanks to Aude Perrin) + * \version 3.2 + * \date 2007-2017 + * + * Interface for Matlab(R) that enables to call qpOASES as a MEX function. + * + */ + +#include + +USING_NAMESPACE_QPOASES + +#include "qpOASES_matlab_utils.hpp" + +/** initialise handle counter of QPInstance class */ +int_t QPInstance::s_nexthandle = 1; + +/** global pointer to QP objects */ +static std::vector g_instances; + +#include "qpOASES_matlab_utils.cpp" + +/* + * Q P r o b l e m _ q p O A S E S + */ +int_t QProblem_qpOASES(int_t nV, + int_t nC, + HessianType hessianType, + int_t nP, + SymmetricMatrix * H, + double * g, + Matrix * A, + double * lb, + double * ub, + double * lbA, + double * ubA, + int_t nWSRin, + real_t maxCpuTimeIn, + const double * const x0, + Options * options, + int_t nOutputs, + mxArray * plhs[], + const double * const guessedBounds, + const double * const guessedConstraints, + const double * const _R, + BooleanType isSparse) +{ + int_t nWSRout; + real_t maxCpuTimeOut; + + /* 1) Setup initial QP. */ + QProblem * QP; + if (isSparse == BT_TRUE) { +#ifdef SOLVER_MA57 + QP = new SQProblemSchur(nV, nC, hessianType); +#else + QP = new QProblem(nV, nC, hessianType); +#endif + } else + QP = new QProblem(nV, nC, hessianType); + QP->setOptions(*options); + + /* 2) Solve initial QP. */ + returnValue returnvalue; + + Bounds bounds(nV); + Constraints constraints(nC); + if (guessedBounds != 0) { + for (int_t i = 0; i < nV; i++) { + if (isEqual(guessedBounds[i], -1.0) == BT_TRUE) { + bounds.setupBound(i, ST_LOWER); + } else if (isEqual(guessedBounds[i], 1.0) == BT_TRUE) { + bounds.setupBound(i, ST_UPPER); + } else if (isEqual(guessedBounds[i], 0.0) == BT_TRUE) { + bounds.setupBound(i, ST_INACTIVE); + } else { + char msg[MAX_STRING_LENGTH]; + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Only {-1, 0, 1} allowed for status of bounds!"); + myMexErrMsgTxt(msg); + return -1; + } + } + } + + if (guessedConstraints != 0) { + for (int_t i = 0; i < nC; i++) { + if (isEqual(guessedConstraints[i], -1.0) == BT_TRUE) { + constraints.setupConstraint(i, ST_LOWER); + } else if (isEqual(guessedConstraints[i], 1.0) == BT_TRUE) { + constraints.setupConstraint(i, ST_UPPER); + } else if (isEqual(guessedConstraints[i], 0.0) == BT_TRUE) { + constraints.setupConstraint(i, ST_INACTIVE); + } else { + char msg[MAX_STRING_LENGTH]; + snprintf( + msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Only {-1, 0, 1} allowed for status of constraints!"); + myMexErrMsgTxt(msg); + return -1; + } + } + } + + nWSRout = nWSRin; + maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + + returnvalue = QP->init(H, + g, + A, + lb, + ub, + lbA, + ubA, + nWSRout, + &maxCpuTimeOut, + x0, + 0, + (guessedBounds != 0) ? &bounds : 0, + (guessedConstraints != 0) ? &constraints : 0, + _R); + + /* 3) Solve remaining QPs and assign lhs arguments. */ + /* Set up pointers to the current QP vectors */ + real_t * g_current = g; + real_t * lb_current = lb; + real_t * ub_current = ub; + real_t * lbA_current = lbA; + real_t * ubA_current = ubA; + + /* Loop through QP sequence. */ + for (int_t k = 0; k < nP; ++k) { + if (k > 0) { + /* update pointers to the current QP vectors */ + g_current = &(g[k * nV]); + if (lb != 0) + lb_current = &(lb[k * nV]); + if (ub != 0) + ub_current = &(ub[k * nV]); + if (lbA != 0) + lbA_current = &(lbA[k * nC]); + if (ubA != 0) + ubA_current = &(ubA[k * nC]); + + nWSRout = nWSRin; + maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + returnvalue = + QP->hotstart(g_current, lb_current, ub_current, lbA_current, ubA_current, nWSRout, &maxCpuTimeOut); + } + + /* write results into output vectors */ + obtainOutputs(k, QP, returnvalue, nWSRout, maxCpuTimeOut, nOutputs, plhs, nV, nC); + } + + // QP->writeQpDataIntoMatFile( "qpDataMat0.mat" ); + + delete QP; + return 0; +} + +/* + * Q P r o b l e m B _ q p O A S E S + */ +int_t QProblemB_qpOASES(int_t nV, + HessianType hessianType, + int_t nP, + SymmetricMatrix * H, + double * g, + double * lb, + double * ub, + int_t nWSRin, + real_t maxCpuTimeIn, + const double * const x0, + Options * options, + int_t nOutputs, + mxArray * plhs[], + const double * const guessedBounds, + const double * const _R) +{ + int_t nWSRout; + real_t maxCpuTimeOut; + + /* 1) Setup initial QP. */ + QProblemB QP(nV, hessianType); + QP.setOptions(*options); + + /* 2) Solve initial QP. */ + returnValue returnvalue; + + Bounds bounds(nV); + if (guessedBounds != 0) { + for (int_t i = 0; i < nV; i++) { + if (isEqual(guessedBounds[i], -1.0) == BT_TRUE) { + bounds.setupBound(i, ST_LOWER); + } else if (isEqual(guessedBounds[i], 1.0) == BT_TRUE) { + bounds.setupBound(i, ST_UPPER); + } else if (isEqual(guessedBounds[i], 0.0) == BT_TRUE) { + bounds.setupBound(i, ST_INACTIVE); + } else { + char msg[MAX_STRING_LENGTH]; + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Only {-1, 0, 1} allowed for status of bounds!"); + myMexErrMsgTxt(msg); + return -1; + } + } + } + + nWSRout = nWSRin; + maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + + returnvalue = + QP.init(H, g, lb, ub, nWSRout, &maxCpuTimeOut, x0, 0, (guessedBounds != 0) ? &bounds : 0, _R); + + /* 3) Solve remaining QPs and assign lhs arguments. */ + /* Set up pointers to the current QP vectors */ + real_t * g_current = g; + real_t * lb_current = lb; + real_t * ub_current = ub; + + /* Loop through QP sequence. */ + for (int_t k = 0; k < nP; ++k) { + if (k > 0) { + /* update pointers to the current QP vectors */ + g_current = &(g[k * nV]); + if (lb != 0) + lb_current = &(lb[k * nV]); + if (ub != 0) + ub_current = &(ub[k * nV]); + + nWSRout = nWSRin; + maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + returnvalue = QP.hotstart(g_current, lb_current, ub_current, nWSRout, &maxCpuTimeOut); + } + + /* write results into output vectors */ + obtainOutputs(k, &QP, returnvalue, nWSRout, maxCpuTimeOut, nOutputs, plhs, nV); + } + + return 0; +} + +/* + * m e x F u n c t i o n + */ +void mexFunction(int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[]) +{ + /* inputs */ + SymmetricMatrix * H = 0; + Matrix * A = 0; + + real_t *g = 0, *lb = 0, *ub = 0, *lbA = 0, *ubA = 0; + HessianType hessianType = HST_UNKNOWN; + double *x0 = 0, *R = 0, *R_for = 0; + double *guessedBounds = 0, *guessedConstraints = 0; + + int H_idx = -1, g_idx = -1, A_idx = -1, lb_idx = -1, ub_idx = -1, lbA_idx = -1, ubA_idx = -1; + int options_idx = -1, x0_idx = -1, auxInput_idx = -1; + + /* Setup default options */ + Options options; + options.printLevel = PL_LOW; +#ifdef __DEBUG__ + options.printLevel = PL_HIGH; +#endif +#ifdef __SUPPRESSANYOUTPUT__ + options.printLevel = PL_NONE; +#endif + + /* dimensions */ + uint_t nV = 0, nC = 0, nP = 0; + BooleanType isSimplyBoundedQp = BT_FALSE; +#ifdef SOLVER_MA57 + BooleanType isSparse = BT_TRUE; // This will be set to BT_FALSE later if a dense matrix is encountered. +#else + BooleanType isSparse = BT_FALSE; +#endif + + /* sparse matrix indices and values */ + sparse_int_t *Hir = 0, *Hjc = 0, *Air = 0, *Ajc = 0; + real_t *Hv = 0, *Av = 0; + + /* I) CONSISTENCY CHECKS: */ + /* 1a) Ensure that qpOASES is called with a feasible number of input arguments. */ + if ((nrhs < 4) || (nrhs > 9)) { + myMexErrMsgTxt( + "ERROR (qpOASES): Invalid number of input arguments!\nType 'help qpOASES' for further information."); + return; + } + + /* 2) Check for proper number of output arguments. */ + if (nlhs > 6) { + myMexErrMsgTxt("ERROR (qpOASES): At most six output arguments are allowed: \n " + "[x,fval,exitflag,iter,lambda,auxOutput]!"); + return; + } + if (nlhs < 1) { + myMexErrMsgTxt("ERROR (qpOASES): At least one output argument is required: [x,...]!"); + return; + } + + /* II) PREPARE RESPECTIVE QPOASES FUNCTION CALL: */ + /* Choose between QProblem and QProblemB object and assign the corresponding + * indices of the input pointer array in to order to access QP data correctly. */ + g_idx = 1; + + if (mxIsEmpty(prhs[0]) == 1) { + H_idx = -1; + nV = (int_t)mxGetM(prhs[g_idx]); /* if Hessian is empty, row number of gradient vector */ + } else { + H_idx = 0; + nV = (int_t)mxGetM(prhs[H_idx]); /* row number of Hessian matrix */ + } + + nP = (int_t)mxGetN(prhs[g_idx]); /* number of columns of the gradient matrix (vectors series have to be + stored columnwise!) */ + + if (nrhs <= 6) + isSimplyBoundedQp = BT_TRUE; + else + isSimplyBoundedQp = BT_FALSE; + + /* 0) Check whether options are specified .*/ + if (isSimplyBoundedQp == BT_TRUE) { + if ((nrhs >= 5) && (!mxIsEmpty(prhs[4])) && (mxIsStruct(prhs[4]))) + options_idx = 4; + } else { + /* Consistency check */ + if ((!mxIsEmpty(prhs[4])) && (mxIsStruct(prhs[4]))) { + myMexErrMsgTxt("ERROR (qpOASES): Fifth input argument must not be a struct when solving QP with " + "general constraints!\nType 'help qpOASES' for further information."); + return; + } + + if ((nrhs >= 8) && (!mxIsEmpty(prhs[7])) && (mxIsStruct(prhs[7]))) + options_idx = 7; + } + + // Is the third argument constraint Matrix A? + int_t numberOfColumns = (int_t)mxGetN(prhs[2]); + + /* 1) Simply bounded QP. */ + if ((isSimplyBoundedQp == BT_TRUE) || ((numberOfColumns == 1) && (nV != 1))) { + lb_idx = 2; + ub_idx = 3; + + if ((nrhs >= 6) && (!mxIsEmpty(prhs[5]))) { + /* auxInput specified */ + if (mxIsStruct(prhs[5])) { + auxInput_idx = 5; + x0_idx = -1; + } else { + auxInput_idx = -1; + x0_idx = 5; + } + } else { + auxInput_idx = -1; + x0_idx = -1; + } + } else { + A_idx = 2; + + /* If constraint matrix is empty, use a QProblemB object! */ + if (mxIsEmpty(prhs[A_idx])) { + lb_idx = 3; + ub_idx = 4; + + nC = 0; + } else { + lb_idx = 3; + ub_idx = 4; + lbA_idx = 5; + ubA_idx = 6; + + nC = (int_t)mxGetM(prhs[A_idx]); /* row number of constraint matrix */ + } + + if ((nrhs >= 9) && (!mxIsEmpty(prhs[8]))) { + /* auxInput specified */ + if (mxIsStruct(prhs[8])) { + auxInput_idx = 8; + x0_idx = -1; + } else { + auxInput_idx = -1; + x0_idx = 8; + } + } else { + auxInput_idx = -1; + x0_idx = -1; + } + } + + /* ensure that data is given in real_t precision */ + if (((H_idx >= 0) && (mxIsDouble(prhs[H_idx]) == 0)) || (mxIsDouble(prhs[g_idx]) == 0)) { + myMexErrMsgTxt("ERROR (qpOASES): All data has to be provided in double precision!"); + return; + } + + /* check if supplied data contains 'NaN' or 'Inf' */ + if (containsNaNorInf(prhs, H_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, g_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lb_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ub_idx, 1) == BT_TRUE) + return; + + /* Check inputs dimensions and assign pointers to inputs. */ + if ((H_idx >= 0) && ((mxGetN(prhs[H_idx]) != nV) || (mxGetM(prhs[H_idx]) != nV))) { + char msg[MAX_STRING_LENGTH]; + snprintf(msg, + MAX_STRING_LENGTH, + "ERROR (qpOASES): Hessian matrix dimension mismatch (%ld != %d)!", + (long int)mxGetN(prhs[H_idx]), + (int)nV); + myMexErrMsgTxt(msg); + return; + } + + if (nC > 0) { + /* ensure that data is given in real_t precision */ + if (mxIsDouble(prhs[A_idx]) == 0) { + myMexErrMsgTxt("ERROR (qpOASES): All data has to be provided in real_t precision!"); + return; + } + + /* Check inputs dimensions and assign pointers to inputs. */ + if (mxGetN(prhs[A_idx]) != nV) { + char msg[MAX_STRING_LENGTH]; + snprintf(msg, + MAX_STRING_LENGTH, + "ERROR (qpOASES): Constraint matrix input dimension mismatch (%ld != %d)!", + (long int)mxGetN(prhs[A_idx]), + (int)nV); + myMexErrMsgTxt(msg); + return; + } + + if (containsNaNorInf(prhs, A_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lbA_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ubA_idx, 1) == BT_TRUE) + return; + } + + /* check dimensions and copy auxInputs */ + if (smartDimensionCheck(&g, nV, nP, BT_FALSE, prhs, g_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lb, nV, nP, BT_TRUE, prhs, lb_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ub, nV, nP, BT_TRUE, prhs, ub_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&x0, nV, 1, BT_TRUE, prhs, x0_idx) != SUCCESSFUL_RETURN) + return; + + if (nC > 0) { + if (smartDimensionCheck(&lbA, nC, nP, BT_TRUE, prhs, lbA_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ubA, nC, nP, BT_TRUE, prhs, ubA_idx) != SUCCESSFUL_RETURN) + return; + } + + if (auxInput_idx >= 0) + setupAuxiliaryInputs( + prhs[auxInput_idx], nV, nC, &hessianType, &x0, &guessedBounds, &guessedConstraints, &R_for); + + /* convert Cholesky factor to C storage format */ + if (R_for != 0) { + R = new real_t[nV * nV]; + convertFortranToC(R_for, nV, nV, R); + } + + /* III) ACTUALLY PERFORM QPOASES FUNCTION CALL: */ + int_t nWSRin = 5 * (nV + nC); + real_t maxCpuTimeIn = -1.0; + + if (options_idx > 0) + setupOptions(&options, prhs[options_idx], nWSRin, maxCpuTimeIn); + + /* make a deep-copy of the user-specified Hessian matrix (possibly sparse) */ + if (H_idx >= 0) + setupHessianMatrix(prhs[H_idx], nV, &H, &Hir, &Hjc, &Hv); + + /* make a deep-copy of the user-specified constraint matrix (possibly sparse) */ + if ((nC > 0) && (A_idx >= 0)) + setupConstraintMatrix(prhs[A_idx], nV, nC, &A, &Air, &Ajc, &Av); + + allocateOutputs(nlhs, plhs, nV, nC, nP); + + /* check if QP is sparse */ + if (H_idx >= 0 && !mxIsSparse(prhs[H_idx])) + isSparse = BT_FALSE; + if (nC > 0 && A_idx >= 0 && !mxIsSparse(prhs[A_idx])) + isSparse = BT_FALSE; + + if (nC == 0) { + /* Call qpOASES (using QProblemB class). */ + QProblemB_qpOASES( + nV, hessianType, nP, H, g, lb, ub, nWSRin, maxCpuTimeIn, x0, &options, nlhs, plhs, guessedBounds, R); + + if (R != 0) + delete R; + if (H != 0) + delete H; + if (Hv != 0) + delete[] Hv; + if (Hjc != 0) + delete[] Hjc; + if (Hir != 0) + delete[] Hir; + return; + } else { + if (A == 0) { + myMexErrMsgTxt("ERROR (qpOASES): Internal interface error related to constraint matrix!"); + return; + } + + /* Call qpOASES (using QProblem class). */ + QProblem_qpOASES(nV, + nC, + hessianType, + nP, + H, + g, + A, + lb, + ub, + lbA, + ubA, + nWSRin, + maxCpuTimeIn, + x0, + &options, + nlhs, + plhs, + guessedBounds, + guessedConstraints, + R, + isSparse); + + if (R != 0) + delete R; + if (A != 0) + delete A; + if (H != 0) + delete H; + if (Av != 0) + delete[] Av; + if (Ajc != 0) + delete[] Ajc; + if (Air != 0) + delete[] Air; + if (Hv != 0) + delete[] Hv; + if (Hjc != 0) + delete[] Hjc; + if (Hir != 0) + delete[] Hir; + return; + } +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES.m new file mode 100755 index 0000000..88f4df9 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES.m @@ -0,0 +1,75 @@ +%qpOASES -- An Implementation of the Online Active Set Strategy. +%Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +%Christian Kirches et al. All rights reserved. +% +%qpOASES is distributed under the terms of the +%GNU Lesser General Public License 2.1 in the hope that it will be +%useful, but WITHOUT ANY WARRANTY; without even the implied warranty +%of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +%See the GNU Lesser General Public License for more details. +% +%--------------------------------------------------------------------------------- +% +%qpOASES solves (a series) of quadratic programming (QP) problems of the +%following form: +% +% min 1/2*x'Hx + x'g +% s.t. lb <= x <= ub +% lbA <= Ax <= ubA {optional} +% +%Call +% +% [x,fval,exitflag,iter,lambda,auxOutput] = +% qpOASES( H,g,A,lb,ub,lbA,ubA{,options{,auxInput}} ) +% +%for solving the above-mentioned QP. H must be a symmetric (but possibly +%indefinite) matrix and all vectors g, lb, ub, lbA, ubA have to be given +%as column vectors. Options can be generated using the qpOASES_options command, +%otherwise default values are used. Optionally, further auxiliary inputs +%may be generated using qpOASES_auxInput command and passed to the solver. +%Both matrices H or A may be passed in sparse matrix format. +% +%Call +% +% [x,fval,exitflag,iter,lambda,auxOutput] = +% qpOASES( H,g,lb,ub{,options{,auxInput}} ) +% +%for solving the above-mentioned QP without general constraints. +% +% +%Optional outputs (only x is mandatory): +% x - Optimal primal solution vector (if exitflag==0). +% fval - Optimal objective function value (if exitflag==0). +% exitflag - 0: QP problem solved, +% 1: QP could not be solved within given number of iterations, +% -1: QP could not be solved due to an internal error, +% -2: QP is infeasible (and thus could not be solved), +% -3: QP is unbounded (and thus could not be solved). +% iter - Number of active set iterations actually performed. +% lambda - Optimal dual solution vector (if exitflag==0). +% auxOutput - Struct containing auxiliary outputs as described below. +% +%The auxOutput struct contains the following entries: +% workingSetB - Working set of bounds at point x. +% workingSetC - Working set of constraints at point x. +% The working set is a subset of the active set (indices +% of bounds/constraints that hold with equality) yielding +% a set linearly independent of bounds/constraints. +% The working sets are encoded as follows: +% 1: bound/constraint at its upper bound +% 0: bound/constraint not at any bound +% -1: bound/constraint at its lower bound +% cpuTime - Internally measured CPU time for solving QP problem. +% +% +%If not a single QP but a sequence of QPs with varying vectors is to be solved, +%the i-th QP is given by the i-th columns of the QP vectors g, lb, ub, lbA, ubA +%(i.e. they are matrices in this case). Both matrices H and A remain constant. +% +%See also QPOASES_OPTIONS, QPOASES_AUXINPUT, QPOASES_SEQUENCE +% +% +%For additional information see the qpOASES User's Manual or +%visit http://www.qpOASES.org/. +% +%Please send remarks and questions to support@qpOASES.org! diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_auxInput.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_auxInput.m new file mode 100755 index 0000000..1ebb8d9 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_auxInput.m @@ -0,0 +1,118 @@ +%qpOASES -- An Implementation of the Online Active Set Strategy. +%Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +%Christian Kirches et al. All rights reserved. +% +%qpOASES is distributed under the terms of the +%GNU Lesser General Public License 2.1 in the hope that it will be +%useful, but WITHOUT ANY WARRANTY; without even the implied warranty +%of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +%See the GNU Lesser General Public License for more details. +% +%--------------------------------------------------------------------------------- +% +%Returns a struct containing all possible auxiliary inputs to be passed +%to qpOASES. +% +%Call +% auxInput = qpOASES_auxInput(); +%to obtain a struct with all auxiliary inputs empty. +% +%Call +% auxInput = qpOASES_auxInput( 'input1',value1,'input2',value2,... ) +%to obtain a struct with 'input1' set to value1 etc. and all remaining +%auxiliary inputs empty. +% +%Call +% auxInput = qpOASES_auxInput( oldInputs,'input1',value1,... ) +%to obtain a copy of the options struct oldInputs but with 'input1' set to +%value1 etc. +% +% +%qpOASES features the following auxiliary inputs: +% hessianType - Provide information on Hessian matrix: +% 0: Hessian is zero matrix (i.e. LP formulation) +% 1: Hessian is identity matrix +% 2: Hessian is (strictly) positive definite +% 3: Hessian is positive definite on null space +% of active bounds/constraints +% 4: Hessian is positive semi-definite. +% 5: Hessian is indefinite +% Leave hessianType empty if Hessian type is unknown. +% x0 - Initial guess for optimal primal solution. +% guessedWorkingSetB - Initial guess for working set of bounds at +% optimal solution (nV elements or empty). +% guessedWorkingSetC - Initial guess for working set of constraints at +% optimal solution (nC elements or empty). +% The working sets needs to be encoded as follows: +% 1: bound/constraint at its upper bound +% 0: bound/constraint not at any bound +% -1: bound/constraint at its lower bound +% R - Cholesky factor of Hessian matrix (upper-triangular); +% only used if both guessedWorkingSets are empty +% and option initialStatusBounds is set to 0. +% +% +%See also QPOASES, QPOASES_SEQUENCE, QPOASES_OPTIONS +% +% +%For additional information see the qpOASES User's Manual or +%visit http://www.qpOASES.org/. +% +%Please send remarks and questions to support@qpOASES.org! +function [ auxInput ] = qpOASES_auxInput( varargin ) + + firstIsStruct = 0; + + if ( nargin == 0 ) + auxInput = qpOASES_emptyAuxInput(); + else + if ( isstruct( varargin{1} ) ) + if ( mod( nargin,2 ) ~= 1 ) + error('ERROR (qpOASES_auxInput): Auxiliary inputs must be specified in pairs!'); + end + auxInput = varargin{1}; + firstIsStruct = 1; + else + if ( mod( nargin,2 ) ~= 0 ) + error('ERROR (qpOASES_auxInput): Auxiliary inputs must be specified in pairs!'); + end + auxInput = qpOASES_emptyAuxInput(); + end + end + + % set options to user-defined values + for i=(1+firstIsStruct):2:nargin + + argName = varargin{i}; + argValue = varargin{i+1}; + + if ( ( isempty( argName ) ) || ( ~ischar( argName ) ) ) + error('ERROR (qpOASES_auxInput): Argmument no. %d has to be a non-empty string!',i ); + end + + if ( ( ischar(argValue) ) || ( ~isnumeric( argValue ) ) ) + error('ERROR (qpOASES_auxInput): Argmument no. %d has to be a numerical constant!',i+1 ); + end + + if ( ~isfield( auxInput,argName ) ) + error('ERROR (qpOASES_auxInput): Argmument no. %d is not a valid auxiliary input!',i ); + end + + eval( ['auxInput.',argName,' = argValue;'] ); + + end + +end + + +function [ auxInput ] = qpOASES_emptyAuxInput( ) + + % setup auxiliary input struct with all entries empty + auxInput = struct( 'hessianType', [], ... + 'x0', [], ... + 'guessedWorkingSetB', [], ... + 'guessedWorkingSetC', [], ... + 'R', [] ... + ); + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_matlab_utils.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_matlab_utils.cpp new file mode 100644 index 0000000..aef40c2 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_matlab_utils.cpp @@ -0,0 +1,898 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file interfaces/matlab/qpOASES_matlab_utils.cpp + * \author Hans Joachim Ferreau, Alexander Buchner + * \version 3.2 + * \date 2007-2017 + * + * Collects utility functions for Interface to Matlab(R) that + * enables to call qpOASES as a MEX function. + * + */ + +QPInstance::QPInstance( + uint_t _nV, uint_t _nC, HessianType _hessianType, BooleanType _isSimplyBounded, BooleanType _sparseLA) +: sparseLA(_sparseLA) +{ + handle = s_nexthandle++; + + if (_nC > 0) + isSimplyBounded = BT_FALSE; + else + isSimplyBounded = _isSimplyBounded; + + if (isSimplyBounded == BT_TRUE && sparseLA == BT_FALSE) { + sqp = 0; + qpb = new QProblemB(_nV, _hessianType); + } else if (sparseLA == BT_FALSE) { + sqp = new SQProblem(_nV, _nC, _hessianType); + qpb = 0; + } else { +#ifdef SOLVER_MA57 + sqp = new SQProblemSchur(_nV, _nC, _hessianType); +#else + sqp = new SQProblem(_nV, _nC, _hessianType); +#endif + qpb = 0; + } + + H = 0; + A = 0; + Hir = 0; + Hjc = 0; + Air = 0; + Ajc = 0; + Hv = 0; + Av = 0; +} + +QPInstance::~QPInstance() +{ + deleteQPMatrices(); + + if (sqp != 0) { + delete sqp; + sqp = 0; + } + + if (qpb != 0) { + delete qpb; + qpb = 0; + } +} + +returnValue QPInstance::deleteQPMatrices() +{ + if (H != 0) { + delete H; + H = 0; + } + + if (Hv != 0) { + delete[] Hv; + Hv = 0; + } + + if (Hjc != 0) { + delete[] Hjc; + Hjc = 0; + } + + if (Hir != 0) { + delete[] Hir; + Hir = 0; + } + + if (A != 0) { + delete A; + A = 0; + } + + if (Av != 0) { + delete[] Av; + Av = 0; + } + + if (Ajc != 0) { + delete[] Ajc; + Ajc = 0; + } + + if (Air != 0) { + delete[] Air; + Air = 0; + } + + return SUCCESSFUL_RETURN; +} + +int_t QPInstance::getNV() const +{ + if (sqp != 0) + return sqp->getNV(); + + if (qpb != 0) + return qpb->getNV(); + + return 0; +} + +int_t QPInstance::getNC() const +{ + if (sqp != 0) + return sqp->getNC(); + + return 0; +} + +/* + * m x I s S c a l a r + */ +bool mxIsScalar(const mxArray * pm) +{ + if ((mxGetM(pm) == 1) && (mxGetN(pm) == 1)) + return true; + else + return false; +} + +/* + * a l l o c a t e Q P r o b l e m I n s t a n c e + */ +int_t allocateQPInstance(int_t nV, + int_t nC, + HessianType hessianType, + BooleanType isSimplyBounded, + BooleanType isSparse, + const Options * options) +{ + QPInstance * inst = new QPInstance(nV, nC, hessianType, isSimplyBounded, isSparse); + + if ((inst->sqp != 0) && (options != 0)) + inst->sqp->setOptions(*options); + + if ((inst->qpb != 0) && (options != 0)) + inst->qpb->setOptions(*options); + + g_instances.push_back(inst); + return inst->handle; +} + +/* + * g e t Q P r o b l e m I n s t a n c e + */ +QPInstance * getQPInstance(int_t handle) +{ + uint_t ii; + // TODO: this may become slow ... + for (ii = 0; ii < g_instances.size(); ++ii) + if (g_instances[ii]->handle == handle) + return g_instances[ii]; + return 0; +} + +/* + * d e l e t e Q P r o b l e m I n s t a n c e + */ +void deleteQPInstance(int_t handle) +{ + QPInstance * instance = getQPInstance(handle); + if (instance != 0) { + for (std::vector::iterator itor = g_instances.begin(); itor != g_instances.end(); ++itor) + if ((*itor)->handle == handle) { + g_instances.erase(itor); + break; + } + delete instance; + } +} + +/* + * s m a r t D i m e n s i o n C h e c k + */ +returnValue smartDimensionCheck( + real_t ** input, uint_t m, uint_t n, BooleanType emptyAllowed, const mxArray * prhs[], int_t idx) +{ + /* If index is negative, the input does not exist. */ + if (idx < 0) { + *input = 0; + return SUCCESSFUL_RETURN; + } + + /* Otherwise the input has been passed by the user. */ + if (mxIsEmpty(prhs[idx])) { + /* input is empty */ + if ((emptyAllowed == BT_TRUE) || (idx == 0)) /* idx==0 used for auxInput */ + { + *input = 0; + return SUCCESSFUL_RETURN; + } else { + char msg[MAX_STRING_LENGTH]; + if (idx > 0) + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Empty argument %d not allowed!", idx + 1); + myMexErrMsgTxt(msg); + return RET_INVALID_ARGUMENTS; + } + } else { + /* input is non-empty */ + if (mxIsSparse(prhs[idx]) == 0) { + if ((mxGetM(prhs[idx]) == m) && (mxGetN(prhs[idx]) == n)) { + *input = (real_t *)mxGetPr(prhs[idx]); + return SUCCESSFUL_RETURN; + } else { + char msg[MAX_STRING_LENGTH]; + if (idx > 0) + snprintf(msg, + MAX_STRING_LENGTH, + "ERROR (qpOASES): Input dimension mismatch for argument %d ([%ld,%ld] ~= [%d,%d]).", + idx + 1, + (long int)mxGetM(prhs[idx]), + (long int)mxGetN(prhs[idx]), + (int)m, + (int)n); + else /* idx==0 used for auxInput */ + snprintf(msg, + MAX_STRING_LENGTH, + "ERROR (qpOASES): Input dimension mismatch for some auxInput entry ([%ld,%ld] ~= [%d,%d]).", + (long int)mxGetM(prhs[idx]), + (long int)mxGetN(prhs[idx]), + (int)m, + (int)n); + myMexErrMsgTxt(msg); + return RET_INVALID_ARGUMENTS; + } + } else { + char msg[MAX_STRING_LENGTH]; + if (idx > 0) + snprintf(msg, + MAX_STRING_LENGTH, + "ERROR (qpOASES): Vector argument %d must not be in sparse format!", + idx + 1); + else /* idx==0 used for auxInput */ + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): auxInput entries must not be in sparse format!"); + myMexErrMsgTxt(msg); + return RET_INVALID_ARGUMENTS; + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * c o n t a i n s N a N + */ +BooleanType containsNaN(const real_t * const data, uint_t dim) +{ + uint_t i; + + if (data == 0) + return BT_FALSE; + + for (i = 0; i < dim; ++i) + if (mxIsNaN(data[i]) == 1) + return BT_TRUE; + + return BT_FALSE; +} + +/* + * c o n t a i n s I n f + */ +BooleanType containsInf(const real_t * const data, uint_t dim) +{ + uint_t i; + + if (data == 0) + return BT_FALSE; + + for (i = 0; i < dim; ++i) + if (mxIsInf(data[i]) == 1) + return BT_TRUE; + + return BT_FALSE; +} + +/* + * c o n t a i n s N a N o r I n f + */ +BooleanType containsNaNorInf(const mxArray * prhs[], int_t rhs_index, bool mayContainInf) +{ + uint_t dim; + char msg[MAX_STRING_LENGTH]; + + if (rhs_index < 0) + return BT_FALSE; + + /* overwrite dim for sparse matrices */ + if (mxIsSparse(prhs[rhs_index]) == 1) + dim = (uint_t)mxGetNzmax(prhs[rhs_index]); + else + dim = (uint_t)(mxGetM(prhs[rhs_index]) * mxGetN(prhs[rhs_index])); + + if (containsNaN((real_t *)mxGetPr(prhs[rhs_index]), dim) == BT_TRUE) { + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Argument %d contains 'NaN' !", rhs_index + 1); + myMexErrMsgTxt(msg); + return BT_TRUE; + } + + if (mayContainInf == 0) { + if (containsInf((real_t *)mxGetPr(prhs[rhs_index]), dim) == BT_TRUE) { + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Argument %d contains 'Inf' !", rhs_index + 1); + myMexErrMsgTxt(msg); + return BT_TRUE; + } + } + + return BT_FALSE; +} + +/* + * c o n v e r t F o r t r a n T o C + */ +returnValue convertFortranToC(const real_t * const M_for, int_t nV, int_t nC, real_t * const M) +{ + int_t i, j; + + if ((M_for == 0) || (M == 0)) + return RET_INVALID_ARGUMENTS; + + if ((nV < 0) || (nC < 0)) + return RET_INVALID_ARGUMENTS; + + for (i = 0; i < nC; ++i) + for (j = 0; j < nV; ++j) + M[i * nV + j] = M_for[j * nC + i]; + + return SUCCESSFUL_RETURN; +} + +/* + * h a s O p t i o n s V a l u e + */ +BooleanType hasOptionsValue( + const mxArray * optionsPtr, const char * const optionString, double ** optionValue) +{ + mxArray * optionName = mxGetField(optionsPtr, 0, optionString); + + if (optionName == 0) { + char msg[MAX_STRING_LENGTH]; + snprintf(msg, + MAX_STRING_LENGTH, + "Option struct does not contain entry '%s', using default value instead!", + optionString); + mexWarnMsgTxt(msg); + return BT_FALSE; + } + + if ((mxIsEmpty(optionName) == false) && (mxIsScalar(optionName) == true)) { + *optionValue = mxGetPr(optionName); + return BT_TRUE; + } else { + char msg[MAX_STRING_LENGTH]; + snprintf( + msg, MAX_STRING_LENGTH, "Option '%s' is not a scalar, using default value instead!", optionString); + mexWarnMsgTxt(msg); + return BT_FALSE; + } +} + +/* + * s e t u p O p t i o n s + */ +returnValue setupOptions(Options * options, const mxArray * optionsPtr, int_t & nWSRin, real_t & maxCpuTime) +{ + double * optionValue; + int_t optionValueInt; + + /* Check for correct number of option entries; + * may occur, e.g., if user types options. = ; */ + if (mxGetNumberOfFields(optionsPtr) != 31) + mexWarnMsgTxt("Options might be set incorrectly as struct has wrong number of entries!\n Type " + "'help qpOASES_options' for further information."); + + if (hasOptionsValue(optionsPtr, "maxIter", &optionValue) == BT_TRUE) + if (*optionValue >= 0.0) + nWSRin = (int_t)*optionValue; + + if (hasOptionsValue(optionsPtr, "maxCpuTime", &optionValue) == BT_TRUE) + if (*optionValue >= 0.0) + maxCpuTime = *optionValue; + + if (hasOptionsValue(optionsPtr, "printLevel", &optionValue) == BT_TRUE) { +#ifdef __SUPPRESSANYOUTPUT__ + options->printLevel = PL_NONE; +#else + optionValueInt = (int_t)*optionValue; + options->printLevel = (REFER_NAMESPACE_QPOASES PrintLevel)optionValueInt; + if (options->printLevel < PL_DEBUG_ITER) + options->printLevel = PL_DEBUG_ITER; + if (options->printLevel > PL_HIGH) + options->printLevel = PL_HIGH; +#endif + } + + if (hasOptionsValue(optionsPtr, "enableRamping", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + options->enableRamping = (REFER_NAMESPACE_QPOASES BooleanType)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "enableFarBounds", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + options->enableFarBounds = (REFER_NAMESPACE_QPOASES BooleanType)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "enableFlippingBounds", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + options->enableFlippingBounds = (REFER_NAMESPACE_QPOASES BooleanType)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "enableRegularisation", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + options->enableRegularisation = (REFER_NAMESPACE_QPOASES BooleanType)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "enableFullLITests", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + options->enableFullLITests = (REFER_NAMESPACE_QPOASES BooleanType)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "enableNZCTests", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + options->enableNZCTests = (REFER_NAMESPACE_QPOASES BooleanType)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "enableDriftCorrection", &optionValue) == BT_TRUE) + options->enableDriftCorrection = (int_t)*optionValue; + + if (hasOptionsValue(optionsPtr, "enableCholeskyRefactorisation", &optionValue) == BT_TRUE) + options->enableCholeskyRefactorisation = (int_t)*optionValue; + + if (hasOptionsValue(optionsPtr, "enableEqualities", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + options->enableEqualities = (REFER_NAMESPACE_QPOASES BooleanType)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "terminationTolerance", &optionValue) == BT_TRUE) + options->terminationTolerance = *optionValue; + + if (hasOptionsValue(optionsPtr, "boundTolerance", &optionValue) == BT_TRUE) + options->boundTolerance = *optionValue; + + if (hasOptionsValue(optionsPtr, "boundRelaxation", &optionValue) == BT_TRUE) + options->boundRelaxation = *optionValue; + + if (hasOptionsValue(optionsPtr, "epsNum", &optionValue) == BT_TRUE) + options->epsNum = *optionValue; + + if (hasOptionsValue(optionsPtr, "epsDen", &optionValue) == BT_TRUE) + options->epsDen = *optionValue; + + if (hasOptionsValue(optionsPtr, "maxPrimalJump", &optionValue) == BT_TRUE) + options->maxPrimalJump = *optionValue; + + if (hasOptionsValue(optionsPtr, "maxDualJump", &optionValue) == BT_TRUE) + options->maxDualJump = *optionValue; + + if (hasOptionsValue(optionsPtr, "initialRamping", &optionValue) == BT_TRUE) + options->initialRamping = *optionValue; + + if (hasOptionsValue(optionsPtr, "finalRamping", &optionValue) == BT_TRUE) + options->finalRamping = *optionValue; + + if (hasOptionsValue(optionsPtr, "initialFarBounds", &optionValue) == BT_TRUE) + options->initialFarBounds = *optionValue; + + if (hasOptionsValue(optionsPtr, "growFarBounds", &optionValue) == BT_TRUE) + options->growFarBounds = *optionValue; + + if (hasOptionsValue(optionsPtr, "initialStatusBounds", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + if (optionValueInt < -1) + optionValueInt = -1; + if (optionValueInt > 1) + optionValueInt = 1; + options->initialStatusBounds = (REFER_NAMESPACE_QPOASES SubjectToStatus)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "epsFlipping", &optionValue) == BT_TRUE) + options->epsFlipping = *optionValue; + + if (hasOptionsValue(optionsPtr, "numRegularisationSteps", &optionValue) == BT_TRUE) + options->numRegularisationSteps = (int_t)*optionValue; + + if (hasOptionsValue(optionsPtr, "epsRegularisation", &optionValue) == BT_TRUE) + options->epsRegularisation = *optionValue; + + if (hasOptionsValue(optionsPtr, "numRefinementSteps", &optionValue) == BT_TRUE) + options->numRefinementSteps = (int_t)*optionValue; + + if (hasOptionsValue(optionsPtr, "epsIterRef", &optionValue) == BT_TRUE) + options->epsIterRef = *optionValue; + + if (hasOptionsValue(optionsPtr, "epsLITests", &optionValue) == BT_TRUE) + options->epsLITests = *optionValue; + + if (hasOptionsValue(optionsPtr, "epsNZCTests", &optionValue) == BT_TRUE) + options->epsNZCTests = *optionValue; + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A u x i l i a r y I n p u t s + */ +returnValue setupAuxiliaryInputs(const mxArray * auxInput, + uint_t nV, + uint_t nC, + HessianType * hessianType, + double ** x0, + double ** guessedBounds, + double ** guessedConstraints, + double ** R) +{ + mxArray * curField = 0; + + /* hessianType */ + curField = mxGetField(auxInput, 0, "hessianType"); + if (curField == NULL) + mexWarnMsgTxt("auxInput struct does not contain entry 'hessianType'!\n Type 'help " + "qpOASES_auxInput' for further information."); + else { + if (mxIsEmpty(curField) == true) { + *hessianType = HST_UNKNOWN; + } else { + if (mxIsScalar(curField) == false) + return RET_INVALID_ARGUMENTS; + + double * hessianTypeTmp = mxGetPr(curField); + int_t hessianTypeInt = (int_t)*hessianTypeTmp; + if (hessianTypeInt < 0) + hessianTypeInt = 6; /* == HST_UNKNOWN */ + if (hessianTypeInt > 5) + hessianTypeInt = 6; /* == HST_UNKNOWN */ + *hessianType = (REFER_NAMESPACE_QPOASES HessianType)hessianTypeInt; + } + } + + /* x0 */ + curField = mxGetField(auxInput, 0, "x0"); + if (curField == NULL) + mexWarnMsgTxt("auxInput struct does not contain entry 'x0'!\n Type 'help qpOASES_auxInput' for " + "further information."); + else { + *x0 = mxGetPr(curField); + if (smartDimensionCheck(x0, nV, 1, BT_TRUE, ((const mxArray **)&curField), 0) != SUCCESSFUL_RETURN) + return RET_INVALID_ARGUMENTS; + } + + /* guessedWorkingSetB */ + curField = mxGetField(auxInput, 0, "guessedWorkingSetB"); + if (curField == NULL) + mexWarnMsgTxt("auxInput struct does not contain entry 'guessedWorkingSetB'!\n Type 'help " + "qpOASES_auxInput' for further information."); + else { + *guessedBounds = mxGetPr(curField); + if (smartDimensionCheck(guessedBounds, nV, 1, BT_TRUE, ((const mxArray **)&curField), 0) != + SUCCESSFUL_RETURN) + return RET_INVALID_ARGUMENTS; + } + + /* guessedWorkingSetC */ + curField = mxGetField(auxInput, 0, "guessedWorkingSetC"); + if (curField == NULL) + mexWarnMsgTxt("auxInput struct does not contain entry 'guessedWorkingSetC'!\n Type 'help " + "qpOASES_auxInput' for further information."); + else { + *guessedConstraints = mxGetPr(curField); + if (smartDimensionCheck(guessedConstraints, nC, 1, BT_TRUE, ((const mxArray **)&curField), 0) != + SUCCESSFUL_RETURN) + return RET_INVALID_ARGUMENTS; + } + + /* R */ + curField = mxGetField(auxInput, 0, "R"); + if (curField == NULL) + mexWarnMsgTxt("auxInput struct does not contain entry 'R'!\n Type 'help qpOASES_auxInput' for " + "further information."); + else { + *R = mxGetPr(curField); + if (smartDimensionCheck(R, nV, nV, BT_TRUE, ((const mxArray **)&curField), 0) != SUCCESSFUL_RETURN) + return RET_INVALID_ARGUMENTS; + } + + return SUCCESSFUL_RETURN; +} + +/* + * a l l o c a t e O u t p u t s + */ +returnValue allocateOutputs( + int nlhs, mxArray * plhs[], int_t nV, int_t nC = 0, int_t nP = 1, int_t handle = -1) +{ + /* Create output vectors and assign pointers to them. */ + int_t curIdx = 0; + + /* handle */ + if (handle >= 0) + plhs[curIdx++] = mxCreateDoubleMatrix(1, 1, mxREAL); + + /* x */ + plhs[curIdx++] = mxCreateDoubleMatrix(nV, nP, mxREAL); + + if (nlhs > curIdx) { + /* fval */ + plhs[curIdx++] = mxCreateDoubleMatrix(1, nP, mxREAL); + + if (nlhs > curIdx) { + /* exitflag */ + plhs[curIdx++] = mxCreateDoubleMatrix(1, nP, mxREAL); + + if (nlhs > curIdx) { + /* iter */ + plhs[curIdx++] = mxCreateDoubleMatrix(1, nP, mxREAL); + + if (nlhs > curIdx) { + /* lambda */ + plhs[curIdx++] = mxCreateDoubleMatrix(nV + nC, nP, mxREAL); + + if (nlhs > curIdx) { + /* setup auxiliary output struct */ + mxArray * auxOutput = mxCreateStructMatrix(1, 1, 0, 0); + int_t curFieldNum; + + /* working set */ + curFieldNum = mxAddField(auxOutput, "workingSetB"); + if (curFieldNum >= 0) + mxSetFieldByNumber(auxOutput, 0, curFieldNum, mxCreateDoubleMatrix(nV, nP, mxREAL)); + + curFieldNum = mxAddField(auxOutput, "workingSetC"); + if (curFieldNum >= 0) + mxSetFieldByNumber(auxOutput, 0, curFieldNum, mxCreateDoubleMatrix(nC, nP, mxREAL)); + + curFieldNum = mxAddField(auxOutput, "cpuTime"); + if (curFieldNum >= 0) + mxSetFieldByNumber(auxOutput, 0, curFieldNum, mxCreateDoubleMatrix(1, nP, mxREAL)); + + plhs[curIdx] = auxOutput; + } + } + } + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * o b t a i n O u t p u t s + */ +returnValue obtainOutputs(int_t k, + QProblemB * qp, + returnValue returnvalue, + int_t _nWSRout, + double _cpuTime, + int nlhs, + mxArray * plhs[], + int_t nV, + int_t nC = 0, + int_t handle = -1) +{ + /* Create output vectors and assign pointers to them. */ + int_t curIdx = 0; + + /* handle */ + if (handle >= 0) + plhs[curIdx++] = mxCreateDoubleScalar(handle); + + /* x */ + double * x = mxGetPr(plhs[curIdx++]); + qp->getPrimalSolution(&(x[k * nV])); + + if (nlhs > curIdx) { + /* fval */ + double * obj = mxGetPr(plhs[curIdx++]); + obj[k] = qp->getObjVal(); + + if (nlhs > curIdx) { + /* exitflag */ + double * status = mxGetPr(plhs[curIdx++]); + status[k] = (double)getSimpleStatus(returnvalue); + + if (nlhs > curIdx) { + /* iter */ + double * nWSRout = mxGetPr(plhs[curIdx++]); + nWSRout[k] = (double)_nWSRout; + + if (nlhs > curIdx) { + /* lambda */ + double * y = mxGetPr(plhs[curIdx++]); + qp->getDualSolution(&(y[k * (nV + nC)])); + + /* auxOutput */ + if (nlhs > curIdx) { + QProblem * problemPointer; + problemPointer = dynamic_cast(qp); + + mxArray * auxOutput = plhs[curIdx]; + mxArray * curField = 0; + + /* working set bounds */ + if (nV > 0) { + curField = mxGetField(auxOutput, 0, "workingSetB"); + double * workingSetB = mxGetPr(curField); + + /* cast successful? */ + if (problemPointer != NULL) { + problemPointer->getWorkingSetBounds(&(workingSetB[k * nV])); + } else { + qp->getWorkingSetBounds(&(workingSetB[k * nV])); + } + } + + /* working set constraints */ + if (nC > 0) { + curField = mxGetField(auxOutput, 0, "workingSetC"); + double * workingSetC = mxGetPr(curField); + + /* cast successful? */ + if (problemPointer != NULL) { + problemPointer->getWorkingSetConstraints(&(workingSetC[k * nC])); + } else { + qp->getWorkingSetConstraints(&(workingSetC[k * nC])); + } + } + + /* cpu time */ + curField = mxGetField(auxOutput, 0, "cpuTime"); + double * cpuTime = mxGetPr(curField); + cpuTime[0] = (double)_cpuTime; + } + } + } + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p H e s s i a n M a t r i x + */ +returnValue setupHessianMatrix(const mxArray * prhsH, + int_t nV, + SymmetricMatrix ** H, + sparse_int_t ** Hir, + sparse_int_t ** Hjc, + real_t ** Hv) +{ + if (prhsH == 0) + return SUCCESSFUL_RETURN; + + if (mxIsSparse(prhsH) != 0) { + mwIndex * mat_ir = mxGetIr(prhsH); + mwIndex * mat_jc = mxGetJc(prhsH); + double * v = (double *)mxGetPr(prhsH); + sparse_int_t nfill = 0; + mwIndex i, j; + BooleanType needInsertDiag; + + /* copy indices to avoid 64/32-bit integer confusion */ + /* also add explicit zeros on diagonal for regularization strategy */ + /* copy values, too */ + *Hir = new sparse_int_t[mat_jc[nV] + nV]; + *Hjc = new sparse_int_t[nV + 1]; + *Hv = new real_t[mat_jc[nV] + nV]; + for (j = 0; j < nV; j++) { + needInsertDiag = BT_TRUE; + + (*Hjc)[j] = (sparse_int_t)(mat_jc[j]) + nfill; + /* fill up to diagonal */ + for (i = mat_jc[j]; i < mat_jc[j + 1]; i++) { + if (mat_ir[i] == j) + needInsertDiag = BT_FALSE; + + /* add zero diagonal element if not present */ + if ((mat_ir[i] > j) && (needInsertDiag == BT_TRUE)) { + (*Hir)[i + nfill] = (sparse_int_t)j; + (*Hv)[i + nfill] = 0.0; + nfill++; + /* only add diag once */ + needInsertDiag = BT_FALSE; + } + + (*Hir)[i + nfill] = (sparse_int_t)(mat_ir[i]); + (*Hv)[i + nfill] = (real_t)(v[i]); + } + } + (*Hjc)[nV] = (sparse_int_t)(mat_jc[nV]) + nfill; + + SymSparseMat * sH; + *H = sH = new SymSparseMat(nV, nV, *Hir, *Hjc, *Hv); + sH->createDiagInfo(); + } else { + /* make a deep-copy in order to avoid modifying input data when regularising */ + real_t * H_for = (real_t *)mxGetPr(prhsH); + real_t * H_mem = new real_t[nV * nV]; + memcpy(H_mem, H_for, nV * nV * sizeof(real_t)); + + *H = new SymDenseMat(nV, nV, nV, H_mem); + (*H)->doFreeMemory(); + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p C o n s t r a i n t M a t r i x + */ +returnValue setupConstraintMatrix(const mxArray * prhsA, + int_t nV, + int_t nC, + Matrix ** A, + sparse_int_t ** Air, + sparse_int_t ** Ajc, + real_t ** Av) +{ + if (prhsA == 0) + return SUCCESSFUL_RETURN; + + if (mxIsSparse(prhsA) != 0) { + mwIndex i; + long j; + + mwIndex * mat_ir = mxGetIr(prhsA); + mwIndex * mat_jc = mxGetJc(prhsA); + double * v = (double *)mxGetPr(prhsA); + + /* copy indices to avoid 64/32-bit integer confusion */ + *Air = new sparse_int_t[mat_jc[nV]]; + *Ajc = new sparse_int_t[nV + 1]; + for (i = 0; i < mat_jc[nV]; i++) + (*Air)[i] = (sparse_int_t)(mat_ir[i]); + for (i = 0; i < nV + 1; i++) + (*Ajc)[i] = (sparse_int_t)(mat_jc[i]); + + /* copy values, too */ + *Av = new real_t[(*Ajc)[nV]]; + for (j = 0; j < (*Ajc)[nV]; j++) + (*Av)[j] = (real_t)(v[j]); + + *A = new SparseMatrix(nC, nV, *Air, *Ajc, *Av); + } else { + /* Convert constraint matrix A from FORTRAN to C style + * (not necessary for H as it should be symmetric!). */ + real_t * A_for = (real_t *)mxGetPr(prhsA); + real_t * A_mem = new real_t[nC * nV]; + convertFortranToC(A_for, nV, nC, A_mem); + *A = new DenseMatrix(nC, nV, nV, A_mem); + (*A)->doFreeMemory(); + } + + return SUCCESSFUL_RETURN; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_matlab_utils.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_matlab_utils.hpp new file mode 100644 index 0000000..2509dcc --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_matlab_utils.hpp @@ -0,0 +1,97 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file interfaces/matlab/qpOASES_matlab_utils.hpp + * \author Hans Joachim Ferreau, Alexander Buchner + * \version 3.2 + * \date 2007-2017 + * + * Collects utility functions for Interface to Matlab(R) that + * enables to call qpOASES as a MEX function. + * + */ + +/* Work-around for settings where mexErrMsgTxt causes unexpected behaviour. */ +#ifdef __AVOID_MEXERRMSGTXT__ +#define myMexErrMsgTxt(TEXT) mexPrintf("%s\n\n", (TEXT)); +#else +#define myMexErrMsgTxt mexErrMsgTxt +#endif + +/* Workaround for problem on Matlab 2012b + * see https://github.com/robotology/codyco-superbuild/issues/84 + * see + * http://stackoverflow.com/questions/22440523/mex-files-using-xcode-5-1-under-os-x-10-9-with-matlab-2012a/22705789#22705789 + */ +#ifdef __APPLE__ +#include +#endif + +#include "matrix.h" +#include "mex.h" +#include "string.h" +#include + +/* + * QProblem instance class + */ +class QPInstance +{ +private: + static int_t s_nexthandle; + +public: + QPInstance(uint_t _nV = 0, + uint_t _nC = 0, + HessianType _hessianType = HST_UNKNOWN, + BooleanType _isSimplyBounded = BT_FALSE, + BooleanType _sparseLA = BT_FALSE); + + ~QPInstance(); + + returnValue deleteQPMatrices(); + + int_t getNV() const; + int_t getNC() const; + + int_t handle; + + SQProblem * sqp; + QProblemB * qpb; + BooleanType isSimplyBounded; + BooleanType sparseLA; + + SymmetricMatrix * H; + Matrix * A; + sparse_int_t * Hir; + sparse_int_t * Hjc; + sparse_int_t * Air; + sparse_int_t * Ajc; + real_t * Hv; + real_t * Av; +}; + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_options.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_options.m new file mode 100755 index 0000000..0cccf95 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_options.m @@ -0,0 +1,251 @@ +%qpOASES -- An Implementation of the Online Active Set Strategy. +%Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +%Christian Kirches et al. All rights reserved. +% +%qpOASES is distributed under the terms of the +%GNU Lesser General Public License 2.1 in the hope that it will be +%useful, but WITHOUT ANY WARRANTY; without even the implied warranty +%of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +%See the GNU Lesser General Public License for more details. +% +%--------------------------------------------------------------------------------- +% +%Returns a struct containing values for all options to be used within qpOASES. +% +%Call +% options = qpOASES_options( 'default' ); +% options = qpOASES_options( 'reliable' ); +% options = qpOASES_options( 'MPC' ); +%to obtain a set of default options or a pre-defined set of options tuned +%for reliable or fast QP solution, respectively. +% +%Call +% options = qpOASES_options( 'option1',value1,'option2',value2,... ) +%to obtain a set of default options but with 'option1' set to value1 etc. +% +%Call +% options = qpOASES_options( oldOptions,'option1',value1,... ) +%to obtain a copy of the options struct oldOptions but with 'option1' set +%to value1 etc. +% +%Call +% options = qpOASES_options( 'default', 'option1',value1,... ) +% options = qpOASES_options( 'reliable','option1',value1,... ) +% options = qpOASES_options( 'MPC', 'option1',value1,... ) +%to obtain a set of default options or a pre-defined set of options tuned +%for reliable or fast QP solution, respectively, but with 'option1' set to +%value1 etc. +% +% +%qpOASES features the following options: +% maxIter - Maximum number of iterations (if set +% to -1, a value is chosen heuristically) +% maxCpuTime - Maximum CPU time in seconds (if set +% to -1, only iteration limit is used) +% printLevel - 0: no printed output, +% 1: only error messages are printed, +% 2: iterations and error messages are printed, +% 3: all available messages are printed. +% +% enableRamping - Enables (1) or disables (0) ramping. +% enableFarBounds - Enables (1) or disables (0) the use of +% far bounds. +% enableFlippingBounds - Enables (1) or disables (0) the use of +% flipping bounds. +% enableRegularisation - Enables (1) or disables (0) automatic +% Hessian regularisation. +% enableFullLITests - Enables (1) or disables (0) condition-hardened +% (but more expensive) LI test. +% enableNZCTests - Enables (1) or disables (0) nonzero curvature +% tests. +% enableDriftCorrection - Specifies the frequency of drift corrections: +% 0: turns them off, +% 1: uses them at each iteration etc. +% enableCholeskyRefactorisation - Specifies the frequency of a full re- +% factorisation of projected Hessian matrix: +% 0: turns them off, +% 1: uses them at each iteration etc. +% enableEqualities - Specifies whether equalities should be treated +% as always active (1) or not (0) +% +% terminationTolerance - Relative termination tolerance to stop homotopy. +% boundTolerance - If upper and lower bounds differ less than this +% tolerance, they are regarded equal, i.e. as +% equality constraint. +% boundRelaxation - Initial relaxation of bounds to start homotopy +% and initial value for far bounds. +% epsNum - Numerator tolerance for ratio tests. +% epsDen - Denominator tolerance for ratio tests. +% maxPrimalJump - Maximum allowed jump in primal variables in +% nonzero curvature tests. +% maxDualJump - Maximum allowed jump in dual variables in +% linear independence tests. +% +% initialRamping - Start value for ramping strategy. +% finalRamping - Final value for ramping strategy. +% initialFarBounds - Initial size for far bounds. +% growFarBounds - Factor to grow far bounds. +% initialStatusBounds - Initial status of bounds at first iteration: +% 0: all bounds inactive, +% -1: all bounds active at their lower bound, +% +1: all bounds active at their upper bound. +% epsFlipping - Tolerance of squared Cholesky diagonal factor +% which triggers flipping bound. +% numRegularisationSteps - Maximum number of successive regularisation steps. +% epsRegularisation - Scaling factor of identity matrix used for +% Hessian regularisation. +% numRefinementSteps - Maximum number of iterative refinement steps. +% epsIterRef - Early termination tolerance for iterative +% refinement. +% epsLITests - Tolerance for linear independence tests. +% epsNZCTests - Tolerance for nonzero curvature tests. +% +% +%See also QPOASES, QPOASES_SEQUENCE, QPOASES_AUXINPUT +% +% +%For additional information see the qpOASES User's Manual or +%visit http://www.qpOASES.org/. +% +%Please send remarks and questions to support@qpOASES.org! +function [ options ] = qpOASES_options( varargin ) + + firstIsStructOrScheme = 0; + + if ( nargin == 0 ) + options = qpOASES_default_options(); + else + if ( isstruct( varargin{1} ) ) + if ( mod( nargin,2 ) ~= 1 ) + error('ERROR (qpOASES_options): Options must be specified in pairs!'); + end + options = varargin{1}; + firstIsStructOrScheme = 1; + else + if ( ischar( varargin{1} ) ) + if ( mod( nargin,2 ) == 0 ) + options = qpOASES_default_options(); + else + if ( ( nargin > 1 ) && ( ischar( varargin{nargin} ) ) ) + error('ERROR (qpOASES_options): Options must be specified in pairs!'); + end + + switch ( varargin{1} ) + case 'default' + options = qpOASES_default_options(); + case 'reliable' + options = qpOASES_reliable_options(); + case {'MPC','mpc','fast'} + options = qpOASES_MPC_options(); + otherwise + error( ['ERROR (qpOASES_options): Only the following option schemes are defined: ''default'', ''reliable'', ''MPC''!'] ); + + end + firstIsStructOrScheme = 1; + end + else + error('ERROR (qpOASES_options): First argument needs to be a string or an options struct!'); + end + end + end + + % set options to user-defined values + for i=(1+firstIsStructOrScheme):2:nargin + + argName = varargin{i}; + argValue = varargin{i+1}; + + if ( ( isempty( argName ) ) || ( ~ischar( argName ) ) ) + error('ERROR (qpOASES_options): Argmument no. %d has to be a non-empty string!',i ); + end + + if ( ( ischar(argValue) ) || ( ~isscalar( argValue ) ) ) + error('ERROR (qpOASES_options): Argmument no. %d has to be a scalar constant!',i+1 ); + end + + if ( ~isfield( options,argName ) ) + error('ERROR (qpOASES_options): Argmument no. %d is an invalid option!',i ); + end + + eval( ['options.',argName,' = ',num2str(argValue),';'] ); + + end + +end + + +function [ options ] = qpOASES_default_options( ) + + % setup options struct with default values + options = struct( 'maxIter', -1, ... + 'maxCpuTime', -1, ... + 'printLevel', 1, ... + ... + 'enableRamping', 1, ... + 'enableFarBounds', 1, ... + 'enableFlippingBounds', 1, ... + 'enableRegularisation', 0, ... + 'enableFullLITests', 0, ... + 'enableNZCTests', 1, ... + 'enableDriftCorrection', 1, ... + 'enableCholeskyRefactorisation', 0, ... + 'enableEqualities', 0, ... + ... + 'terminationTolerance', 5.0e6*eps, ... + 'boundTolerance', 1.0e6*eps, ... + 'boundRelaxation', 1.0e4, ... + 'epsNum', -1.0e3*eps, ... + 'epsDen', 1.0e3*eps, ... + 'maxPrimalJump', 1.0e8, ... + 'maxDualJump', 1.0e8, ... + ... + 'initialRamping', 0.5, ... + 'finalRamping', 1.0, ... + 'initialFarBounds', 1.0e6, ... + 'growFarBounds', 1.0e3, ... + 'initialStatusBounds', -1, ... + 'epsFlipping', 1.0e3*eps, ... + 'numRegularisationSteps', 0, ... + 'epsRegularisation', 1.0e3*eps, ... + 'numRefinementSteps', 1, ... + 'epsIterRef', 1.0e2*eps, ... + 'epsLITests', 1.0e5*eps, ... + 'epsNZCTests', 3.1e3*eps ); + +end + + + +function [ options ] = qpOASES_reliable_options( ) + + % setup options struct with values for most reliable QP solution + options = qpOASES_default_options( ); + + options.enableFullLITests = 1; + options.enableCholeskyRefactorisation = 1; + + options.numRefinementSteps = 2; + +end + + +function [ options ] = qpOASES_MPC_options( ) + + % setup options struct with values for most reliable QP solution + options = qpOASES_default_options( ); + + options.enableRamping = 0; + options.enableFarBounds = 1; + options.enableFlippingBounds = 0; + options.enableRegularisation = 1; + options.enableNZCTests = 0; + options.enableDriftCorrection = 0; + options.enableEqualities = 1; + + options.terminationTolerance = 1.0e9*eps; + + options.initialStatusBounds = 0; + options.numRegularisationSteps = 1; + options.numRefinementSteps = 0; + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_sequence.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_sequence.cpp new file mode 100644 index 0000000..e69d231 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_sequence.cpp @@ -0,0 +1,1042 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file interfaces/matlab/qpOASES_sequence.cpp + * \author Hans Joachim Ferreau, Christian Kirches, Andreas Potschka, Alexander Buchner + * \version 3.2 + * \date 2007-2017 + * + * Interface for Matlab(R) that enables to call qpOASES as a MEX function + * (variant for solving QP sequences). + * + */ + +#include + +USING_NAMESPACE_QPOASES + +#include "qpOASES_matlab_utils.hpp" + +/** initialise handle counter of QPInstance class */ +int_t QPInstance::s_nexthandle = 1; + +/** global pointer to QP objects */ +static std::vector g_instances; + +#include "qpOASES_matlab_utils.cpp" + +/* + * Q P r o b l e m B _ i n i t + */ +int_t QProblemB_init(int_t handle, + SymmetricMatrix * H, + real_t * g, + const real_t * const lb, + const real_t * const ub, + int_t nWSRin, + real_t maxCpuTimeIn, + const double * const x0, + Options * options, + int_t nOutputs, + mxArray * plhs[], + const double * const guessedBounds, + const double * const _R) +{ + int_t nWSRout = nWSRin; + real_t maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + + /* 1) setup initial QP. */ + QProblemB * globalQPB = getQPInstance(handle)->qpb; + + if (globalQPB == 0) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid handle to QP instance!"); + return -1; + } + + globalQPB->setOptions(*options); + + /* 2) Solve initial QP. */ + returnValue returnvalue; + int_t nV = globalQPB->getNV(); + + /* 3) Fill the working set. */ + Bounds bounds(nV); + if (guessedBounds != 0) { + for (int_t i = 0; i < nV; i++) { + if (isEqual(guessedBounds[i], -1.0) == BT_TRUE) { + bounds.setupBound(i, ST_LOWER); + } else if (isEqual(guessedBounds[i], 1.0) == BT_TRUE) { + bounds.setupBound(i, ST_UPPER); + } else if (isEqual(guessedBounds[i], 0.0) == BT_TRUE) { + bounds.setupBound(i, ST_INACTIVE); + } else { + char msg[MAX_STRING_LENGTH]; + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Only {-1, 0, 1} allowed for status of bounds!"); + myMexErrMsgTxt(msg); + return -1; + } + } + } + + returnvalue = + globalQPB->init(H, g, lb, ub, nWSRout, &maxCpuTimeOut, x0, 0, (guessedBounds != 0) ? &bounds : 0, _R); + + /* 3) Assign lhs arguments. */ + obtainOutputs(0, globalQPB, returnvalue, nWSRout, maxCpuTimeOut, nOutputs, plhs, nV, 0, handle); + + return 0; +} + +/* + * S Q P r o b l e m _ i n i t + */ +int_t SQProblem_init(int_t handle, + SymmetricMatrix * H, + real_t * g, + Matrix * A, + const real_t * const lb, + const real_t * const ub, + const real_t * const lbA, + const real_t * const ubA, + int_t nWSRin, + real_t maxCpuTimeIn, + const double * const x0, + Options * options, + int_t nOutputs, + mxArray * plhs[], + const double * const guessedBounds, + const double * const guessedConstraints, + const double * const _R) +{ + int_t nWSRout = nWSRin; + real_t maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + + /* 1) setup initial QP. */ + SQProblem * globalSQP = getQPInstance(handle)->sqp; + + if (globalSQP == 0) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid handle to QP instance!"); + return -1; + } + + globalSQP->setOptions(*options); + + /* 2) Solve initial QP. */ + returnValue returnvalue; + int_t nV = globalSQP->getNV(); + int_t nC = globalSQP->getNC(); + + /* 3) Fill the working set. */ + Bounds bounds(nV); + Constraints constraints(nC); + if (guessedBounds != 0) { + for (int_t i = 0; i < nV; i++) { + if (isEqual(guessedBounds[i], -1.0) == BT_TRUE) { + bounds.setupBound(i, ST_LOWER); + } else if (isEqual(guessedBounds[i], 1.0) == BT_TRUE) { + bounds.setupBound(i, ST_UPPER); + } else if (isEqual(guessedBounds[i], 0.0) == BT_TRUE) { + bounds.setupBound(i, ST_INACTIVE); + } else { + char msg[MAX_STRING_LENGTH]; + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Only {-1, 0, 1} allowed for status of bounds!"); + myMexErrMsgTxt(msg); + return -1; + } + } + } + + if (guessedConstraints != 0) { + for (int_t i = 0; i < nC; i++) { + if (isEqual(guessedConstraints[i], -1.0) == BT_TRUE) { + constraints.setupConstraint(i, ST_LOWER); + } else if (isEqual(guessedConstraints[i], 1.0) == BT_TRUE) { + constraints.setupConstraint(i, ST_UPPER); + } else if (isEqual(guessedConstraints[i], 0.0) == BT_TRUE) { + constraints.setupConstraint(i, ST_INACTIVE); + } else { + char msg[MAX_STRING_LENGTH]; + snprintf( + msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Only {-1, 0, 1} allowed for status of constraints!"); + myMexErrMsgTxt(msg); + return -1; + } + } + } + + returnvalue = globalSQP->init(H, + g, + A, + lb, + ub, + lbA, + ubA, + nWSRout, + &maxCpuTimeOut, + x0, + 0, + (guessedBounds != 0) ? &bounds : 0, + (guessedConstraints != 0) ? &constraints : 0, + _R); + + /* 3) Assign lhs arguments. */ + obtainOutputs(0, globalSQP, returnvalue, nWSRout, maxCpuTimeOut, nOutputs, plhs, nV, nC, handle); + + return 0; +} + +/* + * Q P r o b l e m B _ h o t s t a r t + */ +int_t QProblemB_hotstart(int_t handle, + const real_t * const g, + const real_t * const lb, + const real_t * const ub, + int_t nWSRin, + real_t maxCpuTimeIn, + Options * options, + int_t nOutputs, + mxArray * plhs[]) +{ + int_t nWSRout = nWSRin; + real_t maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + + QProblemB * globalQPB = getQPInstance(handle)->qpb; + + if (globalQPB == 0) { + myMexErrMsgTxt("ERROR (qpOASES): QP needs to be initialised first!"); + return -1; + } + + int_t nV = globalQPB->getNV(); + + /* 1) Solve QP with given options. */ + globalQPB->setOptions(*options); + returnValue returnvalue = globalQPB->hotstart(g, lb, ub, nWSRout, &maxCpuTimeOut); + + /* 2) Assign lhs arguments. */ + obtainOutputs(0, globalQPB, returnvalue, nWSRout, maxCpuTimeOut, nOutputs, plhs, nV, 0); + + return 0; +} + +/* + * Q P r o b l e m _ h o t s t a r t + */ +int_t QProblem_hotstart(int_t handle, + const real_t * const g, + const real_t * const lb, + const real_t * const ub, + const real_t * const lbA, + const real_t * const ubA, + int_t nWSRin, + real_t maxCpuTimeIn, + Options * options, + int_t nOutputs, + mxArray * plhs[]) +{ + int_t nWSRout = nWSRin; + real_t maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + + QProblem * globalSQP = getQPInstance(handle)->sqp; + + if (globalSQP == 0) { + myMexErrMsgTxt("ERROR (qpOASES): QP needs to be initialised first!"); + return -1; + } + + int_t nV = globalSQP->getNV(); + int_t nC = globalSQP->getNC(); + + /* 1) Solve QP with given options. */ + globalSQP->setOptions(*options); + returnValue returnvalue = globalSQP->hotstart(g, lb, ub, lbA, ubA, nWSRout, &maxCpuTimeOut); + + /* 2) Assign lhs arguments. */ + obtainOutputs(0, globalSQP, returnvalue, nWSRout, maxCpuTimeOut, nOutputs, plhs, nV, nC); + + return 0; +} + +/* + * S Q P r o b l e m _ h o t s t a r t + */ +int_t SQProblem_hotstart(int_t handle, + SymmetricMatrix * H, + real_t * g, + Matrix * A, + const real_t * const lb, + const real_t * const ub, + const real_t * const lbA, + const real_t * const ubA, + int_t nWSRin, + real_t maxCpuTimeIn, + Options * options, + int_t nOutputs, + mxArray * plhs[]) +{ + int_t nWSRout = nWSRin; + real_t maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + + SQProblem * globalSQP = getQPInstance(handle)->sqp; + + if (globalSQP == 0) { + myMexErrMsgTxt("ERROR (qpOASES): QP needs to be initialised first!"); + return -1; + } + + int_t nV = globalSQP->getNV(); + int_t nC = globalSQP->getNC(); + + /* 1) Solve QP. */ + globalSQP->setOptions(*options); + returnValue returnvalue = globalSQP->hotstart(H, g, A, lb, ub, lbA, ubA, nWSRout, &maxCpuTimeOut); + + switch (returnvalue) { + case SUCCESSFUL_RETURN: + case RET_QP_UNBOUNDED: + case RET_QP_INFEASIBLE: + break; + + default: + myMexErrMsgTxt("ERROR (qpOASES): Hotstart failed."); + return -1; + } + + /* 2) Assign lhs arguments. */ + obtainOutputs(0, globalSQP, returnvalue, nWSRout, maxCpuTimeOut, nOutputs, plhs, nV, nC); + + return 0; +} + +/* + * m e x F u n c t i o n + */ +void mexFunction(int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[]) +{ + /* inputs */ + char typeString[2]; + + real_t *g = 0, *lb = 0, *ub = 0, *lbA = 0, *ubA = 0; + HessianType hessianType = HST_UNKNOWN; + double *x0 = 0, *R = 0, *R_for = 0; + double *guessedBounds = 0, *guessedConstraints = 0; + + int_t H_idx = -1, g_idx = -1, A_idx = -1, lb_idx = -1, ub_idx = -1, lbA_idx = -1, ubA_idx = -1; + int_t x0_idx = -1, auxInput_idx = -1; + + BooleanType isSimplyBoundedQp = BT_FALSE; +#ifdef SOLVER_MA57 + BooleanType isSparse = BT_TRUE; /* This will be set to BT_FALSE later if a dense matrix is encountered. */ +#else + BooleanType isSparse = BT_FALSE; +#endif + + Options options; + options.printLevel = PL_LOW; +#ifdef __DEBUG__ + options.printLevel = PL_HIGH; +#endif +#ifdef __SUPPRESSANYOUTPUT__ + options.printLevel = PL_NONE; +#endif + + /* dimensions */ + uint_t nV = 0, nC = 0, handle = 0; + int_t nWSRin; + real_t maxCpuTimeIn = -1.0; + QPInstance * globalQP = 0; + + /* I) CONSISTENCY CHECKS: */ + /* 1) Ensure that qpOASES is called with a feasible number of input arguments. */ + if ((nrhs < 5) || (nrhs > 10)) { + if (nrhs != 2) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of input arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + } + + /* 2) Ensure that first input is a string ... */ + if (mxIsChar(prhs[0]) != 1) { + myMexErrMsgTxt("ERROR (qpOASES): First input argument must be a string!"); + return; + } + + mxGetString(prhs[0], typeString, 2); + + /* ... and if so, check if it is an allowed one. */ + if ((strcmp(typeString, "i") != 0) && (strcmp(typeString, "I") != 0) && (strcmp(typeString, "h") != 0) && + (strcmp(typeString, "H") != 0) && (strcmp(typeString, "m") != 0) && (strcmp(typeString, "M") != 0) && + (strcmp(typeString, "e") != 0) && (strcmp(typeString, "E") != 0) && (strcmp(typeString, "c") != 0) && + (strcmp(typeString, "C") != 0)) { + myMexErrMsgTxt("ERROR (qpOASES): Undefined first input argument!\nType 'help qpOASES_sequence' for " + "further information."); + return; + } + + /* II) SELECT RESPECTIVE QPOASES FUNCTION CALL: */ + /* 1) Init (without or with initial guess for primal solution). */ + if ((strcmp(typeString, "i") == 0) || (strcmp(typeString, "I") == 0)) { + /* consistency checks */ + if ((nlhs < 1) || (nlhs > 7)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of output arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if ((nrhs < 5) || (nrhs > 10)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of input arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + g_idx = 2; + + if (mxIsEmpty(prhs[1]) == 1) { + H_idx = -1; + nV = (uint_t)mxGetM(prhs[g_idx]); /* row number of Hessian matrix */ + } else { + H_idx = 1; + nV = (uint_t)mxGetM(prhs[H_idx]); /* row number of Hessian matrix */ + } + + /* ensure that data is given in double precision */ + if (((H_idx >= 0) && (mxIsDouble(prhs[H_idx]) == 0)) || (mxIsDouble(prhs[g_idx]) == 0)) { + myMexErrMsgTxt("ERROR (qpOASES): All data has to be provided in double precision!"); + return; + } + + if ((H_idx >= 0) && ((mxGetN(prhs[H_idx]) != nV) || (mxGetM(prhs[H_idx]) != nV))) { + myMexErrMsgTxt("ERROR (qpOASES): Hessian matrix dimension mismatch!"); + return; + } + + /* Check for 'Inf' and 'Nan' in Hessian */ + if (containsNaNorInf(prhs, H_idx, 0) == BT_TRUE) + return; + + /* Check for 'Inf' and 'Nan' in gradient */ + if (containsNaNorInf(prhs, g_idx, 0) == BT_TRUE) + return; + + /* determine whether is it a simply bounded QP */ + if (nrhs <= 7) + isSimplyBoundedQp = BT_TRUE; + else + isSimplyBoundedQp = BT_FALSE; + + if (isSimplyBoundedQp == BT_TRUE) { + lb_idx = 3; + ub_idx = 4; + + if (containsNaNorInf(prhs, lb_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ub_idx, 1) == BT_TRUE) + return; + + /* Check inputs dimensions and assign pointers to inputs. */ + nC = 0; /* row number of constraint matrix */ + + if (smartDimensionCheck(&g, nV, 1, BT_FALSE, prhs, 2) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lb, nV, 1, BT_TRUE, prhs, 3) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ub, nV, 1, BT_TRUE, prhs, 4) != SUCCESSFUL_RETURN) + return; + + /* default value for nWSR */ + nWSRin = 5 * nV; + + /* Check whether x0 and options are specified .*/ + if (nrhs >= 6) { + if ((!mxIsEmpty(prhs[5])) && (mxIsStruct(prhs[5]))) + setupOptions(&options, prhs[5], nWSRin, maxCpuTimeIn); + + if ((nrhs >= 7) && (!mxIsEmpty(prhs[6]))) { + /* auxInput specified */ + if (mxIsStruct(prhs[6])) { + auxInput_idx = 6; + x0_idx = -1; + } else { + auxInput_idx = -1; + x0_idx = 6; + } + } else { + auxInput_idx = -1; + x0_idx = -1; + } + } + } else { + A_idx = 3; + + /* ensure that data is given in double precision */ + if (mxIsDouble(prhs[A_idx]) == 0) { + myMexErrMsgTxt("ERROR (qpOASES): All data has to be provided in double precision!"); + return; + } + + /* Check inputs dimensions and assign pointers to inputs. */ + nC = (uint_t)mxGetM(prhs[A_idx]); /* row number of constraint matrix */ + + lb_idx = 4; + ub_idx = 5; + lbA_idx = 6; + ubA_idx = 7; + + if (containsNaNorInf(prhs, A_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lb_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ub_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lbA_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ubA_idx, 1) == BT_TRUE) + return; + + if ((mxGetN(prhs[A_idx]) != 0) && (mxGetN(prhs[A_idx]) != nV)) { + myMexErrMsgTxt("ERROR (qpOASES): Constraint matrix dimension mismatch!"); + return; + } + + if (smartDimensionCheck(&g, nV, 1, BT_FALSE, prhs, g_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lb, nV, 1, BT_TRUE, prhs, lb_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ub, nV, 1, BT_TRUE, prhs, ub_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lbA, nC, 1, BT_TRUE, prhs, lbA_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ubA, nC, 1, BT_TRUE, prhs, ubA_idx) != SUCCESSFUL_RETURN) + return; + + /* default value for nWSR */ + nWSRin = 5 * (nV + nC); + + /* Check whether x0 and options are specified .*/ + if (nrhs >= 9) { + if ((!mxIsEmpty(prhs[8])) && (mxIsStruct(prhs[8]))) + setupOptions(&options, prhs[8], nWSRin, maxCpuTimeIn); + + if ((nrhs >= 10) && (!mxIsEmpty(prhs[9]))) { + /* auxInput specified */ + if (mxIsStruct(prhs[9])) { + auxInput_idx = 9; + x0_idx = -1; + } else { + auxInput_idx = -1; + x0_idx = 9; + } + } else { + auxInput_idx = -1; + x0_idx = -1; + } + } + } + + /* check dimensions and copy auxInputs */ + if (smartDimensionCheck(&x0, nV, 1, BT_TRUE, prhs, x0_idx) != SUCCESSFUL_RETURN) + return; + + if (auxInput_idx >= 0) + setupAuxiliaryInputs( + prhs[auxInput_idx], nV, nC, &hessianType, &x0, &guessedBounds, &guessedConstraints, &R_for); + + /* convert Cholesky factor to C storage format */ + if (R_for != 0) { + R = new real_t[nV * nV]; + convertFortranToC(R_for, nV, nV, R); + } + + /* check if QP is sparse */ + if (H_idx >= 0 && !mxIsSparse(prhs[H_idx])) + isSparse = BT_FALSE; + if (nC > 0 && A_idx >= 0 && !mxIsSparse(prhs[A_idx])) + isSparse = BT_FALSE; + + /* allocate instance */ + handle = allocateQPInstance(nV, nC, hessianType, isSimplyBoundedQp, isSparse, &options); + globalQP = getQPInstance(handle); + + /* make a deep-copy of the user-specified Hessian matrix (possibly sparse) */ + if (H_idx >= 0) + setupHessianMatrix( + prhs[H_idx], nV, &(globalQP->H), &(globalQP->Hir), &(globalQP->Hjc), &(globalQP->Hv)); + + /* make a deep-copy of the user-specified constraint matrix (possibly sparse) */ + if ((nC > 0) && (A_idx >= 0)) + setupConstraintMatrix( + prhs[A_idx], nV, nC, &(globalQP->A), &(globalQP->Air), &(globalQP->Ajc), &(globalQP->Av)); + + /* Create output vectors and assign pointers to them. */ + allocateOutputs(nlhs, plhs, nV, nC, 1, handle); + + /* Call qpOASES. */ + if (isSimplyBoundedQp == BT_TRUE) { + QProblemB_init( + handle, globalQP->H, g, lb, ub, nWSRin, maxCpuTimeIn, x0, &options, nlhs, plhs, guessedBounds, R); + } else { + SQProblem_init(handle, + globalQP->H, + g, + globalQP->A, + lb, + ub, + lbA, + ubA, + nWSRin, + maxCpuTimeIn, + x0, + &options, + nlhs, + plhs, + guessedBounds, + guessedConstraints, + R); + } + + if (R != 0) + delete R; + return; + } + + /* 2) Hotstart. */ + if ((strcmp(typeString, "h") == 0) || (strcmp(typeString, "H") == 0)) { + /* consistency checks */ + if ((nlhs < 1) || (nlhs > 6)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of output arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if ((nrhs < 5) || (nrhs > 8)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of input arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + /* determine whether is it a simply bounded QP */ + if (nrhs < 7) + isSimplyBoundedQp = BT_TRUE; + else + isSimplyBoundedQp = BT_FALSE; + + if ((mxIsDouble(prhs[1]) == false) || (mxIsScalar(prhs[1]) == false)) { + myMexErrMsgTxt("ERROR (qpOASES): Expecting a handle to QP object as second argument!\nType 'help " + "qpOASES_sequence' for further information."); + return; + } + + /* get QP instance */ + handle = (uint_t)mxGetScalar(prhs[1]); + globalQP = getQPInstance(handle); + if (globalQP == 0) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid handle to QP instance!"); + return; + } + + nV = globalQP->getNV(); + + g_idx = 2; + lb_idx = 3; + ub_idx = 4; + + if (containsNaNorInf(prhs, g_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lb_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ub_idx, 1) == BT_TRUE) + return; + + /* Check inputs dimensions and assign pointers to inputs. */ + if (isSimplyBoundedQp == BT_TRUE) { + nC = 0; + + if (smartDimensionCheck(&g, nV, 1, BT_FALSE, prhs, g_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lb, nV, 1, BT_TRUE, prhs, lb_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ub, nV, 1, BT_TRUE, prhs, ub_idx) != SUCCESSFUL_RETURN) + return; + + /* default value for nWSR */ + nWSRin = 5 * nV; + + /* Check whether options are specified .*/ + if (nrhs == 6) + if ((!mxIsEmpty(prhs[5])) && (mxIsStruct(prhs[5]))) + setupOptions(&options, prhs[5], nWSRin, maxCpuTimeIn); + } else { + nC = globalQP->getNC(); + + lbA_idx = 5; + ubA_idx = 6; + + if (containsNaNorInf(prhs, lbA_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ubA_idx, 1) == BT_TRUE) + return; + + if (smartDimensionCheck(&g, nV, 1, BT_FALSE, prhs, g_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lb, nV, 1, BT_TRUE, prhs, lb_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ub, nV, 1, BT_TRUE, prhs, ub_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lbA, nC, 1, BT_TRUE, prhs, lbA_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ubA, nC, 1, BT_TRUE, prhs, ubA_idx) != SUCCESSFUL_RETURN) + return; + + /* default value for nWSR */ + nWSRin = 5 * (nV + nC); + + /* Check whether options are specified .*/ + if (nrhs == 8) + if ((!mxIsEmpty(prhs[7])) && (mxIsStruct(prhs[7]))) + setupOptions(&options, prhs[7], nWSRin, maxCpuTimeIn); + } + + /* Create output vectors and assign pointers to them. */ + allocateOutputs(nlhs, plhs, nV, nC); + + /* call qpOASES */ + if (isSimplyBoundedQp == BT_TRUE) { + QProblemB_hotstart(handle, g, lb, ub, nWSRin, maxCpuTimeIn, &options, nlhs, plhs); + } else { + QProblem_hotstart(handle, g, lb, ub, lbA, ubA, nWSRin, maxCpuTimeIn, &options, nlhs, plhs); + } + + return; + } + + /* 3) Modify matrices. */ + if ((strcmp(typeString, "m") == 0) || (strcmp(typeString, "M") == 0)) { + /* consistency checks */ + if ((nlhs < 1) || (nlhs > 6)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of output arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if ((nrhs < 9) || (nrhs > 10)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of input arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if ((mxIsDouble(prhs[1]) == false) || (mxIsScalar(prhs[1]) == false)) { + myMexErrMsgTxt("ERROR (qpOASES): Expecting a handle to QP object as second argument!\nType 'help " + "qpOASES_sequence' for further information."); + return; + } + + /* get QP instance */ + handle = (uint_t)mxGetScalar(prhs[1]); + globalQP = getQPInstance(handle); + if (globalQP == 0) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid handle to QP instance!"); + return; + } + + /* Check inputs dimensions and assign pointers to inputs. */ + g_idx = 3; + + if (mxIsEmpty(prhs[2]) == 1) { + H_idx = -1; + nV = (uint_t)mxGetM(prhs[g_idx]); /* if Hessian is empty, row number of gradient vector */ + } else { + H_idx = 2; + nV = (uint_t)mxGetM(prhs[H_idx]); /* row number of Hessian matrix */ + } + + A_idx = 4; + nC = (uint_t)mxGetM(prhs[A_idx]); /* row number of constraint matrix */ + + lb_idx = 5; + ub_idx = 6; + lbA_idx = 7; + ubA_idx = 8; + + /* ensure that data is given in double precision */ + if (((H_idx >= 0) && (mxIsDouble(prhs[H_idx]) == 0)) || (mxIsDouble(prhs[g_idx]) == 0) || + (mxIsDouble(prhs[A_idx]) == 0)) { + myMexErrMsgTxt("ERROR (qpOASES): All data has to be provided in real_t precision!"); + return; + } + + /* check if supplied data contains 'NaN' or 'Inf' */ + if (containsNaNorInf(prhs, H_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, g_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, A_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lb_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ub_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lbA_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ubA_idx, 1) == BT_TRUE) + return; + + /* Check that dimensions are consistent with existing QP instance */ + if (nV != (uint_t)globalQP->getNV() || nC != (uint_t)globalQP->getNC()) { + myMexErrMsgTxt("ERROR (qpOASES): QP dimensions must be constant during a sequence! Try creating a " + "new QP instance instead."); + return; + } + + if ((H_idx >= 0) && ((mxGetN(prhs[H_idx]) != nV) || (mxGetM(prhs[H_idx]) != nV))) { + myMexErrMsgTxt("ERROR (qpOASES): Hessian matrix dimension mismatch!"); + return; + } + + if ((mxGetN(prhs[A_idx]) != 0) && (mxGetN(prhs[A_idx]) != nV)) { + myMexErrMsgTxt("ERROR (qpOASES): Constraint matrix dimension mismatch!"); + return; + } + + if (smartDimensionCheck(&g, nV, 1, BT_FALSE, prhs, g_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lb, nV, 1, BT_TRUE, prhs, lb_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ub, nV, 1, BT_TRUE, prhs, ub_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lbA, nC, 1, BT_TRUE, prhs, lbA_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ubA, nC, 1, BT_TRUE, prhs, ubA_idx) != SUCCESSFUL_RETURN) + return; + + /* default value for nWSR */ + nWSRin = 5 * (nV + nC); + + /* Check whether options are specified .*/ + if (nrhs > 9) + if ((!mxIsEmpty(prhs[9])) && (mxIsStruct(prhs[9]))) + setupOptions(&options, prhs[9], nWSRin, maxCpuTimeIn); + + globalQP->deleteQPMatrices(); + + /* make a deep-copy of the user-specified Hessian matrix (possibly sparse) */ + if (H_idx >= 0) + setupHessianMatrix( + prhs[H_idx], nV, &(globalQP->H), &(globalQP->Hir), &(globalQP->Hjc), &(globalQP->Hv)); + + /* make a deep-copy of the user-specified constraint matrix (possibly sparse) */ + if ((nC > 0) && (A_idx >= 0)) + setupConstraintMatrix( + prhs[A_idx], nV, nC, &(globalQP->A), &(globalQP->Air), &(globalQP->Ajc), &(globalQP->Av)); + + /* Create output vectors and assign pointers to them. */ + allocateOutputs(nlhs, plhs, nV, nC); + + /* Call qpOASES */ + SQProblem_hotstart( + handle, globalQP->H, g, globalQP->A, lb, ub, lbA, ubA, nWSRin, maxCpuTimeIn, &options, nlhs, plhs); + + return; + } + + /* 4) Solve current equality constrained QP. */ + if ((strcmp(typeString, "e") == 0) || (strcmp(typeString, "E") == 0)) { + /* consistency checks */ + if ((nlhs < 1) || (nlhs > 4)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of output arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if ((nrhs < 7) || (nrhs > 8)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of input arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if ((mxIsDouble(prhs[1]) == false) || (mxIsScalar(prhs[1]) == false)) { + myMexErrMsgTxt("ERROR (qpOASES): Expecting a handle to QP object as second argument!\nType 'help " + "qpOASES_sequence' for further information."); + return; + } + + /* get QP instance */ + handle = (uint_t)mxGetScalar(prhs[1]); + globalQP = getQPInstance(handle); + if (globalQP == 0) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid handle to QP instance!"); + return; + } + + /* Check inputs dimensions and assign pointers to inputs. */ + int_t nRHS = (int_t)mxGetN(prhs[2]); + nV = globalQP->getNV(); + nC = globalQP->getNC(); + real_t *x_out, *y_out; + + g_idx = 2; + lb_idx = 3; + ub_idx = 4; + lbA_idx = 5; + ubA_idx = 6; + + /* check if supplied data contains 'NaN' or 'Inf' */ + if (containsNaNorInf(prhs, g_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lb_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ub_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lbA_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ubA_idx, 1) == BT_TRUE) + return; + + if (smartDimensionCheck(&g, nV, nRHS, BT_FALSE, prhs, g_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lb, nV, nRHS, BT_TRUE, prhs, lb_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ub, nV, nRHS, BT_TRUE, prhs, ub_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lbA, nC, nRHS, BT_TRUE, prhs, lbA_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ubA, nC, nRHS, BT_TRUE, prhs, ubA_idx) != SUCCESSFUL_RETURN) + return; + + /* Check whether options are specified .*/ + if ((nrhs == 8) && (!mxIsEmpty(prhs[7])) && (mxIsStruct(prhs[7]))) { + nWSRin = 5 * (nV + nC); + setupOptions(&options, prhs[7], nWSRin, maxCpuTimeIn); + globalQP->sqp->setOptions(options); + } + + /* Create output vectors and assign pointers to them. */ + plhs[0] = mxCreateDoubleMatrix(nV, nRHS, mxREAL); + x_out = mxGetPr(plhs[0]); + if (nlhs >= 2) { + plhs[1] = mxCreateDoubleMatrix(nV + nC, nRHS, mxREAL); + y_out = mxGetPr(plhs[1]); + + if (nlhs >= 3) { + plhs[2] = mxCreateDoubleMatrix(nV, nRHS, mxREAL); + real_t * workingSetB = mxGetPr(plhs[2]); + globalQP->sqp->getWorkingSetBounds(workingSetB); + + if (nlhs >= 4) { + plhs[3] = mxCreateDoubleMatrix(nC, nRHS, mxREAL); + real_t * workingSetC = mxGetPr(plhs[3]); + globalQP->sqp->getWorkingSetConstraints(workingSetC); + } + } + } else + y_out = new real_t[nV + nC]; + + /* Solve equality constrained QP */ + returnValue returnvalue = globalQP->sqp->solveCurrentEQP(nRHS, g, lb, ub, lbA, ubA, x_out, y_out); + + if (nlhs < 2) + delete[] y_out; + + if (returnvalue != SUCCESSFUL_RETURN) { + char msg[MAX_STRING_LENGTH]; + snprintf( + msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Couldn't solve current EQP (code %d)!", returnvalue); + myMexErrMsgTxt(msg); + return; + } + + return; + } + + /* 5) Cleanup. */ + if ((strcmp(typeString, "c") == 0) || (strcmp(typeString, "C") == 0)) { + /* consistency checks */ + if (nlhs != 0) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of output arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if (nrhs != 2) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of input arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if ((mxIsDouble(prhs[1]) == false) || (mxIsScalar(prhs[1]) == false)) { + myMexErrMsgTxt("ERROR (qpOASES): Expecting a handle to QP object as second argument!\nType 'help " + "qpOASES_sequence' for further information."); + return; + } + + /* Cleanup SQProblem instance. */ + handle = (uint_t)mxGetScalar(prhs[1]); + deleteQPInstance(handle); + + return; + } +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_sequence.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_sequence.m new file mode 100755 index 0000000..e064e8b --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/qpOASES_sequence.m @@ -0,0 +1,111 @@ +%qpOASES -- An Implementation of the Online Active Set Strategy. +%Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +%Christian Kirches et al. All rights reserved. +% +%qpOASES is distributed under the terms of the +%GNU Lesser General Public License 2.1 in the hope that it will be +%useful, but WITHOUT ANY WARRANTY; without even the implied warranty +%of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +%See the GNU Lesser General Public License for more details. +% +%--------------------------------------------------------------------------------- +% +%qpOASES_sequence is intended to solve a sequence of quadratic +%programming (QP) problems of the following form: +% +% min 1/2*x'Hx + x'g +% s.t. lb <= x <= ub +% lbA <= Ax <= ubA {optional} +% +%I) Call +% +% [QP,x,fval,exitflag,iter,lambda,auxOutput] = ... +% qpOASES_sequence( 'i',H,g,A,lb,ub,lbA,ubA{,options{,auxInput}} ) +%or +% [QP,x,fval,exitflag,iter,lambda,auxOutput] = ... +% qpOASES_sequence( 'i',H,g,lb,ub{,options{,auxInput}} ) +% +%for initialising and solving the first above-mentioned QP of the sequence +%starting from an initial guess x0. H must be a symmetric (possibly indefinite) +%matrix and all vectors g, lb, ub, lbA, ubA have to be given as column vectors. +%Options can be generated using the qpOASES_options command, otherwise default +%values are used. Optionally, further auxiliary inputs may be generated +%using qpOASES_auxInput command and passed to the solver. +%Both matrices H or A may be passed in sparse matrix format. +% +%II) Call +% +% [x,fval,exitflag,iter,lambda,auxOutput] = ... +% qpOASES_sequence( 'h',QP,g,lb,ub,lbA,ubA{,options} ) +%or +% [x,fval,exitflag,iter,lambda,auxOutput] = ... +% qpOASES_sequence( 'h',QP,g,lb,ub{,options} ) +% +%for hotstarting from the previous QP solution to the one of the next QP +%given by the vectors g, lb, ub, lbA, ubA. Options can be generated using the +%qpOASES_options command, otherwise default values are used. +% +%III) Call +% +% [x,fval,exitflag,iter,lambda,auxOutput] = ... +% qpOASES_sequence( 'm',QP,H,g,A,lb,ub,lbA,ubA{,options} ) +% +%for hotstarting from the previous QP solution to the one of the next QP +%given by the matrices H, A and the vectors g, lb, ub, lbA, ubA. The previous +%active set serves as a starting guess. If the new projected Hessian matrix +%turns out to be not positive definite, qpOASES recedes to a safe initial active +%set guess automatically. This can result in a high number of iterations iter. +%Options can be generated using the qpOASES_options command, otherwise default +%values are used. +% +%IV) Call +% +% [x,lambda,workingSetB,workingSetC] = ... +% qpOASES_sequence( 'e',QP,g,lb,ub,lbA,ubA{,options} ) +% +%for solving the equality constrained QP with constraints determined by the +%current active set. All inequalities and bounds which were not active in the +%previous solution might be violated. This command does not alter the internal +%state of qpOASES. Instead of calling this command multiple times, it is +%possible to supply several columns simultaneously in g, lb, ub, lbA, and ubA. +%Options can be generated using the qpOASES_options command, otherwise default +%values are used. +% +%V) Having solved the last QP of your sequence, call +% +% qpOASES_sequence( 'c',QP ) +% +%in order to cleanup the internal memory. +% +% +%Optional outputs (only x is mandatory): +% x - Optimal primal solution vector (if exitflag==0). +% fval - Optimal objective function value (if exitflag==0). +% exitflag - 0: QP solved, +% 1: QP could not be solved within given number of iterations, +% -1: QP could not be solved due to an internal error, +% -2: QP is infeasible (and thus could not be solved), +% -3: QP is unbounded (and thus could not be solved). +% iter - Number of active set iterations actually performed. +% lambda - Optimal dual solution vector (if exitflag==0). +% auxOutput - Struct containing auxiliary outputs as described below. +% +%The auxOutput struct contains the following entries: +% workingSetB - Working set of bounds at point x. +% workingSetC - Working set of constraints at point x. +% The working set is a subset of the active set (indices +% of bounds/constraints that hold with equality) yielding +% a set linearly independent of bounds/constraints. +% The working sets are encoded as follows: +% 1: bound/constraint at its upper bound +% 0: bound/constraint not at any bound +% -1: bound/constraint at its lower bound +% cpuTime - Internally measured CPU time for solving QP problem. +% +%See also QPOASES_OPTIONS, QPOASES_AUXINPUT, QPOASES +% +% +%For additional information see the qpOASES User's Manual or +%visit http://www.qpOASES.org/. +% +%Please send remarks and questions to support@qpOASES.org! diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/testQPset.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/testQPset.m new file mode 100755 index 0000000..ebb08ca --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/testQPset.m @@ -0,0 +1,40 @@ +% Requires Lukas Schork's Matlab repository of the Maros Meszaros test set +QPsetDIR = '~/git/QPset/maros'; + +files = dir(QPsetDIR); + +options = qpOASES_options('default', ... + 'printLevel', 0, 'maxIter', 1e8, 'maxCpuTime', 60, ... + 'initialStatusBounds', 0); +nQP = 0; +for i = 1:length(files) + clear mex + try + load([QPsetDIR, '/', files(i).name]); + H = sparse(H); + A = sparse(A); + catch + continue + end + + startTime = tic; + try + [x,fval,exitflag,iter,lambda] = qpOASES(H,g,A,xl,xu,al,au,options); + catch + exitflag = 666; + iter = 666; + fval = 666; + end + elapsedTime = toc(startTime); + + if mod(nQP, 20) == 0 + fprintf('\n%-10s %6s %6s %5s %7s %15s %9s\n', ... + 'name', 'nvar', 'ncon', 'eflag', 'iter', 'fval', 'time [s]'); + end + fprintf('%-10s %6d %6d %5d %7d %15g %9g\n', ... + files(i).name(1:findstr(files(i).name, '.')-1), ... + size(A,2), size(A,1), exitflag, iter, fval, elapsedTime); + + nQP = nQP + 1; +end + diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/testSchur.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/testSchur.m new file mode 100755 index 0000000..8ac27c1 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/matlab/testSchur.m @@ -0,0 +1,16 @@ +m = 2000; +n = 2*m+1; +H = 2*speye(n); +A = 0.5*H(1:m,:); +g = zeros(n,1); +lb = -ones(n,1); +ub = -lb; +lbA = 0.5*ones(m,1); +ubA = 0.5*ones(m,1); + +options = qpOASES_options('default', 'printLevel', -1, 'maxIter', n+m+1, ... + 'enableEqualities', 0, 'initialStatusBounds', 1); + +%[x,fval,exitflag,iter,lambda] = qpOASES(full(H),g,full(A),lb,ub,lbA,ubA,options); +[x,fval,exitflag,iter,lambda] = qpOASES(H,g,A,lb,ub,lbA,ubA,options); + diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/clean b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/clean new file mode 100755 index 0000000..2957397 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/clean @@ -0,0 +1,3 @@ +rm *.*~ +rm *.o +rm qpOASES qpOASES_sequence diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/clean.sh b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/clean.sh new file mode 100755 index 0000000..2957397 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/clean.sh @@ -0,0 +1,3 @@ +rm *.*~ +rm *.o +rm qpOASES qpOASES_sequence diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/example1.mat b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/example1.mat new file mode 100755 index 0000000..c0bd0d2 Binary files /dev/null and b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/example1.mat differ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/example1a.mat b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/example1a.mat new file mode 100755 index 0000000..48c784f Binary files /dev/null and b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/example1a.mat differ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/example1b.mat b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/example1b.mat new file mode 100755 index 0000000..b45b4f7 Binary files /dev/null and b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/example1b.mat differ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/make.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/make.m new file mode 100755 index 0000000..a611ee0 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/make.m @@ -0,0 +1,238 @@ +function [] = make( varargin ) +%MAKE Compiles the octave interface of qpOASES. +% +%Type make to compile all interfaces that +% have been modified, +%type make clean to delete all compiled interfaces, +%type make clean all to first delete and then compile +% all interfaces, +%type make 'name' to compile only the interface with +% the given name (if it has been modified), +%type make 'opt' to compile all interfaces using the +% given compiler options. +% +%Copyright (C) 2013-2017 by Hans Joachim Ferreau, Andreas Potschka, +%Christian Kirches et al. All rights reserved. + +%% +%% This file is part of qpOASES. +%% +%% qpOASES -- An Implementation of the Online Active Set Strategy. +%% Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +%% Christian Kirches et al. All rights reserved. +%% +%% qpOASES is free software; you can redistribute it and/or +%% modify it under the terms of the GNU Lesser General Public +%% License as published by the Free Software Foundation; either +%% version 2.1 of the License, or (at your option) any later version. +%% +%% qpOASES is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +%% See the GNU Lesser General Public License for more details. +%% +%% You should have received a copy of the GNU Lesser General Public +%% License along with qpOASES; if not, write to the Free Software +%% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +%% + +%% +%% Filename: interfaces/octave/make.m +%% Author: Hans Joachim Ferreau, Andreas Potschka, Christian Kirches +%% Version: 3.2 +%% Date: 2007-2017 +%% + + + %% consistency check + if ( exist( [pwd, '/make.m'],'file' ) == 0 ) + error( ['ERROR (',mfilename '.m): Run this make script directly within the directory', ... + '/interfaces/octave, please.'] ); + end + + + if ( nargin > 2 ) + error( ['ERROR (',mfilename '.m): At most two make arguments supported!'] ); + else + [ doClean,fcnNames,userFlags ] = analyseMakeArguments( nargin,varargin ); + end + + + %% define compiler settings + QPOASESPATH = '../../'; + + DEBUGFLAGS = ' '; + %DEBUGFLAGS = ' -g CXXDEBUGFLAGS=''$CXXDEBUGFLAGS -Wall -pedantic -Wshadow'' '; + + IFLAGS = [ '-I. -I',QPOASESPATH,'include',' -I',QPOASESPATH,'src',' ' ]; + CPPFLAGS = [ IFLAGS, DEBUGFLAGS, '-D__cpluplus -D__SINGLE_OBJECT__',' ' ]; %%removed: -largeArrayDims + defaultFlags = '-D__NO_COPYRIGHT__ '; %% -D__SUPPRESSANYOUTPUT__ %%removed: -O + + if ( ispc == 0 ) + CPPFLAGS = [ CPPFLAGS, '-DLINUX ',' ' ]; + else + CPPFLAGS = [ CPPFLAGS, '-DWIN32 ',' ' ]; + end + + if ( isempty(userFlags) > 0 ) + CPPFLAGS = [ CPPFLAGS, defaultFlags,' ' ]; + else + CPPFLAGS = [ CPPFLAGS, userFlags,' ' ]; + end + + mexExt = mexext(); + + + %% ensure copyright notice is displayed + if ~isempty( strfind( CPPFLAGS,'-D__NO_COPYRIGHT__' ) ) + printCopyrightNotice( ); + end + + + %% clean if desired + if ( doClean > 0 ) + + eval( 'delete *.o;' ); + eval( ['delete *.',mexExt,'*;'] ); + disp( [ 'INFO (',mfilename '.m): Cleaned all compiled files.'] ); + pause( 0.2 ); + + end + + + if ( ~isempty(userFlags) ) + disp( [ 'INFO (',mfilename '.m): Compiling all files with user-defined compiler flags (''',userFlags,''')...'] ); + end + + + %% call mex compiler + for ii=1:length(fcnNames) + + cmd = [ 'mkoctfile --mex --output ', fcnNames{ii}, '.', mexext(), ' ', CPPFLAGS, [fcnNames{ii},'.cpp'] ]; + + if ( exist( [fcnNames{ii},'.',mexExt],'file' ) == 0 ) + + eval( cmd ); + disp( [ 'INFO (',mfilename '.m): ', fcnNames{ii},'.',mexExt, ' successfully created.'] ); + + else + + % check modification time of source/Make files and compiled mex file + cppFile = dir( [pwd,'/',fcnNames{ii},'.cpp'] ); + cppFileTimestamp = getTimestamp( cppFile.date ); + + utilsFile = dir( [pwd,'/qpOASES_octave_utils.cpp'] ); + utilsFileTimestamp = getTimestamp( utilsFile.date ); + + makeFile = dir( [pwd,'/make.m'] ); + makeFileTimestamp = getTimestamp( makeFile.date ); + + mexFile = dir( [pwd,'/',fcnNames{ii},'.',mexExt] ); + if ( isempty(mexFile) == 0 ) + mexFileTimestamp = getTimestamp( mexFile.date ); + else + mexFileTimestamp = 0; + end + + if ( ( cppFileTimestamp >= mexFileTimestamp ) || ... + ( utilsFileTimestamp >= mexFileTimestamp ) || ... + ( makeFileTimestamp >= mexFileTimestamp ) ) + eval( cmd ); + disp( [ 'INFO (',mfilename '.m): ', fcnNames{ii},'.',mexExt, ' successfully created.'] ); + else + disp( [ 'INFO (',mfilename '.m): ', fcnNames{ii},'.',mexExt, ' already exists.'] ); + end + + end + + end + + %% add qpOASES directory to path + path( path,pwd ); + +end + + +function [ doClean,fcnNames,userIFlags ] = analyseMakeArguments( nArgs,args ) + + doClean = 0; + fcnNames = []; + userIFlags = []; + + switch ( nArgs ) + + case 1 + if ( strcmp( args{1},'all' ) > 0 ) + fcnNames = { 'qpOASES','qpOASES_sequence' }; + elseif ( strcmp( args{1},'qpOASES' ) > 0 ) + fcnNames = { 'qpOASES' }; + elseif ( strcmp( args{1},'qpOASES_sequence' ) > 0 ) + fcnNames = { 'qpOASES_sequence' }; + elseif ( strcmp( args{1},'clean' ) > 0 ) + doClean = 1; + elseif ( strcmp( args{1}(1),'-' ) > 0 ) + % make clean all with user-specified compiler flags + userIFlags = args{1}; + doClean = 1; + fcnNames = { 'qpOASES','qpOASES_sequence' }; + else + error( ['ERROR (',mfilename '.m): Invalid first argument (''',args{1},''')!'] ); + end + + case 2 + if ( strcmp( args{1},'clean' ) > 0 ) + doClean = 1; + else + error( ['ERROR (',mfilename '.m): First argument must be ''clean'' if two arguments are provided!'] ); + end + + if ( strcmp( args{2},'all' ) > 0 ) + fcnNames = { 'qpOASES','qpOASES_sequence' }; + elseif ( strcmp( args{2},'qpOASES' ) > 0 ) + fcnNames = { 'qpOASES' }; + elseif ( strcmp( args{2},'qpOASES_sequence' ) > 0 ) + fcnNames = { 'qpOASES_sequence' }; + else + error( ['ERROR (',mfilename '.m): Invalid second argument (''',args{2},''')!'] ); + end + + otherwise + fcnNames = { 'qpOASES','qpOASES_sequence' }; + + end + +end + + +function [ timestamp ] = getTimestamp( dateString ) + + try + timestamp = datenum( dateString ); + catch + timestamp = Inf; + end + +end + + +function [ ] = printCopyrightNotice( ) + + disp( ' ' ); + disp( 'qpOASES -- An Implementation of the Online Active Set Strategy.' ); + disp( 'Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka,' ); + disp( 'Christian Kirches et al. All rights reserved.' ); + disp( ' ' ); + disp( 'qpOASES is distributed under the terms of the' ); + disp( 'GNU Lesser General Public License 2.1 in the hope that it will be' ); + disp( 'useful, but WITHOUT ANY WARRANTY; without even the implied warranty' ); + disp( 'of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.' ); + disp( 'See the GNU Lesser General Public License for more details.' ); + disp( ' ' ); + disp( ' ' ); + +end + + +%% +%% end of file +%% diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES.cpp new file mode 100644 index 0000000..ffeb60b --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES.cpp @@ -0,0 +1,576 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file interfaces/octave/qpOASES.cpp + * \author Hans Joachim Ferreau, Alexander Buchner, Andreas Potschka + * \version 3.2 + * \date 2007-2017 + * + * Interface for Matlab(R) that enables to call qpOASES as a MEX function. + * + */ + +#include + +USING_NAMESPACE_QPOASES + +#include "qpOASES_octave_utils.hpp" + +/** initialise handle counter of QPInstance class */ +int_t QPInstance::s_nexthandle = 1; + +/** global pointer to QP objects */ +static std::vector g_instances; + +#include "qpOASES_octave_utils.cpp" + +/* + * Q P r o b l e m _ q p O A S E S + */ +int_t QProblem_qpOASES(int_t nV, + int_t nC, + HessianType hessianType, + int_t nP, + SymmetricMatrix * H, + double * g, + Matrix * A, + double * lb, + double * ub, + double * lbA, + double * ubA, + int_t nWSRin, + real_t maxCpuTimeIn, + const double * const x0, + Options * options, + int_t nOutputs, + mxArray * plhs[], + const double * const guessedBounds, + const double * const guessedConstraints, + const double * const _R) +{ + int_t nWSRout; + real_t maxCpuTimeOut; + + /* 1) Setup initial QP. */ + QProblem QP(nV, nC, hessianType); + QP.setOptions(*options); + + /* 2) Solve initial QP. */ + returnValue returnvalue; + + Bounds bounds(nV); + Constraints constraints(nC); + if (guessedBounds != 0) { + for (int_t i = 0; i < nV; i++) { + if (isEqual(guessedBounds[i], -1.0) == BT_TRUE) { + bounds.setupBound(i, ST_LOWER); + } else if (isEqual(guessedBounds[i], 1.0) == BT_TRUE) { + bounds.setupBound(i, ST_UPPER); + } else if (isEqual(guessedBounds[i], 0.0) == BT_TRUE) { + bounds.setupBound(i, ST_INACTIVE); + } else { + char msg[MAX_STRING_LENGTH]; + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Only {-1, 0, 1} allowed for status of bounds!"); + myMexErrMsgTxt(msg); + return -1; + } + } + } + + if (guessedConstraints != 0) { + for (int_t i = 0; i < nC; i++) { + if (isEqual(guessedConstraints[i], -1.0) == BT_TRUE) { + constraints.setupConstraint(i, ST_LOWER); + } else if (isEqual(guessedConstraints[i], 1.0) == BT_TRUE) { + constraints.setupConstraint(i, ST_UPPER); + } else if (isEqual(guessedConstraints[i], 0.0) == BT_TRUE) { + constraints.setupConstraint(i, ST_INACTIVE); + } else { + char msg[MAX_STRING_LENGTH]; + snprintf( + msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Only {-1, 0, 1} allowed for status of constraints!"); + myMexErrMsgTxt(msg); + return -1; + } + } + } + + nWSRout = nWSRin; + maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + + returnvalue = QP.init(H, + g, + A, + lb, + ub, + lbA, + ubA, + nWSRout, + &maxCpuTimeOut, + x0, + 0, + (guessedBounds != 0) ? &bounds : 0, + (guessedConstraints != 0) ? &constraints : 0, + _R); + + /* 3) Solve remaining QPs and assign lhs arguments. */ + /* Set up pointers to the current QP vectors */ + real_t * g_current = g; + real_t * lb_current = lb; + real_t * ub_current = ub; + real_t * lbA_current = lbA; + real_t * ubA_current = ubA; + + /* Loop through QP sequence. */ + for (int_t k = 0; k < nP; ++k) { + if (k > 0) { + /* update pointers to the current QP vectors */ + g_current = &(g[k * nV]); + if (lb != 0) + lb_current = &(lb[k * nV]); + if (ub != 0) + ub_current = &(ub[k * nV]); + if (lbA != 0) + lbA_current = &(lbA[k * nC]); + if (ubA != 0) + ubA_current = &(ubA[k * nC]); + + nWSRout = nWSRin; + maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + returnvalue = + QP.hotstart(g_current, lb_current, ub_current, lbA_current, ubA_current, nWSRout, &maxCpuTimeOut); + } + + /* write results into output vectors */ + obtainOutputs(k, &QP, returnvalue, nWSRout, maxCpuTimeOut, nOutputs, plhs, nV, nC); + } + + // QP.writeQpDataIntoMatFile( "qpDataMat0.mat" ); + + return 0; +} + +/* + * Q P r o b l e m B _ q p O A S E S + */ +int_t QProblemB_qpOASES(int_t nV, + HessianType hessianType, + int_t nP, + SymmetricMatrix * H, + double * g, + double * lb, + double * ub, + int_t nWSRin, + real_t maxCpuTimeIn, + const double * const x0, + Options * options, + int_t nOutputs, + mxArray * plhs[], + const double * const guessedBounds, + const double * const _R) +{ + int_t nWSRout; + real_t maxCpuTimeOut; + + /* 1) Setup initial QP. */ + QProblemB QP(nV, hessianType); + QP.setOptions(*options); + + /* 2) Solve initial QP. */ + returnValue returnvalue; + + Bounds bounds(nV); + if (guessedBounds != 0) { + for (int_t i = 0; i < nV; i++) { + if (isEqual(guessedBounds[i], -1.0) == BT_TRUE) { + bounds.setupBound(i, ST_LOWER); + } else if (isEqual(guessedBounds[i], 1.0) == BT_TRUE) { + bounds.setupBound(i, ST_UPPER); + } else if (isEqual(guessedBounds[i], 0.0) == BT_TRUE) { + bounds.setupBound(i, ST_INACTIVE); + } else { + char msg[MAX_STRING_LENGTH]; + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Only {-1, 0, 1} allowed for status of bounds!"); + myMexErrMsgTxt(msg); + return -1; + } + } + } + + nWSRout = nWSRin; + maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + + returnvalue = + QP.init(H, g, lb, ub, nWSRout, &maxCpuTimeOut, x0, 0, (guessedBounds != 0) ? &bounds : 0, _R); + + /* 3) Solve remaining QPs and assign lhs arguments. */ + /* Set up pointers to the current QP vectors */ + real_t * g_current = g; + real_t * lb_current = lb; + real_t * ub_current = ub; + + /* Loop through QP sequence. */ + for (int_t k = 0; k < nP; ++k) { + if (k > 0) { + /* update pointers to the current QP vectors */ + g_current = &(g[k * nV]); + if (lb != 0) + lb_current = &(lb[k * nV]); + if (ub != 0) + ub_current = &(ub[k * nV]); + + nWSRout = nWSRin; + maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + returnvalue = QP.hotstart(g_current, lb_current, ub_current, nWSRout, &maxCpuTimeOut); + } + + /* write results into output vectors */ + obtainOutputs(k, &QP, returnvalue, nWSRout, maxCpuTimeOut, nOutputs, plhs, nV); + } + + return 0; +} + +/* + * m e x F u n c t i o n + */ +void mexFunction(int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[]) +{ + /* inputs */ + SymmetricMatrix * H = 0; + Matrix * A = 0; + + real_t *g = 0, *lb = 0, *ub = 0, *lbA = 0, *ubA = 0; + HessianType hessianType = HST_UNKNOWN; + double *x0 = 0, *R = 0, *R_for = 0; + double *guessedBounds = 0, *guessedConstraints = 0; + + int H_idx = -1, g_idx = -1, A_idx = -1, lb_idx = -1, ub_idx = -1, lbA_idx = -1, ubA_idx = -1; + int options_idx = -1, x0_idx = -1, auxInput_idx = -1; + + /* Setup default options */ + Options options; + options.printLevel = PL_LOW; +#ifdef __DEBUG__ + options.printLevel = PL_HIGH; +#endif +#ifdef __SUPPRESSANYOUTPUT__ + options.printLevel = PL_NONE; +#endif + + /* dimensions */ + uint_t nV = 0, nC = 0, nP = 0; + BooleanType isSimplyBoundedQp = BT_FALSE; + + /* sparse matrix indices and values */ + sparse_int_t *Hir = 0, *Hjc = 0, *Air = 0, *Ajc = 0; + real_t *Hv = 0, *Av = 0; + + /* I) CONSISTENCY CHECKS: */ + /* 1a) Ensure that qpOASES is called with a feasible number of input arguments. */ + if ((nrhs < 4) || (nrhs > 9)) { + myMexErrMsgTxt( + "ERROR (qpOASES): Invalid number of input arguments!\nType 'help qpOASES' for further information."); + return; + } + + /* 2) Check for proper number of output arguments. */ + if (nlhs > 6) { + myMexErrMsgTxt("ERROR (qpOASES): At most six output arguments are allowed: \n " + "[x,fval,exitflag,iter,lambda,auxOutput]!"); + return; + } + if (nlhs < 1) { + myMexErrMsgTxt("ERROR (qpOASES): At least one output argument is required: [x,...]!"); + return; + } + + /* II) PREPARE RESPECTIVE QPOASES FUNCTION CALL: */ + /* Choose between QProblem and QProblemB object and assign the corresponding + * indices of the input pointer array in to order to access QP data correctly. */ + g_idx = 1; + + if (mxIsEmpty(prhs[0]) == 1) { + H_idx = -1; + nV = (int_t)mxGetM(prhs[g_idx]); /* if Hessian is empty, row number of gradient vector */ + } else { + H_idx = 0; + nV = (int_t)mxGetM(prhs[H_idx]); /* row number of Hessian matrix */ + } + + nP = (int_t)mxGetN(prhs[g_idx]); /* number of columns of the gradient matrix (vectors series have to be + stored columnwise!) */ + + if (nrhs <= 6) + isSimplyBoundedQp = BT_TRUE; + else + isSimplyBoundedQp = BT_FALSE; + + /* 0) Check whether options are specified .*/ + if (isSimplyBoundedQp == BT_TRUE) { + if ((nrhs >= 5) && (!mxIsEmpty(prhs[4])) && (mxIsStruct(prhs[4]))) + options_idx = 4; + } else { + /* Consistency check */ + if ((!mxIsEmpty(prhs[4])) && (mxIsStruct(prhs[4]))) { + myMexErrMsgTxt("ERROR (qpOASES): Fifth input argument must not be a struct when solving QP with " + "general constraints!\nType 'help qpOASES' for further information."); + return; + } + + if ((nrhs >= 8) && (!mxIsEmpty(prhs[7])) && (mxIsStruct(prhs[7]))) + options_idx = 7; + } + + // Is the third argument constraint Matrix A? + int_t numberOfColumns = (int_t)mxGetN(prhs[2]); + + /* 1) Simply bounded QP. */ + if ((isSimplyBoundedQp == BT_TRUE) || ((numberOfColumns == 1) && (nV != 1))) { + lb_idx = 2; + ub_idx = 3; + + if ((nrhs >= 6) && (!mxIsEmpty(prhs[5]))) { + /* auxInput specified */ + if (mxIsStruct(prhs[5])) { + auxInput_idx = 5; + x0_idx = -1; + } else { + auxInput_idx = -1; + x0_idx = 5; + } + } else { + auxInput_idx = -1; + x0_idx = -1; + } + } else { + A_idx = 2; + + /* If constraint matrix is empty, use a QProblemB object! */ + if (mxIsEmpty(prhs[A_idx])) { + lb_idx = 3; + ub_idx = 4; + + nC = 0; + } else { + lb_idx = 3; + ub_idx = 4; + lbA_idx = 5; + ubA_idx = 6; + + nC = (int_t)mxGetM(prhs[A_idx]); /* row number of constraint matrix */ + } + + if ((nrhs >= 9) && (!mxIsEmpty(prhs[8]))) { + /* auxInput specified */ + if (mxIsStruct(prhs[8])) { + auxInput_idx = 8; + x0_idx = -1; + } else { + auxInput_idx = -1; + x0_idx = 8; + } + } else { + auxInput_idx = -1; + x0_idx = -1; + } + } + + /* ensure that data is given in real_t precision */ + if (((H_idx >= 0) && (mxIsDouble(prhs[H_idx]) == 0)) || (mxIsDouble(prhs[g_idx]) == 0)) { + myMexErrMsgTxt("ERROR (qpOASES): All data has to be provided in double precision!"); + return; + } + + /* check if supplied data contains 'NaN' or 'Inf' */ + if (containsNaNorInf(prhs, H_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, g_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lb_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ub_idx, 1) == BT_TRUE) + return; + + /* Check inputs dimensions and assign pointers to inputs. */ + if ((H_idx >= 0) && ((mxGetN(prhs[H_idx]) != nV) || (mxGetM(prhs[H_idx]) != nV))) { + char msg[MAX_STRING_LENGTH]; + snprintf(msg, + MAX_STRING_LENGTH, + "ERROR (qpOASES): Hessian matrix dimension mismatch (%ld != %d)!", + (long int)mxGetN(prhs[H_idx]), + (int)nV); + myMexErrMsgTxt(msg); + return; + } + + if (nC > 0) { + /* ensure that data is given in real_t precision */ + if (mxIsDouble(prhs[A_idx]) == 0) { + myMexErrMsgTxt("ERROR (qpOASES): All data has to be provided in real_t precision!"); + return; + } + + /* Check inputs dimensions and assign pointers to inputs. */ + if (mxGetN(prhs[A_idx]) != nV) { + char msg[MAX_STRING_LENGTH]; + snprintf(msg, + MAX_STRING_LENGTH, + "ERROR (qpOASES): Constraint matrix input dimension mismatch (%ld != %d)!", + (long int)mxGetN(prhs[A_idx]), + (int)nV); + myMexErrMsgTxt(msg); + return; + } + + if (containsNaNorInf(prhs, A_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lbA_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ubA_idx, 1) == BT_TRUE) + return; + } + + /* check dimensions and copy auxInputs */ + if (smartDimensionCheck(&g, nV, nP, BT_FALSE, prhs, g_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lb, nV, nP, BT_TRUE, prhs, lb_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ub, nV, nP, BT_TRUE, prhs, ub_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&x0, nV, 1, BT_TRUE, prhs, x0_idx) != SUCCESSFUL_RETURN) + return; + + if (nC > 0) { + if (smartDimensionCheck(&lbA, nC, nP, BT_TRUE, prhs, lbA_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ubA, nC, nP, BT_TRUE, prhs, ubA_idx) != SUCCESSFUL_RETURN) + return; + } + + if (auxInput_idx >= 0) + setupAuxiliaryInputs( + prhs[auxInput_idx], nV, nC, &hessianType, &x0, &guessedBounds, &guessedConstraints, &R_for); + + /* convert Cholesky factor to C storage format */ + if (R_for != 0) { + R = new real_t[nV * nV]; + convertFortranToC(R_for, nV, nV, R); + } + + /* III) ACTUALLY PERFORM QPOASES FUNCTION CALL: */ + int_t nWSRin = 5 * (nV + nC); + real_t maxCpuTimeIn = -1.0; + + if (options_idx > 0) + setupOptions(&options, prhs[options_idx], nWSRin, maxCpuTimeIn); + + /* make a deep-copy of the user-specified Hessian matrix (possibly sparse) */ + if (H_idx >= 0) + setupHessianMatrix(prhs[H_idx], nV, &H, &Hir, &Hjc, &Hv); + + /* make a deep-copy of the user-specified constraint matrix (possibly sparse) */ + if ((nC > 0) && (A_idx >= 0)) + setupConstraintMatrix(prhs[A_idx], nV, nC, &A, &Air, &Ajc, &Av); + + allocateOutputs(nlhs, plhs, nV, nC, nP); + + if (nC == 0) { + /* Call qpOASES (using QProblemB class). */ + QProblemB_qpOASES( + nV, hessianType, nP, H, g, lb, ub, nWSRin, maxCpuTimeIn, x0, &options, nlhs, plhs, guessedBounds, R); + + if (R != 0) + delete R; + if (H != 0) + delete H; + if (Hv != 0) + delete[] Hv; + if (Hjc != 0) + delete[] Hjc; + if (Hir != 0) + delete[] Hir; + return; + } else { + if (A == 0) { + myMexErrMsgTxt("ERROR (qpOASES): Internal interface error related to constraint matrix!"); + return; + } + + /* Call qpOASES (using QProblem class). */ + QProblem_qpOASES(nV, + nC, + hessianType, + nP, + H, + g, + A, + lb, + ub, + lbA, + ubA, + nWSRin, + maxCpuTimeIn, + x0, + &options, + nlhs, + plhs, + guessedBounds, + guessedConstraints, + R); + + if (R != 0) + delete R; + if (A != 0) + delete A; + if (H != 0) + delete H; + if (Av != 0) + delete[] Av; + if (Ajc != 0) + delete[] Ajc; + if (Air != 0) + delete[] Air; + if (Hv != 0) + delete[] Hv; + if (Hjc != 0) + delete[] Hjc; + if (Hir != 0) + delete[] Hir; + return; + } +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES.m new file mode 100755 index 0000000..88f4df9 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES.m @@ -0,0 +1,75 @@ +%qpOASES -- An Implementation of the Online Active Set Strategy. +%Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +%Christian Kirches et al. All rights reserved. +% +%qpOASES is distributed under the terms of the +%GNU Lesser General Public License 2.1 in the hope that it will be +%useful, but WITHOUT ANY WARRANTY; without even the implied warranty +%of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +%See the GNU Lesser General Public License for more details. +% +%--------------------------------------------------------------------------------- +% +%qpOASES solves (a series) of quadratic programming (QP) problems of the +%following form: +% +% min 1/2*x'Hx + x'g +% s.t. lb <= x <= ub +% lbA <= Ax <= ubA {optional} +% +%Call +% +% [x,fval,exitflag,iter,lambda,auxOutput] = +% qpOASES( H,g,A,lb,ub,lbA,ubA{,options{,auxInput}} ) +% +%for solving the above-mentioned QP. H must be a symmetric (but possibly +%indefinite) matrix and all vectors g, lb, ub, lbA, ubA have to be given +%as column vectors. Options can be generated using the qpOASES_options command, +%otherwise default values are used. Optionally, further auxiliary inputs +%may be generated using qpOASES_auxInput command and passed to the solver. +%Both matrices H or A may be passed in sparse matrix format. +% +%Call +% +% [x,fval,exitflag,iter,lambda,auxOutput] = +% qpOASES( H,g,lb,ub{,options{,auxInput}} ) +% +%for solving the above-mentioned QP without general constraints. +% +% +%Optional outputs (only x is mandatory): +% x - Optimal primal solution vector (if exitflag==0). +% fval - Optimal objective function value (if exitflag==0). +% exitflag - 0: QP problem solved, +% 1: QP could not be solved within given number of iterations, +% -1: QP could not be solved due to an internal error, +% -2: QP is infeasible (and thus could not be solved), +% -3: QP is unbounded (and thus could not be solved). +% iter - Number of active set iterations actually performed. +% lambda - Optimal dual solution vector (if exitflag==0). +% auxOutput - Struct containing auxiliary outputs as described below. +% +%The auxOutput struct contains the following entries: +% workingSetB - Working set of bounds at point x. +% workingSetC - Working set of constraints at point x. +% The working set is a subset of the active set (indices +% of bounds/constraints that hold with equality) yielding +% a set linearly independent of bounds/constraints. +% The working sets are encoded as follows: +% 1: bound/constraint at its upper bound +% 0: bound/constraint not at any bound +% -1: bound/constraint at its lower bound +% cpuTime - Internally measured CPU time for solving QP problem. +% +% +%If not a single QP but a sequence of QPs with varying vectors is to be solved, +%the i-th QP is given by the i-th columns of the QP vectors g, lb, ub, lbA, ubA +%(i.e. they are matrices in this case). Both matrices H and A remain constant. +% +%See also QPOASES_OPTIONS, QPOASES_AUXINPUT, QPOASES_SEQUENCE +% +% +%For additional information see the qpOASES User's Manual or +%visit http://www.qpOASES.org/. +% +%Please send remarks and questions to support@qpOASES.org! diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_auxInput.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_auxInput.m new file mode 100755 index 0000000..1ebb8d9 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_auxInput.m @@ -0,0 +1,118 @@ +%qpOASES -- An Implementation of the Online Active Set Strategy. +%Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +%Christian Kirches et al. All rights reserved. +% +%qpOASES is distributed under the terms of the +%GNU Lesser General Public License 2.1 in the hope that it will be +%useful, but WITHOUT ANY WARRANTY; without even the implied warranty +%of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +%See the GNU Lesser General Public License for more details. +% +%--------------------------------------------------------------------------------- +% +%Returns a struct containing all possible auxiliary inputs to be passed +%to qpOASES. +% +%Call +% auxInput = qpOASES_auxInput(); +%to obtain a struct with all auxiliary inputs empty. +% +%Call +% auxInput = qpOASES_auxInput( 'input1',value1,'input2',value2,... ) +%to obtain a struct with 'input1' set to value1 etc. and all remaining +%auxiliary inputs empty. +% +%Call +% auxInput = qpOASES_auxInput( oldInputs,'input1',value1,... ) +%to obtain a copy of the options struct oldInputs but with 'input1' set to +%value1 etc. +% +% +%qpOASES features the following auxiliary inputs: +% hessianType - Provide information on Hessian matrix: +% 0: Hessian is zero matrix (i.e. LP formulation) +% 1: Hessian is identity matrix +% 2: Hessian is (strictly) positive definite +% 3: Hessian is positive definite on null space +% of active bounds/constraints +% 4: Hessian is positive semi-definite. +% 5: Hessian is indefinite +% Leave hessianType empty if Hessian type is unknown. +% x0 - Initial guess for optimal primal solution. +% guessedWorkingSetB - Initial guess for working set of bounds at +% optimal solution (nV elements or empty). +% guessedWorkingSetC - Initial guess for working set of constraints at +% optimal solution (nC elements or empty). +% The working sets needs to be encoded as follows: +% 1: bound/constraint at its upper bound +% 0: bound/constraint not at any bound +% -1: bound/constraint at its lower bound +% R - Cholesky factor of Hessian matrix (upper-triangular); +% only used if both guessedWorkingSets are empty +% and option initialStatusBounds is set to 0. +% +% +%See also QPOASES, QPOASES_SEQUENCE, QPOASES_OPTIONS +% +% +%For additional information see the qpOASES User's Manual or +%visit http://www.qpOASES.org/. +% +%Please send remarks and questions to support@qpOASES.org! +function [ auxInput ] = qpOASES_auxInput( varargin ) + + firstIsStruct = 0; + + if ( nargin == 0 ) + auxInput = qpOASES_emptyAuxInput(); + else + if ( isstruct( varargin{1} ) ) + if ( mod( nargin,2 ) ~= 1 ) + error('ERROR (qpOASES_auxInput): Auxiliary inputs must be specified in pairs!'); + end + auxInput = varargin{1}; + firstIsStruct = 1; + else + if ( mod( nargin,2 ) ~= 0 ) + error('ERROR (qpOASES_auxInput): Auxiliary inputs must be specified in pairs!'); + end + auxInput = qpOASES_emptyAuxInput(); + end + end + + % set options to user-defined values + for i=(1+firstIsStruct):2:nargin + + argName = varargin{i}; + argValue = varargin{i+1}; + + if ( ( isempty( argName ) ) || ( ~ischar( argName ) ) ) + error('ERROR (qpOASES_auxInput): Argmument no. %d has to be a non-empty string!',i ); + end + + if ( ( ischar(argValue) ) || ( ~isnumeric( argValue ) ) ) + error('ERROR (qpOASES_auxInput): Argmument no. %d has to be a numerical constant!',i+1 ); + end + + if ( ~isfield( auxInput,argName ) ) + error('ERROR (qpOASES_auxInput): Argmument no. %d is not a valid auxiliary input!',i ); + end + + eval( ['auxInput.',argName,' = argValue;'] ); + + end + +end + + +function [ auxInput ] = qpOASES_emptyAuxInput( ) + + % setup auxiliary input struct with all entries empty + auxInput = struct( 'hessianType', [], ... + 'x0', [], ... + 'guessedWorkingSetB', [], ... + 'guessedWorkingSetC', [], ... + 'R', [] ... + ); + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_octave_utils.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_octave_utils.cpp new file mode 100644 index 0000000..807bb0d --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_octave_utils.cpp @@ -0,0 +1,885 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file interfaces/octave/qpOASES_octave_utils.cpp + * \author Hans Joachim Ferreau, Andreas Potschka, Alexander Buchner + * \version 3.2 + * \date 2007-2017 + * + * Collects utility functions for Interface to octave that + * enables to call qpOASES as a MEX function. + * + */ + +QPInstance::QPInstance(uint_t _nV, uint_t _nC, HessianType _hessianType, BooleanType _isSimplyBounded) +{ + handle = s_nexthandle++; + + if (_nC > 0) + isSimplyBounded = BT_FALSE; + else + isSimplyBounded = _isSimplyBounded; + + if (isSimplyBounded == BT_TRUE) { + sqp = 0; + qpb = new QProblemB(_nV, _hessianType); + } else { + sqp = new SQProblem(_nV, _nC, _hessianType); + qpb = 0; + } + + H = 0; + A = 0; + Hir = 0; + Hjc = 0; + Air = 0; + Ajc = 0; + Hv = 0; + Av = 0; +} + +QPInstance::~QPInstance() +{ + deleteQPMatrices(); + + if (sqp != 0) { + delete sqp; + sqp = 0; + } + + if (qpb != 0) { + delete qpb; + qpb = 0; + } +} + +returnValue QPInstance::deleteQPMatrices() +{ + if (H != 0) { + delete H; + H = 0; + } + + if (Hv != 0) { + delete[] Hv; + Hv = 0; + } + + if (Hjc != 0) { + delete[] Hjc; + Hjc = 0; + } + + if (Hir != 0) { + delete[] Hir; + Hir = 0; + } + + if (A != 0) { + delete A; + A = 0; + } + + if (Av != 0) { + delete[] Av; + Av = 0; + } + + if (Ajc != 0) { + delete[] Ajc; + Ajc = 0; + } + + if (Air != 0) { + delete[] Air; + Air = 0; + } + + return SUCCESSFUL_RETURN; +} + +int_t QPInstance::getNV() const +{ + if (sqp != 0) + return sqp->getNV(); + + if (qpb != 0) + return qpb->getNV(); + + return 0; +} + +int_t QPInstance::getNC() const +{ + if (sqp != 0) + return sqp->getNC(); + + return 0; +} + +/* + * m x I s S c a l a r + */ +bool mxIsScalar(const mxArray * pm) +{ + if ((mxGetM(pm) == 1) && (mxGetN(pm) == 1)) + return true; + else + return false; +} + +/* + * a l l o c a t e Q P r o b l e m I n s t a n c e + */ +int_t allocateQPInstance( + int_t nV, int_t nC, HessianType hessianType, BooleanType isSimplyBounded, const Options * options) +{ + QPInstance * inst = new QPInstance(nV, nC, hessianType, isSimplyBounded); + + if ((inst->sqp != 0) && (options != 0)) + inst->sqp->setOptions(*options); + + if ((inst->qpb != 0) && (options != 0)) + inst->qpb->setOptions(*options); + + g_instances.push_back(inst); + return inst->handle; +} + +/* + * g e t Q P r o b l e m I n s t a n c e + */ +QPInstance * getQPInstance(int_t handle) +{ + uint_t ii; + // TODO: this may become slow ... + for (ii = 0; ii < g_instances.size(); ++ii) + if (g_instances[ii]->handle == handle) + return g_instances[ii]; + return 0; +} + +/* + * d e l e t e Q P r o b l e m I n s t a n c e + */ +void deleteQPInstance(int_t handle) +{ + QPInstance * instance = getQPInstance(handle); + if (instance != 0) { + for (std::vector::iterator itor = g_instances.begin(); itor != g_instances.end(); ++itor) + if ((*itor)->handle == handle) { + g_instances.erase(itor); + break; + } + delete instance; + } +} + +/* + * s m a r t D i m e n s i o n C h e c k + */ +returnValue smartDimensionCheck( + real_t ** input, uint_t m, uint_t n, BooleanType emptyAllowed, const mxArray * prhs[], int_t idx) +{ + /* If index is negative, the input does not exist. */ + if (idx < 0) { + *input = 0; + return SUCCESSFUL_RETURN; + } + + /* Otherwise the input has been passed by the user. */ + if (mxIsEmpty(prhs[idx])) { + /* input is empty */ + if ((emptyAllowed == BT_TRUE) || (idx == 0)) /* idx==0 used for auxInput */ + { + *input = 0; + return SUCCESSFUL_RETURN; + } else { + char msg[MAX_STRING_LENGTH]; + if (idx > 0) + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Empty argument %d not allowed!", idx + 1); + myMexErrMsgTxt(msg); + return RET_INVALID_ARGUMENTS; + } + } else { + /* input is non-empty */ + if (mxIsSparse(prhs[idx]) == 0) { + if ((mxGetM(prhs[idx]) == m) && (mxGetN(prhs[idx]) == n)) { + *input = (real_t *)mxGetPr(prhs[idx]); + return SUCCESSFUL_RETURN; + } else { + char msg[MAX_STRING_LENGTH]; + if (idx > 0) + snprintf(msg, + MAX_STRING_LENGTH, + "ERROR (qpOASES): Input dimension mismatch for argument %d ([%ld,%ld] ~= [%d,%d]).", + idx + 1, + (long int)mxGetM(prhs[idx]), + (long int)mxGetN(prhs[idx]), + (int)m, + (int)n); + else /* idx==0 used for auxInput */ + snprintf(msg, + MAX_STRING_LENGTH, + "ERROR (qpOASES): Input dimension mismatch for some auxInput entry ([%ld,%ld] ~= [%d,%d]).", + (long int)mxGetM(prhs[idx]), + (long int)mxGetN(prhs[idx]), + (int)m, + (int)n); + myMexErrMsgTxt(msg); + return RET_INVALID_ARGUMENTS; + } + } else { + char msg[MAX_STRING_LENGTH]; + if (idx > 0) + snprintf(msg, + MAX_STRING_LENGTH, + "ERROR (qpOASES): Vector argument %d must not be in sparse format!", + idx + 1); + else /* idx==0 used for auxInput */ + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): auxInput entries must not be in sparse format!"); + myMexErrMsgTxt(msg); + return RET_INVALID_ARGUMENTS; + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * c o n t a i n s N a N + */ +BooleanType containsNaN(const real_t * const data, uint_t dim) +{ + uint_t i; + + if (data == 0) + return BT_FALSE; + + for (i = 0; i < dim; ++i) + if (mxIsNaN(data[i]) == 1) + return BT_TRUE; + + return BT_FALSE; +} + +/* + * c o n t a i n s I n f + */ +BooleanType containsInf(const real_t * const data, uint_t dim) +{ + uint_t i; + + if (data == 0) + return BT_FALSE; + + for (i = 0; i < dim; ++i) + if (mxIsInf(data[i]) == 1) + return BT_TRUE; + + return BT_FALSE; +} + +/* + * c o n t a i n s N a N o r I n f + */ +BooleanType containsNaNorInf(const mxArray * prhs[], int_t rhs_index, bool mayContainInf) +{ + uint_t dim; + char msg[MAX_STRING_LENGTH]; + + if (rhs_index < 0) + return BT_FALSE; + + /* overwrite dim for sparse matrices */ + if (mxIsSparse(prhs[rhs_index]) == 1) + dim = (uint_t)mxGetNzmax(prhs[rhs_index]); + else + dim = (uint_t)(mxGetM(prhs[rhs_index]) * mxGetN(prhs[rhs_index])); + + if (containsNaN((real_t *)mxGetPr(prhs[rhs_index]), dim) == BT_TRUE) { + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Argument %d contains 'NaN' !", rhs_index + 1); + myMexErrMsgTxt(msg); + return BT_TRUE; + } + + if (mayContainInf == 0) { + if (containsInf((real_t *)mxGetPr(prhs[rhs_index]), dim) == BT_TRUE) { + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Argument %d contains 'Inf' !", rhs_index + 1); + myMexErrMsgTxt(msg); + return BT_TRUE; + } + } + + return BT_FALSE; +} + +/* + * c o n v e r t F o r t r a n T o C + */ +returnValue convertFortranToC(const real_t * const M_for, int_t nV, int_t nC, real_t * const M) +{ + int_t i, j; + + if ((M_for == 0) || (M == 0)) + return RET_INVALID_ARGUMENTS; + + if ((nV < 0) || (nC < 0)) + return RET_INVALID_ARGUMENTS; + + for (i = 0; i < nC; ++i) + for (j = 0; j < nV; ++j) + M[i * nV + j] = M_for[j * nC + i]; + + return SUCCESSFUL_RETURN; +} + +/* + * h a s O p t i o n s V a l u e + */ +BooleanType hasOptionsValue( + const mxArray * optionsPtr, const char * const optionString, double ** optionValue) +{ + mxArray * optionName = mxGetField(optionsPtr, 0, optionString); + + if (optionName == 0) { + char msg[MAX_STRING_LENGTH]; + snprintf(msg, + MAX_STRING_LENGTH, + "Option struct does not contain entry '%s', using default value instead!", + optionString); + mexWarnMsgTxt(msg); + return BT_FALSE; + } + + if ((mxIsEmpty(optionName) == false) && (mxIsScalar(optionName) == true)) { + *optionValue = mxGetPr(optionName); + return BT_TRUE; + } else { + char msg[MAX_STRING_LENGTH]; + snprintf( + msg, MAX_STRING_LENGTH, "Option '%s' is not a scalar, using default value instead!", optionString); + mexWarnMsgTxt(msg); + return BT_FALSE; + } +} + +/* + * s e t u p O p t i o n s + */ +returnValue setupOptions(Options * options, const mxArray * optionsPtr, int_t & nWSRin, real_t & maxCpuTime) +{ + double * optionValue; + int_t optionValueInt; + + /* Check for correct number of option entries; + * may occur, e.g., if user types options. = ; */ + if (mxGetNumberOfFields(optionsPtr) != 31) + mexWarnMsgTxt("Options might be set incorrectly as struct has wrong number of entries!\n Type " + "'help qpOASES_options' for further information."); + + if (hasOptionsValue(optionsPtr, "maxIter", &optionValue) == BT_TRUE) + if (*optionValue >= 0.0) + nWSRin = (int_t)*optionValue; + + if (hasOptionsValue(optionsPtr, "maxCpuTime", &optionValue) == BT_TRUE) + if (*optionValue >= 0.0) + maxCpuTime = *optionValue; + + if (hasOptionsValue(optionsPtr, "printLevel", &optionValue) == BT_TRUE) { +#ifdef __SUPPRESSANYOUTPUT__ + options->printLevel = PL_NONE; +#else + optionValueInt = (int_t)*optionValue; + options->printLevel = (REFER_NAMESPACE_QPOASES PrintLevel)optionValueInt; + if (options->printLevel < PL_DEBUG_ITER) + options->printLevel = PL_DEBUG_ITER; + if (options->printLevel > PL_HIGH) + options->printLevel = PL_HIGH; +#endif + } + + if (hasOptionsValue(optionsPtr, "enableRamping", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + options->enableRamping = (REFER_NAMESPACE_QPOASES BooleanType)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "enableFarBounds", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + options->enableFarBounds = (REFER_NAMESPACE_QPOASES BooleanType)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "enableFlippingBounds", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + options->enableFlippingBounds = (REFER_NAMESPACE_QPOASES BooleanType)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "enableRegularisation", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + options->enableRegularisation = (REFER_NAMESPACE_QPOASES BooleanType)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "enableFullLITests", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + options->enableFullLITests = (REFER_NAMESPACE_QPOASES BooleanType)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "enableNZCTests", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + options->enableNZCTests = (REFER_NAMESPACE_QPOASES BooleanType)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "enableDriftCorrection", &optionValue) == BT_TRUE) + options->enableDriftCorrection = (int_t)*optionValue; + + if (hasOptionsValue(optionsPtr, "enableCholeskyRefactorisation", &optionValue) == BT_TRUE) + options->enableCholeskyRefactorisation = (int_t)*optionValue; + + if (hasOptionsValue(optionsPtr, "enableEqualities", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + options->enableEqualities = (REFER_NAMESPACE_QPOASES BooleanType)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "terminationTolerance", &optionValue) == BT_TRUE) + options->terminationTolerance = *optionValue; + + if (hasOptionsValue(optionsPtr, "boundTolerance", &optionValue) == BT_TRUE) + options->boundTolerance = *optionValue; + + if (hasOptionsValue(optionsPtr, "boundRelaxation", &optionValue) == BT_TRUE) + options->boundRelaxation = *optionValue; + + if (hasOptionsValue(optionsPtr, "epsNum", &optionValue) == BT_TRUE) + options->epsNum = *optionValue; + + if (hasOptionsValue(optionsPtr, "epsDen", &optionValue) == BT_TRUE) + options->epsDen = *optionValue; + + if (hasOptionsValue(optionsPtr, "maxPrimalJump", &optionValue) == BT_TRUE) + options->maxPrimalJump = *optionValue; + + if (hasOptionsValue(optionsPtr, "maxDualJump", &optionValue) == BT_TRUE) + options->maxDualJump = *optionValue; + + if (hasOptionsValue(optionsPtr, "initialRamping", &optionValue) == BT_TRUE) + options->initialRamping = *optionValue; + + if (hasOptionsValue(optionsPtr, "finalRamping", &optionValue) == BT_TRUE) + options->finalRamping = *optionValue; + + if (hasOptionsValue(optionsPtr, "initialFarBounds", &optionValue) == BT_TRUE) + options->initialFarBounds = *optionValue; + + if (hasOptionsValue(optionsPtr, "growFarBounds", &optionValue) == BT_TRUE) + options->growFarBounds = *optionValue; + + if (hasOptionsValue(optionsPtr, "initialStatusBounds", &optionValue) == BT_TRUE) { + optionValueInt = (int_t)*optionValue; + if (optionValueInt < -1) + optionValueInt = -1; + if (optionValueInt > 1) + optionValueInt = 1; + options->initialStatusBounds = (REFER_NAMESPACE_QPOASES SubjectToStatus)optionValueInt; + } + + if (hasOptionsValue(optionsPtr, "epsFlipping", &optionValue) == BT_TRUE) + options->epsFlipping = *optionValue; + + if (hasOptionsValue(optionsPtr, "numRegularisationSteps", &optionValue) == BT_TRUE) + options->numRegularisationSteps = (int_t)*optionValue; + + if (hasOptionsValue(optionsPtr, "epsRegularisation", &optionValue) == BT_TRUE) + options->epsRegularisation = *optionValue; + + if (hasOptionsValue(optionsPtr, "numRefinementSteps", &optionValue) == BT_TRUE) + options->numRefinementSteps = (int_t)*optionValue; + + if (hasOptionsValue(optionsPtr, "epsIterRef", &optionValue) == BT_TRUE) + options->epsIterRef = *optionValue; + + if (hasOptionsValue(optionsPtr, "epsLITests", &optionValue) == BT_TRUE) + options->epsLITests = *optionValue; + + if (hasOptionsValue(optionsPtr, "epsNZCTests", &optionValue) == BT_TRUE) + options->epsNZCTests = *optionValue; + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A u x i l i a r y I n p u t s + */ +returnValue setupAuxiliaryInputs(const mxArray * auxInput, + uint_t nV, + uint_t nC, + HessianType * hessianType, + double ** x0, + double ** guessedBounds, + double ** guessedConstraints, + double ** R) +{ + mxArray * curField = 0; + + /* hessianType */ + curField = mxGetField(auxInput, 0, "hessianType"); + if (curField == NULL) + mexWarnMsgTxt("auxInput struct does not contain entry 'hessianType'!\n Type 'help " + "qpOASES_auxInput' for further information."); + else { + if (mxIsEmpty(curField) == true) { + *hessianType = HST_UNKNOWN; + } else { + if (mxIsScalar(curField) == false) + return RET_INVALID_ARGUMENTS; + + double * hessianTypeTmp = mxGetPr(curField); + int_t hessianTypeInt = (int_t)*hessianTypeTmp; + if (hessianTypeInt < 0) + hessianTypeInt = 6; /* == HST_UNKNOWN */ + if (hessianTypeInt > 5) + hessianTypeInt = 6; /* == HST_UNKNOWN */ + *hessianType = (REFER_NAMESPACE_QPOASES HessianType)hessianTypeInt; + } + } + + /* x0 */ + curField = mxGetField(auxInput, 0, "x0"); + if (curField == NULL) + mexWarnMsgTxt("auxInput struct does not contain entry 'x0'!\n Type 'help qpOASES_auxInput' for " + "further information."); + else { + *x0 = mxGetPr(curField); + if (smartDimensionCheck(x0, nV, 1, BT_TRUE, ((const mxArray **)&curField), 0) != SUCCESSFUL_RETURN) + return RET_INVALID_ARGUMENTS; + } + + /* guessedWorkingSetB */ + curField = mxGetField(auxInput, 0, "guessedWorkingSetB"); + if (curField == NULL) + mexWarnMsgTxt("auxInput struct does not contain entry 'guessedWorkingSetB'!\n Type 'help " + "qpOASES_auxInput' for further information."); + else { + *guessedBounds = mxGetPr(curField); + if (smartDimensionCheck(guessedBounds, nV, 1, BT_TRUE, ((const mxArray **)&curField), 0) != + SUCCESSFUL_RETURN) + return RET_INVALID_ARGUMENTS; + } + + /* guessedWorkingSetC */ + curField = mxGetField(auxInput, 0, "guessedWorkingSetC"); + if (curField == NULL) + mexWarnMsgTxt("auxInput struct does not contain entry 'guessedWorkingSetC'!\n Type 'help " + "qpOASES_auxInput' for further information."); + else { + *guessedConstraints = mxGetPr(curField); + if (smartDimensionCheck(guessedConstraints, nC, 1, BT_TRUE, ((const mxArray **)&curField), 0) != + SUCCESSFUL_RETURN) + return RET_INVALID_ARGUMENTS; + } + + /* R */ + curField = mxGetField(auxInput, 0, "R"); + if (curField == NULL) + mexWarnMsgTxt("auxInput struct does not contain entry 'R'!\n Type 'help qpOASES_auxInput' for " + "further information."); + else { + *R = mxGetPr(curField); + if (smartDimensionCheck(R, nV, nV, BT_TRUE, ((const mxArray **)&curField), 0) != SUCCESSFUL_RETURN) + return RET_INVALID_ARGUMENTS; + } + + return SUCCESSFUL_RETURN; +} + +/* + * a l l o c a t e O u t p u t s + */ +returnValue allocateOutputs( + int nlhs, mxArray * plhs[], int_t nV, int_t nC = 0, int_t nP = 1, int_t handle = -1) +{ + /* Create output vectors and assign pointers to them. */ + int_t curIdx = 0; + + /* handle */ + if (handle >= 0) + plhs[curIdx++] = mxCreateDoubleMatrix(1, 1, mxREAL); + + /* x */ + plhs[curIdx++] = mxCreateDoubleMatrix(nV, nP, mxREAL); + + if (nlhs > curIdx) { + /* fval */ + plhs[curIdx++] = mxCreateDoubleMatrix(1, nP, mxREAL); + + if (nlhs > curIdx) { + /* exitflag */ + plhs[curIdx++] = mxCreateDoubleMatrix(1, nP, mxREAL); + + if (nlhs > curIdx) { + /* iter */ + plhs[curIdx++] = mxCreateDoubleMatrix(1, nP, mxREAL); + + if (nlhs > curIdx) { + /* lambda */ + plhs[curIdx++] = mxCreateDoubleMatrix(nV + nC, nP, mxREAL); + + if (nlhs > curIdx) { + /* setup auxiliary output struct */ + mxArray * auxOutput = mxCreateStructMatrix(1, 1, 0, 0); + int_t curFieldNum; + + /* working set */ + curFieldNum = mxAddField(auxOutput, "workingSetB"); + if (curFieldNum >= 0) + mxSetFieldByNumber(auxOutput, 0, curFieldNum, mxCreateDoubleMatrix(nV, nP, mxREAL)); + + curFieldNum = mxAddField(auxOutput, "workingSetC"); + if (curFieldNum >= 0) + mxSetFieldByNumber(auxOutput, 0, curFieldNum, mxCreateDoubleMatrix(nC, nP, mxREAL)); + + curFieldNum = mxAddField(auxOutput, "cpuTime"); + if (curFieldNum >= 0) + mxSetFieldByNumber(auxOutput, 0, curFieldNum, mxCreateDoubleMatrix(1, nP, mxREAL)); + + plhs[curIdx] = auxOutput; + } + } + } + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * o b t a i n O u t p u t s + */ +returnValue obtainOutputs(int_t k, + QProblemB * qp, + returnValue returnvalue, + int_t _nWSRout, + double _cpuTime, + int nlhs, + mxArray * plhs[], + int_t nV, + int_t nC = 0, + int_t handle = -1) +{ + /* Create output vectors and assign pointers to them. */ + int_t curIdx = 0; + + /* handle */ + if (handle >= 0) + plhs[curIdx++] = mxCreateDoubleScalar(handle); + + /* x */ + double * x = mxGetPr(plhs[curIdx++]); + qp->getPrimalSolution(&(x[k * nV])); + + if (nlhs > curIdx) { + /* fval */ + double * obj = mxGetPr(plhs[curIdx++]); + obj[k] = qp->getObjVal(); + + if (nlhs > curIdx) { + /* exitflag */ + double * status = mxGetPr(plhs[curIdx++]); + status[k] = (double)getSimpleStatus(returnvalue); + + if (nlhs > curIdx) { + /* iter */ + double * nWSRout = mxGetPr(plhs[curIdx++]); + nWSRout[k] = (double)_nWSRout; + + if (nlhs > curIdx) { + /* lambda */ + double * y = mxGetPr(plhs[curIdx++]); + qp->getDualSolution(&(y[k * (nV + nC)])); + + /* auxOutput */ + if (nlhs > curIdx) { + QProblem * problemPointer; + problemPointer = dynamic_cast(qp); + + mxArray * auxOutput = plhs[curIdx]; + mxArray * curField = 0; + + /* working set bounds */ + if (nV > 0) { + curField = mxGetField(auxOutput, 0, "workingSetB"); + double * workingSetB = mxGetPr(curField); + + /* cast successful? */ + if (problemPointer != NULL) { + problemPointer->getWorkingSetBounds(&(workingSetB[k * nV])); + } else { + qp->getWorkingSetBounds(&(workingSetB[k * nV])); + } + } + + /* working set constraints */ + if (nC > 0) { + curField = mxGetField(auxOutput, 0, "workingSetC"); + double * workingSetC = mxGetPr(curField); + + /* cast successful? */ + if (problemPointer != NULL) { + problemPointer->getWorkingSetConstraints(&(workingSetC[k * nC])); + } else { + qp->getWorkingSetConstraints(&(workingSetC[k * nC])); + } + } + + /* cpu time */ + curField = mxGetField(auxOutput, 0, "cpuTime"); + double * cpuTime = mxGetPr(curField); + cpuTime[0] = (double)_cpuTime; + } + } + } + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p H e s s i a n M a t r i x + */ +returnValue setupHessianMatrix(const mxArray * prhsH, + int_t nV, + SymmetricMatrix ** H, + sparse_int_t ** Hir, + sparse_int_t ** Hjc, + real_t ** Hv) +{ + if (prhsH == 0) + return SUCCESSFUL_RETURN; + + if (mxIsSparse(prhsH) != 0) { + mwIndex * mat_ir = mxGetIr(prhsH); + mwIndex * mat_jc = mxGetJc(prhsH); + double * v = (double *)mxGetPr(prhsH); + long nfill = 0; + mwIndex i, j; + BooleanType needInsertDiag; + + /* copy indices to avoid 64/32-bit integer confusion */ + /* also add explicit zeros on diagonal for regularization strategy */ + /* copy values, too */ + *Hir = new sparse_int_t[mat_jc[nV] + nV]; + *Hjc = new sparse_int_t[nV + 1]; + *Hv = new real_t[mat_jc[nV] + nV]; + for (j = 0; j < nV; j++) { + needInsertDiag = BT_TRUE; + + (*Hjc)[j] = (sparse_int_t)(mat_jc[j]) + nfill; + /* fill up to diagonal */ + for (i = mat_jc[j]; i < mat_jc[j + 1]; i++) { + if (mat_ir[i] == j) + needInsertDiag = BT_FALSE; + + /* add zero diagonal element if not present */ + if ((mat_ir[i] > j) && (needInsertDiag == BT_TRUE)) { + (*Hir)[i + nfill] = (sparse_int_t)j; + (*Hv)[i + nfill] = 0.0; + nfill++; + /* only add diag once */ + needInsertDiag = BT_FALSE; + } + + (*Hir)[i + nfill] = (sparse_int_t)(mat_ir[i]); + (*Hv)[i + nfill] = (real_t)(v[i]); + } + } + (*Hjc)[nV] = (sparse_int_t)(mat_jc[nV]) + nfill; + + SymSparseMat * sH; + *H = sH = new SymSparseMat(nV, nV, *Hir, *Hjc, *Hv); + sH->createDiagInfo(); + } else { + /* make a deep-copy in order to avoid modifying input data when regularising */ + real_t * H_for = (real_t *)mxGetPr(prhsH); + real_t * H_mem = new real_t[nV * nV]; + memcpy(H_mem, H_for, nV * nV * sizeof(real_t)); + + *H = new SymDenseMat(nV, nV, nV, H_mem); + (*H)->doFreeMemory(); + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p C o n s t r a i n t M a t r i x + */ +returnValue setupConstraintMatrix(const mxArray * prhsA, + int_t nV, + int_t nC, + Matrix ** A, + sparse_int_t ** Air, + sparse_int_t ** Ajc, + real_t ** Av) +{ + if (prhsA == 0) + return SUCCESSFUL_RETURN; + + if (mxIsSparse(prhsA) != 0) { + mwIndex i; + long j; + + mwIndex * mat_ir = mxGetIr(prhsA); + mwIndex * mat_jc = mxGetJc(prhsA); + double * v = (double *)mxGetPr(prhsA); + + /* copy indices to avoid 64/32-bit integer confusion */ + *Air = new sparse_int_t[mat_jc[nV]]; + *Ajc = new sparse_int_t[nV + 1]; + for (i = 0; i < mat_jc[nV]; i++) + (*Air)[i] = (sparse_int_t)(mat_ir[i]); + for (i = 0; i < nV + 1; i++) + (*Ajc)[i] = (sparse_int_t)(mat_jc[i]); + + /* copy values, too */ + *Av = new real_t[(*Ajc)[nV]]; + for (j = 0; j < (*Ajc)[nV]; j++) + (*Av)[j] = (real_t)(v[j]); + + *A = new SparseMatrix(nC, nV, *Air, *Ajc, *Av); + } else { + /* Convert constraint matrix A from FORTRAN to C style + * (not necessary for H as it should be symmetric!). */ + real_t * A_for = (real_t *)mxGetPr(prhsA); + real_t * A_mem = new real_t[nC * nV]; + convertFortranToC(A_for, nV, nC, A_mem); + *A = new DenseMatrix(nC, nV, nV, A_mem); + (*A)->doFreeMemory(); + } + + return SUCCESSFUL_RETURN; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_octave_utils.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_octave_utils.hpp new file mode 100644 index 0000000..02e3335 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_octave_utils.hpp @@ -0,0 +1,86 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file interfaces/octave/qpOASES_octave_utils.hpp + * \author Hans Joachim Ferreau, Andreas Potschka, Alexander Buchner + * \version 3.2 + * \date 2007-2017 + * + * Collects utility functions for Interface to octave that + * enables to call qpOASES as a MEX function. + * + */ + +/* Work-around for settings where mexErrMsgTxt causes unexpected behaviour. */ +#ifdef __AVOID_MEXERRMSGTXT__ +#define myMexErrMsgTxt(TEXT) mexPrintf("%s\n\n", (TEXT)); +#else +#define myMexErrMsgTxt mexErrMsgTxt +#endif + +#include "mex.h" +/* #include "matrix.h" */ +#include "string.h" +#include + +/* + * QProblem instance class + */ +class QPInstance +{ +private: + static int_t s_nexthandle; + +public: + QPInstance(uint_t _nV = 0, + uint_t _nC = 0, + HessianType _hessianType = HST_UNKNOWN, + BooleanType _isSimplyBounded = BT_FALSE); + + ~QPInstance(); + + returnValue deleteQPMatrices(); + + int_t getNV() const; + int_t getNC() const; + + int_t handle; + + SQProblem * sqp; + QProblemB * qpb; + BooleanType isSimplyBounded; + + SymmetricMatrix * H; + Matrix * A; + sparse_int_t * Hir; + sparse_int_t * Hjc; + sparse_int_t * Air; + sparse_int_t * Ajc; + real_t * Hv; + real_t * Av; +}; + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_options.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_options.m new file mode 100755 index 0000000..0cccf95 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_options.m @@ -0,0 +1,251 @@ +%qpOASES -- An Implementation of the Online Active Set Strategy. +%Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +%Christian Kirches et al. All rights reserved. +% +%qpOASES is distributed under the terms of the +%GNU Lesser General Public License 2.1 in the hope that it will be +%useful, but WITHOUT ANY WARRANTY; without even the implied warranty +%of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +%See the GNU Lesser General Public License for more details. +% +%--------------------------------------------------------------------------------- +% +%Returns a struct containing values for all options to be used within qpOASES. +% +%Call +% options = qpOASES_options( 'default' ); +% options = qpOASES_options( 'reliable' ); +% options = qpOASES_options( 'MPC' ); +%to obtain a set of default options or a pre-defined set of options tuned +%for reliable or fast QP solution, respectively. +% +%Call +% options = qpOASES_options( 'option1',value1,'option2',value2,... ) +%to obtain a set of default options but with 'option1' set to value1 etc. +% +%Call +% options = qpOASES_options( oldOptions,'option1',value1,... ) +%to obtain a copy of the options struct oldOptions but with 'option1' set +%to value1 etc. +% +%Call +% options = qpOASES_options( 'default', 'option1',value1,... ) +% options = qpOASES_options( 'reliable','option1',value1,... ) +% options = qpOASES_options( 'MPC', 'option1',value1,... ) +%to obtain a set of default options or a pre-defined set of options tuned +%for reliable or fast QP solution, respectively, but with 'option1' set to +%value1 etc. +% +% +%qpOASES features the following options: +% maxIter - Maximum number of iterations (if set +% to -1, a value is chosen heuristically) +% maxCpuTime - Maximum CPU time in seconds (if set +% to -1, only iteration limit is used) +% printLevel - 0: no printed output, +% 1: only error messages are printed, +% 2: iterations and error messages are printed, +% 3: all available messages are printed. +% +% enableRamping - Enables (1) or disables (0) ramping. +% enableFarBounds - Enables (1) or disables (0) the use of +% far bounds. +% enableFlippingBounds - Enables (1) or disables (0) the use of +% flipping bounds. +% enableRegularisation - Enables (1) or disables (0) automatic +% Hessian regularisation. +% enableFullLITests - Enables (1) or disables (0) condition-hardened +% (but more expensive) LI test. +% enableNZCTests - Enables (1) or disables (0) nonzero curvature +% tests. +% enableDriftCorrection - Specifies the frequency of drift corrections: +% 0: turns them off, +% 1: uses them at each iteration etc. +% enableCholeskyRefactorisation - Specifies the frequency of a full re- +% factorisation of projected Hessian matrix: +% 0: turns them off, +% 1: uses them at each iteration etc. +% enableEqualities - Specifies whether equalities should be treated +% as always active (1) or not (0) +% +% terminationTolerance - Relative termination tolerance to stop homotopy. +% boundTolerance - If upper and lower bounds differ less than this +% tolerance, they are regarded equal, i.e. as +% equality constraint. +% boundRelaxation - Initial relaxation of bounds to start homotopy +% and initial value for far bounds. +% epsNum - Numerator tolerance for ratio tests. +% epsDen - Denominator tolerance for ratio tests. +% maxPrimalJump - Maximum allowed jump in primal variables in +% nonzero curvature tests. +% maxDualJump - Maximum allowed jump in dual variables in +% linear independence tests. +% +% initialRamping - Start value for ramping strategy. +% finalRamping - Final value for ramping strategy. +% initialFarBounds - Initial size for far bounds. +% growFarBounds - Factor to grow far bounds. +% initialStatusBounds - Initial status of bounds at first iteration: +% 0: all bounds inactive, +% -1: all bounds active at their lower bound, +% +1: all bounds active at their upper bound. +% epsFlipping - Tolerance of squared Cholesky diagonal factor +% which triggers flipping bound. +% numRegularisationSteps - Maximum number of successive regularisation steps. +% epsRegularisation - Scaling factor of identity matrix used for +% Hessian regularisation. +% numRefinementSteps - Maximum number of iterative refinement steps. +% epsIterRef - Early termination tolerance for iterative +% refinement. +% epsLITests - Tolerance for linear independence tests. +% epsNZCTests - Tolerance for nonzero curvature tests. +% +% +%See also QPOASES, QPOASES_SEQUENCE, QPOASES_AUXINPUT +% +% +%For additional information see the qpOASES User's Manual or +%visit http://www.qpOASES.org/. +% +%Please send remarks and questions to support@qpOASES.org! +function [ options ] = qpOASES_options( varargin ) + + firstIsStructOrScheme = 0; + + if ( nargin == 0 ) + options = qpOASES_default_options(); + else + if ( isstruct( varargin{1} ) ) + if ( mod( nargin,2 ) ~= 1 ) + error('ERROR (qpOASES_options): Options must be specified in pairs!'); + end + options = varargin{1}; + firstIsStructOrScheme = 1; + else + if ( ischar( varargin{1} ) ) + if ( mod( nargin,2 ) == 0 ) + options = qpOASES_default_options(); + else + if ( ( nargin > 1 ) && ( ischar( varargin{nargin} ) ) ) + error('ERROR (qpOASES_options): Options must be specified in pairs!'); + end + + switch ( varargin{1} ) + case 'default' + options = qpOASES_default_options(); + case 'reliable' + options = qpOASES_reliable_options(); + case {'MPC','mpc','fast'} + options = qpOASES_MPC_options(); + otherwise + error( ['ERROR (qpOASES_options): Only the following option schemes are defined: ''default'', ''reliable'', ''MPC''!'] ); + + end + firstIsStructOrScheme = 1; + end + else + error('ERROR (qpOASES_options): First argument needs to be a string or an options struct!'); + end + end + end + + % set options to user-defined values + for i=(1+firstIsStructOrScheme):2:nargin + + argName = varargin{i}; + argValue = varargin{i+1}; + + if ( ( isempty( argName ) ) || ( ~ischar( argName ) ) ) + error('ERROR (qpOASES_options): Argmument no. %d has to be a non-empty string!',i ); + end + + if ( ( ischar(argValue) ) || ( ~isscalar( argValue ) ) ) + error('ERROR (qpOASES_options): Argmument no. %d has to be a scalar constant!',i+1 ); + end + + if ( ~isfield( options,argName ) ) + error('ERROR (qpOASES_options): Argmument no. %d is an invalid option!',i ); + end + + eval( ['options.',argName,' = ',num2str(argValue),';'] ); + + end + +end + + +function [ options ] = qpOASES_default_options( ) + + % setup options struct with default values + options = struct( 'maxIter', -1, ... + 'maxCpuTime', -1, ... + 'printLevel', 1, ... + ... + 'enableRamping', 1, ... + 'enableFarBounds', 1, ... + 'enableFlippingBounds', 1, ... + 'enableRegularisation', 0, ... + 'enableFullLITests', 0, ... + 'enableNZCTests', 1, ... + 'enableDriftCorrection', 1, ... + 'enableCholeskyRefactorisation', 0, ... + 'enableEqualities', 0, ... + ... + 'terminationTolerance', 5.0e6*eps, ... + 'boundTolerance', 1.0e6*eps, ... + 'boundRelaxation', 1.0e4, ... + 'epsNum', -1.0e3*eps, ... + 'epsDen', 1.0e3*eps, ... + 'maxPrimalJump', 1.0e8, ... + 'maxDualJump', 1.0e8, ... + ... + 'initialRamping', 0.5, ... + 'finalRamping', 1.0, ... + 'initialFarBounds', 1.0e6, ... + 'growFarBounds', 1.0e3, ... + 'initialStatusBounds', -1, ... + 'epsFlipping', 1.0e3*eps, ... + 'numRegularisationSteps', 0, ... + 'epsRegularisation', 1.0e3*eps, ... + 'numRefinementSteps', 1, ... + 'epsIterRef', 1.0e2*eps, ... + 'epsLITests', 1.0e5*eps, ... + 'epsNZCTests', 3.1e3*eps ); + +end + + + +function [ options ] = qpOASES_reliable_options( ) + + % setup options struct with values for most reliable QP solution + options = qpOASES_default_options( ); + + options.enableFullLITests = 1; + options.enableCholeskyRefactorisation = 1; + + options.numRefinementSteps = 2; + +end + + +function [ options ] = qpOASES_MPC_options( ) + + % setup options struct with values for most reliable QP solution + options = qpOASES_default_options( ); + + options.enableRamping = 0; + options.enableFarBounds = 1; + options.enableFlippingBounds = 0; + options.enableRegularisation = 1; + options.enableNZCTests = 0; + options.enableDriftCorrection = 0; + options.enableEqualities = 1; + + options.terminationTolerance = 1.0e9*eps; + + options.initialStatusBounds = 0; + options.numRegularisationSteps = 1; + options.numRefinementSteps = 0; + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_sequence.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_sequence.cpp new file mode 100644 index 0000000..9a2c193 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_sequence.cpp @@ -0,0 +1,1031 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file interfaces/octave/qpOASES_sequence.cpp + * \author Hans Joachim Ferreau, Christian Kirches, Andreas Potschka, Alexander Buchner + * \version 3.2 + * \date 2007-2017 + * + * Interface for octave that enables to call qpOASES as a MEX function + * (variant for solving QP sequences). + * + */ + +#include + +USING_NAMESPACE_QPOASES + +#include "qpOASES_octave_utils.hpp" + +/** initialise handle counter of QPInstance class */ +int_t QPInstance::s_nexthandle = 1; + +/** global pointer to QP objects */ +static std::vector g_instances; + +#include "qpOASES_octave_utils.cpp" + +/* + * Q P r o b l e m B _ i n i t + */ +int_t QProblemB_init(int_t handle, + SymmetricMatrix * H, + real_t * g, + const real_t * const lb, + const real_t * const ub, + int_t nWSRin, + real_t maxCpuTimeIn, + const double * const x0, + Options * options, + int_t nOutputs, + mxArray * plhs[], + const double * const guessedBounds, + const double * const _R) +{ + int_t nWSRout = nWSRin; + real_t maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + + /* 1) setup initial QP. */ + QProblemB * globalQPB = getQPInstance(handle)->qpb; + + if (globalQPB == 0) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid handle to QP instance!"); + return -1; + } + + globalQPB->setOptions(*options); + + /* 2) Solve initial QP. */ + returnValue returnvalue; + int_t nV = globalQPB->getNV(); + + /* 3) Fill the working set. */ + Bounds bounds(nV); + if (guessedBounds != 0) { + for (int_t i = 0; i < nV; i++) { + if (isEqual(guessedBounds[i], -1.0) == BT_TRUE) { + bounds.setupBound(i, ST_LOWER); + } else if (isEqual(guessedBounds[i], 1.0) == BT_TRUE) { + bounds.setupBound(i, ST_UPPER); + } else if (isEqual(guessedBounds[i], 0.0) == BT_TRUE) { + bounds.setupBound(i, ST_INACTIVE); + } else { + char msg[MAX_STRING_LENGTH]; + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Only {-1, 0, 1} allowed for status of bounds!"); + myMexErrMsgTxt(msg); + return -1; + } + } + } + + returnvalue = + globalQPB->init(H, g, lb, ub, nWSRout, &maxCpuTimeOut, x0, 0, (guessedBounds != 0) ? &bounds : 0, _R); + + /* 3) Assign lhs arguments. */ + obtainOutputs(0, globalQPB, returnvalue, nWSRout, maxCpuTimeOut, nOutputs, plhs, nV, 0, handle); + + return 0; +} + +/* + * S Q P r o b l e m _ i n i t + */ +int_t SQProblem_init(int_t handle, + SymmetricMatrix * H, + real_t * g, + Matrix * A, + const real_t * const lb, + const real_t * const ub, + const real_t * const lbA, + const real_t * const ubA, + int_t nWSRin, + real_t maxCpuTimeIn, + const double * const x0, + Options * options, + int_t nOutputs, + mxArray * plhs[], + const double * const guessedBounds, + const double * const guessedConstraints, + const double * const _R) +{ + int_t nWSRout = nWSRin; + real_t maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + + /* 1) setup initial QP. */ + SQProblem * globalSQP = getQPInstance(handle)->sqp; + + if (globalSQP == 0) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid handle to QP instance!"); + return -1; + } + + globalSQP->setOptions(*options); + + /* 2) Solve initial QP. */ + returnValue returnvalue; + int_t nV = globalSQP->getNV(); + int_t nC = globalSQP->getNC(); + + /* 3) Fill the working set. */ + Bounds bounds(nV); + Constraints constraints(nC); + if (guessedBounds != 0) { + for (int_t i = 0; i < nV; i++) { + if (isEqual(guessedBounds[i], -1.0) == BT_TRUE) { + bounds.setupBound(i, ST_LOWER); + } else if (isEqual(guessedBounds[i], 1.0) == BT_TRUE) { + bounds.setupBound(i, ST_UPPER); + } else if (isEqual(guessedBounds[i], 0.0) == BT_TRUE) { + bounds.setupBound(i, ST_INACTIVE); + } else { + char msg[MAX_STRING_LENGTH]; + snprintf(msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Only {-1, 0, 1} allowed for status of bounds!"); + myMexErrMsgTxt(msg); + return -1; + } + } + } + + if (guessedConstraints != 0) { + for (int_t i = 0; i < nC; i++) { + if (isEqual(guessedConstraints[i], -1.0) == BT_TRUE) { + constraints.setupConstraint(i, ST_LOWER); + } else if (isEqual(guessedConstraints[i], 1.0) == BT_TRUE) { + constraints.setupConstraint(i, ST_UPPER); + } else if (isEqual(guessedConstraints[i], 0.0) == BT_TRUE) { + constraints.setupConstraint(i, ST_INACTIVE); + } else { + char msg[MAX_STRING_LENGTH]; + snprintf( + msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Only {-1, 0, 1} allowed for status of constraints!"); + myMexErrMsgTxt(msg); + return -1; + } + } + } + + returnvalue = globalSQP->init(H, + g, + A, + lb, + ub, + lbA, + ubA, + nWSRout, + &maxCpuTimeOut, + x0, + 0, + (guessedBounds != 0) ? &bounds : 0, + (guessedConstraints != 0) ? &constraints : 0, + _R); + + /* 3) Assign lhs arguments. */ + obtainOutputs(0, globalSQP, returnvalue, nWSRout, maxCpuTimeOut, nOutputs, plhs, nV, nC, handle); + + return 0; +} + +/* + * Q P r o b l e m B _ h o t s t a r t + */ +int_t QProblemB_hotstart(int_t handle, + const real_t * const g, + const real_t * const lb, + const real_t * const ub, + int_t nWSRin, + real_t maxCpuTimeIn, + Options * options, + int_t nOutputs, + mxArray * plhs[]) +{ + int_t nWSRout = nWSRin; + real_t maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + + QProblemB * globalQPB = getQPInstance(handle)->qpb; + + if (globalQPB == 0) { + myMexErrMsgTxt("ERROR (qpOASES): QP needs to be initialised first!"); + return -1; + } + + int_t nV = globalQPB->getNV(); + + /* 1) Solve QP with given options. */ + globalQPB->setOptions(*options); + returnValue returnvalue = globalQPB->hotstart(g, lb, ub, nWSRout, &maxCpuTimeOut); + + /* 2) Assign lhs arguments. */ + obtainOutputs(0, globalQPB, returnvalue, nWSRout, maxCpuTimeOut, nOutputs, plhs, nV, 0); + + return 0; +} + +/* + * Q P r o b l e m _ h o t s t a r t + */ +int_t QProblem_hotstart(int_t handle, + const real_t * const g, + const real_t * const lb, + const real_t * const ub, + const real_t * const lbA, + const real_t * const ubA, + int_t nWSRin, + real_t maxCpuTimeIn, + Options * options, + int_t nOutputs, + mxArray * plhs[]) +{ + int_t nWSRout = nWSRin; + real_t maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + + QProblem * globalSQP = getQPInstance(handle)->sqp; + + if (globalSQP == 0) { + myMexErrMsgTxt("ERROR (qpOASES): QP needs to be initialised first!"); + return -1; + } + + int_t nV = globalSQP->getNV(); + int_t nC = globalSQP->getNC(); + + /* 1) Solve QP with given options. */ + globalSQP->setOptions(*options); + returnValue returnvalue = globalSQP->hotstart(g, lb, ub, lbA, ubA, nWSRout, &maxCpuTimeOut); + + /* 2) Assign lhs arguments. */ + obtainOutputs(0, globalSQP, returnvalue, nWSRout, maxCpuTimeOut, nOutputs, plhs, nV, nC); + + return 0; +} + +/* + * S Q P r o b l e m _ h o t s t a r t + */ +int_t SQProblem_hotstart(int_t handle, + SymmetricMatrix * H, + real_t * g, + Matrix * A, + const real_t * const lb, + const real_t * const ub, + const real_t * const lbA, + const real_t * const ubA, + int_t nWSRin, + real_t maxCpuTimeIn, + Options * options, + int_t nOutputs, + mxArray * plhs[]) +{ + int_t nWSRout = nWSRin; + real_t maxCpuTimeOut = (maxCpuTimeIn >= 0.0) ? maxCpuTimeIn : INFTY; + + SQProblem * globalSQP = getQPInstance(handle)->sqp; + + if (globalSQP == 0) { + myMexErrMsgTxt("ERROR (qpOASES): QP needs to be initialised first!"); + return -1; + } + + int_t nV = globalSQP->getNV(); + int_t nC = globalSQP->getNC(); + + /* 1) Solve QP. */ + globalSQP->setOptions(*options); + returnValue returnvalue = globalSQP->hotstart(H, g, A, lb, ub, lbA, ubA, nWSRout, &maxCpuTimeOut); + + switch (returnvalue) { + case SUCCESSFUL_RETURN: + case RET_QP_UNBOUNDED: + case RET_QP_INFEASIBLE: + break; + + default: + myMexErrMsgTxt("ERROR (qpOASES): Hotstart failed."); + return -1; + } + + /* 2) Assign lhs arguments. */ + obtainOutputs(0, globalSQP, returnvalue, nWSRout, maxCpuTimeOut, nOutputs, plhs, nV, nC); + + return 0; +} + +/* + * m e x F u n c t i o n + */ +void mexFunction(int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[]) +{ + /* inputs */ + char typeString[2]; + + real_t *g = 0, *lb = 0, *ub = 0, *lbA = 0, *ubA = 0; + HessianType hessianType = HST_UNKNOWN; + double *x0 = 0, *R = 0, *R_for = 0; + double *guessedBounds = 0, *guessedConstraints = 0; + + int_t H_idx = -1, g_idx = -1, A_idx = -1, lb_idx = -1, ub_idx = -1, lbA_idx = -1, ubA_idx = -1; + int_t x0_idx = -1, auxInput_idx = -1; + + BooleanType isSimplyBoundedQp = BT_FALSE; + + Options options; + options.printLevel = PL_LOW; +#ifdef __DEBUG__ + options.printLevel = PL_HIGH; +#endif +#ifdef __SUPPRESSANYOUTPUT__ + options.printLevel = PL_NONE; +#endif + + /* dimensions */ + uint_t nV = 0, nC = 0, handle = 0; + int_t nWSRin; + real_t maxCpuTimeIn = -1.0; + QPInstance * globalQP = 0; + + /* I) CONSISTENCY CHECKS: */ + /* 1) Ensure that qpOASES is called with a feasible number of input arguments. */ + if ((nrhs < 5) || (nrhs > 10)) { + if (nrhs != 2) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of input arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + } + + /* 2) Ensure that first input is a string ... */ + if (mxIsChar(prhs[0]) != 1) { + myMexErrMsgTxt("ERROR (qpOASES): First input argument must be a string!"); + return; + } + + mxGetString(prhs[0], typeString, 2); + + /* ... and if so, check if it is an allowed one. */ + if ((strcmp(typeString, "i") != 0) && (strcmp(typeString, "I") != 0) && (strcmp(typeString, "h") != 0) && + (strcmp(typeString, "H") != 0) && (strcmp(typeString, "m") != 0) && (strcmp(typeString, "M") != 0) && + (strcmp(typeString, "e") != 0) && (strcmp(typeString, "E") != 0) && (strcmp(typeString, "c") != 0) && + (strcmp(typeString, "C") != 0)) { + myMexErrMsgTxt("ERROR (qpOASES): Undefined first input argument!\nType 'help qpOASES_sequence' for " + "further information."); + return; + } + + /* II) SELECT RESPECTIVE QPOASES FUNCTION CALL: */ + /* 1) Init (without or with initial guess for primal solution). */ + if ((strcmp(typeString, "i") == 0) || (strcmp(typeString, "I") == 0)) { + /* consistency checks */ + if ((nlhs < 1) || (nlhs > 7)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of output arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if ((nrhs < 5) || (nrhs > 10)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of input arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + g_idx = 2; + + if (mxIsEmpty(prhs[1]) == 1) { + H_idx = -1; + nV = (uint_t)mxGetM(prhs[g_idx]); /* row number of Hessian matrix */ + } else { + H_idx = 1; + nV = (uint_t)mxGetM(prhs[H_idx]); /* row number of Hessian matrix */ + } + + /* ensure that data is given in double precision */ + if (((H_idx >= 0) && (mxIsDouble(prhs[H_idx]) == 0)) || (mxIsDouble(prhs[g_idx]) == 0)) { + myMexErrMsgTxt("ERROR (qpOASES): All data has to be provided in double precision!"); + return; + } + + if ((H_idx >= 0) && ((mxGetN(prhs[H_idx]) != nV) || (mxGetM(prhs[H_idx]) != nV))) { + myMexErrMsgTxt("ERROR (qpOASES): Hessian matrix dimension mismatch!"); + return; + } + + /* Check for 'Inf' and 'Nan' in Hessian */ + if (containsNaNorInf(prhs, H_idx, 0) == BT_TRUE) + return; + + /* Check for 'Inf' and 'Nan' in gradient */ + if (containsNaNorInf(prhs, g_idx, 0) == BT_TRUE) + return; + + /* determine whether is it a simply bounded QP */ + if (nrhs <= 7) + isSimplyBoundedQp = BT_TRUE; + else + isSimplyBoundedQp = BT_FALSE; + + if (isSimplyBoundedQp == BT_TRUE) { + lb_idx = 3; + ub_idx = 4; + + if (containsNaNorInf(prhs, lb_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ub_idx, 1) == BT_TRUE) + return; + + /* Check inputs dimensions and assign pointers to inputs. */ + nC = 0; /* row number of constraint matrix */ + + if (smartDimensionCheck(&g, nV, 1, BT_FALSE, prhs, 2) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lb, nV, 1, BT_TRUE, prhs, 3) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ub, nV, 1, BT_TRUE, prhs, 4) != SUCCESSFUL_RETURN) + return; + + /* default value for nWSR */ + nWSRin = 5 * nV; + + /* Check whether x0 and options are specified .*/ + if (nrhs >= 6) { + if ((!mxIsEmpty(prhs[5])) && (mxIsStruct(prhs[5]))) + setupOptions(&options, prhs[5], nWSRin, maxCpuTimeIn); + + if ((nrhs >= 7) && (!mxIsEmpty(prhs[6]))) { + /* auxInput specified */ + if (mxIsStruct(prhs[6])) { + auxInput_idx = 6; + x0_idx = -1; + } else { + auxInput_idx = -1; + x0_idx = 6; + } + } else { + auxInput_idx = -1; + x0_idx = -1; + } + } + } else { + A_idx = 3; + + /* ensure that data is given in double precision */ + if (mxIsDouble(prhs[A_idx]) == 0) { + myMexErrMsgTxt("ERROR (qpOASES): All data has to be provided in double precision!"); + return; + } + + /* Check inputs dimensions and assign pointers to inputs. */ + nC = (uint_t)mxGetM(prhs[A_idx]); /* row number of constraint matrix */ + + lb_idx = 4; + ub_idx = 5; + lbA_idx = 6; + ubA_idx = 7; + + if (containsNaNorInf(prhs, A_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lb_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ub_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lbA_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ubA_idx, 1) == BT_TRUE) + return; + + if ((mxGetN(prhs[A_idx]) != 0) && (mxGetN(prhs[A_idx]) != nV)) { + myMexErrMsgTxt("ERROR (qpOASES): Constraint matrix dimension mismatch!"); + return; + } + + if (smartDimensionCheck(&g, nV, 1, BT_FALSE, prhs, g_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lb, nV, 1, BT_TRUE, prhs, lb_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ub, nV, 1, BT_TRUE, prhs, ub_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lbA, nC, 1, BT_TRUE, prhs, lbA_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ubA, nC, 1, BT_TRUE, prhs, ubA_idx) != SUCCESSFUL_RETURN) + return; + + /* default value for nWSR */ + nWSRin = 5 * (nV + nC); + + /* Check whether x0 and options are specified .*/ + if (nrhs >= 9) { + if ((!mxIsEmpty(prhs[8])) && (mxIsStruct(prhs[8]))) + setupOptions(&options, prhs[8], nWSRin, maxCpuTimeIn); + + if ((nrhs >= 10) && (!mxIsEmpty(prhs[9]))) { + /* auxInput specified */ + if (mxIsStruct(prhs[9])) { + auxInput_idx = 9; + x0_idx = -1; + } else { + auxInput_idx = -1; + x0_idx = 9; + } + } else { + auxInput_idx = -1; + x0_idx = -1; + } + } + } + + /* check dimensions and copy auxInputs */ + if (smartDimensionCheck(&x0, nV, 1, BT_TRUE, prhs, x0_idx) != SUCCESSFUL_RETURN) + return; + + if (auxInput_idx >= 0) + setupAuxiliaryInputs( + prhs[auxInput_idx], nV, nC, &hessianType, &x0, &guessedBounds, &guessedConstraints, &R_for); + + /* convert Cholesky factor to C storage format */ + if (R_for != 0) { + R = new real_t[nV * nV]; + convertFortranToC(R_for, nV, nV, R); + } + + /* allocate instance */ + handle = allocateQPInstance(nV, nC, hessianType, isSimplyBoundedQp, &options); + globalQP = getQPInstance(handle); + + /* make a deep-copy of the user-specified Hessian matrix (possibly sparse) */ + if (H_idx >= 0) + setupHessianMatrix( + prhs[H_idx], nV, &(globalQP->H), &(globalQP->Hir), &(globalQP->Hjc), &(globalQP->Hv)); + + /* make a deep-copy of the user-specified constraint matrix (possibly sparse) */ + if ((nC > 0) && (A_idx >= 0)) + setupConstraintMatrix( + prhs[A_idx], nV, nC, &(globalQP->A), &(globalQP->Air), &(globalQP->Ajc), &(globalQP->Av)); + + /* Create output vectors and assign pointers to them. */ + allocateOutputs(nlhs, plhs, nV, nC, 1, handle); + + /* Call qpOASES. */ + if (isSimplyBoundedQp == BT_TRUE) { + QProblemB_init( + handle, globalQP->H, g, lb, ub, nWSRin, maxCpuTimeIn, x0, &options, nlhs, plhs, guessedBounds, R); + } else { + SQProblem_init(handle, + globalQP->H, + g, + globalQP->A, + lb, + ub, + lbA, + ubA, + nWSRin, + maxCpuTimeIn, + x0, + &options, + nlhs, + plhs, + guessedBounds, + guessedConstraints, + R); + } + + if (R != 0) + delete R; + return; + } + + /* 2) Hotstart. */ + if ((strcmp(typeString, "h") == 0) || (strcmp(typeString, "H") == 0)) { + /* consistency checks */ + if ((nlhs < 1) || (nlhs > 6)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of output arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if ((nrhs < 5) || (nrhs > 8)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of input arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + /* determine whether is it a simply bounded QP */ + if (nrhs < 7) + isSimplyBoundedQp = BT_TRUE; + else + isSimplyBoundedQp = BT_FALSE; + + if ((mxIsDouble(prhs[1]) == false) || (mxIsScalar(prhs[1]) == false)) { + myMexErrMsgTxt("ERROR (qpOASES): Expecting a handle to QP object as second argument!\nType 'help " + "qpOASES_sequence' for further information."); + return; + } + + /* get QP instance */ + handle = (uint_t)mxGetScalar(prhs[1]); + globalQP = getQPInstance(handle); + if (globalQP == 0) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid handle to QP instance!"); + return; + } + + nV = globalQP->getNV(); + + g_idx = 2; + lb_idx = 3; + ub_idx = 4; + + if (containsNaNorInf(prhs, g_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lb_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ub_idx, 1) == BT_TRUE) + return; + + /* Check inputs dimensions and assign pointers to inputs. */ + if (isSimplyBoundedQp == BT_TRUE) { + nC = 0; + + if (smartDimensionCheck(&g, nV, 1, BT_FALSE, prhs, g_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lb, nV, 1, BT_TRUE, prhs, lb_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ub, nV, 1, BT_TRUE, prhs, ub_idx) != SUCCESSFUL_RETURN) + return; + + /* default value for nWSR */ + nWSRin = 5 * nV; + + /* Check whether options are specified .*/ + if (nrhs == 6) + if ((!mxIsEmpty(prhs[5])) && (mxIsStruct(prhs[5]))) + setupOptions(&options, prhs[5], nWSRin, maxCpuTimeIn); + } else { + nC = globalQP->getNC(); + + lbA_idx = 5; + ubA_idx = 6; + + if (containsNaNorInf(prhs, lbA_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ubA_idx, 1) == BT_TRUE) + return; + + if (smartDimensionCheck(&g, nV, 1, BT_FALSE, prhs, g_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lb, nV, 1, BT_TRUE, prhs, lb_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ub, nV, 1, BT_TRUE, prhs, ub_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lbA, nC, 1, BT_TRUE, prhs, lbA_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ubA, nC, 1, BT_TRUE, prhs, ubA_idx) != SUCCESSFUL_RETURN) + return; + + /* default value for nWSR */ + nWSRin = 5 * (nV + nC); + + /* Check whether options are specified .*/ + if (nrhs == 8) + if ((!mxIsEmpty(prhs[7])) && (mxIsStruct(prhs[7]))) + setupOptions(&options, prhs[7], nWSRin, maxCpuTimeIn); + } + + /* Create output vectors and assign pointers to them. */ + allocateOutputs(nlhs, plhs, nV, nC); + + /* call qpOASES */ + if (isSimplyBoundedQp == BT_TRUE) { + QProblemB_hotstart(handle, g, lb, ub, nWSRin, maxCpuTimeIn, &options, nlhs, plhs); + } else { + QProblem_hotstart(handle, g, lb, ub, lbA, ubA, nWSRin, maxCpuTimeIn, &options, nlhs, plhs); + } + + return; + } + + /* 3) Modify matrices. */ + if ((strcmp(typeString, "m") == 0) || (strcmp(typeString, "M") == 0)) { + /* consistency checks */ + if ((nlhs < 1) || (nlhs > 6)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of output arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if ((nrhs < 9) || (nrhs > 10)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of input arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if ((mxIsDouble(prhs[1]) == false) || (mxIsScalar(prhs[1]) == false)) { + myMexErrMsgTxt("ERROR (qpOASES): Expecting a handle to QP object as second argument!\nType 'help " + "qpOASES_sequence' for further information."); + return; + } + + /* get QP instance */ + handle = (uint_t)mxGetScalar(prhs[1]); + globalQP = getQPInstance(handle); + if (globalQP == 0) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid handle to QP instance!"); + return; + } + + /* Check inputs dimensions and assign pointers to inputs. */ + g_idx = 3; + + if (mxIsEmpty(prhs[2]) == 1) { + H_idx = -1; + nV = (uint_t)mxGetM(prhs[g_idx]); /* if Hessian is empty, row number of gradient vector */ + } else { + H_idx = 2; + nV = (uint_t)mxGetM(prhs[H_idx]); /* row number of Hessian matrix */ + } + + A_idx = 4; + nC = (uint_t)mxGetM(prhs[A_idx]); /* row number of constraint matrix */ + + lb_idx = 5; + ub_idx = 6; + lbA_idx = 7; + ubA_idx = 8; + + /* ensure that data is given in double precision */ + if (((H_idx >= 0) && (mxIsDouble(prhs[H_idx]) == 0)) || (mxIsDouble(prhs[g_idx]) == 0) || + (mxIsDouble(prhs[A_idx]) == 0)) { + myMexErrMsgTxt("ERROR (qpOASES): All data has to be provided in real_t precision!"); + return; + } + + /* check if supplied data contains 'NaN' or 'Inf' */ + if (containsNaNorInf(prhs, H_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, g_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, A_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lb_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ub_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lbA_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ubA_idx, 1) == BT_TRUE) + return; + + /* Check that dimensions are consistent with existing QP instance */ + if (nV != (uint_t)globalQP->getNV() || nC != (uint_t)globalQP->getNC()) { + myMexErrMsgTxt("ERROR (qpOASES): QP dimensions must be constant during a sequence! Try creating a " + "new QP instance instead."); + return; + } + + if ((H_idx >= 0) && ((mxGetN(prhs[H_idx]) != nV) || (mxGetM(prhs[H_idx]) != nV))) { + myMexErrMsgTxt("ERROR (qpOASES): Hessian matrix dimension mismatch!"); + return; + } + + if ((mxGetN(prhs[A_idx]) != 0) && (mxGetN(prhs[A_idx]) != nV)) { + myMexErrMsgTxt("ERROR (qpOASES): Constraint matrix dimension mismatch!"); + return; + } + + if (smartDimensionCheck(&g, nV, 1, BT_FALSE, prhs, g_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lb, nV, 1, BT_TRUE, prhs, lb_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ub, nV, 1, BT_TRUE, prhs, ub_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lbA, nC, 1, BT_TRUE, prhs, lbA_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ubA, nC, 1, BT_TRUE, prhs, ubA_idx) != SUCCESSFUL_RETURN) + return; + + /* default value for nWSR */ + nWSRin = 5 * (nV + nC); + + /* Check whether options are specified .*/ + if (nrhs > 9) + if ((!mxIsEmpty(prhs[9])) && (mxIsStruct(prhs[9]))) + setupOptions(&options, prhs[9], nWSRin, maxCpuTimeIn); + + globalQP->deleteQPMatrices(); + + /* make a deep-copy of the user-specified Hessian matrix (possibly sparse) */ + if (H_idx >= 0) + setupHessianMatrix( + prhs[H_idx], nV, &(globalQP->H), &(globalQP->Hir), &(globalQP->Hjc), &(globalQP->Hv)); + + /* make a deep-copy of the user-specified constraint matrix (possibly sparse) */ + if ((nC > 0) && (A_idx >= 0)) + setupConstraintMatrix( + prhs[A_idx], nV, nC, &(globalQP->A), &(globalQP->Air), &(globalQP->Ajc), &(globalQP->Av)); + + /* Create output vectors and assign pointers to them. */ + allocateOutputs(nlhs, plhs, nV, nC); + + /* Call qpOASES */ + SQProblem_hotstart( + handle, globalQP->H, g, globalQP->A, lb, ub, lbA, ubA, nWSRin, maxCpuTimeIn, &options, nlhs, plhs); + + return; + } + + /* 4) Solve current equality constrained QP. */ + if ((strcmp(typeString, "e") == 0) || (strcmp(typeString, "E") == 0)) { + /* consistency checks */ + if ((nlhs < 1) || (nlhs > 4)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of output arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if ((nrhs < 7) || (nrhs > 8)) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of input arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if ((mxIsDouble(prhs[1]) == false) || (mxIsScalar(prhs[1]) == false)) { + myMexErrMsgTxt("ERROR (qpOASES): Expecting a handle to QP object as second argument!\nType 'help " + "qpOASES_sequence' for further information."); + return; + } + + /* get QP instance */ + handle = (uint_t)mxGetScalar(prhs[1]); + globalQP = getQPInstance(handle); + if (globalQP == 0) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid handle to QP instance!"); + return; + } + + /* Check inputs dimensions and assign pointers to inputs. */ + int_t nRHS = (int_t)mxGetN(prhs[2]); + nV = globalQP->getNV(); + nC = globalQP->getNC(); + real_t *x_out, *y_out; + + g_idx = 2; + lb_idx = 3; + ub_idx = 4; + lbA_idx = 5; + ubA_idx = 6; + + /* check if supplied data contains 'NaN' or 'Inf' */ + if (containsNaNorInf(prhs, g_idx, 0) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lb_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ub_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, lbA_idx, 1) == BT_TRUE) + return; + + if (containsNaNorInf(prhs, ubA_idx, 1) == BT_TRUE) + return; + + if (smartDimensionCheck(&g, nV, nRHS, BT_FALSE, prhs, g_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lb, nV, nRHS, BT_TRUE, prhs, lb_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ub, nV, nRHS, BT_TRUE, prhs, ub_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&lbA, nC, nRHS, BT_TRUE, prhs, lbA_idx) != SUCCESSFUL_RETURN) + return; + + if (smartDimensionCheck(&ubA, nC, nRHS, BT_TRUE, prhs, ubA_idx) != SUCCESSFUL_RETURN) + return; + + /* Check whether options are specified .*/ + if ((nrhs == 8) && (!mxIsEmpty(prhs[7])) && (mxIsStruct(prhs[7]))) { + nWSRin = 5 * (nV + nC); + setupOptions(&options, prhs[7], nWSRin, maxCpuTimeIn); + globalQP->sqp->setOptions(options); + } + + /* Create output vectors and assign pointers to them. */ + plhs[0] = mxCreateDoubleMatrix(nV, nRHS, mxREAL); + x_out = mxGetPr(plhs[0]); + if (nlhs >= 2) { + plhs[1] = mxCreateDoubleMatrix(nV + nC, nRHS, mxREAL); + y_out = mxGetPr(plhs[1]); + + if (nlhs >= 3) { + plhs[2] = mxCreateDoubleMatrix(nV, nRHS, mxREAL); + real_t * workingSetB = mxGetPr(plhs[2]); + globalQP->sqp->getWorkingSetBounds(workingSetB); + + if (nlhs >= 4) { + plhs[3] = mxCreateDoubleMatrix(nC, nRHS, mxREAL); + real_t * workingSetC = mxGetPr(plhs[3]); + globalQP->sqp->getWorkingSetConstraints(workingSetC); + } + } + } else + y_out = new real_t[nV + nC]; + + /* Solve equality constrained QP */ + returnValue returnvalue = globalQP->sqp->solveCurrentEQP(nRHS, g, lb, ub, lbA, ubA, x_out, y_out); + + if (nlhs < 2) + delete[] y_out; + + if (returnvalue != SUCCESSFUL_RETURN) { + char msg[MAX_STRING_LENGTH]; + snprintf( + msg, MAX_STRING_LENGTH, "ERROR (qpOASES): Couldn't solve current EQP (code %d)!", returnvalue); + myMexErrMsgTxt(msg); + return; + } + + return; + } + + /* 5) Cleanup. */ + if ((strcmp(typeString, "c") == 0) || (strcmp(typeString, "C") == 0)) { + /* consistency checks */ + if (nlhs != 0) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of output arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if (nrhs != 2) { + myMexErrMsgTxt("ERROR (qpOASES): Invalid number of input arguments!\nType 'help qpOASES_sequence' " + "for further information."); + return; + } + + if ((mxIsDouble(prhs[1]) == false) || (mxIsScalar(prhs[1]) == false)) { + myMexErrMsgTxt("ERROR (qpOASES): Expecting a handle to QP object as second argument!\nType 'help " + "qpOASES_sequence' for further information."); + return; + } + + /* Cleanup SQProblem instance. */ + handle = (uint_t)mxGetScalar(prhs[1]); + deleteQPInstance(handle); + + return; + } +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_sequence.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_sequence.m new file mode 100755 index 0000000..e064e8b --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/octave/qpOASES_sequence.m @@ -0,0 +1,111 @@ +%qpOASES -- An Implementation of the Online Active Set Strategy. +%Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +%Christian Kirches et al. All rights reserved. +% +%qpOASES is distributed under the terms of the +%GNU Lesser General Public License 2.1 in the hope that it will be +%useful, but WITHOUT ANY WARRANTY; without even the implied warranty +%of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +%See the GNU Lesser General Public License for more details. +% +%--------------------------------------------------------------------------------- +% +%qpOASES_sequence is intended to solve a sequence of quadratic +%programming (QP) problems of the following form: +% +% min 1/2*x'Hx + x'g +% s.t. lb <= x <= ub +% lbA <= Ax <= ubA {optional} +% +%I) Call +% +% [QP,x,fval,exitflag,iter,lambda,auxOutput] = ... +% qpOASES_sequence( 'i',H,g,A,lb,ub,lbA,ubA{,options{,auxInput}} ) +%or +% [QP,x,fval,exitflag,iter,lambda,auxOutput] = ... +% qpOASES_sequence( 'i',H,g,lb,ub{,options{,auxInput}} ) +% +%for initialising and solving the first above-mentioned QP of the sequence +%starting from an initial guess x0. H must be a symmetric (possibly indefinite) +%matrix and all vectors g, lb, ub, lbA, ubA have to be given as column vectors. +%Options can be generated using the qpOASES_options command, otherwise default +%values are used. Optionally, further auxiliary inputs may be generated +%using qpOASES_auxInput command and passed to the solver. +%Both matrices H or A may be passed in sparse matrix format. +% +%II) Call +% +% [x,fval,exitflag,iter,lambda,auxOutput] = ... +% qpOASES_sequence( 'h',QP,g,lb,ub,lbA,ubA{,options} ) +%or +% [x,fval,exitflag,iter,lambda,auxOutput] = ... +% qpOASES_sequence( 'h',QP,g,lb,ub{,options} ) +% +%for hotstarting from the previous QP solution to the one of the next QP +%given by the vectors g, lb, ub, lbA, ubA. Options can be generated using the +%qpOASES_options command, otherwise default values are used. +% +%III) Call +% +% [x,fval,exitflag,iter,lambda,auxOutput] = ... +% qpOASES_sequence( 'm',QP,H,g,A,lb,ub,lbA,ubA{,options} ) +% +%for hotstarting from the previous QP solution to the one of the next QP +%given by the matrices H, A and the vectors g, lb, ub, lbA, ubA. The previous +%active set serves as a starting guess. If the new projected Hessian matrix +%turns out to be not positive definite, qpOASES recedes to a safe initial active +%set guess automatically. This can result in a high number of iterations iter. +%Options can be generated using the qpOASES_options command, otherwise default +%values are used. +% +%IV) Call +% +% [x,lambda,workingSetB,workingSetC] = ... +% qpOASES_sequence( 'e',QP,g,lb,ub,lbA,ubA{,options} ) +% +%for solving the equality constrained QP with constraints determined by the +%current active set. All inequalities and bounds which were not active in the +%previous solution might be violated. This command does not alter the internal +%state of qpOASES. Instead of calling this command multiple times, it is +%possible to supply several columns simultaneously in g, lb, ub, lbA, and ubA. +%Options can be generated using the qpOASES_options command, otherwise default +%values are used. +% +%V) Having solved the last QP of your sequence, call +% +% qpOASES_sequence( 'c',QP ) +% +%in order to cleanup the internal memory. +% +% +%Optional outputs (only x is mandatory): +% x - Optimal primal solution vector (if exitflag==0). +% fval - Optimal objective function value (if exitflag==0). +% exitflag - 0: QP solved, +% 1: QP could not be solved within given number of iterations, +% -1: QP could not be solved due to an internal error, +% -2: QP is infeasible (and thus could not be solved), +% -3: QP is unbounded (and thus could not be solved). +% iter - Number of active set iterations actually performed. +% lambda - Optimal dual solution vector (if exitflag==0). +% auxOutput - Struct containing auxiliary outputs as described below. +% +%The auxOutput struct contains the following entries: +% workingSetB - Working set of bounds at point x. +% workingSetC - Working set of constraints at point x. +% The working set is a subset of the active set (indices +% of bounds/constraints that hold with equality) yielding +% a set linearly independent of bounds/constraints. +% The working sets are encoded as follows: +% 1: bound/constraint at its upper bound +% 0: bound/constraint not at any bound +% -1: bound/constraint at its lower bound +% cpuTime - Internally measured CPU time for solving QP problem. +% +%See also QPOASES_OPTIONS, QPOASES_AUXINPUT, QPOASES +% +% +%For additional information see the qpOASES User's Manual or +%visit http://www.qpOASES.org/. +% +%Please send remarks and questions to support@qpOASES.org! diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/README.rst b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/README.rst new file mode 100755 index 0000000..2b17d11 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/README.rst @@ -0,0 +1,75 @@ +pyqpOASES: a Python interface to qpOASES + +:Author: Sebastian F. Walter, Manuel Kudruss + +Known to work with +------------------ + +* python2.7 +* qpOASES 3.2 (rev 259) + + +Installation +------------ + +Requirements: + + You'll need numpy and cython. Install for instance with:: + + sudo pip install cython + sudo pip install numpy + +Method 1: + + This is a local installation and creates `./interfaces/python/qpoases.so`:: + + make python + + Then, you'll have to update your PYTHONPATH, e.g., on LINUX you have to add:: + + export PYTHONPATH=$PYTHONPATH:/home/swalter/projects/qpOASES/interfaces/python + + to your ``~/.bashrc``. + +Method 2: + + global installation:: + + sudo make pythoninstall + +Method 3:: + + cd ./interfaces/python/ + python setup.py build_ext --inplace + # or python setup.py install + + +Testing your installation +------------------------- + +For a quick test run:: + + cd ./interfaces/python + python example1.py + + +To run a complete unit test you need ``nose``. Install for instance with:: + + sudo pip install nose + +Then:: + + cd ./interfaces/python/ + nosestests ./tests + +The results of the tests can be found in `./interfaces/python/tests/results`. + +Tested setups +------------- + +The Python interface is known to work on + +* Windows, Python 3 +* Linux (Ubuntu 12.04) using Python 2.7.3, Python 3.2.3. NumPy 1.8, Cython 0.19 +* MacOS Mojave (10.14.3) using Python 3.7 (anaconda suite) + diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/examples/cython/example1.pyx b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/examples/cython/example1.pyx new file mode 100755 index 0000000..c837611 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/examples/cython/example1.pyx @@ -0,0 +1,73 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + +## Example adapted from examples/example1.cpp. +## author of this file: Sebastian F. Walter + +import numpy as np +from qpoases import PyQProblem as QProblem +from qpoases import PyPrintLevel as PrintLevel +from qpoases import PyOptions as Options +cimport numpy as np + +def run(): + + #Setup data of QP. + + cdef np.ndarray[np.double_t, ndim=2] H + cdef np.ndarray[np.double_t, ndim=2] A + cdef np.ndarray[np.double_t, ndim=1] g + cdef np.ndarray[np.double_t, ndim=1] lb + cdef np.ndarray[np.double_t, ndim=1] ub + cdef np.ndarray[np.double_t, ndim=1] lbA + cdef np.ndarray[np.double_t, ndim=1] ubA + + H = np.array([1.0, 0.0, 0.0, 0.5 ]).reshape((2,2)) + A = np.array([1.0, 1.0 ]).reshape((2,1)) + g = np.array([1.5, 1.0 ]) + lb = np.array([0.5, -2.0]) + ub = np.array([5.0, 2.0 ]) + lbA = np.array([-1.0 ]) + ubA = np.array([2.0]) + + # Setting up QProblem object. + + cdef example = QProblem(2, 1) + cdef options = Options() + options.printLevel = PrintLevel.NONE + example.setOptions(options) + + # Solve first QP. + + cdef int nWSR = 10 + example.init(H, g, A, lb, ub, lbA, ubA, nWSR) + + # Solve subsequent QPs + + cdef int i,j + for i in range(100000): + for j in range(1, 100): + g[0] = i%j + example.hotstart(g, lb, ub, lbA, ubA, nWSR) + +run() + diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/examples/cython/setup.py b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/examples/cython/setup.py new file mode 100755 index 0000000..d605d2c --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/examples/cython/setup.py @@ -0,0 +1,16 @@ +from distutils.core import setup +from distutils.extension import Extension +from Cython.Distutils import build_ext + +ext_module = Extension( + "example1", + ["example1.pyx"], + extra_compile_args=['-fopenmp'], + extra_link_args=['-fopenmp'], +) + +setup( + name = 'Hello world app', + cmdclass = {'build_ext': build_ext}, + ext_modules = [ext_module], +) diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/examples/example1.py b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/examples/example1.py new file mode 100755 index 0000000..c1a7df4 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/examples/example1.py @@ -0,0 +1,74 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + +## Example adapted from examples/example1.cpp. +## author of this file: Sebastian F. Walter + +import numpy as np +from qpoases import PyQProblem as QProblem +from qpoases import PyOptions as Options +from qpoases import PyPrintLevel as PrintLevel + +#Setup data of first QP. + +H = np.array([1.0, 0.0, 0.0, 0.5 ]).reshape((2,2)) +A = np.array([1.0, 1.0 ]).reshape((2,1)) +g = np.array([1.5, 1.0 ]) +lb = np.array([0.5, -2.0]) +ub = np.array([5.0, 2.0 ]) +lbA = np.array([-1.0 ]) +ubA = np.array([2.0]) + + +# Setup data of second QP. + +g_new = np.array([1.0, 1.5]) +lb_new = np.array([0.0, -1.0]) +ub_new = np.array([5.0, -0.5]) +lbA_new = np.array([-2.0]) +ubA_new = np.array([1.0]) + + +# Setting up QProblem object. + +example = QProblem(2, 1) +options = Options() +#options.printLevel = PrintLevel.NONE +example.setOptions(options) + +# Solve first QP. +nWSR = np.array([10]) +example.init(H, g, A, lb, ub, lbA, ubA, nWSR) + +xOpt = np.zeros(2) +example.getPrimalSolution(xOpt) +print("\nxOpt = [ %e, %e ]; objVal = %e\n\n"%(xOpt[0],xOpt[1],example.getObjVal())) + +# Solve second QP. +nWSR = np.array([10]) +example.hotstart( g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR) + +# Get and print solution of second QP. + +example.getPrimalSolution(xOpt) +print("\nxOpt = [ %e, %e ]; objVal = %e\n\n"%(xOpt[0],xOpt[1],example.getObjVal())) +example.printOptions() diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/examples/example1b.py b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/examples/example1b.py new file mode 100755 index 0000000..989c914 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/examples/example1b.py @@ -0,0 +1,72 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + +## Example adapted from examples/example1b.cpp. +## author of this file: Sebastian F. Walter + +import numpy as np +from qpoases import PyQProblemB as QProblemB +from qpoases import PyBooleanType as BooleanType +from qpoases import PySubjectToStatus as SubjectToStatus +from qpoases import PyOptions as Options + +# Example for qpOASES main function using the QProblemB class. + +#Setup data of first QP. + +H = np.array([1.0, 0.0, 0.0, 0.5 ]).reshape((2,2)) +g = np.array([1.5, 1.0 ]) +lb = np.array([0.5, -2.0]) +ub = np.array([5.0, 2.0 ]) + +# Setup data of second QP. + +g_new = np.array([1.0, 1.5]) +lb_new = np.array([0.0, -1.0]) +ub_new = np.array([5.0, -0.5]) + + +# Setting up QProblemB object. +example = QProblemB(2) + +options = Options() +options.enableFlippingBounds = BooleanType.FALSE +options.initialStatusBounds = SubjectToStatus.INACTIVE +options.numRefinementSteps = 1 + +example.setOptions(options) + +# Solve first QP. +nWSR = np.array([10]) +example.init(H, g, lb, ub, nWSR) +print("\nnWSR = %d\n\n"%nWSR) + +# Solve second QP. +nWSR = np.array([10]) +example.hotstart(g_new, lb_new, ub_new, nWSR) +print("\nnWSR = %d\n\n"% nWSR) + +# Get and print solution of second QP. +xOpt = np.zeros(2) +example.getPrimalSolution(xOpt) +print("\nxOpt = [ %e, %e ]; objVal = %e\n\n" %(xOpt[0], xOpt[1], + example.getObjVal())) diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/examples/example2.py b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/examples/example2.py new file mode 100755 index 0000000..748b7cb --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/examples/example2.py @@ -0,0 +1,94 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + +## Example adapted from examples/example2.cpp. +## author of this file: Sebastian F. Walter + +import os +import sys +import numpy as np +from qpoases import PySQProblem as SQProblem +from qpoases import PySolutionAnalysis as SolutionAnalysis + + +# Setup data of first QP. +H = np.array([ 1.0, 0.0, 0.0, 0.5 ]).reshape((2,2)) +A = np.array([ 1.0, 1.0 ]).reshape((2,1)) +g = np.array([ 1.5, 1.0 ]) +lb = np.array([ 0.5, -2.0 ]) +ub = np.array([ 5.0, 2.0 ]) +lbA = np.array([ -1.0 ]) +ubA = np.array([ 2.0 ]) + +# Setup data of second QP. +H_new = np.array([ 1.0, 0.5, 0.5, 0.5 ]).reshape((2,2)) +A_new = np.array([ 1.0, 5.0 ]).reshape((2,1)) +g_new = np.array([ 1.0, 1.5 ]) +lb_new = np.array([ 0.0, -1.0 ]) +ub_new = np.array([ 5.0, -0.5 ]) +lbA_new = np.array([ -2.0 ]) +ubA_new = np.array([ 1.0 ]) + +# Setting up SQProblem object and solution analyser. +example = SQProblem(2, 1) +analyser = SolutionAnalysis() + +# Solve first QP ... +nWSR = np.array([10]) +example.init(H, g, A, lb, ub, lbA, ubA, nWSR) + +# ... and analyse it. +maxStat = np.zeros(1) +maxFeas = np.zeros(1) +maxCmpl = np.zeros(1) + +analyser.getKktViolation(example, maxStat, maxFeas, maxCmpl) +print("maxStat: %e, maxFeas:%e, maxCmpl: %e\n"%(maxStat, maxFeas, maxCmpl)) + +# Solve second QP ... +nWSR = np.array([10]) +example.hotstart(H_new, g_new, A_new, lb_new, ub_new, + lbA_new, ubA_new, nWSR) + +# ... and analyse it. +analyser.getKktViolation(example, maxStat, maxFeas, maxCmpl) +print("maxStat: %e, maxFeas:%e, maxCmpl: %e\n"%(maxStat, maxFeas, maxCmpl)) + + +# ------------ VARIANCE-COVARIANCE EVALUATION -------------------- + +Var = np.zeros(5*5) +Primal_Dual_Var = np.zeros(5*5) + +Var.reshape((5,5))[0,0] = 1. +Var.reshape((5,5))[1,1] = 1. + +# ( 1 0 0 0 0 ) +# ( 0 1 0 0 0 ) +# Var = ( 0 0 0 0 0 ) +# ( 0 0 0 0 0 ) +# ( 0 0 0 0 0 ) + + +analyser.getVarianceCovariance(example, Var, Primal_Dual_Var) +print('Primal_Dual_Var=\n', Primal_Dual_Var.reshape((5,5))) +print("maxStat: %e, maxFeas:%e, maxCmpl: %e\n"%(maxStat, maxFeas, maxCmpl)) diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/qpoases.pxd b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/qpoases.pxd new file mode 100755 index 0000000..9c92cfc --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/qpoases.pxd @@ -0,0 +1,515 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + +## +## Filename: qpoases.pxd +## Author: Sebastian F. Walter, Manuel Kudruss (thanks to Felix Lenders) +## Version: 3.2 +## Date: 2013-2017 +## + +cdef extern from "qpOASES.hpp" namespace "qpOASES": + + ctypedef double real_t + # NOTE we use long type for integers to be compatible with the C/C++ + # interface in all cases, i.e, either __USE_LONG_INTEGERS__ is defined + # or not. + ctypedef long int_t + + cdef enum BooleanType: + + BT_FALSE + BT_TRUE + + cdef enum PrintLevel: + + PL_DEBUG_ITER = -2 + PL_TABULAR + PL_NONE + PL_LOW + PL_MEDIUM + PL_HIGH + + cdef enum VisibilityStatus: + + VS_HIDDEN + VS_VISIBLE + + cdef enum QProblemStatus: + + QPS_NOTINITIALISED + QPS_PREPARINGAUXILIARYQP + + QPS_AUXILIARYQPSOLVED + + QPS_PERFORMINGHOMOTOPY + + QPS_HOMOTOPYQPSOLVED + QPS_SOLVED + + cdef enum HessianType: + HST_ZERO + HST_IDENTITY + HST_POSDEF + HST_POSDEF_NULLSPACE + HST_SEMIDEF + HST_INDEF + HST_UNKNOWN + + cdef enum SubjectToType: + + ST_UNBOUNDED + ST_BOUNDED + ST_EQUALITY + ST_DISABLED + ST_UNKNOWN + + cdef enum SubjectToStatus: + + ST_LOWER = -1 + ST_INACTIVE + ST_UPPER + ST_INFEASIBLE_LOWER + ST_INFEASIBLE_UPPER + ST_UNDEFINED + + cdef enum returnValue: + TERMINAL_LIST_ELEMENT = -1 + SUCCESSFUL_RETURN = 0 + RET_DIV_BY_ZERO + RET_INDEX_OUT_OF_BOUNDS + RET_INVALID_ARGUMENTS + RET_ERROR_UNDEFINED + RET_WARNING_UNDEFINED + RET_INFO_UNDEFINED + RET_EWI_UNDEFINED + RET_AVAILABLE_WITH_LINUX_ONLY + RET_UNKNOWN_BUG + RET_PRINTLEVEL_CHANGED + RET_NOT_YET_IMPLEMENTED + RET_INDEXLIST_MUST_BE_REORDERD + RET_INDEXLIST_EXCEEDS_MAX_LENGTH + RET_INDEXLIST_CORRUPTED + RET_INDEXLIST_OUTOFBOUNDS + RET_INDEXLIST_ADD_FAILED + RET_INDEXLIST_INTERSECT_FAILED + RET_INDEX_ALREADY_OF_DESIRED_STATUS + RET_ADDINDEX_FAILED + RET_REMOVEINDEX_FAILED + RET_SWAPINDEX_FAILED + RET_NOTHING_TO_DO + RET_SETUP_BOUND_FAILED + RET_SETUP_CONSTRAINT_FAILED + RET_MOVING_BOUND_FAILED + RET_MOVING_CONSTRAINT_FAILED + RET_SHIFTING_FAILED + RET_ROTATING_FAILED + RET_QPOBJECT_NOT_SETUP + RET_QP_ALREADY_INITIALISED + RET_NO_INIT_WITH_STANDARD_SOLVER + RET_RESET_FAILED + RET_INIT_FAILED + RET_INIT_FAILED_TQ + RET_INIT_FAILED_CHOLESKY + RET_INIT_FAILED_HOTSTART + RET_INIT_FAILED_INFEASIBILITY + RET_INIT_FAILED_UNBOUNDEDNESS + RET_INIT_FAILED_REGULARISATION + RET_INIT_SUCCESSFUL + RET_OBTAINING_WORKINGSET_FAILED + RET_SETUP_WORKINGSET_FAILED + RET_SETUP_AUXILIARYQP_FAILED + RET_NO_CHOLESKY_WITH_INITIAL_GUESS + RET_NO_EXTERN_SOLVER + RET_QP_UNBOUNDED + RET_QP_INFEASIBLE + RET_QP_NOT_SOLVED + RET_QP_SOLVED + RET_UNABLE_TO_SOLVE_QP + RET_INITIALISATION_STARTED + RET_HOTSTART_FAILED + RET_HOTSTART_FAILED_TO_INIT + RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED + RET_ITERATION_STARTED + RET_SHIFT_DETERMINATION_FAILED + RET_STEPDIRECTION_DETERMINATION_FAILED + RET_STEPLENGTH_DETERMINATION_FAILED + RET_OPTIMAL_SOLUTION_FOUND + RET_HOMOTOPY_STEP_FAILED + RET_HOTSTART_STOPPED_INFEASIBILITY + RET_HOTSTART_STOPPED_UNBOUNDEDNESS + RET_WORKINGSET_UPDATE_FAILED + RET_MAX_NWSR_REACHED + RET_CONSTRAINTS_NOT_SPECIFIED + RET_INVALID_FACTORISATION_FLAG + RET_UNABLE_TO_SAVE_QPDATA + RET_STEPDIRECTION_FAILED_TQ + RET_STEPDIRECTION_FAILED_CHOLESKY + RET_CYCLING_DETECTED + RET_CYCLING_NOT_RESOLVED + RET_CYCLING_RESOLVED + RET_STEPSIZE + RET_STEPSIZE_NONPOSITIVE + RET_SETUPSUBJECTTOTYPE_FAILED + RET_ADDCONSTRAINT_FAILED + RET_ADDCONSTRAINT_FAILED_INFEASIBILITY + RET_ADDBOUND_FAILED + RET_ADDBOUND_FAILED_INFEASIBILITY + RET_REMOVECONSTRAINT_FAILED + RET_REMOVEBOUND_FAILED + RET_REMOVE_FROM_ACTIVESET + RET_ADD_TO_ACTIVESET + RET_REMOVE_FROM_ACTIVESET_FAILED + RET_ADD_TO_ACTIVESET_FAILED + RET_CONSTRAINT_ALREADY_ACTIVE + RET_ALL_CONSTRAINTS_ACTIVE + RET_LINEARLY_DEPENDENT + RET_LINEARLY_INDEPENDENT + RET_LI_RESOLVED + RET_ENSURELI_FAILED + RET_ENSURELI_FAILED_TQ + RET_ENSURELI_FAILED_NOINDEX + RET_ENSURELI_FAILED_CYCLING + RET_BOUND_ALREADY_ACTIVE + RET_ALL_BOUNDS_ACTIVE + RET_CONSTRAINT_NOT_ACTIVE + RET_BOUND_NOT_ACTIVE + RET_HESSIAN_NOT_SPD + RET_HESSIAN_INDEFINITE + RET_MATRIX_SHIFT_FAILED + RET_MATRIX_FACTORISATION_FAILED + RET_PRINT_ITERATION_FAILED + RET_NO_GLOBAL_MESSAGE_OUTPUTFILE + RET_DISABLECONSTRAINTS_FAILED + RET_ENABLECONSTRAINTS_FAILED + RET_ALREADY_ENABLED + RET_ALREADY_DISABLED + RET_NO_HESSIAN_SPECIFIED + RET_USING_REGULARISATION + RET_EPS_MUST_BE_POSITVE + RET_REGSTEPS_MUST_BE_POSITVE + RET_HESSIAN_ALREADY_REGULARISED + RET_CANNOT_REGULARISE_IDENTITY + RET_CANNOT_REGULARISE_SPARSE + RET_NO_REGSTEP_NWSR + RET_FEWER_REGSTEPS_NWSR + RET_CHOLESKY_OF_ZERO_HESSIAN + RET_ZERO_HESSIAN_ASSUMED + RET_CONSTRAINTS_ARE_NOT_SCALED + RET_INITIAL_BOUNDS_STATUS_NYI + RET_ERROR_IN_CONSTRAINTPRODUCT + RET_FIX_BOUNDS_FOR_LP + RET_USE_REGULARISATION_FOR_LP + RET_UPDATEMATRICES_FAILED + RET_UPDATEMATRICES_FAILED_AS_QP_NOT_SOLVED + RET_UNABLE_TO_OPEN_FILE + RET_UNABLE_TO_WRITE_FILE + RET_UNABLE_TO_READ_FILE + RET_FILEDATA_INCONSISTENT + RET_UNABLE_TO_ANALYSE_QPROBLEM + RET_OPTIONS_ADJUSTED + RET_NWSR_SET_TO_ONE + RET_UNABLE_TO_READ_BENCHMARK + RET_BENCHMARK_ABORTED + RET_INITIAL_QP_SOLVED + RET_QP_SOLUTION_STARTED + RET_BENCHMARK_SUCCESSFUL + RET_NO_DIAGONAL_AVAILABLE + RET_DIAGONAL_NOT_INITIALISED + RET_ENSURELI_DROPPED + RET_KKT_MATRIX_SINGULAR + RET_QR_FACTORISATION_FAILED + RET_INERTIA_CORRECTION_FAILED + RET_NO_SPARSE_SOLVER + RET_SIMPLE_STATUS_P1 + RET_SIMPLE_STATUS_P0 + RET_SIMPLE_STATUS_M1 + RET_SIMPLE_STATUS_M2 + RET_SIMPLE_STATUS_M3 + + + cdef cppclass Options: + + Options() + Options(const Options&) + # Options& operator=( const Options&) # equality operator cannot be overloaded in Python + returnValue setToDefault() + returnValue setToReliable() + returnValue setToMPC() + returnValue setToFast() + returnValue ensureConsistency() + # returnValue print() # print is a reserved keyword in Python + returnValue copy(const Options& ) + + PrintLevel printLevel + + BooleanType enableRamping + BooleanType enableFarBounds + BooleanType enableFlippingBounds + BooleanType enableRegularisation + BooleanType enableFullLITests + BooleanType enableNZCTests + int_t enableDriftCorrection + int_t enableCholeskyRefactorisation + BooleanType enableEqualities + + real_t terminationTolerance + real_t boundTolerance + real_t boundRelaxation + real_t epsNum + real_t epsDen + real_t maxPrimalJump + real_t maxDualJump + + real_t initialRamping + real_t finalRamping + real_t initialFarBounds + real_t growFarBounds + SubjectToStatus initialStatusBounds + real_t epsFlipping + int_t numRegularisationSteps + real_t epsRegularisation + int_t numRefinementSteps + real_t epsIterRef + real_t epsLITests + real_t epsNZCTests + + real_t rcondSMin + BooleanType enableInertiaCorrection + + BooleanType enableDropInfeasibles + int_t dropBoundPriority + int_t dropEqConPriority + int_t dropIneqConPriority + + + cdef cppclass Bounds: + Bounds() + + + cdef cppclass Constraints: + Constraints() + + + cdef cppclass QProblemB: + QProblemB() + QProblemB(int_t, HessianType, BooleanType) + + QProblemB(const QProblemB&) + + returnValue init(real_t*, + real_t*, + real_t*, + real_t*, + int_t&) + + returnValue init(real_t*, + real_t*, + real_t*, + real_t*, + int_t&, + real_t*) + + returnValue hotstart(real_t*, + real_t*, + real_t*, + int_t&) + + returnValue hotstart(real_t*, + real_t*, + real_t*, + int_t&, + real_t*) + + + returnValue getPrimalSolution(real_t*) + returnValue getDualSolution(real_t*) + returnValue printOptions() + real_t getObjVal() + + Options getOptions() + returnValue setOptions(Options&) + + cdef cppclass QProblem: + QProblem() + QProblem(int_t, int_t, HessianType, BooleanType) + + QProblem(const QProblem&) + + returnValue init(real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + int_t&) + + returnValue init(real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + int_t&, + real_t*) + + returnValue hotstart(real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + int_t&) + + returnValue hotstart(real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + int_t&, + real_t*) + + returnValue getPrimalSolution(real_t*) + returnValue getDualSolution(real_t*) + returnValue printOptions() + real_t getObjVal() + + Options getOptions() + returnValue setOptions(Options&) + + + cdef cppclass SQProblem: + SQProblem() + SQProblem(int_t, int_t, HessianType, BooleanType) + + SQProblem(const QProblem&) + + returnValue init(real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + int_t&) + + returnValue init(real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + int_t&, + real_t*) + + returnValue init(real_t* _H, + real_t* _g, + real_t* _A, + real_t* _lb, + real_t* _ub, + real_t* _lbA, + real_t* _ubA, + int_t& nWSR, + real_t* cputime, + real_t* xOpt, + real_t* yOpt, + Bounds* guessedBounds, + Constraints* guessedConstraints, + real_t* _R) + + + returnValue hotstart(real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + int_t&) + + returnValue hotstart(real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + real_t*, + int_t&, + real_t*) + + returnValue getPrimalSolution(real_t*) + returnValue getDualSolution(real_t*) + returnValue printOptions() + real_t getObjVal() + + Options getOptions() + returnValue setOptions(Options&) + +cdef extern from "qpOASES/extras/SolutionAnalysis.hpp" namespace "qpOASES": + cdef cppclass SolutionAnalysis: + SolutionAnalysis() + SolutionAnalysis(const SolutionAnalysis&) + # ~SolutionAnalysis() + # SolutionAnalysis& operator=(const SolutionAnalysis&) + real_t getKktViolation(const QProblem*, const real_t*, const real_t*, const real_t*) + real_t getKktViolation(const QProblemB*, const real_t*, const real_t*, const real_t*) + real_t getKktViolation(const SQProblem*, const real_t*, const real_t*, const real_t*) + returnValue getVarianceCovariance(QProblem*, real_t*, real_t*) + returnValue getVarianceCovariance(QProblemB*, real_t*, real_t*) + returnValue getVarianceCovariance(SQProblem*, real_t*, real_t*) + + +cdef extern from "qpOASES/Utils.hpp" namespace "qpOASES": + pass + #void getKktViolation(int_t nV, # Number of variables. + # int_t nC, # Number of constraints. + # const real_t* const H, # Hessian matrix. + # const real_t* const g, # Sequence of gradient vectors. + # const real_t* const A, # Constraint matrix. + # const real_t* const lb, # Sequence of lower bound vectors (on variables). + # const real_t* const ub, # Sequence of upper bound vectors (on variables). + # const real_t* const lbA, # Sequence of lower constraints' bound vectors. + # const real_t* const ubA, # Sequence of upper constraints' bound vectors. + # const real_t* const x, # Sequence of primal trial vectors. + # const real_t* const y, # Sequence of dual trial vectors. + # real_t& stat, # Maximum value of stationarity condition residual. + # real_t& feas, # Maximum value of primal feasibility violation. + # real_t& cmpl # Maximum value of complementarity residual. + # ) + + +cdef extern from "qpOASES/extras/OQPinterface.hpp" namespace "qpOASES": + returnValue runOqpBenchmark(const char* path, # Full path of the benchmark files (without trailing slash!). + BooleanType isSparse, # Shall convert matrices to sparse format before solution? + BooleanType useHotstarts, # Shall QP solution be hotstarted? + const Options& options, # QP solver options to be used while solving benchmark problems. + int_t maxAllowedNWSR, # Maximum number of working set recalculations to be performed. + real_t& maxNWSR, # Output: Maximum number of performed working set recalculations. + real_t& avgNWSR, # Output: Average number of performed working set recalculations. + real_t& maxCPUtime, # Output: Maximum CPU time required for solving each QP. + real_t& avgCPUtime, # Output: Average CPU time required for solving each QP. + real_t& maxStationarity, # Output: Maximum residual of stationarity condition. + real_t& maxFeasibility, # Output: Maximum residual of primal feasibility condition. + real_t& maxComplementarity # Output: Maximum residual of complementarity condition. + ) diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/qpoases.pyx b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/qpoases.pyx new file mode 100755 index 0000000..eb85542 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/qpoases.pyx @@ -0,0 +1,920 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + +## authors of this file: Sebastian F. Walter (thanks to Felix Lenders) + +""" +Python interface to qpOASES +using Cython +:author: Sebastian F. Walter, Manuel Kudruss (thanks to Felix Lenders) +""" + +import warnings +warnings.simplefilter("once", DeprecationWarning) +import numpy as np +cimport numpy as np + +from cython.operator cimport dereference as deref + +cimport qpoases + +def deprecation_warning_nWSR(): + warnings.warn("\nInteger nWSR will be deprecated in qpOASES 4.0.\nUse nWSR = numpy.array([10]) as input to qp.init() and qp.hotstart()", DeprecationWarning, stacklevel=2) + +def deprecation_warning_cputime(): + warnings.warn("\nFloat cputime will be deprecated in qpOASES 4.0.\nUse cputime = numpy.array([2.0]) as input to qp.init() and qp.hotstart()", DeprecationWarning, stacklevel=2) + + +cdef str __version__ = "3.2.2" + +cdef class PyBooleanType: + FALSE = BT_FALSE + TRUE = BT_TRUE + +cdef class PyPrintLevel: + DEBUG_ITER = PL_DEBUG_ITER + TABULAR = PL_TABULAR + NONE = PL_NONE + LOW = PL_LOW + MEDIUM = PL_MEDIUM + HIGH = PL_HIGH + +cdef class PyHessianType: + ZERO = HST_ZERO + IDENTITY = HST_IDENTITY + POSDEF = HST_POSDEF + POSDEF_NULLSPACE = HST_POSDEF_NULLSPACE + SEMIDEF = HST_SEMIDEF + INDEF = HST_INDEF + UNKNOWN = HST_UNKNOWN + +cdef class PySubjectToStatus: + LOWER = ST_LOWER + INACTIVE = ST_INACTIVE + UPPER = ST_UPPER + INFEASIBLE_LOWER = ST_INFEASIBLE_LOWER + INFEASIBLE_UPPER = ST_INFEASIBLE_UPPER + UNDEFINED = ST_UNDEFINED + +cdef class PyReturnValue: + TERMINAL_LIST_ELEMENT = -1 + SUCCESSFUL_RETURN = 0 + DIV_BY_ZERO = RET_DIV_BY_ZERO + INDEX_OUT_OF_BOUNDS = RET_INDEX_OUT_OF_BOUNDS + INVALID_ARGUMENTS = RET_INVALID_ARGUMENTS + ERROR_UNDEFINED = RET_ERROR_UNDEFINED + WARNING_UNDEFINED = RET_WARNING_UNDEFINED + INFO_UNDEFINED = RET_INFO_UNDEFINED + EWI_UNDEFINED = RET_EWI_UNDEFINED + AVAILABLE_WITH_LINUX_ONLY = RET_AVAILABLE_WITH_LINUX_ONLY + UNKNOWN_BUG = RET_UNKNOWN_BUG + PRINTLEVEL_CHANGED = RET_PRINTLEVEL_CHANGED + NOT_YET_IMPLEMENTED = RET_NOT_YET_IMPLEMENTED + INDEXLIST_MUST_BE_REORDERD = RET_INDEXLIST_MUST_BE_REORDERD + INDEXLIST_EXCEEDS_MAX_LENGTH = RET_INDEXLIST_EXCEEDS_MAX_LENGTH + INDEXLIST_CORRUPTED = RET_INDEXLIST_CORRUPTED + INDEXLIST_OUTOFBOUNDS = RET_INDEXLIST_OUTOFBOUNDS + INDEXLIST_ADD_FAILED = RET_INDEXLIST_ADD_FAILED + INDEXLIST_INTERSECT_FAILED = RET_INDEXLIST_INTERSECT_FAILED + INDEX_ALREADY_OF_DESIRED_STATUS = RET_INDEX_ALREADY_OF_DESIRED_STATUS + ADDINDEX_FAILED = RET_ADDINDEX_FAILED + REMOVEINDEX_FAILED = RET_REMOVEINDEX_FAILED + SWAPINDEX_FAILED = RET_SWAPINDEX_FAILED + NOTHING_TO_DO = RET_NOTHING_TO_DO + SETUP_BOUND_FAILED = RET_SETUP_BOUND_FAILED + SETUP_CONSTRAINT_FAILED = RET_SETUP_CONSTRAINT_FAILED + MOVING_BOUND_FAILED = RET_MOVING_BOUND_FAILED + MOVING_CONSTRAINT_FAILED = RET_MOVING_CONSTRAINT_FAILED + SHIFTING_FAILED = RET_SHIFTING_FAILED + ROTATING_FAILED = RET_ROTATING_FAILED + QPOBJECT_NOT_SETUP = RET_QPOBJECT_NOT_SETUP + QP_ALREADY_INITIALISED = RET_QP_ALREADY_INITIALISED + NO_INIT_WITH_STANDARD_SOLVER = RET_NO_INIT_WITH_STANDARD_SOLVER + RESET_FAILED = RET_RESET_FAILED + INIT_FAILED = RET_INIT_FAILED + INIT_FAILED_TQ = RET_INIT_FAILED_TQ + INIT_FAILED_CHOLESKY = RET_INIT_FAILED_CHOLESKY + INIT_FAILED_HOTSTART = RET_INIT_FAILED_HOTSTART + INIT_FAILED_INFEASIBILITY = RET_INIT_FAILED_INFEASIBILITY + INIT_FAILED_UNBOUNDEDNESS = RET_INIT_FAILED_UNBOUNDEDNESS + INIT_FAILED_REGULARISATION = RET_INIT_FAILED_REGULARISATION + INIT_SUCCESSFUL = RET_INIT_SUCCESSFUL + OBTAINING_WORKINGSET_FAILED = RET_OBTAINING_WORKINGSET_FAILED + SETUP_WORKINGSET_FAILED = RET_SETUP_WORKINGSET_FAILED + SETUP_AUXILIARYQP_FAILED = RET_SETUP_AUXILIARYQP_FAILED + NO_CHOLESKY_WITH_INITIAL_GUESS = RET_NO_CHOLESKY_WITH_INITIAL_GUESS + NO_EXTERN_SOLVER = RET_NO_EXTERN_SOLVER + QP_UNBOUNDED = RET_QP_UNBOUNDED + QP_INFEASIBLE = RET_QP_INFEASIBLE + QP_NOT_SOLVED = RET_QP_NOT_SOLVED + QP_SOLVED = RET_QP_SOLVED + UNABLE_TO_SOLVE_QP = RET_UNABLE_TO_SOLVE_QP + INITIALISATION_STARTED = RET_INITIALISATION_STARTED + HOTSTART_FAILED = RET_HOTSTART_FAILED + HOTSTART_FAILED_TO_INIT = RET_HOTSTART_FAILED_TO_INIT + HOTSTART_FAILED_AS_QP_NOT_INITIALISED = RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED + ITERATION_STARTED = RET_ITERATION_STARTED + SHIFT_DETERMINATION_FAILED = RET_SHIFT_DETERMINATION_FAILED + STEPDIRECTION_DETERMINATION_FAILED = RET_STEPDIRECTION_DETERMINATION_FAILED + STEPLENGTH_DETERMINATION_FAILED = RET_STEPLENGTH_DETERMINATION_FAILED + OPTIMAL_SOLUTION_FOUND = RET_OPTIMAL_SOLUTION_FOUND + HOMOTOPY_STEP_FAILED = RET_HOMOTOPY_STEP_FAILED + HOTSTART_STOPPED_INFEASIBILITY = RET_HOTSTART_STOPPED_INFEASIBILITY + HOTSTART_STOPPED_UNBOUNDEDNESS = RET_HOTSTART_STOPPED_UNBOUNDEDNESS + WORKINGSET_UPDATE_FAILED = RET_WORKINGSET_UPDATE_FAILED + MAX_NWSR_REACHED = RET_MAX_NWSR_REACHED + CONSTRAINTS_NOT_SPECIFIED = RET_CONSTRAINTS_NOT_SPECIFIED + INVALID_FACTORISATION_FLAG = RET_INVALID_FACTORISATION_FLAG + UNABLE_TO_SAVE_QPDATA = RET_UNABLE_TO_SAVE_QPDATA + STEPDIRECTION_FAILED_TQ = RET_STEPDIRECTION_FAILED_TQ + STEPDIRECTION_FAILED_CHOLESKY = RET_STEPDIRECTION_FAILED_CHOLESKY + CYCLING_DETECTED = RET_CYCLING_DETECTED + CYCLING_NOT_RESOLVED = RET_CYCLING_NOT_RESOLVED + CYCLING_RESOLVED = RET_CYCLING_RESOLVED + STEPSIZE = RET_STEPSIZE + STEPSIZE_NONPOSITIVE = RET_STEPSIZE_NONPOSITIVE + SETUPSUBJECTTOTYPE_FAILED = RET_SETUPSUBJECTTOTYPE_FAILED + ADDCONSTRAINT_FAILED = RET_ADDCONSTRAINT_FAILED + ADDCONSTRAINT_FAILED_INFEASIBILITY = RET_ADDCONSTRAINT_FAILED_INFEASIBILITY + ADDBOUND_FAILED = RET_ADDBOUND_FAILED + ADDBOUND_FAILED_INFEASIBILITY = RET_ADDBOUND_FAILED_INFEASIBILITY + REMOVECONSTRAINT_FAILED = RET_REMOVECONSTRAINT_FAILED + REMOVEBOUND_FAILED = RET_REMOVEBOUND_FAILED + REMOVE_FROM_ACTIVESET = RET_REMOVE_FROM_ACTIVESET + ADD_TO_ACTIVESET = RET_ADD_TO_ACTIVESET + REMOVE_FROM_ACTIVESET_FAILED = RET_REMOVE_FROM_ACTIVESET_FAILED + ADD_TO_ACTIVESET_FAILED = RET_ADD_TO_ACTIVESET_FAILED + CONSTRAINT_ALREADY_ACTIVE = RET_CONSTRAINT_ALREADY_ACTIVE + ALL_CONSTRAINTS_ACTIVE = RET_ALL_CONSTRAINTS_ACTIVE + LINEARLY_DEPENDENT = RET_LINEARLY_DEPENDENT + LINEARLY_INDEPENDENT = RET_LINEARLY_INDEPENDENT + LI_RESOLVED = RET_LI_RESOLVED + ENSURELI_FAILED = RET_ENSURELI_FAILED + ENSURELI_FAILED_TQ = RET_ENSURELI_FAILED_TQ + ENSURELI_FAILED_NOINDEX = RET_ENSURELI_FAILED_NOINDEX + ENSURELI_FAILED_CYCLING = RET_ENSURELI_FAILED_CYCLING + BOUND_ALREADY_ACTIVE = RET_BOUND_ALREADY_ACTIVE + ALL_BOUNDS_ACTIVE = RET_ALL_BOUNDS_ACTIVE + CONSTRAINT_NOT_ACTIVE = RET_CONSTRAINT_NOT_ACTIVE + BOUND_NOT_ACTIVE = RET_BOUND_NOT_ACTIVE + HESSIAN_NOT_SPD = RET_HESSIAN_NOT_SPD + HESSIAN_INDEFINITE = RET_HESSIAN_INDEFINITE + MATRIX_SHIFT_FAILED = RET_MATRIX_SHIFT_FAILED + MATRIX_FACTORISATION_FAILED = RET_MATRIX_FACTORISATION_FAILED + PRINT_ITERATION_FAILED = RET_PRINT_ITERATION_FAILED + NO_GLOBAL_MESSAGE_OUTPUTFILE = RET_NO_GLOBAL_MESSAGE_OUTPUTFILE + DISABLECONSTRAINTS_FAILED = RET_DISABLECONSTRAINTS_FAILED + ENABLECONSTRAINTS_FAILED = RET_ENABLECONSTRAINTS_FAILED + ALREADY_ENABLED = RET_ALREADY_ENABLED + ALREADY_DISABLED = RET_ALREADY_DISABLED + NO_HESSIAN_SPECIFIED = RET_NO_HESSIAN_SPECIFIED + USING_REGULARISATION = RET_USING_REGULARISATION + EPS_MUST_BE_POSITVE = RET_EPS_MUST_BE_POSITVE + REGSTEPS_MUST_BE_POSITVE = RET_REGSTEPS_MUST_BE_POSITVE + HESSIAN_ALREADY_REGULARISED = RET_HESSIAN_ALREADY_REGULARISED + CANNOT_REGULARISE_IDENTITY = RET_CANNOT_REGULARISE_IDENTITY + CANNOT_REGULARISE_SPARSE = RET_CANNOT_REGULARISE_SPARSE + NO_REGSTEP_NWSR = RET_NO_REGSTEP_NWSR + FEWER_REGSTEPS_NWSR = RET_FEWER_REGSTEPS_NWSR + CHOLESKY_OF_ZERO_HESSIAN = RET_CHOLESKY_OF_ZERO_HESSIAN + ZERO_HESSIAN_ASSUMED = RET_ZERO_HESSIAN_ASSUMED + CONSTRAINTS_ARE_NOT_SCALED = RET_CONSTRAINTS_ARE_NOT_SCALED + INITIAL_BOUNDS_STATUS_NYI = RET_INITIAL_BOUNDS_STATUS_NYI + ERROR_IN_CONSTRAINTPRODUCT = RET_ERROR_IN_CONSTRAINTPRODUCT + FIX_BOUNDS_FOR_LP = RET_FIX_BOUNDS_FOR_LP + USE_REGULARISATION_FOR_LP = RET_USE_REGULARISATION_FOR_LP + UPDATEMATRICES_FAILED = RET_UPDATEMATRICES_FAILED + UPDATEMATRICES_FAILED_AS_QP_NOT_SOLVED= RET_UPDATEMATRICES_FAILED_AS_QP_NOT_SOLVED + UNABLE_TO_OPEN_FILE = RET_UNABLE_TO_OPEN_FILE + UNABLE_TO_WRITE_FILE = RET_UNABLE_TO_WRITE_FILE + UNABLE_TO_READ_FILE = RET_UNABLE_TO_READ_FILE + FILEDATA_INCONSISTENT = RET_FILEDATA_INCONSISTENT + UNABLE_TO_ANALYSE_QPROBLEM = RET_UNABLE_TO_ANALYSE_QPROBLEM + OPTIONS_ADJUSTED = RET_OPTIONS_ADJUSTED + NWSR_SET_TO_ONE = RET_NWSR_SET_TO_ONE + UNABLE_TO_READ_BENCHMARK = RET_UNABLE_TO_READ_BENCHMARK + BENCHMARK_ABORTED = RET_BENCHMARK_ABORTED + INITIAL_QP_SOLVED = RET_INITIAL_QP_SOLVED + QP_SOLUTION_STARTED = RET_QP_SOLUTION_STARTED + BENCHMARK_SUCCESSFUL = RET_BENCHMARK_SUCCESSFUL + NO_DIAGONAL_AVAILABLE = RET_NO_DIAGONAL_AVAILABLE + DIAGONAL_NOT_INITIALISED = RET_DIAGONAL_NOT_INITIALISED + ENSURELI_DROPPED = RET_ENSURELI_DROPPED + KKT_MATRIX_SINGULAR = RET_KKT_MATRIX_SINGULAR + QR_FACTORISATION_FAILED = RET_QR_FACTORISATION_FAILED + INERTIA_CORRECTION_FAILED = RET_INERTIA_CORRECTION_FAILED + NO_SPARSE_SOLVER = RET_NO_SPARSE_SOLVER + SIMPLE_STATUS_P1 = RET_SIMPLE_STATUS_P1 + SIMPLE_STATUS_P0 = RET_SIMPLE_STATUS_P0 + SIMPLE_STATUS_M1 = RET_SIMPLE_STATUS_M1 + SIMPLE_STATUS_M2 = RET_SIMPLE_STATUS_M2 + SIMPLE_STATUS_M3 = RET_SIMPLE_STATUS_M3 + + + +cdef class PyOptions: + cdef Options *thisptr # hold a C++ instance which we're wrapping + def __cinit__(self): + # FIXME: add support for the other constructors + self.thisptr = new Options() + + def __dealloc__(self): + del self.thisptr + + def setToDefault(self): + return self.thisptr.setToDefault() + + def setToReliable(self): + return self.thisptr.setToReliable() + + def setToMPC(self): + return self.thisptr.setToMPC() + + def setToFast(self): + return self.thisptr.setToFast() + + def ensureConsistency(self): + return self.thisptr.ensureConsistency() + + property printLevel: + def __get__(self): return self.thisptr.printLevel + def __set__(self, printLevel): self.thisptr.printLevel = printLevel + + property enableRamping: + def __get__(self): return self.thisptr.enableRamping + def __set__(self, enableRamping): self.thisptr.enableRamping = enableRamping + + property enableFarBounds: + def __get__(self): return self.thisptr.enableFarBounds + def __set__(self, enableFarBounds): self.thisptr.enableFarBounds = enableFarBounds + + property enableFlippingBounds: + def __get__(self): return self.thisptr.enableFlippingBounds + def __set__(self, enableFlippingBounds): self.thisptr.enableFlippingBounds = enableFlippingBounds + + property enableRegularisation: + def __get__(self): return self.thisptr.enableRegularisation + def __set__(self, enableRegularisation): self.thisptr.enableRegularisation = enableRegularisation + + property enableFullLITests: + def __get__(self): return self.thisptr.enableFullLITests + def __set__(self, enableFullLITests): self.thisptr.enableFullLITests = enableFullLITests + + property enableNZCTests: + def __get__(self): return self.thisptr.enableNZCTests + def __set__(self, enableNZCTests): self.thisptr.enableNZCTests = enableNZCTests + + property enableDriftCorrection: + def __get__(self): return self.thisptr.enableDriftCorrection + def __set__(self, enableDriftCorrection): self.thisptr.enableDriftCorrection = enableDriftCorrection + + property enableCholeskyRefactorisation: + def __get__(self): return self.thisptr.enableCholeskyRefactorisation + def __set__(self, enableCholeskyRefactorisation): self.thisptr.enableCholeskyRefactorisation = enableCholeskyRefactorisation + + property enableEqualities: + def __get__(self): return self.thisptr.enableEqualities + def __set__(self, enableEqualities): self.thisptr.enableEqualities = enableEqualities + + property terminationTolerance: + def __get__(self): return self.thisptr.terminationTolerance + def __set__(self, terminationTolerance): self.thisptr.terminationTolerance = terminationTolerance + + property boundTolerance: + def __get__(self): return self.thisptr.boundTolerance + def __set__(self, boundTolerance): self.thisptr.boundTolerance = boundTolerance + + property boundRelaxation: + def __get__(self): return self.thisptr.boundRelaxation + def __set__(self, boundRelaxation): self.thisptr.boundRelaxation = boundRelaxation + + property epsNum: + def __get__(self): return self.thisptr.epsNum + def __set__(self, epsNum): self.thisptr.epsNum = epsNum + + property epsDen: + def __get__(self): return self.thisptr.epsDen + def __set__(self, epsDen): self.thisptr.epsDen = epsDen + + property maxPrimalJump: + def __get__(self): return self.thisptr.maxPrimalJump + def __set__(self, maxPrimalJump): self.thisptr.maxPrimalJump = maxPrimalJump + + property maxDualJump: + def __get__(self): return self.thisptr.maxDualJump + def __set__(self, maxDualJump): self.thisptr.maxDualJump = maxDualJump + + property initialRamping: + def __get__(self): return self.thisptr.initialRamping + def __set__(self, initialRamping): self.thisptr.initialRamping = initialRamping + + property finalRamping: + def __get__(self): return self.thisptr.finalRamping + def __set__(self, finalRamping): self.thisptr.finalRamping = finalRamping + + property initialFarBounds: + def __get__(self): return self.thisptr.initialFarBounds + def __set__(self, initialFarBounds): self.thisptr.initialFarBounds = initialFarBounds + + property growFarBounds: + def __get__(self): return self.thisptr.growFarBounds + def __set__(self, growFarBounds): self.thisptr.growFarBounds = growFarBounds + + property initialStatusBounds: + def __get__(self): return self.thisptr.initialStatusBounds + def __set__(self, initialStatusBounds): self.thisptr.initialStatusBounds = initialStatusBounds + + property epsFlipping: + def __get__(self): return self.thisptr.epsFlipping + def __set__(self, epsFlipping): self.thisptr.epsFlipping = epsFlipping + + property numRegularisationSteps: + def __get__(self): return self.thisptr.numRegularisationSteps + def __set__(self, numRegularisationSteps): self.thisptr.numRegularisationSteps = numRegularisationSteps + + property epsRegularisation: + def __get__(self): return self.thisptr.epsRegularisation + def __set__(self, epsRegularisation): self.thisptr.epsRegularisation = epsRegularisation + + property numRefinementSteps: + def __get__(self): return self.thisptr.numRefinementSteps + def __set__(self, numRefinementSteps): self.thisptr.numRefinementSteps = numRefinementSteps + + property epsIterRef: + def __get__(self): return self.thisptr.epsIterRef + def __set__(self, epsIterRef): self.thisptr.epsIterRef = epsIterRef + + property epsLITests: + def __get__(self): return self.thisptr.epsLITests + def __set__(self, epsLITests): self.thisptr.epsLITests = epsLITests + + property epsNZCTests: + def __get__(self): return self.thisptr.epsNZCTests + def __set__(self, epsNZCTests): self.thisptr.epsNZCTests = epsNZCTests + + property dropBoundPriority: + def __get__(self): return self.thisptr.dropBoundPriority + def __set__(self, dropBoundPriority): self.thisptr.dropBoundPriority = dropBoundPriority + + property dropEqConPriority: + def __get__(self): return self.thisptr.dropEqConPriority + def __set__(self, dropEqConPriority): self.thisptr.dropEqConPriority = dropEqConPriority + + property dropIneqConPriority: + def __get__(self): return self.thisptr.dropIneqConPriority + def __set__(self, dropIneqConPriority): self.thisptr.dropIneqConPriority = dropIneqConPriority + + + +cdef class PyQProblemB: + cdef QProblemB *thisptr # hold a C++ instance which we're wrapping + def __cinit__(self, long nV): + # FIXME: allow other HessianTypes! + self.thisptr = new QProblemB( nV, HST_UNKNOWN, BT_TRUE) + + def __dealloc__(self): + del self.thisptr + + def init(self, + np.ndarray[np.double_t, ndim=2] H, + np.ndarray[np.double_t, ndim=1] g, + np.ndarray[np.double_t, ndim=1] lb, + np.ndarray[np.double_t, ndim=1] ub, + nWSR, + cputime = 0.0 + ): + # FIXME: add asserts + cdef np.ndarray nWSR_tmp + cdef np.ndarray cput_tmp + + # enable nWSR as return value in argument list + if isinstance(nWSR, long) or isinstance(nWSR, int): + deprecation_warning_nWSR() + nWSR_tmp = np.array([nWSR], dtype=long) + else: + nWSR_tmp = nWSR + + if cputime > 1.e-16: + # enable cputime as return value in argument list + if isinstance(cputime, float): + deprecation_warning_cputime() + cput_tmp = np.array([cputime], dtype=float) + else: + cput_tmp = cputime + + return self.thisptr.init( + H.data, + g.data, + lb.data, + ub.data, + nWSR_tmp.data[0], + &cput_tmp.data[0] + ) + + return self.thisptr.init( + H.data, + g.data, + lb.data, + ub.data, + nWSR_tmp.data[0] + ) + + def hotstart(self, + np.ndarray[np.double_t, ndim=1] g, + np.ndarray[np.double_t, ndim=1] lb, + np.ndarray[np.double_t, ndim=1] ub, + nWSR, + cputime = 0.0 + ): + # FIXME: add asserts + cdef np.ndarray nWSR_tmp + cdef np.ndarray cput_tmp + + # enable nWSR as return value in argument list + if isinstance(nWSR, long) or isinstance(nWSR, int): + deprecation_warning_nWSR() + nWSR_tmp = np.array([nWSR], dtype=long) + else: + nWSR_tmp = nWSR#np.asarray(nWSR, dtype=int) + + if cputime > 1.e-16: + # enable cputime as return value in argument list + if isinstance(cputime, float): + deprecation_warning_cputime() + cput_tmp = np.array([cputime], dtype=float) + else: + cput_tmp = cputime#np.asarray(cputime, dtype=float) + + return self.thisptr.hotstart( + g.data, + lb.data, + ub.data, + nWSR_tmp.data[0], + &cput_tmp.data[0] + ) + + return self.thisptr.hotstart( + g.data, + lb.data, + ub.data, + nWSR_tmp.data[0] + ) + + def getPrimalSolution(self, np.ndarray[np.double_t, ndim=1] xOpt): + return self.thisptr.getPrimalSolution( xOpt.data) + + def getDualSolution(self, np.ndarray[np.double_t, ndim=1] yOpt): + return self.thisptr.getDualSolution( yOpt.data) + + def getObjVal(self): + return self.thisptr.getObjVal() + + def printOptions(self): + return self.thisptr.printOptions() + + def getOptions(self): + # FIXME: memory management? who deallocates o + cdef Options *o = new Options(self.thisptr.getOptions()) + retval = PyOptions() + retval.thisptr = o + return retval + + def setOptions(self, PyOptions options): + self.thisptr.setOptions(deref(options.thisptr)) + + +cdef class PyQProblem: + cdef QProblem *thisptr # hold a C++ instance which we're wrapping + + def __cinit__(self, long nV, long nC): + self.thisptr = new QProblem(nV, nC, HST_UNKNOWN, BT_TRUE) + + def __dealloc__(self): + del self.thisptr + + cpdef init(self, + np.ndarray[np.double_t, ndim=2] H, + np.ndarray[np.double_t, ndim=1] g, + np.ndarray[np.double_t, ndim=2] A, + np.ndarray[np.double_t, ndim=1] lb, + np.ndarray[np.double_t, ndim=1] ub, + np.ndarray[np.double_t, ndim=1] lbA, + np.ndarray[np.double_t, ndim=1] ubA, + nWSR, + cputime=0.0): + + # FIXME: add asserts + cdef np.ndarray nWSR_tmp + cdef np.ndarray cput_tmp + + # enable nWSR as return value in argument list + if isinstance(nWSR, long) or isinstance(nWSR, int): + deprecation_warning_nWSR() + nWSR_tmp = np.array([nWSR], dtype=long) + else: + nWSR_tmp = nWSR + + if cputime > 1.e-16: + # enable cputime as return value in argument list + if isinstance(cputime, float): + deprecation_warning_cputime() + cput_tmp = np.array([cputime], dtype=float) + else: + cput_tmp = cputime + + return self.thisptr.init( + H.data, + g.data, + A.data, + lb.data, + ub.data, + lbA.data, + ubA.data, + nWSR_tmp.data[0], + &cput_tmp.data[0] + ) + + return self.thisptr.init( + H.data, + g.data, + A.data, + lb.data, + ub.data, + lbA.data, + ubA.data, + nWSR_tmp.data[0] + ) + + cpdef hotstart(self, + np.ndarray[np.double_t, ndim=1] g, + np.ndarray[np.double_t, ndim=1] lb, + np.ndarray[np.double_t, ndim=1] ub, + np.ndarray[np.double_t, ndim=1] lbA, + np.ndarray[np.double_t, ndim=1] ubA, + nWSR, + cputime=0.0 + ): + # FIXME: add asserts + cdef np.ndarray nWSR_tmp + cdef np.ndarray cput_tmp + + # enable nWSR as return value in argument list + if isinstance(nWSR, long) or isinstance(nWSR, int): + deprecation_warning_nWSR() + nWSR_tmp = np.array([nWSR], dtype=long) + else: + nWSR_tmp = nWSR + + if cputime > 1.e-16: + # enable cputime as return value in argument list + if isinstance(cputime, float): + deprecation_warning_cputime() + cput_tmp = np.array([cputime], dtype=float) + else: + cput_tmp = cputime + + return self.thisptr.hotstart( + g.data, + lb.data, + ub.data, + lbA.data, + ubA.data, + nWSR_tmp.data[0], + &cput_tmp.data[0] + ) + + return self.thisptr.hotstart( + g.data, + lb.data, + ub.data, + lbA.data, + ubA.data, + nWSR_tmp.data[0] + ) + + cpdef getPrimalSolution(self, np.ndarray[np.double_t, ndim=1] xOpt): + return self.thisptr.getPrimalSolution( xOpt.data) + + cpdef getDualSolution(self, np.ndarray[np.double_t, ndim=1] yOpt): + return self.thisptr.getDualSolution( yOpt.data) + + cpdef getObjVal(self): + return self.thisptr.getObjVal() + + cpdef printOptions(self): + return self.thisptr.printOptions() + + cpdef setOptions(self, PyOptions options): + self.thisptr.setOptions(deref(options.thisptr)) + + +cdef class PySQProblem: + cdef SQProblem *thisptr # hold a C++ instance which we're wrapping + + def __cinit__(self, long nV, long nC): + self.thisptr = new SQProblem(nV, nC, HST_UNKNOWN, BT_TRUE) + + def __dealloc__(self): + del self.thisptr + + cpdef init(self, + np.ndarray[np.double_t, ndim=2] H, + np.ndarray[np.double_t, ndim=1] g, + np.ndarray[np.double_t, ndim=2] A, + np.ndarray[np.double_t, ndim=1] lb, + np.ndarray[np.double_t, ndim=1] ub, + np.ndarray[np.double_t, ndim=1] lbA, + np.ndarray[np.double_t, ndim=1] ubA, + nWSR, + cputime=0.0 + ): + # FIXME: add asserts + cpdef np.ndarray nWSR_tmp + cpdef np.ndarray cput_tmp + # nWSR_tmp = np.zeros(1, dtype=long) + # cput_tmp = np.zeros(1, dtype=float) + + # enable nWSR as return value in argument list + if isinstance(nWSR, long) or isinstance(nWSR, int): + deprecation_warning_nWSR() + nWSR_tmp = np.array([nWSR], dtype=long) + else: + nWSR_tmp = np.asarray(nWSR, dtype=long) + + if cputime > 1.e-16: + # enable cputime as return value in argument list + if isinstance(cputime, float): + deprecation_warning_cputime() + cput_tmp = np.array([cputime], dtype=float) + else: + cput_tmp = cputime + # print "cput_tmp: ", cput_tmp + + return self.thisptr.init( + H.data, + g.data, + A.data, + lb.data, + ub.data, + lbA.data, + ubA.data, + nWSR_tmp.data[0], + &cput_tmp.data[0] + ) + + return self.thisptr.init( + H.data, + g.data, + A.data, + lb.data, + ub.data, + lbA.data, + ubA.data, + nWSR_tmp.data[0], + ) + + cpdef hotstart(self, + np.ndarray[np.double_t, ndim=2] H, + np.ndarray[np.double_t, ndim=1] g, + np.ndarray[np.double_t, ndim=2] A, + np.ndarray[np.double_t, ndim=1] lb, + np.ndarray[np.double_t, ndim=1] ub, + np.ndarray[np.double_t, ndim=1] lbA, + np.ndarray[np.double_t, ndim=1] ubA, + nWSR, + cputime=0.0): + + # FIXME: add asserts + cdef np.ndarray nWSR_tmp + cdef np.ndarray cput_tmp + + # enable nWSR as return value in argument list + if isinstance(nWSR, long) or isinstance(nWSR, int): + deprecation_warning_nWSR() + nWSR_tmp = np.array([nWSR], dtype=long) + else: + nWSR_tmp = nWSR + + if cputime > 1.e-16: + # enable cputime as return value in argument list + if isinstance(cputime, float): + deprecation_warning_cputime() + cput_tmp = np.array([cputime], dtype=float) + else: + cput_tmp = cputime + + return self.thisptr.hotstart( + H.data, + g.data, + A.data, + lb.data, + ub.data, + lbA.data, + ubA.data, + nWSR_tmp.data[0], + &cput_tmp.data[0] + ) + + return self.thisptr.hotstart( + H.data, + g.data, + A.data, + lb.data, + ub.data, + lbA.data, + ubA.data, + nWSR_tmp.data[0], + ) + + cpdef getPrimalSolution(self, np.ndarray[np.double_t, ndim=1] xOpt): + return self.thisptr.getPrimalSolution( xOpt.data) + + cpdef getDualSolution(self, np.ndarray[np.double_t, ndim=1] yOpt): + return self.thisptr.getDualSolution( yOpt.data) + + cpdef getObjVal(self): + return self.thisptr.getObjVal() + + cpdef printOptions(self): + return self.thisptr.printOptions() + + cpdef setOptions(self, PyOptions options): + self.thisptr.setOptions(deref(options.thisptr)) + + +cdef class PySolutionAnalysis: + cdef SolutionAnalysis *thisptr # hold a C++ instance which we're wrapping + def __cinit__(self): + self.thisptr = new SolutionAnalysis() + def __dealloc__(self): + del self.thisptr + + cpdef getKktViolation(self, qp, + np.ndarray[np.double_t, ndim=1] maxStat, + np.ndarray[np.double_t, ndim=1] maxFeas, + np.ndarray[np.double_t, ndim=1] maxCmpl + ): + """ """ + if isinstance(qp, PyQProblemB): + return self._getKktViolation_QProblemB(qp, maxStat, maxFeas, maxCmpl) + + elif isinstance(qp, PyQProblem): + return self._getKktViolation_QProblem(qp, maxStat, maxFeas, maxCmpl) + + elif isinstance(qp, PySQProblem): + return self._getKktViolation_SQProblem(qp, maxStat, maxFeas, maxCmpl) + + else: + raise ValueError('argument 1 must be QProblemB, QProblem or SQProblem') + + cpdef _getKktViolation_QProblemB(self, + PyQProblemB qp, + np.ndarray[np.double_t, ndim=1] maxStat, + np.ndarray[np.double_t, ndim=1] maxFeas, + np.ndarray[np.double_t, ndim=1] maxCmpl + ): + return self.thisptr.getKktViolation( + qp.thisptr, + maxStat.data[0], + maxFeas.data[0], + maxCmpl.data[0] + ) + + cpdef _getKktViolation_QProblem(self, + PyQProblem qp, + np.ndarray[np.double_t, ndim=1] maxStat, + np.ndarray[np.double_t, ndim=1] maxFeas, + np.ndarray[np.double_t, ndim=1] maxCmpl + ): + return self.thisptr.getKktViolation( + qp.thisptr, + maxStat.data[0], + maxFeas.data[0], + maxCmpl.data[0] + ) + + + cpdef _getKktViolation_SQProblem(self, + PySQProblem qp, + np.ndarray[np.double_t, ndim=1] maxStat, + np.ndarray[np.double_t, ndim=1] maxFeas, + np.ndarray[np.double_t, ndim=1] maxCmpl + ): + return self.thisptr.getKktViolation( + qp.thisptr, + maxStat.data[0], + maxFeas.data[0], + maxCmpl.data[0] + ) + + cpdef getVarianceCovariance(self, + qp, + np.ndarray[np.double_t, ndim=1] g_b_bA_VAR, + np.ndarray[np.double_t, ndim=1] Primal_Dual_VAR ): + + if isinstance(qp, PyQProblemB): + return self._getVarianceCovariance_QProblemB(qp, g_b_bA_VAR, Primal_Dual_VAR) + + elif isinstance(qp, PyQProblem): + return self._getVarianceCovariance_QProblem(qp, g_b_bA_VAR, Primal_Dual_VAR) + + elif isinstance(qp, PySQProblem): + return self._getVarianceCovariance_SQProblem(qp, g_b_bA_VAR, Primal_Dual_VAR) + + else: + raise ValueError('argument 1 must be QProblemB, QProblem or SQProblem') + + cpdef _getVarianceCovariance_QProblemB(self, + PyQProblemB qp, + np.ndarray[np.double_t, ndim=1] g_b_bA_VAR, + np.ndarray[np.double_t, ndim=1] Primal_Dual_VAR ): + return self.thisptr.getVarianceCovariance(qp.thisptr, + g_b_bA_VAR.data, + Primal_Dual_VAR.data) + + cpdef _getVarianceCovariance_QProblem(self, + PyQProblem qp, + np.ndarray[np.double_t, ndim=1] g_b_bA_VAR, + np.ndarray[np.double_t, ndim=1] Primal_Dual_VAR ): + return self.thisptr.getVarianceCovariance(qp.thisptr, + g_b_bA_VAR.data, + Primal_Dual_VAR.data) + + cpdef _getVarianceCovariance_SQProblem(self, + PySQProblem qp, + np.ndarray[np.double_t, ndim=1] g_b_bA_VAR, + np.ndarray[np.double_t, ndim=1] Primal_Dual_VAR ): + return self.thisptr.getVarianceCovariance(qp.thisptr, + g_b_bA_VAR.data, + Primal_Dual_VAR.data) + +# Wrapped some utility functions for unit testing +cpdef py_runOqpBenchmark(path, # Full path of the benchmark files (without trailing slash!). + isSparse, # Shall convert matrices to sparse format before solution? + useHotstarts, # Shall QP solution be hotstarted? + PyOptions options, # QP solver options to be used while solving benchmark problems. + long maxAllowedNWSR, # Maximum number of working set recalculations to be performed. + double maxCPUTime, # Maximum allowed CPU time for qp solving. + ): + """run a QP benchmark example""" + maxNWSR = 0.0 # Output: Maximum number of performed working set recalculations. + avgNWSR = 0.0 # Output: Average number of performed working set recalculations. + maxCPUtime = 0.0 # Output: Maximum CPU time required for solving each QP. + avgCPUtime = 0.0 # Output: Average CPU time required for solving each QP. + maxStationarity = 0.0 # Output: Maximum residual of stationarity condition. + maxFeasibility = 0.0 # Output: Maximum residual of primal feasibility condition. + maxComplementarity = 0.0 # Output: Maximum residual of complementarity condition. + +""" +def py_getKktViolation(long nV, # Number of variables. + long nC, # Number of constraints. + np.ndarray[np.double_t, ndim=2] H, # Hessian matrix. + np.ndarray[np.double_t, ndim=1] g, # Sequence of gradient vectors. + np.ndarray[np.double_t, ndim=2] A, # Constraint matrix. + np.ndarray[np.double_t, ndim=1] lb, # Sequence of lower bound vectors (on variables). + np.ndarray[np.double_t, ndim=1] ub, # Sequence of upper bound vectors (on variables). + np.ndarray[np.double_t, ndim=1] lbA, # Sequence of lower constraints' bound vectors. + np.ndarray[np.double_t, ndim=1] ubA, # Sequence of upper constraints' bound vectors. + np.ndarray[np.double_t, ndim=1] x, # Sequence of primal trial vectors. + np.ndarray[np.double_t, ndim=1] y, # Sequence of dual trial vectors. + ): + stat = 0.0 # Maximum value of stationarity condition residual. + feas = 0.0 # Maximum value of primal feasibility violation. + cmpl = 0.0 # Maximum value of complementarity residual. + getKktViolation(nV, + nC, + H.data, + g.data, + A.data, + lb.data, + ub.data, + lbA.data, + ubA.data, + x.data, + y.data, + stat, + feas, + cmpl + ) + return stat, feas, cmpl +""" + diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/setup.py b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/setup.py new file mode 100755 index 0000000..913f8da --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/setup.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python +"""qpOASES python distutils setup script.""" + +# +# This file is part of qpOASES. +# +# qpOASES -- An Implementation of the Online Active Set Strategy. +# Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +# Christian Kirches et al. All rights reserved. +# +# qpOASES is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# qpOASES is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with qpOASES; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# + +# +# Filename: setup.py +# Author: Sebastian F. Walter, Manuel Kudruss (thanks to Felix Lenders) +# Version: 3.2 +# Date: 2013-2017 +# + +import os +import numpy as np +import platform + +from distutils.core import setup +from distutils.extension import Extension +from Cython.Distutils import build_ext +from Cython.Build import cythonize + +BASEDIR = os.path.dirname(os.path.abspath(__file__)) +BASEDIR = os.path.dirname(BASEDIR) +BASEDIR = os.path.dirname(BASEDIR) + +extra_params = {} +extra_params['include_dirs'] = [ + '/usr/include', + os.path.join(BASEDIR, 'include'), + os.path.join(BASEDIR, 'include', 'qpOASES'), + np.get_include()] +extra_params['extra_compile_args'] = ["-O2", "-Wno-unused-variable"] +extra_params['extra_link_args'] = ["-Wl,-O1", "-Wl,--as-needed"] + +extra_params = extra_params.copy() +extra_params['libraries'] = ['qpOASES'] + +extra_params['library_dirs'] = ['/usr/lib', os.path.join(BASEDIR, 'bin')] +extra_params['language'] = 'c++' + +if platform.system() in ['Linux', 'Darwin']: + extra_params['extra_compile_args'] = ['-D__USE_LONG_INTEGERS__', + '-D__USE_LONG_FINTS__'] + +if platform.system() == 'Darwin': + extra_params['include_dirs'].append( + '/Library/Developer/CommandLineTools/usr/include/c++/v1') + extra_params['extra_compile_args'] += ['-stdlib=libc++', + '-Wno-c++11-long-long'] + extra_params['extra_link_args'] = ['-stdlib=libc++'] # override the others! + +if os.name == 'posix': + extra_params['runtime_library_dirs'] = extra_params['library_dirs'] + # NOTE the python wrapper compiles the interface from the header files + # and therefore requires access to all defines made. + # Therefore, we provide the CPPFLAGS from the make_linux.mk file + # directly to the compile process by extra_compile_args. + # NOTE not all FLAGS can be added automatically, e.g. DEF_SOLVER. + # Please fix this yourself in case of problems. + # TODO maybe add automatic make file parsing and choose from those options + extra_params['extra_compile_args'] += [ + "-Wall", + "-pedantic", + "-Wshadow", + "-Wfloat-equal", + "-O3", + "-Wconversion", + "-Wsign-conversion", + "-finline-functions", + "-fPIC", + "-DLINUX", + "-D__USE_LONG_INTEGERS__", + "-D__USE_LONG_FINTS__", + "-D__NO_COPYRIGHT__", + ] + +ext_modules = [ + Extension("qpoases", ["qpoases.pyx", "qpoases.pxd"], **extra_params), +] + +setup( + name='qpOASES interface', + cmdclass={'build_ext': build_ext}, + ext_modules=cythonize(ext_modules), +) diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/tests/__init__.py b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/tests/__init__.py new file mode 100755 index 0000000..8b13789 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/tests/__init__.py @@ -0,0 +1 @@ + diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/tests/test_examples.py b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/tests/test_examples.py new file mode 100755 index 0000000..a345188 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/python/tests/test_examples.py @@ -0,0 +1,360 @@ +""" +This file is part of qpOASES. + +qpOASES -- An Implementation of the Online Active Set Strategy. +Copyright (C) 2007-2017 by Hans Joachim Ferreau et al. All rights reserved. + +qpOASES is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +qpOASES is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with qpOASES; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +author Manuel Kudruss +version 3.2 +date 2013-2017 +""" + +import os +import re +import numpy as np +from numpy.testing import * +from subprocess import Popen, PIPE, STDOUT + +from qpoases import PyQProblem as QProblem +from qpoases import PyQProblemB as QProblemB +from qpoases import PySQProblem as SQProblem +from qpoases import PySolutionAnalysis as SolutionAnalysis +from qpoases import PyBooleanType as BooleanType +from qpoases import PySubjectToStatus as SubjectToStatus +from qpoases import PyOptions as Options +from qpoases import PyPrintLevel as PrintLevel + +# get qpOASES path +qpoases_path = os.path.dirname(os.path.abspath(__file__)) +qpoases_path = os.path.dirname(qpoases_path) +qpoases_path = os.path.dirname(qpoases_path) +qpoases_path = os.path.dirname(qpoases_path) + +# set qpOASES binary path +bin_path = os.path.join(qpoases_path, "bin") + +class TestExamples(TestCase): + + def test_example1(self): + return 0 + # Example for qpOASES main function using the QProblem class. + #Setup data of first QP. + + H = np.array([1.0, 0.0, 0.0, 0.5 ]).reshape((2,2)) + A = np.array([1.0, 1.0 ]).reshape((2,1)) + g = np.array([1.5, 1.0 ]) + lb = np.array([0.5, -2.0]) + ub = np.array([5.0, 2.0 ]) + lbA = np.array([-1.0 ]) + ubA = np.array([2.0]) + + # Setup data of second QP. + + g_new = np.array([1.0, 1.5]) + lb_new = np.array([0.0, -1.0]) + ub_new = np.array([5.0, -0.5]) + lbA_new = np.array([-2.0]) + ubA_new = np.array([1.0]) + + # Setting up QProblemB object. + qp = QProblem(2, 1) + options = Options() + options.printLevel = PrintLevel.NONE + qp.setOptions(options) + + # Solve first QP. + nWSR = 10 + qp.init(H, g, A, lb, ub, lbA, ubA, nWSR) + + # Solve second QP. + nWSR = 10 + qp.hotstart(g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR) + + # Get and print solution of second QP. + xOpt_actual = np.zeros(2) + qp.getPrimalSolution(xOpt_actual) + xOpt_actual = np.asarray(xOpt_actual, dtype=float) + objVal_actual = qp.getObjVal() + objVal_actual = np.asarray(objVal_actual, dtype=float) + + cmd = os.path.join(bin_path, "example1") + p = Popen(cmd, shell=True, stdout=PIPE) + stdout, stderr = p.communicate() + stdout = str(stdout).replace('\\n', '\n') + stdout = stdout.replace("'", '') + print(stdout) + + # get c++ solution from std + pattern = re.compile(r'xOpt\s*=\s*\[\s+(?P([0-9., e+-])*)\];') + match = pattern.search(stdout) + xOpt_expected = match.group('xOpt') + xOpt_expected = xOpt_expected.split(",") + xOpt_expected = np.asarray(xOpt_expected, dtype=float) + + pattern = re.compile(r'objVal = (?P[0-9-+e.]*)') + match = pattern.search(stdout) + objVal_expected = match.group('objVal') + objVal_expected = np.asarray(objVal_expected, dtype=float) + + print("xOpt_actual =", xOpt_actual) + print("xOpt_expected =", xOpt_expected) + print("objVal_actual = ", objVal_actual) + print("objVal_expected = ", objVal_expected) + + assert_almost_equal(xOpt_actual, xOpt_expected, decimal=7) + assert_almost_equal(objVal_actual, objVal_expected, decimal=7) + + def test_example1b(self): + """Example for qpOASES main function using the QProblemB class.""" + # Setup data of first QP. + H = np.array([1.0, 0.0, 0.0, 0.5]).reshape((2, 2)) + g = np.array([1.5, 1.0]) + lb = np.array([0.5, -2.0]) + ub = np.array([5.0, 2.0]) + + # Setup data of second QP. + + g_new = np.array([1.0, 1.5]) + lb_new = np.array([0.0, -1.0]) + ub_new = np.array([5.0, -0.5]) + + # Setting up QProblemB object. + qp = QProblemB(2) + + options = Options() + # options.enableFlippingBounds = BooleanType.FALSE + options.initialStatusBounds = SubjectToStatus.INACTIVE + options.numRefinementSteps = 1 + options.enableCholeskyRefactorisation = 1 + options.printLevel = PrintLevel.NONE + qp.setOptions(options) + + # Solve first QP. + nWSR = 10 + qp.init(H, g, lb, ub, nWSR) + + xOpt_actual = np.zeros(2) + qp.getPrimalSolution(xOpt_actual) + xOpt_actual = np.asarray(xOpt_actual, dtype=float) + objVal_actual = qp.getObjVal() + objVal_actual = np.asarray(objVal_actual, dtype=float) + print 'xOpt_actual:', xOpt_actual + print 'objVal_actual:', objVal_actual + + # Solve second QP. + nWSR = 10 + qp.hotstart(g_new, lb_new, ub_new, nWSR) + + xOpt_actual = np.zeros(2) + qp.getPrimalSolution(xOpt_actual) + xOpt_actual = np.asarray(xOpt_actual, dtype=float) + objVal_actual = qp.getObjVal() + objVal_actual = np.asarray(objVal_actual, dtype=float) + print 'xOpt_actual:', xOpt_actual + print 'objVal_actual:', objVal_actual + + # Get and print solution of second QP. + xOpt_actual = np.zeros(2) + qp.getPrimalSolution(xOpt_actual) + xOpt_actual = np.asarray(xOpt_actual, dtype=float) + objVal_actual = qp.getObjVal() + objVal_actual = np.asarray(objVal_actual, dtype=float) + + cmd = os.path.join(bin_path, "example1b") + p = Popen(cmd, shell=True, stdout=PIPE) + stdout, stderr = p.communicate() + stdout = str(stdout).replace('\\n', '\n') + stdout = stdout.replace("'", '') + + # get c++ solution from std + pattern = re.compile(r'xOpt\s*=\s*\[\s+(?P([0-9., e+-])*)\];') + match = pattern.findall(stdout) + xOpt_expected = match[-1][0] + xOpt_expected = xOpt_expected.split(",") + xOpt_expected = np.asarray(xOpt_expected, dtype=float) + + pattern = re.compile(r'objVal = (?P[0-9-+e.]*)') + match = pattern.findall(stdout) + print match + objVal_expected = match[-1] + objVal_expected = np.asarray(objVal_expected, dtype=float) + + print("xOpt_actual =", xOpt_actual) + print("xOpt_expected =", xOpt_expected) + print("objVal_actual = ", objVal_actual) + print("objVal_expected = ", objVal_expected) + + assert_almost_equal(xOpt_actual, xOpt_expected, decimal=7) + assert_almost_equal(objVal_actual, objVal_expected, decimal=7) + + + def test_example2(self): + # Example for qpOASES main function using the SQProblem class. + # Setup data of first QP. + H = np.array([ 1.0, 0.0, 0.0, 0.5 ]).reshape((2,2)) + A = np.array([ 1.0, 1.0 ]).reshape((2,1)) + g = np.array([ 1.5, 1.0 ]) + lb = np.array([ 0.5, -2.0 ]) + ub = np.array([ 5.0, 2.0 ]) + lbA = np.array([ -1.0 ]) + ubA = np.array([ 2.0 ]) + + # Setup data of second QP. + H_new = np.array([ 1.0, 0.5, 0.5, 0.5 ]).reshape((2,2)) + A_new = np.array([ 1.0, 5.0 ]).reshape((2,1)) + g_new = np.array([ 1.0, 1.5 ]) + lb_new = np.array([ 0.0, -1.0 ]) + ub_new = np.array([ 5.0, -0.5 ]) + lbA_new = np.array([ -2.0 ]) + ubA_new = np.array([ 1.0 ]) + + # Setting up SQProblem object and solution analyser. + qp = SQProblem(2, 1) + options = Options() + options.printLevel = PrintLevel.NONE + qp.setOptions(options) + + analyser = SolutionAnalysis() + + # get c++ solution from std + cmd = os.path.join(bin_path, "example2") + p = Popen(cmd, shell=True, stdout=PIPE) + stdout, stderr = p.communicate() + stdout = str(stdout).replace('\\n', '\n') + stdout = stdout.replace("'", '') + print(stdout) + + # Solve first QP ... + nWSR = 10 + qp.init(H, g, A, lb, ub, lbA, ubA, nWSR) + + # ... and analyse it. + maxViol = np.zeros(1) + maxStat = np.zeros(1) + maxFeas = np.zeros(1) + maxCmpl = np.zeros(1) + maxViol[0] = analyser.getKktViolation( + qp, maxStat, maxFeas, maxCmpl + ) + print("maxViol: %e\n" % maxViol) + actual = np.asarray(maxViol) + + pattern = re.compile( + r'maxKktViolation: (?P[0-9+-e.]*)' + ) + + match = pattern.findall(stdout) + expected = np.asarray(match[0], dtype=float) + + assert_almost_equal(actual, expected, decimal=7) + + # Solve second QP ... + nWSR = 10 + qp.hotstart( + H_new, g_new, A_new, + lb_new, ub_new, + lbA_new, ubA_new, + nWSR + ) + + # ... and analyse it. + maxViol = np.zeros(1) + maxStat = np.zeros(1) + maxFeas = np.zeros(1) + maxCmpl = np.zeros(1) + maxViol[0] = analyser.getKktViolation( + qp, maxStat, maxFeas, maxCmpl + ) + print("maxViol: %e\n" % maxViol) + actual = np.asarray(maxViol) + + expected = np.asarray(match[1], dtype=float) + + assert_almost_equal(actual, expected, decimal=7) + + # ------------ VARIANCE-COVARIANCE EVALUATION -------------------- + + Var = np.zeros(5*5) + Primal_Dual_Var = np.zeros(5*5) + + Var.reshape((5, 5))[0, 0] = 1. + Var.reshape((5, 5))[1, 1] = 1. + + # ( 1 0 0 0 0 ) + # ( 0 1 0 0 0 ) + # Var = ( 0 0 0 0 0 ) + # ( 0 0 0 0 0 ) + # ( 0 0 0 0 0 ) + + analyser.getVarianceCovariance(qp, Var, Primal_Dual_Var) + print('Primal_Dual_Var=\n', Primal_Dual_Var.reshape((5, 5))) + actual = Primal_Dual_Var.reshape((5, 5)) + + pattern = re.compile( + r'Primal_Dual_VAR = (?P.*)', + re.DOTALL + ) + + print(stdout) + match = pattern.search(stdout) + expected = match.group('VAR').strip().split("\n") + expected = [x.strip().split() for x in expected] + print(expected) + expected = np.asarray(expected, dtype=float) + + assert_almost_equal(actual, expected, decimal=7) + + def test_example7(self): + H = np.array([ + 0.8514828085899353, -0.15739890933036804, -0.081726007163524628, -0.530426025390625, 0.16773293912410736, + -0.15739890933036804, 1.1552412509918213, 0.57780224084854126, -0.0072606131434440613, 0.010559185408055782, + -0.081726007163524628, 0.57780224084854126, 0.28925251960754395, 5.324830453901086e-006, -3.0256599075073609e-006, + -0.530426025390625, -0.0072606131434440613, 5.324830453901086e-006, 0.35609596967697144, -0.15124998986721039, + 0.16773293912410736, 0.010559185408055782, -3.0256599075073609e-006, -0.15124998986721039, 0.15129712224006653 + ], dtype=float + ).reshape((5, 5)) + g = np.array([0.30908384919166565, 0.99325823783874512, 0.49822014570236206, -0.26309865713119507, 0.024296050891280174], dtype=float).reshape((5,)) + A = np.array([1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1], dtype=float).reshape((5, 5)) + lb = np.array([-0.052359879016876221, -0.052359879016876221, -0.052359879016876221, -0.052359879016876221, -0.052359938621520996], dtype=float).reshape((5,)) + ub = np.array([ 0.052359879016876221, 0.052359879016876221, 0.052359879016876221, 0, 0], dtype=float).reshape((5,)) + lbA = np.array([-0.052359879016876221, -0.052359879016876221, -0.052359879016876221, -0.052359879016876221, -0.052359938621520996], dtype=float).reshape((5,)) + ubA = np.array([0.052359879016876221, 0.052359879016876221, 0.052359879016876221, 0, 0], dtype=float).reshape((5,)) + + # Setting up QProblem object. + qp = QProblem(5, 5) + options = Options() + options.printLevel = PrintLevel.NONE + qp.setOptions(options) + + # Solve first QP. + nWSR = 100 + qp.init(H, g, A, lb, ub, lbA, ubA, nWSR) + + result = np.zeros((5,)) + qp.getPrimalSolution(result) + + # TODO check against what? + # Where can I find solution? + +if __name__=="__main__": + try: + import nose + nose.runmodule() + + except ImportError: + sys.stderr.write("Please install nosestests for python unittesting.\n") + diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/Makefile b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/Makefile new file mode 100755 index 0000000..c22c2a5 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/Makefile @@ -0,0 +1,93 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: interfaces/scilab/Makefile +## Author: Holger Diedam, Hans Joachim Ferreau +## Version: 3.2 +## Date: 2007-2017 +## + + + +PATH_LIB = . +PATH_SRC = . +PATH_OBJ = . +PATH_QPOASES_INC = ../../include +PATH_QPOASES_SRC = ../../src +PATH_QPOASES_OBJ = ../../src + + +## +## bins +## + +CC = gcc +CPP = g++ +LD = g++ +CP = cp + + + +## +## flags +## + +CFLAGS = -I$(PATH_QPOASES_INC) -I$(PATH_QPOASES_SRC) -Wall -pedantic -Wshadow -O3 -fPIC +CPPFLAGS = -I$(PATH_QPOASES_INC) -I$(PATH_QPOASES_SRC) -Wall -pedantic -Wshadow -O3 -fPIC -DLINUX -D__SCILAB__ -D__SINGLE_OBJECT__ +LDFLAGS = -shared +LIBEXT = .so + + +LIB = libqpOASESinterface$(LIBEXT) + +OBJ = \ + qpOASESroutines.o \ + qpOASESinterface.o + + + +## +## targets +## + +all: $(PATH_LIB)/$(LIB) + +$(PATH_OBJ)/%.o: $(PATH_SRC)/%.c + $(CC) -c -o $(@) $(CFLAGS) $< + +$(PATH_OBJ)/%.o: $(PATH_SRC)/%.cpp + $(CPP) -c -o $(@) $(CPPFLAGS) $< + +$(PATH_LIB)/$(LIB) : $(addprefix $(PATH_OBJ)/, $(OBJ)) + $(LD) $(LDFLAGS) $^ -o $@ + +clean: + $(RM) $(PATH_OBJ)/*.o $(PATH_LIB)/$(LIB) + + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/example1.dat b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/example1.dat new file mode 100755 index 0000000..1c9e594 Binary files /dev/null and b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/example1.dat differ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/example1a.dat b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/example1a.dat new file mode 100755 index 0000000..4e67850 Binary files /dev/null and b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/example1a.dat differ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/example1b.dat b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/example1b.dat new file mode 100755 index 0000000..b591a7d Binary files /dev/null and b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/example1b.dat differ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/qpOASESinterface.c b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/qpOASESinterface.c new file mode 100755 index 0000000..00adef3 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/qpOASESinterface.c @@ -0,0 +1,893 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file interfaces/scilab/qpOASESinterface.c + * \author Holger Diedam, Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + * + * Interface that enables to call qpOASES from scilab. + * (Please excuse a lot of copy and paste...) + * + */ + + +#include +#include + +#include +#include + +#include "../c/qpOASES_wrapper.h" + + + +extern int interface_qpOASES( char* fname ); + +extern int interface_QProblem_init( char* fname ); +extern int interface_QProblemB_init( char* fname ); +extern int interface_SQProblem_init( char* fname ); + +extern int interface_QProblem_hotstart( char* fname ); +extern int interface_QProblemB_hotstart( char* fname ); +extern int interface_SQProblem_hotstart( char* fname ); + +extern int interface_QProblem_cleanup( char* fname ); +extern int interface_QProblemB_cleanup( char* fname ); +extern int interface_SQProblem_cleanup( char* fname ); + + +typedef int (*gate_function) ( char* ); +extern int sci_gateway( char* name, gate_function f ); +extern int C2F(qpOASESgateway)(); + + +/* forward declaration of C++ routines */ +void sci_qpOASES( real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA, + int_t *nV, int_t* nC, int_t* nWSR, + real_t* x, real_t* obj, int_t* status, int_t* nWSRout, real_t* y + ); + +void sci_QProblem_init( real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA, + int_t *nV, int_t* nC, int_t* nWSR, + real_t* x, real_t* obj, int_t* status, int_t* nWSRout, real_t* y + ); +void sci_QProblemB_init( real_t* H, real_t* g, real_t* lb, real_t* ub, + int_t *nV, int_t* nWSR, + real_t* x, real_t* obj, int_t* status, int_t* nWSRout, real_t* y + ); +void sci_SQProblem_init( real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA, + int_t *nV, int_t* nC, int_t* nWSR, + real_t* x, real_t* obj, int_t* status, int_t* nWSRout, real_t* y + ); + +void sci_QProblem_hotstart( real_t* g, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA, + int_t* nWSR, + real_t* x, real_t* obj, int_t* status, int_t* nWSRout, real_t* y + ); +void sci_QProblemB_hotstart( real_t* g, real_t* lb, real_t* ub, + int_t* nWSR, + real_t* x, real_t* obj, int_t* status, int_t* nWSRout, real_t* y + ); +void sci_SQProblem_hotstart( real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA, + int_t* nWSR, + real_t* x, real_t* obj, int_t* status, int_t* nWSRout, real_t* y + ); + +void sci_QProblem_cleanup( ); +void sci_QProblemB_cleanup( ); +void sci_SQProblem_cleanup( ); + + +/* global variables containing dimensions of matrices + * (also used to check whether qpOASES object were initialised) */ +static int_t qp_rowsH = -1; +static int_t qp_rowsA = -1; +static int_t qpb_rowsH = -1; +static int_t sqp_rowsH = -1; +static int_t sqp_rowsA = -1; + + +/* + * i n t e r f a c e _ q p O A S E S + */ +int interface_qpOASES( char* fname ) +{ + int_t H, H_rows, H_cols; + int_t g, g_rows, g_cols; + int_t A, A_rows, A_cols; + int_t lb, lb_rows, lb_cols; + int_t ub, ub_rows, ub_cols; + int_t lbA, lbA_rows, lbA_cols; + int_t ubA, ubA_rows, ubA_cols; + int_t nWSR, nWSR_rows, nWSR_cols; + + int_t x, obj, status, nWSRout, y; + + + int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size; + + CheckRhs( minrhs,maxrhs ); + CheckLhs( minlhs,maxlhs ); + + + /* check dimensions */ + GetRhsVar( 1,"d", &H_rows,&H_cols,&H ); + if ( ( H_rows != H_cols ) || ( H_rows < 1 ) ) + { + Scierror( 111,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 2,"d", &g_rows,&g_cols,&g ); + if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) ) + { + Scierror( 112,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 3,"d", &A_rows,&A_cols,&A ); + if ( ( A_cols != H_rows ) || ( A_rows < 1 ) ) + { + Scierror( 113,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb); + if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) ) + { + Scierror( 114,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub); + if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) ) + { + Scierror( 115,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA); + if ( !( ( ( lbA_rows == A_rows ) && ( lbA_cols == 1 ) ) || ( ( lbA_rows == 0 ) && ( lbA_cols == 0 ) ) ) ) + { + Scierror( 116,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA); + if ( !( ( ( ubA_rows == A_rows ) && ( ubA_cols == 1 ) ) || ( ( ubA_rows == 0 ) && ( ubA_cols == 0 ) ) ) ) + { + Scierror( 117,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR); + if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) ) + { + Scierror( 118,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + + y_size = H_rows + A_rows; + + CreateVar( 9,"d", &H_rows,&one,&x ); + CreateVar( 10,"d", &one,&one,&obj ); + CreateVar( 11,"i", &one,&one,&status ); + CreateVar( 12,"i", &one,&one,&nWSRout ); + CreateVar( 13,"d", &y_size,&one,&y ); + + + /* call interfaced qpOASES routines with appropriate arguments */ + sci_qpOASES( stk(H),stk(g),stk(A), (lb_rows!=0) ? stk(lb) : 0, (ub_rows!=0) ? stk(ub) : 0, (lbA_rows!=0) ? stk(lbA) : 0, (ubA_rows!=0) ? stk(ubA) : 0, + &H_rows,&A_rows,istk(nWSR), + stk(x),stk(obj),istk(status),istk(nWSRout),stk(y) + ); + + LhsVar(1) = 9; + LhsVar(2) = 10; + LhsVar(3) = 11; + LhsVar(4) = 12; + LhsVar(5) = 13; + + return 0; +} + + +/* + * i n t e r f a c e _ Q P r o b l e m _ i n i t + */ +int interface_QProblem_init( char* fname ) +{ + int_t H, H_rows, H_cols; + int_t g, g_rows, g_cols; + int_t A, A_rows, A_cols; + int_t lb, lb_rows, lb_cols; + int_t ub, ub_rows, ub_cols; + int_t lbA, lbA_rows, lbA_cols; + int_t ubA, ubA_rows, ubA_cols; + int_t nWSR, nWSR_rows, nWSR_cols; + + int_t x, obj, status, nWSRout, y; + + + int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size; + + CheckRhs( minrhs,maxrhs ); + CheckLhs( minlhs,maxlhs ); + + + /* check dimensions */ + GetRhsVar( 1,"d", &H_rows,&H_cols,&H ); + if ( ( H_rows != H_cols ) || ( H_rows < 1 ) ) + { + Scierror( 211,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 2,"d", &g_rows,&g_cols,&g ); + if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) ) + { + Scierror( 212,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 3,"d", &A_rows,&A_cols,&A ); + if ( ( A_cols != H_rows ) || ( A_rows < 1 ) ) + { + Scierror( 213,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb); + if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) ) + { + Scierror( 214,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub); + if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) ) + { + Scierror( 215,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA); + if ( !( ( ( lbA_rows == A_rows ) && ( lbA_cols == 1 ) ) || ( ( lbA_rows == 0 ) && ( lbA_cols == 0 ) ) ) ) + { + Scierror( 216,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA); + if ( !( ( ( ubA_rows == A_rows ) && ( ubA_cols == 1 ) ) || ( ( ubA_rows == 0 ) && ( ubA_cols == 0 ) ) ) ) + { + Scierror( 217,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR); + if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) ) + { + Scierror( 218,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + + y_size = H_rows + A_rows; + + CreateVar( 9,"d", &H_rows,&one,&x ); + CreateVar( 10,"d", &one,&one,&obj ); + CreateVar( 11,"i", &one,&one,&status ); + CreateVar( 12,"i", &one,&one,&nWSRout ); + CreateVar( 13,"d", &y_size,&one,&y ); + + + qp_rowsH = H_rows; + qp_rowsA = A_rows; + + + /* call interfaced qpOASES routines with appropriate arguments */ + sci_QProblem_init( stk(H),stk(g),stk(A), (lb_rows!=0) ? stk(lb) : 0, (ub_rows!=0) ? stk(ub) : 0, (lbA_rows!=0) ? stk(lbA) : 0, (ubA_rows!=0) ? stk(ubA) : 0, + &H_rows,&A_rows,istk(nWSR), + stk(x),stk(obj),istk(status),istk(nWSRout),stk(y) + ); + + LhsVar(1) = 9; + LhsVar(2) = 10; + LhsVar(3) = 11; + LhsVar(4) = 12; + LhsVar(5) = 13; + + return 0; +} + + +/* + * i n t e r f a c e _ Q P r o b l e m B _ i n i t + */ +int interface_QProblemB_init( char* fname ) +{ + int_t H, H_rows, H_cols; + int_t g, g_rows, g_cols; + int_t lb, lb_rows, lb_cols; + int_t ub, ub_rows, ub_cols; + int_t nWSR, nWSR_rows, nWSR_cols; + + int_t x, obj, status, nWSRout, y; + + + int minlhs = 1, maxlhs = 5, minrhs = 5, maxrhs = 5, one = 1; + + CheckRhs( minrhs,maxrhs ); + CheckLhs( minlhs,maxlhs ); + + + /* check dimensions */ + GetRhsVar( 1,"d", &H_rows,&H_cols,&H ); + if ( ( H_rows != H_cols ) || ( H_rows < 1 ) ) + { + Scierror( 221,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 2,"d", &g_rows,&g_cols,&g ); + if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) ) + { + Scierror( 222,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 3,"d", &lb_rows,&lb_cols,&lb); + if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) ) + { + Scierror( 223,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 4,"d", &ub_rows,&ub_cols,&ub); + if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) ) + { + Scierror( 224,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 5,"i", &nWSR_rows,&nWSR_cols,&nWSR); + if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) ) + { + Scierror( 225,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + + CreateVar( 9,"d", &H_rows,&one,&x ); + CreateVar( 10,"d", &one,&one,&obj ); + CreateVar( 11,"i", &one,&one,&status ); + CreateVar( 12,"i", &one,&one,&nWSRout ); + CreateVar( 13,"d", &H_rows,&one,&y ); + + + qpb_rowsH = H_rows; + + + /* call interfaced qpOASES routines with appropriate arguments */ + sci_QProblemB_init( stk(H),stk(g), (lb_rows!=0) ? stk(lb) : 0, (ub_rows!=0) ? stk(ub) : 0, + &H_rows,istk(nWSR), + stk(x),stk(obj),istk(status),istk(nWSRout),stk(y) + ); + + LhsVar(1) = 9; + LhsVar(2) = 10; + LhsVar(3) = 11; + LhsVar(4) = 12; + LhsVar(5) = 13; + + return 0; +} + + +/* + * i n t e r f a c e _ S Q P r o b l e m _ i n i t + */ +int interface_SQProblem_init( char* fname ) +{ + int_t H, H_rows, H_cols; + int_t g, g_rows, g_cols; + int_t A, A_rows, A_cols; + int_t lb, lb_rows, lb_cols; + int_t ub, ub_rows, ub_cols; + int_t lbA, lbA_rows, lbA_cols; + int_t ubA, ubA_rows, ubA_cols; + int_t nWSR, nWSR_rows, nWSR_cols; + + int_t x, obj, status, nWSRout, y; + + + int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size; + + CheckRhs( minrhs,maxrhs ); + CheckLhs( minlhs,maxlhs ); + + + /* check dimensions */ + GetRhsVar( 1,"d", &H_rows,&H_cols,&H ); + if ( ( H_rows != H_cols ) || ( H_rows < 1 ) ) + { + Scierror( 231,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 2,"d", &g_rows,&g_cols,&g ); + if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) ) + { + Scierror( 232,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 3,"d", &A_rows,&A_cols,&A ); + if ( ( A_cols != H_rows ) || ( A_rows < 1 ) ) + { + Scierror( 233,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb ); + if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) ) + { + Scierror( 234,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub ); + if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) ) + { + Scierror( 235,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA ); + if ( !( ( ( lbA_rows == A_rows ) && ( lbA_cols == 1 ) ) || ( ( lbA_rows == 0 ) && ( lbA_cols == 0 ) ) ) ) + { + Scierror( 236,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA ); + if ( !( ( ( ubA_rows == A_rows ) && ( ubA_cols == 1 ) ) || ( ( ubA_rows == 0 ) && ( ubA_cols == 0 ) ) ) ) + { + Scierror( 237,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR) ; + if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) ) + { + Scierror( 238,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + + y_size = H_rows + A_rows; + + CreateVar( 9,"d", &H_rows,&one,&x ); + CreateVar( 10,"d", &one,&one,&obj ); + CreateVar( 11,"i", &one,&one,&status ); + CreateVar( 12,"i", &one,&one,&nWSRout ); + CreateVar( 13,"d", &y_size,&one,&y ); + + + sqp_rowsH = H_rows; + sqp_rowsA = A_rows; + + + /* call interfaced qpOASES routines with appropriate arguments */ + sci_SQProblem_init( stk(H),stk(g),stk(A), (lb_rows!=0) ? stk(lb) : 0, (ub_rows!=0) ? stk(ub) : 0, (lbA_rows!=0) ? stk(lbA) : 0, (ubA_rows!=0) ? stk(ubA) : 0, + &H_rows,&A_rows,istk(nWSR), + stk(x),stk(obj),istk(status),istk(nWSRout),stk(y) + ); + + LhsVar(1) = 9; + LhsVar(2) = 10; + LhsVar(3) = 11; + LhsVar(4) = 12; + LhsVar(5) = 13; + + return 0; +} + + +/* + * i n t e r f a c e _ Q P r o b l e m _ h o t s t a r t + */ +int interface_QProblem_hotstart( char* fname ) +{ + int_t g, g_rows, g_cols; + int_t lb, lb_rows, lb_cols; + int_t ub, ub_rows, ub_cols; + int_t lbA, lbA_rows, lbA_cols; + int_t ubA, ubA_rows, ubA_cols; + int_t nWSR, nWSR_rows, nWSR_cols; + + int_t x, obj, status, nWSRout, y; + + + int minlhs = 1, maxlhs = 5, minrhs = 6, maxrhs = 6, one = 1, y_size; + + CheckRhs( minrhs,maxrhs ); + CheckLhs( minlhs,maxlhs ); + + + if ( ( qp_rowsH == -1 ) || ( qp_rowsA == -1 ) ) + { + Scierror( 311,"ERROR (qpOASES): Need to call qpOASES_init first!\n" ); + return 0; + } + + /* check dimensions */ + GetRhsVar( 1,"d", &g_rows,&g_cols,&g ); + if ( !( ( ( g_rows == qp_rowsH ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == qp_rowsH ) ) ) ) + { + Scierror( 312,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 2,"d", &lb_rows,&lb_cols,&lb ); + if ( !( ( ( lb_rows == qp_rowsH ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) ) + { + Scierror( 313,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 3,"d", &ub_rows,&ub_cols,&ub ); + if ( !( ( ( ub_rows == qp_rowsH ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) ) + { + Scierror( 314,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 4,"d", &lbA_rows,&lbA_cols,&lbA ); + if ( !( ( ( lbA_rows == qp_rowsA ) && ( lbA_cols == 1 ) ) || ( ( lbA_rows == 0 ) && ( lbA_cols == 0 ) ) ) ) + { + Scierror( 315,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 5,"d", &ubA_rows,&ubA_cols,&ubA ); + if ( !( ( ( ubA_rows == qp_rowsA ) && ( ubA_cols == 1 ) ) || ( ( ubA_rows == 0 ) && ( ubA_cols == 0 ) ) ) ) + { + Scierror( 316,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 6,"i", &nWSR_rows,&nWSR_cols,&nWSR ); + if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) ) + { + Scierror( 317,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + + y_size = qp_rowsH + qp_rowsA; + + CreateVar( 7,"d", &qp_rowsH,&one,&x ); + CreateVar( 8,"d", &one,&one,&obj ); + CreateVar( 9,"i", &one,&one,&status ); + CreateVar( 10,"i", &one,&one,&nWSRout ); + CreateVar( 11,"d", &y_size,&one,&y ); + + + /* call interfaced qpOASES routines with appropriate arguments */ + sci_QProblem_hotstart( stk(g), (lb_rows!=0) ? stk(lb) : 0, (ub_rows!=0) ? stk(ub) : 0, (lbA_rows!=0) ? stk(lbA) : 0, (ubA_rows!=0) ? stk(ubA) : 0, + istk(nWSR), + stk(x),stk(obj),istk(status),istk(nWSRout),stk(y) + ); + + LhsVar(1) = 7; + LhsVar(2) = 8; + LhsVar(3) = 9; + LhsVar(4) = 10; + LhsVar(5) = 11; + + return 0; +} + + +/* + * i n t e r f a c e _ Q P r o b l e m B _ h o t s t a r t + */ +int interface_QProblemB_hotstart( char* fname ) +{ + int_t g, g_rows, g_cols; + int_t lb, lb_rows, lb_cols; + int_t ub, ub_rows, ub_cols; + int_t nWSR, nWSR_rows, nWSR_cols; + + int_t x, obj, status, nWSRout, y; + + + int minlhs = 1, maxlhs = 5, minrhs = 4, maxrhs = 4, one = 1; + + CheckRhs( minrhs,maxrhs ); + CheckLhs( minlhs,maxlhs ); + + + if ( qpb_rowsH == -1 ) + { + Scierror( 321,"ERROR (qpOASES): Need to call qpOASES_initSB first!\n" ); + return 0; + } + + /* check dimensions */ + GetRhsVar( 1,"d", &g_rows,&g_cols,&g ); + if ( !( ( ( g_rows == qpb_rowsH ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == qpb_rowsH ) ) ) ) + { + Scierror( 322,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 2,"d", &lb_rows,&lb_cols,&lb ); + if ( !( ( ( lb_rows == qpb_rowsH ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) ) + { + Scierror( 323,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 3,"d", &ub_rows,&ub_cols,&ub ); + if ( !( ( ( ub_rows == qpb_rowsH ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) ) + { + Scierror( 324,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 4,"i", &nWSR_rows,&nWSR_cols,&nWSR ); + if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) ) + { + Scierror( 325,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + + CreateVar( 5,"d", &qpb_rowsH,&one,&x ); + CreateVar( 6,"d", &one,&one,&obj ); + CreateVar( 7,"i", &one,&one,&status ); + CreateVar( 8,"i", &one,&one,&nWSRout ); + CreateVar( 9,"d", &qpb_rowsH,&one,&y ); + + + /* call interfaced qpOASES routines with appropriate arguments */ + sci_QProblemB_hotstart( stk(g), (lb_rows!=0) ? stk(lb) : 0, (ub_rows!=0) ? stk(ub) : 0, + istk(nWSR), + stk(x),stk(obj),istk(status),istk(nWSRout),stk(y) + ); + + LhsVar(1) = 5; + LhsVar(2) = 6; + LhsVar(3) = 7; + LhsVar(4) = 8; + LhsVar(5) = 9; + + return 0; +} + + +/* + * i n t e r f a c e _ S Q P r o b l e m _ h o t s t a r t + */ +int interface_SQProblem_hotstart( char* fname ) +{ + int_t H, H_rows, H_cols; + int_t g, g_rows, g_cols; + int_t A, A_rows, A_cols; + int_t lb, lb_rows, lb_cols; + int_t ub, ub_rows, ub_cols; + int_t lbA, lbA_rows, lbA_cols; + int_t ubA, ubA_rows, ubA_cols; + int_t nWSR, nWSR_rows, nWSR_cols; + + int_t obj, x, y, status, nWSRout; + + + int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size; + + CheckRhs( minrhs,maxrhs ); + CheckLhs( minlhs,maxlhs ); + + + if ( ( sqp_rowsH == -1 ) || ( sqp_rowsA == -1 ) ) + { + Scierror( 331,"ERROR (qpOASES): Need to call qpOASES_initVM first!\n" ); + return 0; + } + + /* check dimensions */ + GetRhsVar( 1,"d", &H_rows,&H_cols,&H ); + if ( ( H_rows != H_cols ) || ( H_rows < 1 ) ) + { + Scierror( 332,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 2,"d", &g_rows,&g_cols,&g ); + if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) ) + { + Scierror( 333,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 3,"d", &A_rows,&A_cols,&A ); + if ( ( A_cols != H_rows ) || ( A_rows < 1 ) ) + { + Scierror( 334,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb); + if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) ) + { + Scierror( 335,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub); + if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) ) + { + Scierror( 399,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA); + if ( !( ( ( lbA_rows == A_rows ) && ( lbA_cols == 1 ) ) || ( ( lbA_rows == 0 ) && ( lbA_cols == 0 ) ) ) ) + { + Scierror( 336,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA); + if ( !( ( ( ubA_rows == A_rows ) && ( ubA_cols == 1 ) ) || ( ( ubA_rows == 0 ) && ( ubA_cols == 0 ) ) ) ) + { + Scierror( 337,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR); + if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) ) + { + Scierror( 338,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + /* have matrices same dimension as last QP? */ + if ( ( sqp_rowsH != H_rows ) || ( sqp_rowsA != A_rows ) ) + { + Scierror( 339,"ERROR (qpOASES): Dimension mismatch!\n" ); + return 0; + } + + + y_size = H_rows + A_rows; + + CreateVar( 9,"d", &H_rows,&one,&x ); + CreateVar( 10,"d", &one,&one,&obj ); + CreateVar( 11,"i", &one,&one,&status ); + CreateVar( 12,"i", &one,&one,&nWSRout ); + CreateVar( 13,"d", &y_size,&one,&y ); + + + /* call interfaced qpOASES routines with appropriate arguments */ + sci_SQProblem_hotstart( stk(H),stk(g),stk(A), (lb_rows!=0) ? stk(lb) : 0, (ub_rows!=0) ? stk(ub) : 0, (lbA_rows!=0) ? stk(lbA) : 0, (ubA_rows!=0) ? stk(ubA) : 0, + istk(nWSR), + stk(x),stk(obj),istk(status),istk(nWSRout),stk(y) + ); + + LhsVar(1) = 9; + LhsVar(2) = 10; + LhsVar(3) = 11; + LhsVar(4) = 12; + LhsVar(5) = 13; + + return 0; +} + + +/* + * i n t e r f a c e _ Q P r o b l e m _ c l e a n u p + */ +int interface_QProblem_cleanup( char* fname ) +{ + const int minlhs = 0, maxlhs = 1, minrhs = 0, maxrhs = 0; + + CheckRhs( minrhs,maxrhs ); + CheckLhs( minlhs,maxlhs ); + + sci_QProblem_cleanup( ); + qp_rowsH = -1; + qp_rowsA = -1; + + return 0; +} + + +/* + * i n t e r f a c e _ Q P r o b l e m B _ c l e a n u p + */ +int interface_QProblemB_cleanup( char* fname ) +{ + const int minlhs = 0, maxlhs = 1, minrhs = 0, maxrhs = 0; + + CheckRhs( minrhs,maxrhs ); + CheckLhs( minlhs,maxlhs ); + + sci_QProblemB_cleanup( ); + qpb_rowsH = -1; + + return 0; +} + + +/* + * i n t e r f a c e _ S Q P r o b l e m _ c l e a n u p + */ +int interface_SQProblem_cleanup( char* fname ) +{ + const int minlhs = 0, maxlhs = 1, minrhs = 0, maxrhs = 0; + + CheckRhs( minrhs,maxrhs ); + CheckLhs( minlhs,maxlhs ); + + sci_SQProblem_cleanup( ); + sqp_rowsH = -1; + sqp_rowsA = -1; + + return 0; +} + + +/* + * q p O A S E S g a t e w a y + */ +int C2F(qpOASESgateway)( ) +{ + gate_function function[] = { interface_qpOASES, + interface_QProblem_init, interface_QProblemB_init, interface_SQProblem_init, + interface_QProblem_hotstart, interface_QProblemB_hotstart, interface_SQProblem_hotstart, + interface_QProblem_cleanup, interface_QProblemB_cleanup, interface_SQProblem_cleanup + }; + char* name[] = { "qpOASES", + "qpOASES_init", "qpOASES_initSB", "qpOASES_initVM", + "qpOASES_hotstart", "qpOASES_hotstartSB", "qpOASES_hotstartVM", + "qpOASES_cleanup", "qpOASES_cleanupSB", "qpOASES_cleanupVM" + }; + + Rhs = Max( 0,Rhs ); + sci_gateway( name[Fin-1],function[Fin-1] ); + + return 0; +} + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/qpOASESinterface.sce b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/qpOASESinterface.sce new file mode 100755 index 0000000..77907ab --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/qpOASESinterface.sce @@ -0,0 +1,41 @@ +// +// This file is part of qpOASES. +// +// qpOASES -- An Implementation of the Online Active Set Strategy. +// Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +// Christian Kirches et al. All rights reserved. +// +// qpOASES is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// qpOASES is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with qpOASES; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + + + +// +// Filename: interfaces/scilab/qpOASESinterface.sci +// Author: Holger Diedam, Hans Joachim Ferreau +// Version: 3.2 +// Date: 2007-2017 +// + + + +sharedlib = link( './libqpOASESinterface.so' ); +addinter( './libqpOASESinterface.so', 'qpOASESgateway', ["qpOASES", "qpOASES_init","qpOASES_initSB","qpOASES_initVM", "qpOASES_hotstart","qpOASES_hotstartSB","qpOASES_hotstartVM", "qpOASES_cleanup","qpOASES_cleanupSB","qpOASES_cleanupVM"] ); + + + +// +// end of file +// diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/qpOASESroutines.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/qpOASESroutines.cpp new file mode 100644 index 0000000..484e1d6 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/scilab/qpOASESroutines.cpp @@ -0,0 +1,467 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file interfaces/scilab/qpOASESroutines.cpp + * \author Holger Diedam, Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + * + * Interface that enables to call qpOASES from scilab + * (C++ file to provide an interface between the files that + * have to be compiled with gcc and the qpOASES library). + * + */ + +#include + +#include + +USING_NAMESPACE_QPOASES + +/*extern "C" { +#include "../c/qpOASES_wrapper.h" +}*/ + +/* global pointers to qpOASES objects */ +static QProblem * qp = 0; +static QProblemB * qpb = 0; +static SQProblem * sqp = 0; + +extern "C" +{ + void sci_qpOASES(real_t * H, + real_t * g, + real_t * A, + real_t * lb, + real_t * ub, + real_t * lbA, + real_t * ubA, + int_t * nV, + int_t * nC, + int_t * nWSR, + real_t * x, + real_t * obj, + int_t * status, + int_t * nWSRout, + real_t * y); + + void sci_QProblem_init(real_t * H, + real_t * g, + real_t * A, + real_t * lb, + real_t * ub, + real_t * lbA, + real_t * ubA, + int_t * nV, + int_t * nC, + int_t * nWSR, + real_t * x, + real_t * obj, + int_t * status, + int_t * nWSRout, + real_t * y); + void sci_QProblemB_init(real_t * H, + real_t * g, + real_t * lb, + real_t * ub, + int_t * nV, + int_t * nWSR, + real_t * x, + real_t * obj, + int_t * status, + int_t * nWSRout, + real_t * y); + void sci_SQProblem_init(real_t * H, + real_t * g, + real_t * A, + real_t * lb, + real_t * ub, + real_t * lbA, + real_t * ubA, + int_t * nV, + int_t * nC, + int_t * nWSR, + real_t * x, + real_t * obj, + int_t * status, + int_t * nWSRout, + real_t * y); + + void sci_QProblem_hotstart(real_t * g, + real_t * lb, + real_t * ub, + real_t * lbA, + real_t * ubA, + int_t * nWSR, + real_t * x, + real_t * obj, + int_t * status, + int_t * nWSRout, + real_t * y); + void sci_QProblemB_hotstart(real_t * g, + real_t * lb, + real_t * ub, + int_t * nWSR, + real_t * x, + real_t * obj, + int_t * status, + int_t * nWSRout, + real_t * y); + void sci_SQProblem_hotstart(real_t * H, + real_t * g, + real_t * A, + real_t * lb, + real_t * ub, + real_t * lbA, + real_t * ubA, + int_t * nWSR, + real_t * x, + real_t * obj, + int_t * status, + int_t * nWSRout, + real_t * y); + + void sci_QProblem_cleanup(); + void sci_QProblemB_cleanup(); + void sci_SQProblem_cleanup(); +} /* extern "C" */ + +/* + * t r a n s f o r m A + */ +void transformA(real_t * A, int_t nV, int_t nC) +{ + int_t i, j; + + real_t * A_tmp = new real_t[nC * nV]; + + for (i = 0; i < nV * nC; ++i) + A_tmp[i] = A[i]; + + for (i = 0; i < nC; ++i) + for (j = 0; j < nV; ++j) + A[i * nV + j] = A_tmp[j * nC + i]; + + delete[] A_tmp; + + return; +} + +/* + * q p O A S E S + */ +void sci_qpOASES(real_t * H, + real_t * g, + real_t * A, + real_t * lb, + real_t * ub, + real_t * lbA, + real_t * ubA, + int_t * nV, + int_t * nC, + int_t * nWSR, + real_t * x, + real_t * obj, + int_t * status, + int_t * nWSRout, + real_t * y) +{ + /* transform A into C style matrix */ + transformA(A, *nV, *nC); + + /* setup and solve initial QP */ + QProblem single_qp(*nV, *nC); + single_qp.setPrintLevel(PL_LOW); + returnValue returnvalue = single_qp.init(H, g, A, lb, ub, lbA, ubA, *nWSR, 0); + + /* assign lhs arguments */ + single_qp.getPrimalSolution(x); + *obj = single_qp.getObjVal(); + *status = getSimpleStatus(returnvalue); + *nWSRout = *nWSR; + single_qp.getDualSolution(y); + + return; +} + +/* + * Q P r o b l e m _ i n i t + */ +void sci_QProblem_init(real_t * H, + real_t * g, + real_t * A, + real_t * lb, + real_t * ub, + real_t * lbA, + real_t * ubA, + int_t * nV, + int_t * nC, + int_t * nWSR, + real_t * x, + real_t * obj, + int_t * status, + int_t * nWSRout, + real_t * y) +{ + sci_QProblem_cleanup(); + + /* transform A into C style matrix */ + transformA(A, *nV, *nC); + + /* setup and solve initial QP */ + qp = new QProblem(*nV, *nC); + qp->setPrintLevel(PL_LOW); + returnValue returnvalue = qp->init(H, g, A, lb, ub, lbA, ubA, *nWSR, 0); + + /* assign lhs arguments */ + qp->getPrimalSolution(x); + *obj = qp->getObjVal(); + *status = getSimpleStatus(returnvalue); + *nWSRout = *nWSR; + qp->getDualSolution(y); + + return; +} + +/* + * Q P r o b l e m B _ i n i t + */ +void sci_QProblemB_init(real_t * H, + real_t * g, + real_t * lb, + real_t * ub, + int_t * nV, + int_t * nWSR, + real_t * x, + real_t * obj, + int_t * status, + int_t * nWSRout, + real_t * y) +{ + sci_QProblemB_cleanup(); + + /* setup and solve initial QP */ + qpb = new QProblemB(*nV); + qpb->setPrintLevel(PL_LOW); + returnValue returnvalue = qpb->init(H, g, lb, ub, *nWSR, 0); + + /* assign lhs arguments */ + qpb->getPrimalSolution(x); + *obj = qpb->getObjVal(); + *status = getSimpleStatus(returnvalue); + *nWSRout = *nWSR; + qpb->getDualSolution(y); + + return; +} + +/* + * S Q P r o b l e m _ i n i t + */ +void sci_SQProblem_init(real_t * H, + real_t * g, + real_t * A, + real_t * lb, + real_t * ub, + real_t * lbA, + real_t * ubA, + int_t * nV, + int_t * nC, + int_t * nWSR, + real_t * x, + real_t * obj, + int_t * status, + int_t * nWSRout, + real_t * y) +{ + sci_SQProblem_cleanup(); + + /* transform A into C style matrix */ + transformA(A, *nV, *nC); + + /* setup and solve initial QP */ + sqp = new SQProblem(*nV, *nC); + sqp->setPrintLevel(PL_LOW); + returnValue returnvalue = sqp->init(H, g, A, lb, ub, lbA, ubA, *nWSR, 0); + + /* assign lhs arguments */ + sqp->getPrimalSolution(x); + *obj = sqp->getObjVal(); + *status = getSimpleStatus(returnvalue); + *nWSRout = *nWSR; + sqp->getDualSolution(y); + + return; +} + +/* + * Q P r o b l e m _ h o t s t a r t + */ +void sci_QProblem_hotstart(real_t * g, + real_t * lb, + real_t * ub, + real_t * lbA, + real_t * ubA, + int_t * nWSR, + real_t * x, + real_t * obj, + int_t * status, + int_t * nWSRout, + real_t * y) +{ + /* has QP been initialised? */ + if (qp == 0) { + *status = -1; + Scierror(999, "ERROR (qpOASES): Need to call qpOASES_init first!\n"); + return; + } + + /* solve QP */ + returnValue returnvalue = qp->hotstart(g, lb, ub, lbA, ubA, *nWSR, 0); + + /* assign lhs arguments */ + qp->getPrimalSolution(x); + *obj = qp->getObjVal(); + *status = getSimpleStatus(returnvalue); + *nWSRout = *nWSR; + qp->getDualSolution(y); + + return; +} + +/* + * Q P r o b l e m B _ h o t s t a r t + */ +void sci_QProblemB_hotstart(real_t * g, + real_t * lb, + real_t * ub, + int_t * nWSR, + real_t * x, + real_t * obj, + int_t * status, + int_t * nWSRout, + real_t * y) +{ + /* has QP been initialised? */ + if (qpb == 0) { + *status = -1; + Scierror(999, "ERROR (qpOASES): Need to call qpOASES_initSB first!\n"); + return; + } + + /* solve QP */ + returnValue returnvalue = qpb->hotstart(g, lb, ub, *nWSR, 0); + + /* assign lhs arguments */ + qpb->getPrimalSolution(x); + *obj = qpb->getObjVal(); + *status = getSimpleStatus(returnvalue); + *nWSRout = *nWSR; + qpb->getDualSolution(y); + + return; +} + +/* + * S Q P r o b l e m _ h o t s t a r t + */ +void sci_SQProblem_hotstart(real_t * H, + real_t * g, + real_t * A, + real_t * lb, + real_t * ub, + real_t * lbA, + real_t * ubA, + int_t * nWSR, + real_t * x, + real_t * obj, + int_t * status, + int_t * nWSRout, + real_t * y) +{ + /* has QP been initialised? */ + if (sqp == 0) { + *status = -1; + Scierror(999, "ERROR (qpOASES): Need to call qpOASES_initVM first!\n"); + return; + } + + /* transform A into C style matrix */ + transformA(A, sqp->getNV(), sqp->getNC()); + + /* solve QP */ + returnValue returnvalue = sqp->hotstart(H, g, A, lb, ub, lbA, ubA, *nWSR, 0); + + /* assign lhs arguments */ + sqp->getPrimalSolution(x); + *obj = sqp->getObjVal(); + *status = getSimpleStatus(returnvalue); + *nWSRout = *nWSR; + sqp->getDualSolution(y); + + return; +} + +/* + * Q P r o b l e m _ c l e a n u p + */ +void sci_QProblem_cleanup() +{ + if (qp != 0) { + delete qp; + qp = 0; + } + + return; +} + +/* + * Q P r o b l e m B _ c l e a n u p + */ +void sci_QProblemB_cleanup() +{ + if (qpb != 0) { + delete qpb; + qpb = 0; + } + + return; +} + +/* + * S Q P r o b l e m _ c l e a n u p + */ +void sci_SQProblem_cleanup() +{ + if (sqp != 0) { + delete sqp; + sqp = 0; + } + + return; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/example_QProblem.mdl b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/example_QProblem.mdl new file mode 100755 index 0000000..0e7d0be --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/example_QProblem.mdl @@ -0,0 +1,762 @@ +Model { + Name "example_QProblem" + Version 7.4 + MdlSubVersion 0 + GraphicalInterface { + NumRootInports 0 + NumRootOutports 0 + ParameterArgumentNames "" + ComputedModelVersion "1.69" + NumModelReferences 0 + NumTestPointedSignals 0 + } + SavedCharacterEncoding "UTF-8" + SaveDefaultBlockParams on + ScopeRefreshTime 0.035000 + OverrideScopeRefreshTime on + DisableAllScopes off + DataTypeOverride "UseLocalSettings" + MinMaxOverflowLogging "UseLocalSettings" + MinMaxOverflowArchiveMode "Overwrite" + MaxMDLFileLineLength 120 + Created "Fri Apr 13 11:08:51 2007" + Creator "jferreau" + UpdateHistory "UpdateHistoryNever" + ModifiedByFormat "%" + LastModifiedBy "chjofer2" + ModifiedDateFormat "%" + LastModifiedDate "Tue Jan 06 16:16:07 2015" + RTWModifiedTimeStamp 342461745 + ModelVersionFormat "1.%" + ConfigurationManager "None" + SampleTimeColors off + SampleTimeAnnotations off + LibraryLinkDisplay "none" + WideLines off + ShowLineDimensions off + ShowPortDataTypes off + ShowLoopsOnError on + IgnoreBidirectionalLines off + ShowStorageClass off + ShowTestPointIcons on + ShowSignalResolutionIcons on + ShowViewerIcons on + SortedOrder off + ExecutionContextIcon off + ShowLinearizationAnnotations on + BlockNameDataTip off + BlockParametersDataTip off + BlockDescriptionStringDataTip off + ToolBar on + StatusBar on + BrowserShowLibraryLinks off + BrowserLookUnderMasks off + SimulationMode "normal" + LinearizationMsg "none" + Profile off + ParamWorkspaceSource "MATLABWorkspace" + AccelSystemTargetFile "accel.tlc" + AccelTemplateMakefile "accel_default_tmf" + AccelMakeCommand "make_rtw" + TryForcingSFcnDF off + RecordCoverage off + CovPath "/" + CovSaveName "covdata" + CovMetricSettings "dw" + CovNameIncrementing off + CovHtmlReporting on + CovForceBlockReductionOff on + covSaveCumulativeToWorkspaceVar on + CovSaveSingleToWorkspaceVar on + CovCumulativeVarName "covCumulativeData" + CovCumulativeReport off + CovReportOnPause on + CovModelRefEnable "Off" + CovExternalEMLEnable off + ExtModeBatchMode off + ExtModeEnableFloating on + ExtModeTrigType "manual" + ExtModeTrigMode "normal" + ExtModeTrigPort "1" + ExtModeTrigElement "any" + ExtModeTrigDuration 1000 + ExtModeTrigDurationFloating "auto" + ExtModeTrigHoldOff 0 + ExtModeTrigDelay 0 + ExtModeTrigDirection "rising" + ExtModeTrigLevel 0 + ExtModeArchiveMode "off" + ExtModeAutoIncOneShot off + ExtModeIncDirWhenArm off + ExtModeAddSuffixToVar off + ExtModeWriteAllDataToWs off + ExtModeArmWhenConnect on + ExtModeSkipDownloadWhenConnect off + ExtModeLogAll on + ExtModeAutoUpdateStatusClock off + BufferReuse on + ShowModelReferenceBlockVersion off + ShowModelReferenceBlockIO off + Array { + Type "Handle" + Dimension 1 + Simulink.ConfigSet { + $ObjectID 1 + Version "1.6.0" + Array { + Type "Handle" + Dimension 8 + Simulink.SolverCC { + $ObjectID 2 + Version "1.6.0" + StartTime "0.0" + StopTime "0.5" + AbsTol "auto" + FixedStep "auto" + InitialStep "auto" + MaxNumMinSteps "-1" + MaxOrder 5 + ZcThreshold "auto" + ConsecutiveZCsStepRelTol "10*128*eps" + MaxConsecutiveZCs "1000" + ExtrapolationOrder 4 + NumberNewtonIterations 1 + MaxStep "auto" + MinStep "auto" + MaxConsecutiveMinStep "1" + RelTol "1e-3" + SolverMode "Auto" + Solver "FixedStepDiscrete" + SolverName "FixedStepDiscrete" + ShapePreserveControl "DisableAll" + ZeroCrossControl "UseLocalSettings" + ZeroCrossAlgorithm "Nonadaptive" + AlgebraicLoopSolver "TrustRegion" + SolverResetMethod "Fast" + PositivePriorityOrder off + AutoInsertRateTranBlk off + SampleTimeConstraint "Unconstrained" + InsertRTBMode "Whenever possible" + } + Simulink.DataIOCC { + $ObjectID 3 + Version "1.6.0" + Decimation "1" + ExternalInput "[t, u]" + FinalStateName "xFinal" + InitialState "xInitial" + LimitDataPoints on + MaxDataPoints "1000" + LoadExternalInput off + LoadInitialState off + SaveFinalState off + SaveCompleteFinalSimState off + SaveFormat "Array" + SaveOutput on + SaveState off + SignalLogging on + InspectSignalLogs off + SaveTime on + ReturnWorkspaceOutputs off + StateSaveName "xout" + TimeSaveName "tout" + OutputSaveName "yout" + SignalLoggingName "logsout" + OutputOption "RefineOutputTimes" + OutputTimes "[]" + ReturnWorkspaceOutputsName "out" + Refine "1" + } + Simulink.OptimizationCC { + $ObjectID 4 + Version "1.6.0" + Array { + Type "Cell" + Dimension 4 + Cell "ZeroExternalMemoryAtStartup" + Cell "ZeroInternalMemoryAtStartup" + Cell "NoFixptDivByZeroProtection" + Cell "OptimizeModelRefInitCode" + PropName "DisabledProps" + } + BlockReduction on + BooleanDataType on + ConditionallyExecuteInputs on + InlineParams off + UseIntDivNetSlope off + InlineInvariantSignals off + OptimizeBlockIOStorage on + BufferReuse on + EnhancedBackFolding off + StrengthReduction off + EnforceIntegerDowncast on + ExpressionFolding on + BooleansAsBitfields off + EnableMemcpy on + MemcpyThreshold 64 + PassReuseOutputArgsAs "Structure reference" + ExpressionDepthLimit 2147483647 + FoldNonRolledExpr on + LocalBlockOutputs on + RollThreshold 5 + SystemCodeInlineAuto off + StateBitsets off + DataBitsets off + UseTempVars off + ZeroExternalMemoryAtStartup on + ZeroInternalMemoryAtStartup on + InitFltsAndDblsToZero on + NoFixptDivByZeroProtection off + EfficientFloat2IntCast off + EfficientMapNaN2IntZero on + OptimizeModelRefInitCode off + LifeSpan "inf" + BufferReusableBoundary on + SimCompilerOptimization "Off" + AccelVerboseBuild off + } + Simulink.DebuggingCC { + $ObjectID 5 + Version "1.6.0" + RTPrefix "error" + ConsistencyChecking "none" + ArrayBoundsChecking "none" + SignalInfNanChecking "none" + SignalRangeChecking "none" + ReadBeforeWriteMsg "UseLocalSettings" + WriteAfterWriteMsg "UseLocalSettings" + WriteAfterReadMsg "UseLocalSettings" + AlgebraicLoopMsg "warning" + ArtificialAlgebraicLoopMsg "warning" + SaveWithDisabledLinksMsg "warning" + SaveWithParameterizedLinksMsg "none" + CheckSSInitialOutputMsg on + UnderspecifiedInitializationDetection "Classic" + MergeDetectMultiDrivingBlocksExec "none" + CheckExecutionContextPreStartOutputMsg off + CheckExecutionContextRuntimeOutputMsg off + SignalResolutionControl "TryResolveAllWithWarning" + BlockPriorityViolationMsg "warning" + MinStepSizeMsg "warning" + TimeAdjustmentMsg "none" + MaxConsecutiveZCsMsg "error" + SolverPrmCheckMsg "warning" + InheritedTsInSrcMsg "warning" + DiscreteInheritContinuousMsg "warning" + MultiTaskDSMMsg "error" + MultiTaskCondExecSysMsg "error" + MultiTaskRateTransMsg "error" + SingleTaskRateTransMsg "none" + TasksWithSamePriorityMsg "warning" + SigSpecEnsureSampleTimeMsg "warning" + CheckMatrixSingularityMsg "none" + IntegerOverflowMsg "warning" + Int32ToFloatConvMsg "warning" + ParameterDowncastMsg "error" + ParameterOverflowMsg "error" + ParameterUnderflowMsg "none" + ParameterPrecisionLossMsg "warning" + ParameterTunabilityLossMsg "warning" + FixptConstUnderflowMsg "none" + FixptConstOverflowMsg "none" + FixptConstPrecisionLossMsg "none" + UnderSpecifiedDataTypeMsg "none" + UnnecessaryDatatypeConvMsg "none" + VectorMatrixConversionMsg "none" + InvalidFcnCallConnMsg "error" + FcnCallInpInsideContextMsg "Use local settings" + SignalLabelMismatchMsg "none" + UnconnectedInputMsg "warning" + UnconnectedOutputMsg "warning" + UnconnectedLineMsg "warning" + SFcnCompatibilityMsg "none" + UniqueDataStoreMsg "none" + BusObjectLabelMismatch "warning" + RootOutportRequireBusObject "warning" + AssertControl "UseLocalSettings" + EnableOverflowDetection off + ModelReferenceIOMsg "none" + ModelReferenceVersionMismatchMessage "none" + ModelReferenceIOMismatchMessage "none" + ModelReferenceCSMismatchMessage "none" + UnknownTsInhSupMsg "warning" + ModelReferenceDataLoggingMessage "warning" + ModelReferenceSymbolNameMessage "warning" + ModelReferenceExtraNoncontSigs "error" + StateNameClashWarn "warning" + SimStateInterfaceChecksumMismatchMsg "warning" + StrictBusMsg "Warning" + LoggingUnavailableSignals "error" + BlockIODiagnostic "none" + } + Simulink.HardwareCC { + $ObjectID 6 + Version "1.6.0" + ProdBitPerChar 8 + ProdBitPerShort 16 + ProdBitPerInt 32 + ProdBitPerLong 32 + ProdIntDivRoundTo "Undefined" + ProdEndianess "Unspecified" + ProdWordSize 32 + ProdShiftRightIntArith on + ProdHWDeviceType "32-bit Generic" + TargetBitPerChar 8 + TargetBitPerShort 16 + TargetBitPerInt 32 + TargetBitPerLong 32 + TargetShiftRightIntArith on + TargetIntDivRoundTo "Undefined" + TargetEndianess "Unspecified" + TargetWordSize 32 + TargetTypeEmulationWarnSuppressLevel 0 + TargetPreprocMaxBitsSint 32 + TargetPreprocMaxBitsUint 32 + TargetHWDeviceType "Specified" + TargetUnknown off + ProdEqTarget on + } + Simulink.ModelReferenceCC { + $ObjectID 7 + Version "1.6.0" + UpdateModelReferenceTargets "IfOutOfDateOrStructuralChange" + CheckModelReferenceTargetMessage "error" + ModelReferenceNumInstancesAllowed "Multi" + ModelReferencePassRootInputsByReference on + ModelReferenceMinAlgLoopOccurrences off + } + Simulink.SFSimCC { + $ObjectID 8 + Version "1.6.0" + SFSimEnableDebug on + SFSimOverflowDetection on + SFSimEcho on + SimBlas on + SimCtrlC on + SimExtrinsic on + SimIntegrity on + SimUseLocalCustomCode off + SimBuildMode "sf_incremental_build" + } + Simulink.RTWCC { + $BackupClass "Simulink.RTWCC" + $ObjectID 9 + Version "1.6.0" + Array { + Type "Cell" + Dimension 1 + Cell "IncludeHyperlinkInReport" + PropName "DisabledProps" + } + SystemTargetFile "grt.tlc" + GenCodeOnly off + MakeCommand "make_rtw" + GenerateMakefile on + TemplateMakefile "grt_default_tmf" + GenerateReport off + SaveLog off + RTWVerbose on + RetainRTWFile off + ProfileTLC off + TLCDebug off + TLCCoverage off + TLCAssert off + ProcessScriptMode "Default" + ConfigurationMode "Optimized" + ConfigAtBuild off + RTWUseLocalCustomCode off + RTWUseSimCustomCode off + IncludeHyperlinkInReport off + LaunchReport off + TargetLang "C" + IncludeBusHierarchyInRTWFileBlockHierarchyMap off + IncludeERTFirstTime off + GenerateTraceInfo off + GenerateTraceReport off + GenerateTraceReportSl off + GenerateTraceReportSf off + GenerateTraceReportEml off + GenerateCodeInfo off + RTWCompilerOptimization "Off" + CheckMdlBeforeBuild "Off" + Array { + Type "Handle" + Dimension 2 + Simulink.CodeAppCC { + $ObjectID 10 + Version "1.6.0" + Array { + Type "Cell" + Dimension 16 + Cell "IgnoreCustomStorageClasses" + Cell "InsertBlockDesc" + Cell "SFDataObjDesc" + Cell "SimulinkDataObjDesc" + Cell "DefineNamingRule" + Cell "SignalNamingRule" + Cell "ParamNamingRule" + Cell "InlinedPrmAccess" + Cell "CustomSymbolStr" + Cell "CustomSymbolStrGlobalVar" + Cell "CustomSymbolStrType" + Cell "CustomSymbolStrField" + Cell "CustomSymbolStrFcn" + Cell "CustomSymbolStrBlkIO" + Cell "CustomSymbolStrTmpVar" + Cell "CustomSymbolStrMacro" + PropName "DisabledProps" + } + ForceParamTrailComments off + GenerateComments on + IgnoreCustomStorageClasses on + IgnoreTestpoints off + IncHierarchyInIds off + MaxIdLength 31 + PreserveName off + PreserveNameWithParent off + ShowEliminatedStatement off + IncAutoGenComments off + SimulinkDataObjDesc off + SFDataObjDesc off + IncDataTypeInIds off + MangleLength 1 + CustomSymbolStrGlobalVar "$R$N$M" + CustomSymbolStrType "$N$R$M" + CustomSymbolStrField "$N$M" + CustomSymbolStrFcn "$R$N$M$F" + CustomSymbolStrFcnArg "rt$I$N$M" + CustomSymbolStrBlkIO "rtb_$N$M" + CustomSymbolStrTmpVar "$N$M" + CustomSymbolStrMacro "$R$N$M" + DefineNamingRule "None" + ParamNamingRule "None" + SignalNamingRule "None" + InsertBlockDesc off + SimulinkBlockComments on + EnableCustomComments off + InlinedPrmAccess "Literals" + ReqsInCode off + UseSimReservedNames off + } + Simulink.GRTTargetCC { + $BackupClass "Simulink.TargetCC" + $ObjectID 11 + Version "1.6.0" + Array { + Type "Cell" + Dimension 13 + Cell "IncludeMdlTerminateFcn" + Cell "CombineOutputUpdateFcns" + Cell "SuppressErrorStatus" + Cell "ERTCustomFileBanners" + Cell "GenerateSampleERTMain" + Cell "GenerateTestInterfaces" + Cell "MultiInstanceERTCode" + Cell "PurelyIntegerCode" + Cell "SupportNonFinite" + Cell "SupportComplex" + Cell "SupportAbsoluteTime" + Cell "SupportContinuousTime" + Cell "SupportNonInlinedSFcns" + PropName "DisabledProps" + } + TargetFcnLib "ansi_tfl_tmw.mat" + TargetLibSuffix "" + TargetPreCompLibLocation "" + TargetFunctionLibrary "ANSI_C" + UtilityFuncGeneration "Auto" + ERTMultiwordTypeDef "System defined" + ERTMultiwordLength 256 + MultiwordLength 2048 + GenerateFullHeader on + GenerateSampleERTMain off + GenerateTestInterfaces off + IsPILTarget off + ModelReferenceCompliant on + ParMdlRefBuildCompliant on + CompOptLevelCompliant on + IncludeMdlTerminateFcn on + GeneratePreprocessorConditionals "Disable all" + CombineOutputUpdateFcns off + SuppressErrorStatus off + ERTFirstTimeCompliant off + IncludeFileDelimiter "Auto" + ERTCustomFileBanners off + SupportAbsoluteTime on + LogVarNameModifier "rt_" + MatFileLogging on + MultiInstanceERTCode off + SupportNonFinite on + SupportComplex on + PurelyIntegerCode off + SupportContinuousTime on + SupportNonInlinedSFcns on + SupportVariableSizeSignals off + EnableShiftOperators on + ParenthesesLevel "Nominal" + PortableWordSizes off + ModelStepFunctionPrototypeControlCompliant off + CPPClassGenCompliant off + AutosarCompliant off + UseMalloc off + ExtMode off + ExtModeStaticAlloc off + ExtModeTesting off + ExtModeStaticAllocSize 1000000 + ExtModeTransport 0 + ExtModeMexFile "ext_comm" + ExtModeIntrfLevel "Level1" + RTWCAPISignals off + RTWCAPIParams off + RTWCAPIStates off + GenerateASAP2 off + } + PropName "Components" + } + } + PropName "Components" + } + Name "Configuration" + CurrentDlgPage "Solver" + ConfigPrmDlgPosition " [ 200, 197, 1080, 827 ] " + } + PropName "ConfigurationSets" + } + Simulink.ConfigSet { + $PropName "ActiveConfigurationSet" + $ObjectID 1 + } + BlockDefaults { + ForegroundColor "black" + BackgroundColor "white" + DropShadow off + NamePlacement "normal" + FontName "Courier" + FontSize 10 + FontWeight "normal" + FontAngle "normal" + ShowName on + BlockRotation 0 + BlockMirror off + } + AnnotationDefaults { + HorizontalAlignment "center" + VerticalAlignment "middle" + ForegroundColor "black" + BackgroundColor "white" + DropShadow off + FontName "Courier" + FontSize 10 + FontWeight "normal" + FontAngle "normal" + UseDisplayTextAsClickCallback off + } + LineDefaults { + FontName "Courier" + FontSize 9 + FontWeight "normal" + FontAngle "normal" + } + BlockParameterDefaults { + Block { + BlockType FromWorkspace + VariableName "simulink_input" + SampleTime "-1" + Interpolate on + ZeroCross off + OutputAfterFinalValue "Extrapolation" + } + Block { + BlockType "S-Function" + FunctionName "system" + SFunctionModules "''" + PortCounts "[]" + SFunctionDeploymentMode off + } + Block { + BlockType Scope + ModelBased off + TickLabels "OneTimeTick" + ZoomMode "on" + Grid "on" + TimeRange "auto" + YMin "-5" + YMax "5" + SaveToWorkspace off + SaveName "ScopeData" + LimitDataPoints on + MaxDataPoints "5000" + Decimation "1" + SampleInput off + SampleTime "-1" + } + } + System { + Name "example_QProblem" + Location [2, 74, 1918, 1139] + Open on + ModelBrowserVisibility off + ModelBrowserWidth 200 + ScreenColor "white" + PaperOrientation "landscape" + PaperPositionMode "auto" + PaperType "usletter" + PaperUnits "inches" + TiledPaperMargins [0.500000, 0.500000, 0.500000, 0.500000] + TiledPageScale 1 + ShowPageBoundaries off + ZoomFactor "125" + ReportName "simulink-default.rpt" + SIDHighWatermark 9 + Block { + BlockType FromWorkspace + Name "g" + SID 2 + Position [200, 158, 265, 182] + VariableName "g" + SampleTime "0.1" + ZeroCross on + OutputAfterFinalValue "Holding final value" + } + Block { + BlockType FromWorkspace + Name "lb" + SID 4 + Position [200, 203, 265, 227] + VariableName "lb" + SampleTime "0.1" + ZeroCross on + OutputAfterFinalValue "Holding final value" + } + Block { + BlockType FromWorkspace + Name "lbA" + SID 6 + Position [200, 293, 265, 317] + VariableName "lbA" + SampleTime "0.1" + ZeroCross on + OutputAfterFinalValue "Holding final value" + } + Block { + BlockType "S-Function" + Name "qpOASES" + SID 9 + Ports [5, 4] + Position [595, 222, 795, 298] + BackgroundColor "[1.000000, 0.915850, 0.439000]" + FunctionName "qpOASES_QProblem" + Parameters "H,A" + EnableBusSupport off + } + Block { + BlockType FromWorkspace + Name "ub" + SID 5 + Position [200, 248, 265, 272] + VariableName "ub" + SampleTime "0.1" + ZeroCross on + OutputAfterFinalValue "Holding final value" + } + Block { + BlockType FromWorkspace + Name "ubA" + SID 7 + Position [200, 338, 265, 362] + VariableName "ubA" + SampleTime "0.1" + ZeroCross on + OutputAfterFinalValue "Holding final value" + } + Block { + BlockType Scope + Name "x,\nfval,\nexitflag,\niter" + SID 8 + Ports [4] + Position [945, 222, 1000, 298] + Floating off + Location [6, 78, 1276, 993] + Open off + NumInputPorts "4" + List { + ListType AxesTitles + axes1 "%" + axes2 "%" + axes3 "%" + axes4 "%" + } + YMin "-5~-5~-5~-5" + YMax "5~5~5~5" + SaveName "ScopeData1" + DataFormat "StructureWithTime" + SampleTime "0" + } + Line { + SrcBlock "qpOASES" + SrcPort 1 + DstBlock "x,\nfval,\nexitflag,\niter" + DstPort 1 + } + Line { + SrcBlock "qpOASES" + SrcPort 2 + DstBlock "x,\nfval,\nexitflag,\niter" + DstPort 2 + } + Line { + SrcBlock "qpOASES" + SrcPort 3 + DstBlock "x,\nfval,\nexitflag,\niter" + DstPort 3 + } + Line { + SrcBlock "qpOASES" + SrcPort 4 + DstBlock "x,\nfval,\nexitflag,\niter" + DstPort 4 + } + Line { + SrcBlock "ub" + SrcPort 1 + DstBlock "qpOASES" + DstPort 3 + } + Line { + SrcBlock "lb" + SrcPort 1 + Points [55, 0; 0, 30] + DstBlock "qpOASES" + DstPort 2 + } + Line { + SrcBlock "g" + SrcPort 1 + Points [80, 0; 0, 60] + DstBlock "qpOASES" + DstPort 1 + } + Line { + SrcBlock "lbA" + SrcPort 1 + Points [55, 0; 0, -30] + DstBlock "qpOASES" + DstPort 4 + } + Line { + SrcBlock "ubA" + SrcPort 1 + Points [80, 0; 0, -60] + DstBlock "qpOASES" + DstPort 5 + } + Annotation { + Position [335, 96] + } + Annotation { + Name "This file is part of qpOASES.\n\nqpOASES -- An Implementation of the Online Active Set Strategy.\nC" + "opyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, Christian Kirches et al.\nAll rights reserved." + Position [693, 128] + } + } +} diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/example_QProblemB.mdl b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/example_QProblemB.mdl new file mode 100755 index 0000000..42b1df6 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/example_QProblemB.mdl @@ -0,0 +1,728 @@ +Model { + Name "example_QProblemB" + Version 7.4 + MdlSubVersion 0 + GraphicalInterface { + NumRootInports 0 + NumRootOutports 0 + ParameterArgumentNames "" + ComputedModelVersion "1.67" + NumModelReferences 0 + NumTestPointedSignals 0 + } + SavedCharacterEncoding "UTF-8" + SaveDefaultBlockParams on + ScopeRefreshTime 0.035000 + OverrideScopeRefreshTime on + DisableAllScopes off + DataTypeOverride "UseLocalSettings" + MinMaxOverflowLogging "UseLocalSettings" + MinMaxOverflowArchiveMode "Overwrite" + MaxMDLFileLineLength 120 + Created "Fri Apr 13 11:08:51 2007" + Creator "jferreau" + UpdateHistory "UpdateHistoryNever" + ModifiedByFormat "%" + LastModifiedBy "chjofer2" + ModifiedDateFormat "%" + LastModifiedDate "Tue Jan 06 16:15:23 2015" + RTWModifiedTimeStamp 342461721 + ModelVersionFormat "1.%" + ConfigurationManager "None" + SampleTimeColors off + SampleTimeAnnotations off + LibraryLinkDisplay "none" + WideLines off + ShowLineDimensions off + ShowPortDataTypes off + ShowLoopsOnError on + IgnoreBidirectionalLines off + ShowStorageClass off + ShowTestPointIcons on + ShowSignalResolutionIcons on + ShowViewerIcons on + SortedOrder off + ExecutionContextIcon off + ShowLinearizationAnnotations on + BlockNameDataTip off + BlockParametersDataTip off + BlockDescriptionStringDataTip off + ToolBar on + StatusBar on + BrowserShowLibraryLinks off + BrowserLookUnderMasks off + SimulationMode "normal" + LinearizationMsg "none" + Profile off + ParamWorkspaceSource "MATLABWorkspace" + AccelSystemTargetFile "accel.tlc" + AccelTemplateMakefile "accel_default_tmf" + AccelMakeCommand "make_rtw" + TryForcingSFcnDF off + RecordCoverage off + CovPath "/" + CovSaveName "covdata" + CovMetricSettings "dw" + CovNameIncrementing off + CovHtmlReporting on + CovForceBlockReductionOff on + covSaveCumulativeToWorkspaceVar on + CovSaveSingleToWorkspaceVar on + CovCumulativeVarName "covCumulativeData" + CovCumulativeReport off + CovReportOnPause on + CovModelRefEnable "Off" + CovExternalEMLEnable off + ExtModeBatchMode off + ExtModeEnableFloating on + ExtModeTrigType "manual" + ExtModeTrigMode "normal" + ExtModeTrigPort "1" + ExtModeTrigElement "any" + ExtModeTrigDuration 1000 + ExtModeTrigDurationFloating "auto" + ExtModeTrigHoldOff 0 + ExtModeTrigDelay 0 + ExtModeTrigDirection "rising" + ExtModeTrigLevel 0 + ExtModeArchiveMode "off" + ExtModeAutoIncOneShot off + ExtModeIncDirWhenArm off + ExtModeAddSuffixToVar off + ExtModeWriteAllDataToWs off + ExtModeArmWhenConnect on + ExtModeSkipDownloadWhenConnect off + ExtModeLogAll on + ExtModeAutoUpdateStatusClock off + BufferReuse on + ShowModelReferenceBlockVersion off + ShowModelReferenceBlockIO off + Array { + Type "Handle" + Dimension 1 + Simulink.ConfigSet { + $ObjectID 1 + Version "1.6.0" + Array { + Type "Handle" + Dimension 8 + Simulink.SolverCC { + $ObjectID 2 + Version "1.6.0" + StartTime "0.0" + StopTime "0.5" + AbsTol "auto" + FixedStep "auto" + InitialStep "auto" + MaxNumMinSteps "-1" + MaxOrder 5 + ZcThreshold "auto" + ConsecutiveZCsStepRelTol "10*128*eps" + MaxConsecutiveZCs "1000" + ExtrapolationOrder 4 + NumberNewtonIterations 1 + MaxStep "auto" + MinStep "auto" + MaxConsecutiveMinStep "1" + RelTol "1e-3" + SolverMode "Auto" + Solver "VariableStepDiscrete" + SolverName "VariableStepDiscrete" + ShapePreserveControl "DisableAll" + ZeroCrossControl "UseLocalSettings" + ZeroCrossAlgorithm "Nonadaptive" + AlgebraicLoopSolver "TrustRegion" + SolverResetMethod "Fast" + PositivePriorityOrder off + AutoInsertRateTranBlk off + SampleTimeConstraint "Unconstrained" + InsertRTBMode "Whenever possible" + } + Simulink.DataIOCC { + $ObjectID 3 + Version "1.6.0" + Decimation "1" + ExternalInput "[t, u]" + FinalStateName "xFinal" + InitialState "xInitial" + LimitDataPoints on + MaxDataPoints "1000" + LoadExternalInput off + LoadInitialState off + SaveFinalState off + SaveCompleteFinalSimState off + SaveFormat "Array" + SaveOutput on + SaveState off + SignalLogging on + InspectSignalLogs off + SaveTime on + ReturnWorkspaceOutputs off + StateSaveName "xout" + TimeSaveName "tout" + OutputSaveName "yout" + SignalLoggingName "logsout" + OutputOption "RefineOutputTimes" + OutputTimes "[]" + ReturnWorkspaceOutputsName "out" + Refine "1" + } + Simulink.OptimizationCC { + $ObjectID 4 + Version "1.6.0" + Array { + Type "Cell" + Dimension 4 + Cell "ZeroExternalMemoryAtStartup" + Cell "ZeroInternalMemoryAtStartup" + Cell "NoFixptDivByZeroProtection" + Cell "OptimizeModelRefInitCode" + PropName "DisabledProps" + } + BlockReduction on + BooleanDataType on + ConditionallyExecuteInputs on + InlineParams off + UseIntDivNetSlope off + InlineInvariantSignals off + OptimizeBlockIOStorage on + BufferReuse on + EnhancedBackFolding off + StrengthReduction off + EnforceIntegerDowncast on + ExpressionFolding on + BooleansAsBitfields off + EnableMemcpy on + MemcpyThreshold 64 + PassReuseOutputArgsAs "Structure reference" + ExpressionDepthLimit 2147483647 + FoldNonRolledExpr on + LocalBlockOutputs on + RollThreshold 5 + SystemCodeInlineAuto off + StateBitsets off + DataBitsets off + UseTempVars off + ZeroExternalMemoryAtStartup on + ZeroInternalMemoryAtStartup on + InitFltsAndDblsToZero on + NoFixptDivByZeroProtection off + EfficientFloat2IntCast off + EfficientMapNaN2IntZero on + OptimizeModelRefInitCode off + LifeSpan "inf" + BufferReusableBoundary on + SimCompilerOptimization "Off" + AccelVerboseBuild off + } + Simulink.DebuggingCC { + $ObjectID 5 + Version "1.6.0" + RTPrefix "error" + ConsistencyChecking "none" + ArrayBoundsChecking "none" + SignalInfNanChecking "none" + SignalRangeChecking "none" + ReadBeforeWriteMsg "UseLocalSettings" + WriteAfterWriteMsg "UseLocalSettings" + WriteAfterReadMsg "UseLocalSettings" + AlgebraicLoopMsg "warning" + ArtificialAlgebraicLoopMsg "warning" + SaveWithDisabledLinksMsg "warning" + SaveWithParameterizedLinksMsg "none" + CheckSSInitialOutputMsg on + UnderspecifiedInitializationDetection "Classic" + MergeDetectMultiDrivingBlocksExec "none" + CheckExecutionContextPreStartOutputMsg off + CheckExecutionContextRuntimeOutputMsg off + SignalResolutionControl "TryResolveAllWithWarning" + BlockPriorityViolationMsg "warning" + MinStepSizeMsg "warning" + TimeAdjustmentMsg "none" + MaxConsecutiveZCsMsg "error" + SolverPrmCheckMsg "warning" + InheritedTsInSrcMsg "warning" + DiscreteInheritContinuousMsg "warning" + MultiTaskDSMMsg "error" + MultiTaskCondExecSysMsg "error" + MultiTaskRateTransMsg "error" + SingleTaskRateTransMsg "none" + TasksWithSamePriorityMsg "warning" + SigSpecEnsureSampleTimeMsg "warning" + CheckMatrixSingularityMsg "none" + IntegerOverflowMsg "warning" + Int32ToFloatConvMsg "warning" + ParameterDowncastMsg "error" + ParameterOverflowMsg "error" + ParameterUnderflowMsg "none" + ParameterPrecisionLossMsg "warning" + ParameterTunabilityLossMsg "warning" + FixptConstUnderflowMsg "none" + FixptConstOverflowMsg "none" + FixptConstPrecisionLossMsg "none" + UnderSpecifiedDataTypeMsg "none" + UnnecessaryDatatypeConvMsg "none" + VectorMatrixConversionMsg "none" + InvalidFcnCallConnMsg "error" + FcnCallInpInsideContextMsg "Use local settings" + SignalLabelMismatchMsg "none" + UnconnectedInputMsg "warning" + UnconnectedOutputMsg "warning" + UnconnectedLineMsg "warning" + SFcnCompatibilityMsg "none" + UniqueDataStoreMsg "none" + BusObjectLabelMismatch "warning" + RootOutportRequireBusObject "warning" + AssertControl "UseLocalSettings" + EnableOverflowDetection off + ModelReferenceIOMsg "none" + ModelReferenceVersionMismatchMessage "none" + ModelReferenceIOMismatchMessage "none" + ModelReferenceCSMismatchMessage "none" + UnknownTsInhSupMsg "warning" + ModelReferenceDataLoggingMessage "warning" + ModelReferenceSymbolNameMessage "warning" + ModelReferenceExtraNoncontSigs "error" + StateNameClashWarn "warning" + SimStateInterfaceChecksumMismatchMsg "warning" + StrictBusMsg "Warning" + LoggingUnavailableSignals "error" + BlockIODiagnostic "none" + } + Simulink.HardwareCC { + $ObjectID 6 + Version "1.6.0" + ProdBitPerChar 8 + ProdBitPerShort 16 + ProdBitPerInt 32 + ProdBitPerLong 32 + ProdIntDivRoundTo "Undefined" + ProdEndianess "Unspecified" + ProdWordSize 32 + ProdShiftRightIntArith on + ProdHWDeviceType "32-bit Generic" + TargetBitPerChar 8 + TargetBitPerShort 16 + TargetBitPerInt 32 + TargetBitPerLong 32 + TargetShiftRightIntArith on + TargetIntDivRoundTo "Undefined" + TargetEndianess "Unspecified" + TargetWordSize 32 + TargetTypeEmulationWarnSuppressLevel 0 + TargetPreprocMaxBitsSint 32 + TargetPreprocMaxBitsUint 32 + TargetHWDeviceType "Specified" + TargetUnknown off + ProdEqTarget on + } + Simulink.ModelReferenceCC { + $ObjectID 7 + Version "1.6.0" + UpdateModelReferenceTargets "IfOutOfDateOrStructuralChange" + CheckModelReferenceTargetMessage "error" + ModelReferenceNumInstancesAllowed "Multi" + ModelReferencePassRootInputsByReference on + ModelReferenceMinAlgLoopOccurrences off + } + Simulink.SFSimCC { + $ObjectID 8 + Version "1.6.0" + SFSimEnableDebug on + SFSimOverflowDetection on + SFSimEcho on + SimBlas on + SimCtrlC on + SimExtrinsic on + SimIntegrity on + SimUseLocalCustomCode off + SimBuildMode "sf_incremental_build" + } + Simulink.RTWCC { + $BackupClass "Simulink.RTWCC" + $ObjectID 9 + Version "1.6.0" + Array { + Type "Cell" + Dimension 1 + Cell "IncludeHyperlinkInReport" + PropName "DisabledProps" + } + SystemTargetFile "grt.tlc" + GenCodeOnly off + MakeCommand "make_rtw" + GenerateMakefile on + TemplateMakefile "grt_default_tmf" + GenerateReport off + SaveLog off + RTWVerbose on + RetainRTWFile off + ProfileTLC off + TLCDebug off + TLCCoverage off + TLCAssert off + ProcessScriptMode "Default" + ConfigurationMode "Optimized" + ConfigAtBuild off + RTWUseLocalCustomCode off + RTWUseSimCustomCode off + IncludeHyperlinkInReport off + LaunchReport off + TargetLang "C" + IncludeBusHierarchyInRTWFileBlockHierarchyMap off + IncludeERTFirstTime off + GenerateTraceInfo off + GenerateTraceReport off + GenerateTraceReportSl off + GenerateTraceReportSf off + GenerateTraceReportEml off + GenerateCodeInfo off + RTWCompilerOptimization "Off" + CheckMdlBeforeBuild "Off" + Array { + Type "Handle" + Dimension 2 + Simulink.CodeAppCC { + $ObjectID 10 + Version "1.6.0" + Array { + Type "Cell" + Dimension 16 + Cell "IgnoreCustomStorageClasses" + Cell "InsertBlockDesc" + Cell "SFDataObjDesc" + Cell "SimulinkDataObjDesc" + Cell "DefineNamingRule" + Cell "SignalNamingRule" + Cell "ParamNamingRule" + Cell "InlinedPrmAccess" + Cell "CustomSymbolStr" + Cell "CustomSymbolStrGlobalVar" + Cell "CustomSymbolStrType" + Cell "CustomSymbolStrField" + Cell "CustomSymbolStrFcn" + Cell "CustomSymbolStrBlkIO" + Cell "CustomSymbolStrTmpVar" + Cell "CustomSymbolStrMacro" + PropName "DisabledProps" + } + ForceParamTrailComments off + GenerateComments on + IgnoreCustomStorageClasses on + IgnoreTestpoints off + IncHierarchyInIds off + MaxIdLength 31 + PreserveName off + PreserveNameWithParent off + ShowEliminatedStatement off + IncAutoGenComments off + SimulinkDataObjDesc off + SFDataObjDesc off + IncDataTypeInIds off + MangleLength 1 + CustomSymbolStrGlobalVar "$R$N$M" + CustomSymbolStrType "$N$R$M" + CustomSymbolStrField "$N$M" + CustomSymbolStrFcn "$R$N$M$F" + CustomSymbolStrFcnArg "rt$I$N$M" + CustomSymbolStrBlkIO "rtb_$N$M" + CustomSymbolStrTmpVar "$N$M" + CustomSymbolStrMacro "$R$N$M" + DefineNamingRule "None" + ParamNamingRule "None" + SignalNamingRule "None" + InsertBlockDesc off + SimulinkBlockComments on + EnableCustomComments off + InlinedPrmAccess "Literals" + ReqsInCode off + UseSimReservedNames off + } + Simulink.GRTTargetCC { + $BackupClass "Simulink.TargetCC" + $ObjectID 11 + Version "1.6.0" + Array { + Type "Cell" + Dimension 13 + Cell "IncludeMdlTerminateFcn" + Cell "CombineOutputUpdateFcns" + Cell "SuppressErrorStatus" + Cell "ERTCustomFileBanners" + Cell "GenerateSampleERTMain" + Cell "GenerateTestInterfaces" + Cell "MultiInstanceERTCode" + Cell "PurelyIntegerCode" + Cell "SupportNonFinite" + Cell "SupportComplex" + Cell "SupportAbsoluteTime" + Cell "SupportContinuousTime" + Cell "SupportNonInlinedSFcns" + PropName "DisabledProps" + } + TargetFcnLib "ansi_tfl_tmw.mat" + TargetLibSuffix "" + TargetPreCompLibLocation "" + TargetFunctionLibrary "ANSI_C" + UtilityFuncGeneration "Auto" + ERTMultiwordTypeDef "System defined" + ERTMultiwordLength 256 + MultiwordLength 2048 + GenerateFullHeader on + GenerateSampleERTMain off + GenerateTestInterfaces off + IsPILTarget off + ModelReferenceCompliant on + ParMdlRefBuildCompliant on + CompOptLevelCompliant on + IncludeMdlTerminateFcn on + GeneratePreprocessorConditionals "Disable all" + CombineOutputUpdateFcns off + SuppressErrorStatus off + ERTFirstTimeCompliant off + IncludeFileDelimiter "Auto" + ERTCustomFileBanners off + SupportAbsoluteTime on + LogVarNameModifier "rt_" + MatFileLogging on + MultiInstanceERTCode off + SupportNonFinite on + SupportComplex on + PurelyIntegerCode off + SupportContinuousTime on + SupportNonInlinedSFcns on + SupportVariableSizeSignals off + EnableShiftOperators on + ParenthesesLevel "Nominal" + PortableWordSizes off + ModelStepFunctionPrototypeControlCompliant off + CPPClassGenCompliant off + AutosarCompliant off + UseMalloc off + ExtMode off + ExtModeStaticAlloc off + ExtModeTesting off + ExtModeStaticAllocSize 1000000 + ExtModeTransport 0 + ExtModeMexFile "ext_comm" + ExtModeIntrfLevel "Level1" + RTWCAPISignals off + RTWCAPIParams off + RTWCAPIStates off + GenerateASAP2 off + } + PropName "Components" + } + } + PropName "Components" + } + Name "Configuration" + CurrentDlgPage "Solver" + ConfigPrmDlgPosition " [ 200, 197, 1080, 827 ] " + } + PropName "ConfigurationSets" + } + Simulink.ConfigSet { + $PropName "ActiveConfigurationSet" + $ObjectID 1 + } + BlockDefaults { + ForegroundColor "black" + BackgroundColor "white" + DropShadow off + NamePlacement "normal" + FontName "Courier" + FontSize 10 + FontWeight "normal" + FontAngle "normal" + ShowName on + BlockRotation 0 + BlockMirror off + } + AnnotationDefaults { + HorizontalAlignment "center" + VerticalAlignment "middle" + ForegroundColor "black" + BackgroundColor "white" + DropShadow off + FontName "Courier" + FontSize 10 + FontWeight "normal" + FontAngle "normal" + UseDisplayTextAsClickCallback off + } + LineDefaults { + FontName "Courier" + FontSize 9 + FontWeight "normal" + FontAngle "normal" + } + BlockParameterDefaults { + Block { + BlockType FromWorkspace + VariableName "simulink_input" + SampleTime "-1" + Interpolate on + ZeroCross off + OutputAfterFinalValue "Extrapolation" + } + Block { + BlockType "S-Function" + FunctionName "system" + SFunctionModules "''" + PortCounts "[]" + SFunctionDeploymentMode off + } + Block { + BlockType Scope + ModelBased off + TickLabels "OneTimeTick" + ZoomMode "on" + Grid "on" + TimeRange "auto" + YMin "-5" + YMax "5" + SaveToWorkspace off + SaveName "ScopeData" + LimitDataPoints on + MaxDataPoints "5000" + Decimation "1" + SampleInput off + SampleTime "-1" + } + } + System { + Name "example_QProblemB" + Location [1922, 224, 3598, 1179] + Open on + ModelBrowserVisibility off + ModelBrowserWidth 200 + ScreenColor "white" + PaperOrientation "landscape" + PaperPositionMode "auto" + PaperType "usletter" + PaperUnits "inches" + TiledPaperMargins [0.500000, 0.500000, 0.500000, 0.500000] + TiledPageScale 1 + ShowPageBoundaries off + ZoomFactor "125" + ReportName "simulink-default.rpt" + SIDHighWatermark 6 + Block { + BlockType FromWorkspace + Name "g" + SID 2 + Position [170, 153, 235, 177] + VariableName "g" + SampleTime "0.1" + ZeroCross on + OutputAfterFinalValue "Holding final value" + } + Block { + BlockType FromWorkspace + Name "lb" + SID 3 + Position [170, 203, 235, 227] + VariableName "lb" + SampleTime "0.1" + ZeroCross on + OutputAfterFinalValue "Holding final value" + } + Block { + BlockType "S-Function" + Name "qpOASES" + SID 6 + Ports [3, 4] + Position [505, 180, 700, 245] + BackgroundColor "yellow" + FunctionName "qpOASES_QProblemB" + Parameters "H" + EnableBusSupport off + } + Block { + BlockType FromWorkspace + Name "ub" + SID 4 + Position [170, 253, 235, 277] + VariableName "ub" + SampleTime "0.1" + ZeroCross on + OutputAfterFinalValue "Holding final value" + } + Block { + BlockType Scope + Name "x,\nfval,\nexitflag,\niter" + SID 5 + Ports [4] + Position [855, 185, 905, 240] + Floating off + Location [6, 78, 1276, 993] + Open off + NumInputPorts "4" + List { + ListType AxesTitles + axes1 "%" + axes2 "%" + axes3 "%" + axes4 "%" + } + YMin "-5~-5~-5~-5" + YMax "5~5~5~5" + SaveName "ScopeData1" + DataFormat "StructureWithTime" + SampleTime "0" + } + Line { + SrcBlock "qpOASES" + SrcPort 1 + DstBlock "x,\nfval,\nexitflag,\niter" + DstPort 1 + } + Line { + SrcBlock "qpOASES" + SrcPort 2 + DstBlock "x,\nfval,\nexitflag,\niter" + DstPort 2 + } + Line { + SrcBlock "qpOASES" + SrcPort 3 + DstBlock "x,\nfval,\nexitflag,\niter" + DstPort 3 + } + Line { + SrcBlock "qpOASES" + SrcPort 4 + DstBlock "x,\nfval,\nexitflag,\niter" + DstPort 4 + } + Line { + SrcBlock "g" + SrcPort 1 + Points [50, 0; 0, 30] + DstBlock "qpOASES" + DstPort 1 + } + Line { + SrcBlock "lb" + SrcPort 1 + DstBlock "qpOASES" + DstPort 2 + } + Line { + SrcBlock "ub" + SrcPort 1 + Points [50, 0; 0, -30] + DstBlock "qpOASES" + DstPort 3 + } + Annotation { + Position [335, 96] + } + Annotation { + Name "This file is part of qpOASES.\n\nqpOASES -- An Implementation of the Online Active Set Strategy.\nC" + "opyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, Christian Kirches et al.\nAll rights reserved." + Position [608, 108] + } + } +} diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/example_SQProblem.mdl b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/example_SQProblem.mdl new file mode 100755 index 0000000..94ed087 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/example_SQProblem.mdl @@ -0,0 +1,797 @@ +Model { + Name "example_SQProblem" + Version 7.4 + MdlSubVersion 0 + GraphicalInterface { + NumRootInports 0 + NumRootOutports 0 + ParameterArgumentNames "" + ComputedModelVersion "1.67" + NumModelReferences 0 + NumTestPointedSignals 0 + } + SavedCharacterEncoding "UTF-8" + SaveDefaultBlockParams on + ScopeRefreshTime 0.035000 + OverrideScopeRefreshTime on + DisableAllScopes off + DataTypeOverride "UseLocalSettings" + MinMaxOverflowLogging "UseLocalSettings" + MinMaxOverflowArchiveMode "Overwrite" + MaxMDLFileLineLength 120 + Created "Fri Apr 13 11:08:51 2007" + Creator "jferreau" + UpdateHistory "UpdateHistoryNever" + ModifiedByFormat "%" + LastModifiedBy "chjofer2" + ModifiedDateFormat "%" + LastModifiedDate "Wed Jan 07 09:31:42 2015" + RTWModifiedTimeStamp 342523898 + ModelVersionFormat "1.%" + ConfigurationManager "None" + SampleTimeColors off + SampleTimeAnnotations off + LibraryLinkDisplay "none" + WideLines off + ShowLineDimensions off + ShowPortDataTypes off + ShowLoopsOnError on + IgnoreBidirectionalLines off + ShowStorageClass off + ShowTestPointIcons on + ShowSignalResolutionIcons on + ShowViewerIcons on + SortedOrder off + ExecutionContextIcon off + ShowLinearizationAnnotations on + BlockNameDataTip off + BlockParametersDataTip off + BlockDescriptionStringDataTip off + ToolBar on + StatusBar on + BrowserShowLibraryLinks off + BrowserLookUnderMasks off + SimulationMode "normal" + LinearizationMsg "none" + Profile off + ParamWorkspaceSource "MATLABWorkspace" + AccelSystemTargetFile "accel.tlc" + AccelTemplateMakefile "accel_default_tmf" + AccelMakeCommand "make_rtw" + TryForcingSFcnDF off + RecordCoverage off + CovPath "/" + CovSaveName "covdata" + CovMetricSettings "dw" + CovNameIncrementing off + CovHtmlReporting on + CovForceBlockReductionOff on + covSaveCumulativeToWorkspaceVar on + CovSaveSingleToWorkspaceVar on + CovCumulativeVarName "covCumulativeData" + CovCumulativeReport off + CovReportOnPause on + CovModelRefEnable "Off" + CovExternalEMLEnable off + ExtModeBatchMode off + ExtModeEnableFloating on + ExtModeTrigType "manual" + ExtModeTrigMode "normal" + ExtModeTrigPort "1" + ExtModeTrigElement "any" + ExtModeTrigDuration 1000 + ExtModeTrigDurationFloating "auto" + ExtModeTrigHoldOff 0 + ExtModeTrigDelay 0 + ExtModeTrigDirection "rising" + ExtModeTrigLevel 0 + ExtModeArchiveMode "off" + ExtModeAutoIncOneShot off + ExtModeIncDirWhenArm off + ExtModeAddSuffixToVar off + ExtModeWriteAllDataToWs off + ExtModeArmWhenConnect on + ExtModeSkipDownloadWhenConnect off + ExtModeLogAll on + ExtModeAutoUpdateStatusClock off + BufferReuse on + ShowModelReferenceBlockVersion off + ShowModelReferenceBlockIO off + Array { + Type "Handle" + Dimension 1 + Simulink.ConfigSet { + $ObjectID 1 + Version "1.6.0" + Array { + Type "Handle" + Dimension 8 + Simulink.SolverCC { + $ObjectID 2 + Version "1.6.0" + StartTime "0.0" + StopTime "0.5" + AbsTol "auto" + FixedStep "auto" + InitialStep "auto" + MaxNumMinSteps "-1" + MaxOrder 5 + ZcThreshold "auto" + ConsecutiveZCsStepRelTol "10*128*eps" + MaxConsecutiveZCs "1000" + ExtrapolationOrder 4 + NumberNewtonIterations 1 + MaxStep "auto" + MinStep "auto" + MaxConsecutiveMinStep "1" + RelTol "1e-3" + SolverMode "Auto" + Solver "VariableStepDiscrete" + SolverName "VariableStepDiscrete" + ShapePreserveControl "DisableAll" + ZeroCrossControl "UseLocalSettings" + ZeroCrossAlgorithm "Nonadaptive" + AlgebraicLoopSolver "TrustRegion" + SolverResetMethod "Fast" + PositivePriorityOrder off + AutoInsertRateTranBlk off + SampleTimeConstraint "Unconstrained" + InsertRTBMode "Whenever possible" + } + Simulink.DataIOCC { + $ObjectID 3 + Version "1.6.0" + Decimation "1" + ExternalInput "[t, u]" + FinalStateName "xFinal" + InitialState "xInitial" + LimitDataPoints on + MaxDataPoints "1000" + LoadExternalInput off + LoadInitialState off + SaveFinalState off + SaveCompleteFinalSimState off + SaveFormat "Array" + SaveOutput on + SaveState off + SignalLogging on + InspectSignalLogs off + SaveTime on + ReturnWorkspaceOutputs off + StateSaveName "xout" + TimeSaveName "tout" + OutputSaveName "yout" + SignalLoggingName "logsout" + OutputOption "RefineOutputTimes" + OutputTimes "[]" + ReturnWorkspaceOutputsName "out" + Refine "1" + } + Simulink.OptimizationCC { + $ObjectID 4 + Version "1.6.0" + Array { + Type "Cell" + Dimension 4 + Cell "ZeroExternalMemoryAtStartup" + Cell "ZeroInternalMemoryAtStartup" + Cell "NoFixptDivByZeroProtection" + Cell "OptimizeModelRefInitCode" + PropName "DisabledProps" + } + BlockReduction on + BooleanDataType on + ConditionallyExecuteInputs on + InlineParams off + UseIntDivNetSlope off + InlineInvariantSignals off + OptimizeBlockIOStorage on + BufferReuse on + EnhancedBackFolding off + StrengthReduction off + EnforceIntegerDowncast on + ExpressionFolding on + BooleansAsBitfields off + EnableMemcpy on + MemcpyThreshold 64 + PassReuseOutputArgsAs "Structure reference" + ExpressionDepthLimit 2147483647 + FoldNonRolledExpr on + LocalBlockOutputs on + RollThreshold 5 + SystemCodeInlineAuto off + StateBitsets off + DataBitsets off + UseTempVars off + ZeroExternalMemoryAtStartup on + ZeroInternalMemoryAtStartup on + InitFltsAndDblsToZero on + NoFixptDivByZeroProtection off + EfficientFloat2IntCast off + EfficientMapNaN2IntZero on + OptimizeModelRefInitCode off + LifeSpan "inf" + BufferReusableBoundary on + SimCompilerOptimization "Off" + AccelVerboseBuild off + } + Simulink.DebuggingCC { + $ObjectID 5 + Version "1.6.0" + RTPrefix "error" + ConsistencyChecking "none" + ArrayBoundsChecking "none" + SignalInfNanChecking "none" + SignalRangeChecking "none" + ReadBeforeWriteMsg "UseLocalSettings" + WriteAfterWriteMsg "UseLocalSettings" + WriteAfterReadMsg "UseLocalSettings" + AlgebraicLoopMsg "warning" + ArtificialAlgebraicLoopMsg "warning" + SaveWithDisabledLinksMsg "warning" + SaveWithParameterizedLinksMsg "none" + CheckSSInitialOutputMsg on + UnderspecifiedInitializationDetection "Classic" + MergeDetectMultiDrivingBlocksExec "none" + CheckExecutionContextPreStartOutputMsg off + CheckExecutionContextRuntimeOutputMsg off + SignalResolutionControl "TryResolveAllWithWarning" + BlockPriorityViolationMsg "warning" + MinStepSizeMsg "warning" + TimeAdjustmentMsg "none" + MaxConsecutiveZCsMsg "error" + SolverPrmCheckMsg "warning" + InheritedTsInSrcMsg "warning" + DiscreteInheritContinuousMsg "warning" + MultiTaskDSMMsg "error" + MultiTaskCondExecSysMsg "error" + MultiTaskRateTransMsg "error" + SingleTaskRateTransMsg "none" + TasksWithSamePriorityMsg "warning" + SigSpecEnsureSampleTimeMsg "warning" + CheckMatrixSingularityMsg "none" + IntegerOverflowMsg "warning" + Int32ToFloatConvMsg "warning" + ParameterDowncastMsg "error" + ParameterOverflowMsg "error" + ParameterUnderflowMsg "none" + ParameterPrecisionLossMsg "warning" + ParameterTunabilityLossMsg "warning" + FixptConstUnderflowMsg "none" + FixptConstOverflowMsg "none" + FixptConstPrecisionLossMsg "none" + UnderSpecifiedDataTypeMsg "none" + UnnecessaryDatatypeConvMsg "none" + VectorMatrixConversionMsg "none" + InvalidFcnCallConnMsg "error" + FcnCallInpInsideContextMsg "Use local settings" + SignalLabelMismatchMsg "none" + UnconnectedInputMsg "warning" + UnconnectedOutputMsg "warning" + UnconnectedLineMsg "warning" + SFcnCompatibilityMsg "none" + UniqueDataStoreMsg "none" + BusObjectLabelMismatch "warning" + RootOutportRequireBusObject "warning" + AssertControl "UseLocalSettings" + EnableOverflowDetection off + ModelReferenceIOMsg "none" + ModelReferenceVersionMismatchMessage "none" + ModelReferenceIOMismatchMessage "none" + ModelReferenceCSMismatchMessage "none" + UnknownTsInhSupMsg "warning" + ModelReferenceDataLoggingMessage "warning" + ModelReferenceSymbolNameMessage "warning" + ModelReferenceExtraNoncontSigs "error" + StateNameClashWarn "warning" + SimStateInterfaceChecksumMismatchMsg "warning" + StrictBusMsg "Warning" + LoggingUnavailableSignals "error" + BlockIODiagnostic "none" + } + Simulink.HardwareCC { + $ObjectID 6 + Version "1.6.0" + ProdBitPerChar 8 + ProdBitPerShort 16 + ProdBitPerInt 32 + ProdBitPerLong 32 + ProdIntDivRoundTo "Undefined" + ProdEndianess "Unspecified" + ProdWordSize 32 + ProdShiftRightIntArith on + ProdHWDeviceType "32-bit Generic" + TargetBitPerChar 8 + TargetBitPerShort 16 + TargetBitPerInt 32 + TargetBitPerLong 32 + TargetShiftRightIntArith on + TargetIntDivRoundTo "Undefined" + TargetEndianess "Unspecified" + TargetWordSize 32 + TargetTypeEmulationWarnSuppressLevel 0 + TargetPreprocMaxBitsSint 32 + TargetPreprocMaxBitsUint 32 + TargetHWDeviceType "Specified" + TargetUnknown off + ProdEqTarget on + } + Simulink.ModelReferenceCC { + $ObjectID 7 + Version "1.6.0" + UpdateModelReferenceTargets "IfOutOfDateOrStructuralChange" + CheckModelReferenceTargetMessage "error" + ModelReferenceNumInstancesAllowed "Multi" + ModelReferencePassRootInputsByReference on + ModelReferenceMinAlgLoopOccurrences off + } + Simulink.SFSimCC { + $ObjectID 8 + Version "1.6.0" + SFSimEnableDebug on + SFSimOverflowDetection on + SFSimEcho on + SimBlas on + SimCtrlC on + SimExtrinsic on + SimIntegrity on + SimUseLocalCustomCode off + SimBuildMode "sf_incremental_build" + } + Simulink.RTWCC { + $BackupClass "Simulink.RTWCC" + $ObjectID 9 + Version "1.6.0" + Array { + Type "Cell" + Dimension 1 + Cell "IncludeHyperlinkInReport" + PropName "DisabledProps" + } + SystemTargetFile "grt.tlc" + GenCodeOnly off + MakeCommand "make_rtw" + GenerateMakefile on + TemplateMakefile "grt_default_tmf" + GenerateReport off + SaveLog off + RTWVerbose on + RetainRTWFile off + ProfileTLC off + TLCDebug off + TLCCoverage off + TLCAssert off + ProcessScriptMode "Default" + ConfigurationMode "Optimized" + ConfigAtBuild off + RTWUseLocalCustomCode off + RTWUseSimCustomCode off + IncludeHyperlinkInReport off + LaunchReport off + TargetLang "C" + IncludeBusHierarchyInRTWFileBlockHierarchyMap off + IncludeERTFirstTime off + GenerateTraceInfo off + GenerateTraceReport off + GenerateTraceReportSl off + GenerateTraceReportSf off + GenerateTraceReportEml off + GenerateCodeInfo off + RTWCompilerOptimization "Off" + CheckMdlBeforeBuild "Off" + Array { + Type "Handle" + Dimension 2 + Simulink.CodeAppCC { + $ObjectID 10 + Version "1.6.0" + Array { + Type "Cell" + Dimension 16 + Cell "IgnoreCustomStorageClasses" + Cell "InsertBlockDesc" + Cell "SFDataObjDesc" + Cell "SimulinkDataObjDesc" + Cell "DefineNamingRule" + Cell "SignalNamingRule" + Cell "ParamNamingRule" + Cell "InlinedPrmAccess" + Cell "CustomSymbolStr" + Cell "CustomSymbolStrGlobalVar" + Cell "CustomSymbolStrType" + Cell "CustomSymbolStrField" + Cell "CustomSymbolStrFcn" + Cell "CustomSymbolStrBlkIO" + Cell "CustomSymbolStrTmpVar" + Cell "CustomSymbolStrMacro" + PropName "DisabledProps" + } + ForceParamTrailComments off + GenerateComments on + IgnoreCustomStorageClasses on + IgnoreTestpoints off + IncHierarchyInIds off + MaxIdLength 31 + PreserveName off + PreserveNameWithParent off + ShowEliminatedStatement off + IncAutoGenComments off + SimulinkDataObjDesc off + SFDataObjDesc off + IncDataTypeInIds off + MangleLength 1 + CustomSymbolStrGlobalVar "$R$N$M" + CustomSymbolStrType "$N$R$M" + CustomSymbolStrField "$N$M" + CustomSymbolStrFcn "$R$N$M$F" + CustomSymbolStrFcnArg "rt$I$N$M" + CustomSymbolStrBlkIO "rtb_$N$M" + CustomSymbolStrTmpVar "$N$M" + CustomSymbolStrMacro "$R$N$M" + DefineNamingRule "None" + ParamNamingRule "None" + SignalNamingRule "None" + InsertBlockDesc off + SimulinkBlockComments on + EnableCustomComments off + InlinedPrmAccess "Literals" + ReqsInCode off + UseSimReservedNames off + } + Simulink.GRTTargetCC { + $BackupClass "Simulink.TargetCC" + $ObjectID 11 + Version "1.6.0" + Array { + Type "Cell" + Dimension 13 + Cell "IncludeMdlTerminateFcn" + Cell "CombineOutputUpdateFcns" + Cell "SuppressErrorStatus" + Cell "ERTCustomFileBanners" + Cell "GenerateSampleERTMain" + Cell "GenerateTestInterfaces" + Cell "MultiInstanceERTCode" + Cell "PurelyIntegerCode" + Cell "SupportNonFinite" + Cell "SupportComplex" + Cell "SupportAbsoluteTime" + Cell "SupportContinuousTime" + Cell "SupportNonInlinedSFcns" + PropName "DisabledProps" + } + TargetFcnLib "ansi_tfl_tmw.mat" + TargetLibSuffix "" + TargetPreCompLibLocation "" + TargetFunctionLibrary "ANSI_C" + UtilityFuncGeneration "Auto" + ERTMultiwordTypeDef "System defined" + ERTMultiwordLength 256 + MultiwordLength 2048 + GenerateFullHeader on + GenerateSampleERTMain off + GenerateTestInterfaces off + IsPILTarget off + ModelReferenceCompliant on + ParMdlRefBuildCompliant on + CompOptLevelCompliant on + IncludeMdlTerminateFcn on + GeneratePreprocessorConditionals "Disable all" + CombineOutputUpdateFcns off + SuppressErrorStatus off + ERTFirstTimeCompliant off + IncludeFileDelimiter "Auto" + ERTCustomFileBanners off + SupportAbsoluteTime on + LogVarNameModifier "rt_" + MatFileLogging on + MultiInstanceERTCode off + SupportNonFinite on + SupportComplex on + PurelyIntegerCode off + SupportContinuousTime on + SupportNonInlinedSFcns on + SupportVariableSizeSignals off + EnableShiftOperators on + ParenthesesLevel "Nominal" + PortableWordSizes off + ModelStepFunctionPrototypeControlCompliant off + CPPClassGenCompliant off + AutosarCompliant off + UseMalloc off + ExtMode off + ExtModeStaticAlloc off + ExtModeTesting off + ExtModeStaticAllocSize 1000000 + ExtModeTransport 0 + ExtModeMexFile "ext_comm" + ExtModeIntrfLevel "Level1" + RTWCAPISignals off + RTWCAPIParams off + RTWCAPIStates off + GenerateASAP2 off + } + PropName "Components" + } + } + PropName "Components" + } + Name "Configuration" + CurrentDlgPage "Solver" + ConfigPrmDlgPosition " [ 200, 197, 1080, 827 ] " + } + PropName "ConfigurationSets" + } + Simulink.ConfigSet { + $PropName "ActiveConfigurationSet" + $ObjectID 1 + } + BlockDefaults { + ForegroundColor "black" + BackgroundColor "white" + DropShadow off + NamePlacement "normal" + FontName "Courier" + FontSize 10 + FontWeight "normal" + FontAngle "normal" + ShowName on + BlockRotation 0 + BlockMirror off + } + AnnotationDefaults { + HorizontalAlignment "center" + VerticalAlignment "middle" + ForegroundColor "black" + BackgroundColor "white" + DropShadow off + FontName "Courier" + FontSize 10 + FontWeight "normal" + FontAngle "normal" + UseDisplayTextAsClickCallback off + } + LineDefaults { + FontName "Courier" + FontSize 9 + FontWeight "normal" + FontAngle "normal" + } + BlockParameterDefaults { + Block { + BlockType FromWorkspace + VariableName "simulink_input" + SampleTime "-1" + Interpolate on + ZeroCross off + OutputAfterFinalValue "Extrapolation" + } + Block { + BlockType "S-Function" + FunctionName "system" + SFunctionModules "''" + PortCounts "[]" + SFunctionDeploymentMode off + } + Block { + BlockType Scope + ModelBased off + TickLabels "OneTimeTick" + ZoomMode "on" + Grid "on" + TimeRange "auto" + YMin "-5" + YMax "5" + SaveToWorkspace off + SaveName "ScopeData" + LimitDataPoints on + MaxDataPoints "5000" + Decimation "1" + SampleInput off + SampleTime "-1" + } + } + System { + Name "example_SQProblem" + Location [122, 122, 1798, 1077] + Open on + ModelBrowserVisibility off + ModelBrowserWidth 200 + ScreenColor "white" + PaperOrientation "landscape" + PaperPositionMode "auto" + PaperType "usletter" + PaperUnits "inches" + TiledPaperMargins [0.500000, 0.500000, 0.500000, 0.500000] + TiledPageScale 1 + ShowPageBoundaries off + ZoomFactor "125" + ReportName "simulink-default.rpt" + SIDHighWatermark 14 + Block { + BlockType FromWorkspace + Name "A" + SID 3 + Position [100, 198, 165, 222] + VariableName "A" + SampleTime "0.1" + ZeroCross on + OutputAfterFinalValue "Holding final value" + } + Block { + BlockType FromWorkspace + Name "H" + SID 1 + Position [100, 98, 165, 122] + VariableName "H" + SampleTime "0.1" + ZeroCross on + OutputAfterFinalValue "Holding final value" + } + Block { + BlockType FromWorkspace + Name "g" + SID 2 + Position [100, 148, 165, 172] + VariableName "g" + SampleTime "0.1" + ZeroCross on + OutputAfterFinalValue "Holding final value" + } + Block { + BlockType FromWorkspace + Name "lb" + SID 4 + Position [100, 248, 165, 272] + VariableName "lb" + SampleTime "0.1" + ZeroCross on + OutputAfterFinalValue "Holding final value" + } + Block { + BlockType FromWorkspace + Name "lbA" + SID 6 + Position [100, 348, 165, 372] + VariableName "lbA" + SampleTime "0.1" + ZeroCross on + OutputAfterFinalValue "Holding final value" + } + Block { + BlockType "S-Function" + Name "qpOASES" + SID 9 + Ports [7, 4] + Position [590, 224, 790, 296] + BackgroundColor "yellow" + FunctionName "qpOASES_SQProblem" + EnableBusSupport off + } + Block { + BlockType FromWorkspace + Name "ub" + SID 5 + Position [100, 298, 165, 322] + VariableName "ub" + SampleTime "0.1" + ZeroCross on + OutputAfterFinalValue "Holding final value" + } + Block { + BlockType FromWorkspace + Name "ubA" + SID 7 + Position [100, 398, 165, 422] + VariableName "ubA" + SampleTime "0.1" + ZeroCross on + OutputAfterFinalValue "Holding final value" + } + Block { + BlockType Scope + Name "x,\nfval,\nexitflag,\niter" + SID 8 + Ports [4] + Position [950, 223, 1005, 297] + Floating off + Location [6, 78, 1276, 993] + Open off + NumInputPorts "4" + List { + ListType AxesTitles + axes1 "%" + axes2 "%" + axes3 "%" + axes4 "%" + } + YMin "-5~-5~-5~-5" + YMax "5~5~5~5" + SaveName "ScopeData1" + DataFormat "StructureWithTime" + SampleTime "0" + } + Line { + SrcBlock "H" + SrcPort 1 + Points [155, 0; 0, 120] + DstBlock "qpOASES" + DstPort 1 + } + Line { + SrcBlock "g" + SrcPort 1 + Points [115, 0; 0, 80] + DstBlock "qpOASES" + DstPort 2 + } + Line { + Labels [3, 0] + SrcBlock "ubA" + SrcPort 1 + Points [160, 0; 0, -120] + DstBlock "qpOASES" + DstPort 7 + } + Line { + SrcBlock "ub" + SrcPort 1 + Points [80, 0; 0, -40] + DstBlock "qpOASES" + DstPort 5 + } + Line { + SrcBlock "lb" + SrcPort 1 + DstBlock "qpOASES" + DstPort 4 + } + Line { + SrcBlock "A" + SrcPort 1 + Points [80, 0; 0, 40] + DstBlock "qpOASES" + DstPort 3 + } + Line { + Labels [3, 0] + SrcBlock "lbA" + SrcPort 1 + Points [115, 0; 0, -80] + DstBlock "qpOASES" + DstPort 6 + } + Line { + SrcBlock "qpOASES" + SrcPort 1 + DstBlock "x,\nfval,\nexitflag,\niter" + DstPort 1 + } + Line { + SrcBlock "qpOASES" + SrcPort 2 + DstBlock "x,\nfval,\nexitflag,\niter" + DstPort 2 + } + Line { + SrcBlock "qpOASES" + SrcPort 3 + DstBlock "x,\nfval,\nexitflag,\niter" + DstPort 3 + } + Line { + SrcBlock "qpOASES" + SrcPort 4 + DstBlock "x,\nfval,\nexitflag,\niter" + DstPort 4 + } + Annotation { + Position [350, 96] + } + Annotation { + Name "This file is part of qpOASES.\n\nqpOASES -- An Implementation of the Online Active Set Strategy.\nC" + "opyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, Christian Kirches et al.\nAll rights reserved." + Position [683, 128] + } + } +} diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/load_example_QProblem.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/load_example_QProblem.m new file mode 100755 index 0000000..464d89b --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/load_example_QProblem.m @@ -0,0 +1,86 @@ +%% +%% This file is part of qpOASES. +%% +%% qpOASES -- An Implementation of the Online Active Set Strategy. +%% Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +%% Christian Kirches et al. All rights reserved. +%% +%% qpOASES is free software; you can redistribute it and/or +%% modify it under the terms of the GNU Lesser General Public +%% License as published by the Free Software Foundation; either +%% version 2.1 of the License, or (at your option) any later version. +%% +%% qpOASES is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +%% See the GNU Lesser General Public License for more details. +%% +%% You should have received a copy of the GNU Lesser General Public +%% License along with qpOASES; if not, write to the Free Software +%% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +%% + + + +%% +%% Filename: interfaces/simulink/load_example_QProblem.m +%% Author: Hans Joachim Ferreau (thanks to Aude Perrin) +%% Version: 3.2 +%% Date: 2007-2017 +%% + + + +clear all; + + +%% setup QP data +simulationTime = [0;0.1]; + +H = [ 1.0,0.0; ... + 0.0,0.5 ]; + +A = [ 1.0,1.0 ]; + +g.time = simulationTime; +data1 = [ 1.5,1.0 ]; +data2 = [ 1.0,1.5 ]; +g.signals.values = [data1; data2]; +g.signals.dimensions = numel(data1); + +lb.time = simulationTime; +data1 = [ 0.5,-2.0 ]; +data2 = [ 0.0,-1.0 ]; +lb.signals.values = [data1; data2]; +lb.signals.dimensions = numel(data1); + +ub.time = simulationTime; +data1 = [ 5.0,2.0 ]; +data2 = [ 5.0,-0.5 ]; +ub.signals.values = [data1; data2]; +ub.signals.dimensions = numel(data1); + +lbA.time = simulationTime; +data1 = [ -1.0 ]; +data2 = [ -2.0 ]; +lbA.signals.values = [data1; data2]; +lbA.signals.dimensions = numel(data1); + +ubA.time = simulationTime; +data1 = [ 2.0 ]; +data2 = [ 1.0 ]; +ubA.signals.values = [data1; data2]; +ubA.signals.dimensions = numel(data1); + + +clear simulationTime data1 data2 + + +%% open corresponding simulink example +open( 'example_QProblem.mdl' ); + + + +%% +%% end of file +%% diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/load_example_QProblemB.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/load_example_QProblemB.m new file mode 100755 index 0000000..bc06729 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/load_example_QProblemB.m @@ -0,0 +1,72 @@ +%% +%% This file is part of qpOASES. +%% +%% qpOASES -- An Implementation of the Online Active Set Strategy. +%% Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +%% Christian Kirches et al. All rights reserved. +%% +%% qpOASES is free software; you can redistribute it and/or +%% modify it under the terms of the GNU Lesser General Public +%% License as published by the Free Software Foundation; either +%% version 2.1 of the License, or (at your option) any later version. +%% +%% qpOASES is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +%% See the GNU Lesser General Public License for more details. +%% +%% You should have received a copy of the GNU Lesser General Public +%% License along with qpOASES; if not, write to the Free Software +%% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +%% + + + +%% +%% Filename: interfaces/simulink/load_example_QProblemB.m +%% Author: Hans Joachim Ferreau (thanks to Aude Perrin) +%% Version: 3.2 +%% Date: 2007-2017 +%% + + + +clear all; + + +%% setup QP data +simulationTime = [0;0.1]; + +H = [ 1.0,0.0; ... + 0.0,0.5 ]; + +g.time = simulationTime; +data1 = [ 1.5,1.0 ]; +data2 = [ 1.0,1.5 ]; +g.signals.values = [data1; data2]; +g.signals.dimensions = numel(data1); + +lb.time = simulationTime; +data1 = [ 0.5,-2.0 ]; +data2 = [ 0.0,-1.0 ]; +lb.signals.values = [data1; data2]; +lb.signals.dimensions = numel(data1); + +ub.time = simulationTime; +data1 = [ 5.0,2.0 ]; +data2 = [ 5.0,-0.5 ]; +ub.signals.values = [data1; data2]; +ub.signals.dimensions = numel(data1); + + +clear simulationTime data1 data2 + + +%% open corresponding simulink example +open( 'example_QProblemB.mdl' ); + + + +%% +%% end of file +%% diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/load_example_SQProblem.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/load_example_SQProblem.m new file mode 100755 index 0000000..8835b72 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/load_example_SQProblem.m @@ -0,0 +1,95 @@ +%% +%% This file is part of qpOASES. +%% +%% qpOASES -- An Implementation of the Online Active Set Strategy. +%% Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +%% Christian Kirches et al. All rights reserved. +%% +%% qpOASES is free software; you can redistribute it and/or +%% modify it under the terms of the GNU Lesser General Public +%% License as published by the Free Software Foundation; either +%% version 2.1 of the License, or (at your option) any later version. +%% +%% qpOASES is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +%% See the GNU Lesser General Public License for more details. +%% +%% You should have received a copy of the GNU Lesser General Public +%% License along with qpOASES; if not, write to the Free Software +%% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +%% + + + +%% +%% Filename: interfaces/simulink/load_example_SQProblem.m +%% Author: Hans Joachim Ferreau (thanks to Aude Perrin) +%% Version: 3.2 +%% Date: 2007-2017 +%% + + + +clear all; + + +%% setup QP data +simulationTime = [0;0.1]; + +H.time = simulationTime; +data1 = [ 1.0,0.0; ... + 0.0,0.5 ]; +data2 = [ 1.0,0.5; ... + 0.5,0.5 ]; +H.signals.values = [ data1(:)'; data2(:)' ]; +H.signals.dimensions = numel(data1); + +g.time = simulationTime; +data1 = [ 1.5,1.0 ]; +data2 = [ 1.0,1.5 ]; +g.signals.values = [data1; data2]; +g.signals.dimensions = numel(data1); + +A.time = simulationTime; +data1 = [ 1.0,1.0 ]; +data2 = [ 1.0,5.0 ]; +A.signals.values = [ data1(:)'; data2(:)' ]; +A.signals.dimensions = numel(data1); + +lb.time = simulationTime; +data1 = [ 0.5,-2.0 ]; +data2 = [ 0.0,-1.0 ]; +lb.signals.values = [data1; data2]; +lb.signals.dimensions = numel(data1); + +ub.time = simulationTime; +data1 = [ 5.0,2.0 ]; +data2 = [ 5.0,-0.5 ]; +ub.signals.values = [data1; data2]; +ub.signals.dimensions = numel(data1); + +lbA.time = simulationTime; +data1 = [ -1.0 ]; +data2 = [ -2.0 ]; +lbA.signals.values = [data1; data2]; +lbA.signals.dimensions = numel(data1); + +ubA.time = simulationTime; +data1 = [ 2.0 ]; +data2 = [ 1.0 ]; +ubA.signals.values = [data1; data2]; +ubA.signals.dimensions = numel(data1); + + +clear simulationTime data1 data2 + + +%% open corresponding simulink example +open( 'example_SQProblem.mdl' ); + + + +%% +%% end of file +%% diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/make.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/make.m new file mode 100755 index 0000000..be4314b --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/make.m @@ -0,0 +1,239 @@ +function [] = make( varargin ) +%MAKE Compiles the Simulink interface of qpOASES. +% +%Type make to compile all interfaces that +% have been modified, +%type make clean to delete all compiled interfaces, +%type make clean all to first delete and then compile +% all interfaces, +%type make 'name' to compile only the interface with +% the given name (if it has been modified), +%type make 'opt' to compile all interfaces using the +% given compiler options. +% +%Copyright (C) 2013-2017 by Hans Joachim Ferreau, Andreas Potschka, +%Christian Kirches et al. All rights reserved. + +%% +%% This file is part of qpOASES. +%% +%% qpOASES -- An Implementation of the Online Active Set Strategy. +%% Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +%% Christian Kirches et al. All rights reserved. +%% +%% qpOASES is free software; you can redistribute it and/or +%% modify it under the terms of the GNU Lesser General Public +%% License as published by the Free Software Foundation; either +%% version 2.1 of the License, or (at your option) any later version. +%% +%% qpOASES is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +%% See the GNU Lesser General Public License for more details. +%% +%% You should have received a copy of the GNU Lesser General Public +%% License along with qpOASES; if not, write to the Free Software +%% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +%% + +%% +%% Filename: interfaces/simulink/make.m +%% Author: Hans Joachim Ferreau, Andreas Potschka, Christian Kirches +%% Version: 3.2 +%% Date: 2007-2017 +%% + + + %% consistency check + if ( exist( [pwd, '/make.m'],'file' ) == 0 ) + error( ['ERROR (',mfilename '.m): Run this make script directly within the directory ', ... + '/interfaces/simulink, please.'] ); + end + + + if ( nargin > 2 ) + error( ['ERROR (',mfilename '.m): At most two make arguments supported!'] ); + else + [ doClean,fcnNames,userFlags ] = analyseMakeArguments( nargin,varargin ); + end + + + %% define compiler settings + QPOASESPATH = '../../'; + + DEBUGFLAGS = ' '; + %DEBUGFLAGS = ' -g CXXDEBUGFLAGS=''$CXXDEBUGFLAGS -Wall -pedantic -Wshadow'' '; + + IFLAGS = [ '-I. -I',QPOASESPATH,'include',' -I',QPOASESPATH,'src',' ' ]; + CPPFLAGS = [ IFLAGS, DEBUGFLAGS, '-largeArrayDims -D__cpluplus -D__MATLAB__ -D__SINGLE_OBJECT__',' ' ]; + defaultFlags = '-O '; %% -D__NO_COPYRIGHT__ -D__SUPPRESSANYOUTPUT__ + + if ( ispc == 0 ) + CPPFLAGS = [ CPPFLAGS, '-DLINUX ',' ' ]; + else + CPPFLAGS = [ CPPFLAGS, '-DWIN32 ',' ' ]; + end + + if ( isempty(userFlags) > 0 ) + CPPFLAGS = [ CPPFLAGS, defaultFlags,' ' ]; + else + CPPFLAGS = [ CPPFLAGS, userFlags,' ' ]; + end + + mexExt = eval('mexext'); + + + %% ensure copyright notice is displayed + if ~isempty( strfind( CPPFLAGS,'-D__NO_COPYRIGHT__' ) ) + printCopyrightNotice( ); + end + + + %% clean if desired + if ( doClean > 0 ) + + eval( 'delete *.o;' ); + eval( ['delete *.',mexExt,'*;'] ); + disp( [ 'INFO (',mfilename '.m): Cleaned all compiled files.'] ); + pause( 0.2 ); + + end + + + if ( ~isempty(userFlags) ) + disp( [ 'INFO (',mfilename '.m): Compiling all files with user-defined compiler flags (''',userFlags,''')...'] ); + end + + + %% call mex compiler + for ii=1:length(fcnNames) + + cmd = [ 'mex -output ', fcnNames{ii}, ' ', CPPFLAGS, [fcnNames{ii},'.cpp'] ]; + + if ( exist( [fcnNames{ii},'.',mexExt],'file' ) == 0 ) + + eval( cmd ); + disp( [ 'INFO (',mfilename '.m): ', fcnNames{ii},'.',mexExt, ' successfully created.'] ); + + else + + % check modification time of source/Make files and compiled mex file + cppFile = dir( [pwd,'/',fcnNames{ii},'.cpp'] ); + cppFileTimestamp = getTimestamp( cppFile ); + + makeFile = dir( [pwd,'/make.m'] ); + makeFileTimestamp = getTimestamp( makeFile ); + + mexFile = dir( [pwd,'/',fcnNames{ii},'.',mexExt] ); + if ( isempty(mexFile) == 0 ) + mexFileTimestamp = getTimestamp( mexFile ); + else + mexFileTimestamp = 0; + end + + if ( ( cppFileTimestamp >= mexFileTimestamp ) || ... + ( makeFileTimestamp >= mexFileTimestamp ) ) + eval( cmd ); + disp( [ 'INFO (',mfilename '.m): ', fcnNames{ii},'.',mexExt, ' successfully created.'] ); + else + disp( [ 'INFO (',mfilename '.m): ', fcnNames{ii},'.',mexExt, ' already exists.'] ); + end + + end + + end + + %% add qpOASES directory to path + path( path,pwd ); + +end + + +function [ doClean,fcnNames,userIFlags ] = analyseMakeArguments( nArgs,args ) + + doClean = 0; + fcnNames = []; + userIFlags = []; + + switch ( nArgs ) + + case 1 + if ( strcmp( args{1},'all' ) > 0 ) + fcnNames = { 'qpOASES_QProblemB','qpOASES_QProblem','qpOASES_SQProblem' }; + elseif ( strcmp( args{1},'qpOASES_QProblemB' ) > 0 ) + fcnNames = { 'qpOASES_QProblemB' }; + elseif ( strcmp( args{1},'qpOASES_QProblem' ) > 0 ) + fcnNames = { 'qpOASES_QProblem' }; + elseif ( strcmp( args{1},'qpOASES_SQProblem' ) > 0 ) + fcnNames = { 'qpOASES_SQProblem' }; + elseif ( strcmp( args{1},'clean' ) > 0 ) + doClean = 1; + elseif ( strcmp( args{1}(1),'-' ) > 0 ) + % make clean all with user-specified compiler flags + userIFlags = args{1}; + doClean = 1; + fcnNames = { 'qpOASES_QProblemB','qpOASES_QProblem','qpOASES_SQProblem' }; + else + error( ['ERROR (',mfilename '.m): Invalid first argument (''',args{1},''')!'] ); + end + + case 2 + if ( strcmp( args{1},'clean' ) > 0 ) + doClean = 1; + else + error( ['ERROR (',mfilename '.m): First argument must be ''clean'' if two arguments are provided!'] ); + end + + if ( strcmp( args{2},'all' ) > 0 ) + fcnNames = { 'qpOASES_QProblemB','qpOASES_QProblem','qpOASES_SQProblem' }; + elseif ( strcmp( args{2},'qpOASES_QProblemB' ) > 0 ) + fcnNames = { 'qpOASES_QProblemB' }; + elseif ( strcmp( args{2},'qpOASES_QProblem' ) > 0 ) + fcnNames = { 'qpOASES_QProblem' }; + elseif ( strcmp( args{2},'qpOASES_SQProblem' ) > 0 ) + fcnNames = { 'qpOASES_SQProblem' }; + else + error( ['ERROR (',mfilename '.m): Invalid second argument (''',args{2},''')!'] ); + end + + otherwise + doClean = 0; + fcnNames = { 'qpOASES_QProblemB','qpOASES_QProblem','qpOASES_SQProblem' }; + userIFlags = []; + end + +end + + +function [ timestamp ] = getTimestamp( dateString ) + + try + timestamp = dateString.datenum; + catch + timestamp = Inf; + end + +end + + +function [ ] = printCopyrightNotice( ) + + disp( ' ' ); + disp( 'qpOASES -- An Implementation of the Online Active Set Strategy.' ); + disp( 'Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka,' ); + disp( 'Christian Kirches et al. All rights reserved.' ); + disp( ' ' ); + disp( 'qpOASES is distributed under the terms of the' ); + disp( 'GNU Lesser General Public License 2.1 in the hope that it will be' ); + disp( 'useful, but WITHOUT ANY WARRANTY; without even the implied warranty' ); + disp( 'of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.' ); + disp( 'See the GNU Lesser General Public License for more details.' ); + disp( ' ' ); + disp( ' ' ); + +end + + +%% +%% end of file +%% diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/qpOASES_QProblem.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/qpOASES_QProblem.cpp new file mode 100644 index 0000000..b4a0f5f --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/qpOASES_QProblem.cpp @@ -0,0 +1,459 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file interfaces/simulink/qpOASES_QProblem.cpp + * \author Hans Joachim Ferreau (thanks to Aude Perrin) + * \version 3.2 + * \date 2007-2017 + * + * Interface for Simulink(R) that enables to call qpOASES as a S function + * (variant for QPs with fixed matrices). + * + */ + +#include + +#include "qpOASES_simulink_utils.cpp" +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define S_FUNCTION_NAME qpOASES_QProblem /**< Name of the S function. */ +#define S_FUNCTION_LEVEL 2 /**< S function level. */ + +#define MDL_START /**< Activate call to mdlStart. */ + +#include "simstruc.h" + +/* SETTINGS: */ +#define SAMPLINGTIME -1 /**< Sampling time. */ +#define NCONTROLINPUTS 2 /**< Number of control inputs. */ +#define MAXITER 100 /**< Maximum number of iterations. */ +#define HESSIANTYPE HST_UNKNOWN /**< Hessian type, see documentation of QProblem class constructor. */ + + static void mdlInitializeSizes(SimStruct * S) /* Init sizes array */ + { + int ii; + int nU = NCONTROLINPUTS; + + /* Specify the number of continuous and discrete states */ + ssSetNumContStates(S, 0); + ssSetNumDiscStates(S, 0); + + /* Specify the number of parameters */ + ssSetNumSFcnParams(S, 2); /* H, A */ + if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) + return; + + /* Specify the number of intput ports */ + if (!ssSetNumInputPorts(S, 5)) + return; + + /* Specify the number of output ports */ + if (!ssSetNumOutputPorts(S, 4)) + return; + + /* Specify dimension information for the input ports */ + ssSetInputPortVectorDimension(S, 0, DYNAMICALLY_SIZED); /* g */ + ssSetInputPortVectorDimension(S, 1, DYNAMICALLY_SIZED); /* lb */ + ssSetInputPortVectorDimension(S, 2, DYNAMICALLY_SIZED); /* ub */ + ssSetInputPortVectorDimension(S, 3, DYNAMICALLY_SIZED); /* lbA */ + ssSetInputPortVectorDimension(S, 4, DYNAMICALLY_SIZED); /* ubA */ + + /* Specify dimension information for the output ports */ + ssSetOutputPortVectorDimension(S, 0, nU); /* uOpt */ + ssSetOutputPortVectorDimension(S, 1, 1); /* fval */ + ssSetOutputPortVectorDimension(S, 2, 1); /* exitflag */ + ssSetOutputPortVectorDimension(S, 3, 1); /* iter */ + + /* Specify the direct feedthrough status */ + for (ii = 0; ii < 5; ++ii) { + ssSetInputPortDirectFeedThrough(S, ii, 1); + // ssSetInputPortRequiredContiguous(S, ii, 1); + } + + /* One sample time */ + ssSetNumSampleTimes(S, 1); + + /* global variables: + * 0: problem + * 1: H + * 2: g + * 3: A + * 4: lb + * 5: ub + * 6: lbA + * 7: ubA + */ + + /* Specify the size of the block's pointer work vector */ + ssSetNumPWork(S, 8); + } + +#if defined(MATLAB_MEX_FILE) + +#define MDL_SET_INPUT_PORT_DIMENSION_INFO +#define MDL_SET_OUTPUT_PORT_DIMENSION_INFO + + static void mdlSetInputPortDimensionInfo(SimStruct * S, int_T port, const DimsInfo_T * dimsInfo) + { + if (!ssSetInputPortDimensionInfo(S, port, dimsInfo)) + return; + } + + static void mdlSetOutputPortDimensionInfo(SimStruct * S, int_T port, const DimsInfo_T * dimsInfo) + { + if (!ssSetOutputPortDimensionInfo(S, port, dimsInfo)) + return; + } + +#endif + + static void mdlInitializeSampleTimes(SimStruct * S) + { + ssSetSampleTime(S, 0, SAMPLINGTIME); + ssSetOffsetTime(S, 0, 0.0); + } + + static void mdlStart(SimStruct * S) + { + USING_NAMESPACE_QPOASES + + int nU = NCONTROLINPUTS; + int size_g, size_lb, size_ub, size_lbA, size_ubA; + int size_H, nRows_H, nCols_H, size_A, nRows_A, nCols_A; + int nV, nC; + + QProblem * problem; + + /* get block inputs dimensions */ + const mxArray * in_H = ssGetSFcnParam(S, 0); + const mxArray * in_A = ssGetSFcnParam(S, 1); + + if (mxIsEmpty(in_H) == 1) { + if ((HESSIANTYPE != HST_ZERO) && (HESSIANTYPE != HST_IDENTITY)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt( + "ERROR (qpOASES): Hessian can only be empty if type is set to HST_ZERO or HST_IDENTITY!"); +#endif + return; + } + + nRows_H = 0; + nCols_H = 0; + size_H = 0; + } else { + nRows_H = (int)mxGetM(in_H); + nCols_H = (int)mxGetN(in_H); + size_H = nRows_H * nCols_H; + } + + if (mxIsEmpty(in_A) == 1) { + nRows_A = 0; + nCols_A = 0; + size_A = 0; + } else { + nRows_A = (int)mxGetM(in_A); + nCols_A = (int)mxGetN(in_A); + size_A = nRows_A * nCols_A; + } + + size_g = ssGetInputPortWidth(S, 0); + size_lb = ssGetInputPortWidth(S, 1); + size_ub = ssGetInputPortWidth(S, 2); + size_lbA = ssGetInputPortWidth(S, 3); + size_ubA = ssGetInputPortWidth(S, 4); + + /* dimension checks */ + nV = size_g; + nC = nRows_A; + + if (MAXITER < 0) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Maximum number of iterations must not be negative!"); +#endif + return; + } + + if (nV <= 0) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch!"); +#endif + return; + } + + if ((size_H != nV * nV) && (size_H != 0)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch in H!"); +#endif + return; + } + + if (nRows_H != nCols_H) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Hessian matrix must be square matrix!"); +#endif + return; + } + + if ((nU < 1) || (nU > nV)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Invalid number of control inputs!"); +#endif + return; + } + + if ((size_lb != nV) && (size_lb != 0)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch in lb!"); +#endif + return; + } + + if ((size_ub != nV) && (size_lb != 0)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch in ub!"); +#endif + return; + } + + if ((size_lbA != nC) && (size_lbA != 0)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch in lbA!"); +#endif + return; + } + + if ((size_ubA != nC) && (size_ubA != 0)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch in ubA!"); +#endif + return; + } + + /* allocate QProblem object */ + problem = new QProblem(nV, nC, HESSIANTYPE); + if (problem == 0) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Unable to create QProblem object!"); +#endif + return; + } + + Options problemOptions; + problemOptions.setToMPC(); + problem->setOptions(problemOptions); + +#ifndef __DEBUG__ + problem->setPrintLevel(PL_LOW); +#endif +#ifdef __SUPPRESSANYOUTPUT__ + problem->setPrintLevel(PL_NONE); +#endif + + ssGetPWork(S)[0] = (void *)problem; + + /* allocate memory for QP data ... */ + if (size_H > 0) + ssGetPWork(S)[1] = (void *)calloc(size_H, sizeof(real_t)); /* H */ + else + ssGetPWork(S)[1] = 0; + + ssGetPWork(S)[2] = (void *)calloc(size_g, sizeof(real_t)); /* g */ + ssGetPWork(S)[3] = (void *)calloc(size_A, sizeof(real_t)); /* A */ + + if (size_lb > 0) + ssGetPWork(S)[4] = (void *)calloc(size_lb, sizeof(real_t)); /* lb */ + else + ssGetPWork(S)[4] = 0; + + if (size_ub > 0) + ssGetPWork(S)[5] = (void *)calloc(size_ub, sizeof(real_t)); /* ub */ + else + ssGetPWork(S)[5] = 0; + + if (size_lbA > 0) + ssGetPWork(S)[6] = (void *)calloc(size_lbA, sizeof(real_t)); /* lbA */ + else + ssGetPWork(S)[6] = 0; + + if (size_ubA > 0) + ssGetPWork(S)[7] = (void *)calloc(size_ubA, sizeof(real_t)); /* ubA */ + else + ssGetPWork(S)[7] = 0; + } + + static void mdlOutputs(SimStruct * S, int_T tid) + { + USING_NAMESPACE_QPOASES + + int ii; + int nV, nC; + returnValue status; + + int_t nWSR = MAXITER; + int nU = NCONTROLINPUTS; + + InputRealPtrsType in_g, in_lb, in_ub, in_lbA, in_ubA; + + QProblem * problem; + real_t *H, *g, *A, *lb, *ub, *lbA, *ubA; + + real_t * xOpt; + + real_T *out_uOpt, *out_objVal, *out_status, *out_nWSR; + + /* get pointers to block inputs ... */ + const mxArray * in_H = ssGetSFcnParam(S, 0); + const mxArray * in_A = ssGetSFcnParam(S, 1); + in_g = ssGetInputPortRealSignalPtrs(S, 0); + in_lb = ssGetInputPortRealSignalPtrs(S, 1); + in_ub = ssGetInputPortRealSignalPtrs(S, 2); + in_lbA = ssGetInputPortRealSignalPtrs(S, 3); + in_ubA = ssGetInputPortRealSignalPtrs(S, 4); + + /* ... and to the QP data */ + problem = (QProblem *)(ssGetPWork(S)[0]); + + H = (real_t *)ssGetPWork(S)[1]; + g = (real_t *)ssGetPWork(S)[2]; + A = (real_t *)ssGetPWork(S)[3]; + lb = (real_t *)ssGetPWork(S)[4]; + ub = (real_t *)ssGetPWork(S)[5]; + lbA = (real_t *)ssGetPWork(S)[6]; + ubA = (real_t *)ssGetPWork(S)[7]; + + /* setup QP data */ + nV = ssGetInputPortWidth(S, 0); /* nV = size_g */ + nC = (int)mxGetM(in_A); /* nC = nRows_A*/ + + if (H != 0) { + /* no conversion from FORTRAN to C as Hessian is symmetric! */ + for (ii = 0; ii < nV * nV; ++ii) + H[ii] = (mxGetPr(in_H))[ii]; + } + + convertFortranToC(mxGetPr(in_A), nV, nC, A); + + for (ii = 0; ii < nV; ++ii) + g[ii] = (*in_g)[ii]; + + if (lb != 0) { + for (ii = 0; ii < nV; ++ii) + lb[ii] = (*in_lb)[ii]; + } + + if (ub != 0) { + for (ii = 0; ii < nV; ++ii) + ub[ii] = (*in_ub)[ii]; + } + + if (lbA != 0) { + for (ii = 0; ii < nC; ++ii) + lbA[ii] = (*in_lbA)[ii]; + } + + if (ubA != 0) { + for (ii = 0; ii < nC; ++ii) + ubA[ii] = (*in_ubA)[ii]; + } + + xOpt = new real_t[nV]; + + if (problem->getCount() == 0) { + /* initialise and solve first QP */ + status = problem->init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + problem->getPrimalSolution(xOpt); + } else { + /* solve neighbouring QP using hotstart technique */ + status = problem->hotstart(g, lb, ub, lbA, ubA, nWSR, 0); + if ((status != SUCCESSFUL_RETURN) && (status != RET_MAX_NWSR_REACHED)) { + /* if an error occurs, reset problem data structures ... */ + problem->reset(); + + /* ... and initialise/solve again with remaining number of iterations. */ + int_t nWSR_retry = MAXITER - nWSR; + status = problem->init(H, g, A, lb, ub, lbA, ubA, nWSR_retry, 0); + nWSR += nWSR_retry; + } + + /* obtain optimal solution */ + problem->getPrimalSolution(xOpt); + } + + /* generate block output: status information ... */ + out_uOpt = ssGetOutputPortRealSignal(S, 0); + out_objVal = ssGetOutputPortRealSignal(S, 1); + out_status = ssGetOutputPortRealSignal(S, 2); + out_nWSR = ssGetOutputPortRealSignal(S, 3); + + for (ii = 0; ii < nU; ++ii) + out_uOpt[ii] = (real_T)(xOpt[ii]); + + out_objVal[0] = (real_T)(problem->getObjVal()); + out_status[0] = (real_t)(getSimpleStatus(status)); + out_nWSR[0] = (real_T)(nWSR); + + removeNaNs(out_uOpt, nU); + removeInfs(out_uOpt, nU); + removeNaNs(out_objVal, 1); + removeInfs(out_objVal, 1); + + delete[] xOpt; + } + + static void mdlTerminate(SimStruct * S) + { + USING_NAMESPACE_QPOASES + + int ii; + + /* reset global message handler */ + getGlobalMessageHandler()->reset(); + + if (ssGetPWork(S)[0] != 0) + delete ((QProblem *)(ssGetPWork(S)[0])); + + for (ii = 1; ii < 8; ++ii) { + if (ssGetPWork(S)[ii] != 0) + free(ssGetPWork(S)[ii]); + } + } + +#ifdef MATLAB_MEX_FILE +#include "simulink.c" +#else +#include "cg_sfun.h" +#endif + +#ifdef __cplusplus +} +#endif + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/qpOASES_QProblemB.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/qpOASES_QProblemB.cpp new file mode 100644 index 0000000..17a5526 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/qpOASES_QProblemB.cpp @@ -0,0 +1,396 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file interfaces/simulink/qpOASES_QProblemB.cpp + * \author Hans Joachim Ferreau (thanks to Aude Perrin) + * \version 3.2 + * \date 2007-2017 + * + * Interface for Simulink(R) that enables to call qpOASES as a S function + * (variant for simply bounded QPs with fixed matrices). + * + */ + +#include + +#include "qpOASES_simulink_utils.cpp" +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define S_FUNCTION_NAME qpOASES_QProblemB /**< Name of the S function. */ +#define S_FUNCTION_LEVEL 2 /**< S function level. */ + +#define MDL_START /**< Activate call to mdlStart. */ + +#include "simstruc.h" + +/* SETTINGS */ +#define SAMPLINGTIME -1 /**< Sampling time. */ +#define NCONTROLINPUTS 2 /**< Number of control inputs. */ +#define MAXITER 100 /**< Maximum number of iteration. */ +#define HESSIANTYPE HST_UNKNOWN /**< Hessian type, see documentation of QProblemB class constructor. */ + + static void mdlInitializeSizes(SimStruct * S) /* Init sizes array */ + { + int ii; + int nU = NCONTROLINPUTS; + + /* Specify the number of continuous and discrete states */ + ssSetNumContStates(S, 0); + ssSetNumDiscStates(S, 0); + + /* Specify the number of parameters */ + ssSetNumSFcnParams(S, 1); /* H */ + if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) + return; + + /* Specify the number of intput ports */ + if (!ssSetNumInputPorts(S, 3)) + return; + + /* Specify the number of output ports */ + if (!ssSetNumOutputPorts(S, 4)) + return; + + /* Specify dimension information for the input ports */ + ssSetInputPortVectorDimension(S, 0, DYNAMICALLY_SIZED); /* g */ + ssSetInputPortVectorDimension(S, 1, DYNAMICALLY_SIZED); /* lb */ + ssSetInputPortVectorDimension(S, 2, DYNAMICALLY_SIZED); /* ub */ + + /* Specify dimension information for the output ports */ + ssSetOutputPortVectorDimension(S, 0, nU); /* uOpt */ + ssSetOutputPortVectorDimension(S, 1, 1); /* fval */ + ssSetOutputPortVectorDimension(S, 2, 1); /* exitflag */ + ssSetOutputPortVectorDimension(S, 3, 1); /* iter */ + + /* Specify the direct feedthrough status */ + for (ii = 0; ii < 3; ++ii) { + ssSetInputPortDirectFeedThrough(S, ii, 1); + // ssSetInputPortRequiredContiguous(S, ii, 1); + } + + /* One sample time */ + ssSetNumSampleTimes(S, 1); + + /* global variables: + * 0: problem + * 1: H + * 2: g + * 3: lb + * 4: ub + */ + + /* Specify the size of the block's pointer work vector */ + ssSetNumPWork(S, 5); + } + +#if defined(MATLAB_MEX_FILE) + +#define MDL_SET_INPUT_PORT_DIMENSION_INFO +#define MDL_SET_OUTPUT_PORT_DIMENSION_INFO + + static void mdlSetInputPortDimensionInfo(SimStruct * S, int_T port, const DimsInfo_T * dimsInfo) + { + if (!ssSetInputPortDimensionInfo(S, port, dimsInfo)) + return; + } + + static void mdlSetOutputPortDimensionInfo(SimStruct * S, int_T port, const DimsInfo_T * dimsInfo) + { + if (!ssSetOutputPortDimensionInfo(S, port, dimsInfo)) + return; + } + +#endif + + static void mdlInitializeSampleTimes(SimStruct * S) + { + ssSetSampleTime(S, 0, SAMPLINGTIME); + ssSetOffsetTime(S, 0, 0.0); + } + + static void mdlStart(SimStruct * S) + { + USING_NAMESPACE_QPOASES + + int nU = NCONTROLINPUTS; + int size_g, size_lb, size_ub; + int size_H, nRows_H, nCols_H; + int nV; + + QProblemB * problem; + + /* get block inputs dimensions */ + const mxArray * in_H = ssGetSFcnParam(S, 0); + + if (mxIsEmpty(in_H) == 1) { + if ((HESSIANTYPE != HST_ZERO) && (HESSIANTYPE != HST_IDENTITY)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt( + "ERROR (qpOASES): Hessian can only be empty if type is set to HST_ZERO or HST_IDENTITY!"); +#endif + return; + } + + nRows_H = 0; + nCols_H = 0; + size_H = 0; + } else { + nRows_H = (int)mxGetM(in_H); + nCols_H = (int)mxGetN(in_H); + size_H = nRows_H * nCols_H; + } + + size_g = ssGetInputPortWidth(S, 0); + size_lb = ssGetInputPortWidth(S, 1); + size_ub = ssGetInputPortWidth(S, 2); + + /* dimension checks */ + nV = size_g; + + if (MAXITER < 0) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Maximum number of iterations must not be negative!"); +#endif + return; + } + + if (nV <= 0) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch!"); +#endif + return; + } + + if ((size_H != nV * nV) && (size_H != 0)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch in H!"); +#endif + return; + } + + if (nRows_H != nCols_H) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Hessian matrix must be square matrix!"); +#endif + return; + } + + if ((nU < 1) || (nU > nV)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Invalid number of control inputs!"); +#endif + return; + } + + if ((size_lb != nV) && (size_lb != 0)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch in lb!"); +#endif + return; + } + + if ((size_ub != nV) && (size_ub != 0)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch in ub!"); +#endif + return; + } + + /* allocate QProblemB object */ + problem = new QProblemB(nV, HESSIANTYPE); + if (problem == 0) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Unable to create QProblemB object!"); +#endif + return; + } + + Options problemOptions; + problemOptions.setToMPC(); + problem->setOptions(problemOptions); + +#ifndef __DEBUG__ + problem->setPrintLevel(PL_LOW); +#endif +#ifdef __SUPPRESSANYOUTPUT__ + problem->setPrintLevel(PL_NONE); +#endif + + ssGetPWork(S)[0] = (void *)problem; + + /* allocate memory for QP data ... */ + if (size_H > 0) + ssGetPWork(S)[1] = (void *)calloc(size_H, sizeof(real_t)); /* H */ + else + ssGetPWork(S)[1] = 0; + + ssGetPWork(S)[2] = (void *)calloc(size_g, sizeof(real_t)); /* g */ + + if (size_lb > 0) + ssGetPWork(S)[3] = (void *)calloc(size_lb, sizeof(real_t)); /* lb */ + else + ssGetPWork(S)[3] = 0; + + if (size_ub > 0) + ssGetPWork(S)[4] = (void *)calloc(size_ub, sizeof(real_t)); /* ub */ + else + ssGetPWork(S)[4] = 0; + } + + static void mdlOutputs(SimStruct * S, int_T tid) + { + USING_NAMESPACE_QPOASES + + int ii; + int nV; + returnValue status; + + int_t nWSR = MAXITER; + int nU = NCONTROLINPUTS; + + InputRealPtrsType in_g, in_lb, in_ub; + + QProblemB * problem; + real_t *H, *g, *lb, *ub; + + real_t * xOpt; + + real_T *out_uOpt, *out_objVal, *out_status, *out_nWSR; + + /* get pointers to block inputs ... */ + const mxArray * in_H = ssGetSFcnParam(S, 0); + in_g = ssGetInputPortRealSignalPtrs(S, 0); + in_lb = ssGetInputPortRealSignalPtrs(S, 1); + in_ub = ssGetInputPortRealSignalPtrs(S, 2); + + /* ... and to the QP data */ + problem = (QProblemB *)ssGetPWork(S)[0]; + + H = (real_t *)ssGetPWork(S)[1]; + g = (real_t *)ssGetPWork(S)[2]; + lb = (real_t *)ssGetPWork(S)[3]; + ub = (real_t *)ssGetPWork(S)[4]; + + /* setup QP data */ + nV = ssGetInputPortWidth(S, 1); /* nV = size_g */ + + if (H != 0) { + /* no conversion from FORTRAN to C as Hessian is symmetric! */ + for (ii = 0; ii < nV * nV; ++ii) + H[ii] = (mxGetPr(in_H))[ii]; + } + + for (ii = 0; ii < nV; ++ii) + g[ii] = (*in_g)[ii]; + + if (lb != 0) { + for (ii = 0; ii < nV; ++ii) + lb[ii] = (*in_lb)[ii]; + } + + if (ub != 0) { + for (ii = 0; ii < nV; ++ii) + ub[ii] = (*in_ub)[ii]; + } + + xOpt = new real_t[nV]; + + if (problem->getCount() == 0) { + /* initialise and solve first QP */ + status = problem->init(H, g, lb, ub, nWSR, 0); + problem->getPrimalSolution(xOpt); + } else { + /* solve neighbouring QP using hotstart technique */ + status = problem->hotstart(g, lb, ub, nWSR, 0); + if ((status != SUCCESSFUL_RETURN) && (status != RET_MAX_NWSR_REACHED)) { + /* if an error occurs, reset problem data structures ... */ + problem->reset(); + + /* ... and initialise/solve again with remaining number of iterations. */ + int_t nWSR_retry = MAXITER - nWSR; + status = problem->init(H, g, lb, ub, nWSR_retry, 0); + nWSR += nWSR_retry; + } + + /* obtain optimal solution */ + problem->getPrimalSolution(xOpt); + } + + /* generate block output: status information ... */ + out_uOpt = ssGetOutputPortRealSignal(S, 0); + out_objVal = ssGetOutputPortRealSignal(S, 1); + out_status = ssGetOutputPortRealSignal(S, 2); + out_nWSR = ssGetOutputPortRealSignal(S, 3); + + for (ii = 0; ii < nU; ++ii) + out_uOpt[ii] = (real_T)(xOpt[ii]); + + out_objVal[0] = (real_T)(problem->getObjVal()); + out_status[0] = (real_t)(getSimpleStatus(status)); + out_nWSR[0] = (real_T)(nWSR); + + removeNaNs(out_uOpt, nU); + removeInfs(out_uOpt, nU); + removeNaNs(out_objVal, 1); + removeInfs(out_objVal, 1); + + delete[] xOpt; + } + + static void mdlTerminate(SimStruct * S) + { + USING_NAMESPACE_QPOASES + + int ii; + + /* reset global message handler */ + getGlobalMessageHandler()->reset(); + + if (ssGetPWork(S)[0] != 0) + delete ((QProblemB *)(ssGetPWork(S)[0])); + + for (ii = 1; ii < 5; ++ii) { + if (ssGetPWork(S)[ii] != 0) + free(ssGetPWork(S)[ii]); + } + } + +#ifdef MATLAB_MEX_FILE +#include "simulink.c" +#else +#include "cg_sfun.h" +#endif + +#ifdef __cplusplus +} +#endif + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/qpOASES_SQProblem.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/qpOASES_SQProblem.cpp new file mode 100644 index 0000000..dd546e8 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/qpOASES_SQProblem.cpp @@ -0,0 +1,432 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file interfaces/simulink/qpOASES_SQProblem.cpp + * \author Hans Joachim Ferreau (thanks to Aude Perrin) + * \version 3.2 + * \date 2007-2017 + * + * Interface for Simulink(R) that enables to call qpOASES as a S function + * (variant for QPs with varying matrices). + * + */ + +#include + +#include "qpOASES_simulink_utils.cpp" +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define S_FUNCTION_NAME qpOASES_SQProblem /**< Name of the S function. */ +#define S_FUNCTION_LEVEL 2 /**< S function level. */ + +#define MDL_START /**< Activate call to mdlStart. */ + +#include "simstruc.h" + +/* SETTINGS */ +#define SAMPLINGTIME -1 /**< Sampling time. */ +#define NCONTROLINPUTS 2 /**< Number of control inputs. */ +#define MAXITER 100 /**< Maximum number of iterations. */ +#define HESSIANTYPE HST_UNKNOWN /**< Hessian type, see documentation of SQProblem class constructor. */ + + static void mdlInitializeSizes(SimStruct * S) /* Init sizes array */ + { + int ii; + int nU = NCONTROLINPUTS; + + /* Specify the number of continuous and discrete states */ + ssSetNumContStates(S, 0); + ssSetNumDiscStates(S, 0); + + /* Specify the number of parameters */ + ssSetNumSFcnParams(S, 0); + if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) + return; + + /* Specify the number of intput ports */ + if (!ssSetNumInputPorts(S, 7)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Invalid number of input ports!"); +#endif + return; + } + + /* Specify the number of output ports */ + if (!ssSetNumOutputPorts(S, 4)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Invalid number of output ports!"); +#endif + return; + } + + /* Specify dimension information for the input ports */ + ssSetInputPortVectorDimension(S, 0, DYNAMICALLY_SIZED); /* H */ + ssSetInputPortVectorDimension(S, 1, DYNAMICALLY_SIZED); /* g */ + ssSetInputPortVectorDimension(S, 2, DYNAMICALLY_SIZED); /* A */ + ssSetInputPortVectorDimension(S, 3, DYNAMICALLY_SIZED); /* lb */ + ssSetInputPortVectorDimension(S, 4, DYNAMICALLY_SIZED); /* ub */ + ssSetInputPortVectorDimension(S, 5, DYNAMICALLY_SIZED); /* lbA */ + ssSetInputPortVectorDimension(S, 6, DYNAMICALLY_SIZED); /* ubA */ + + /* Specify dimension information for the output ports */ + ssSetOutputPortVectorDimension(S, 0, nU); /* uOpt */ + ssSetOutputPortVectorDimension(S, 1, 1); /* fval */ + ssSetOutputPortVectorDimension(S, 2, 1); /* exitflag */ + ssSetOutputPortVectorDimension(S, 3, 1); /* iter */ + + /* Specify the direct feedthrough status */ + for (ii = 0; ii < 7; ++ii) { + ssSetInputPortDirectFeedThrough(S, ii, 1); + // ssSetInputPortRequiredContiguous(S, ii, 1); + } + + /* One sample time */ + ssSetNumSampleTimes(S, 1); + + /* global variables: + * 0: problem + * 1: H + * 2: g + * 3: A + * 4: lb + * 5: ub + * 6: lbA + * 7: ubA + */ + + /* Specify the size of the block's pointer work vector */ + ssSetNumPWork(S, 8); + } + +#if defined(MATLAB_MEX_FILE) + +#define MDL_SET_INPUT_PORT_DIMENSION_INFO +#define MDL_SET_OUTPUT_PORT_DIMENSION_INFO + + static void mdlSetInputPortDimensionInfo(SimStruct * S, int_T port, const DimsInfo_T * dimsInfo) + { + if (!ssSetInputPortDimensionInfo(S, port, dimsInfo)) + return; + } + + static void mdlSetOutputPortDimensionInfo(SimStruct * S, int_T port, const DimsInfo_T * dimsInfo) + { + if (!ssSetOutputPortDimensionInfo(S, port, dimsInfo)) + return; + } + +#endif + + static void mdlInitializeSampleTimes(SimStruct * S) + { + ssSetSampleTime(S, 0, SAMPLINGTIME); + ssSetOffsetTime(S, 0, 0.0); + } + + static void mdlStart(SimStruct * S) + { + USING_NAMESPACE_QPOASES + + int nU = NCONTROLINPUTS; + int size_H, size_g, size_A, size_lb, size_ub, size_lbA, size_ubA; + int nV, nC; + + SQProblem * problem; + + /* get block inputs dimensions */ + size_H = ssGetInputPortWidth(S, 0); + size_g = ssGetInputPortWidth(S, 1); + size_A = ssGetInputPortWidth(S, 2); + size_lb = ssGetInputPortWidth(S, 3); + size_ub = ssGetInputPortWidth(S, 4); + size_lbA = ssGetInputPortWidth(S, 5); + size_ubA = ssGetInputPortWidth(S, 6); + + /* dimension checks */ + nV = size_g; + nC = (int)(((real_t)size_A) / ((real_t)nV)); + + if (MAXITER < 0) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Maximum number of iterations must not be negative!"); +#endif + return; + } + + if (nV <= 0) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch!"); +#endif + return; + } + + if ((size_H != nV * nV) && (size_H != 0)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch in H!"); +#endif + return; + } + + if ((nU < 1) || (nU > nV)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Invalid number of control inputs!"); +#endif + return; + } + + if ((size_lb != nV) && (size_lb != 0)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch in lb!"); +#endif + return; + } + + if ((size_ub != nV) && (size_ub != 0)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch in ub!"); +#endif + return; + } + + if ((size_lbA != nC) && (size_lbA != 0)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch in lbA!"); +#endif + return; + } + + if ((size_ubA != nC) && (size_ubA != 0)) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Dimension mismatch in ubA!"); +#endif + return; + } + + /* allocate QProblem object */ + problem = new SQProblem(nV, nC, HESSIANTYPE); + if (problem == 0) { +#ifndef __SUPPRESSANYOUTPUT__ + mexErrMsgTxt("ERROR (qpOASES): Unable to create SQProblem object!"); +#endif + return; + } + + Options problemOptions; + problemOptions.setToMPC(); + problem->setOptions(problemOptions); + +#ifndef __DEBUG__ + problem->setPrintLevel(PL_LOW); +#endif +#ifdef __SUPPRESSANYOUTPUT__ + problem->setPrintLevel(PL_NONE); +#endif + + ssGetPWork(S)[0] = (void *)problem; + + /* allocate memory for QP data ... */ + if (size_H > 0) + ssGetPWork(S)[1] = (void *)calloc(size_H, sizeof(real_t)); /* H */ + else + ssGetPWork(S)[1] = 0; + + ssGetPWork(S)[2] = (void *)calloc(size_g, sizeof(real_t)); /* g */ + ssGetPWork(S)[3] = (void *)calloc(size_A, sizeof(real_t)); /* A */ + + if (size_lb > 0) + ssGetPWork(S)[4] = (void *)calloc(size_lb, sizeof(real_t)); /* lb */ + else + ssGetPWork(S)[4] = 0; + + if (size_ub > 0) + ssGetPWork(S)[5] = (void *)calloc(size_ub, sizeof(real_t)); /* ub */ + else + ssGetPWork(S)[5] = 0; + + if (size_lbA > 0) + ssGetPWork(S)[6] = (void *)calloc(size_lbA, sizeof(real_t)); /* lbA */ + else + ssGetPWork(S)[6] = 0; + + if (size_ubA > 0) + ssGetPWork(S)[7] = (void *)calloc(size_ubA, sizeof(real_t)); /* ubA */ + else + ssGetPWork(S)[7] = 0; + } + + static void mdlOutputs(SimStruct * S, int_T tid) + { + USING_NAMESPACE_QPOASES + + int ii; + int nV, nC; + returnValue status; + + int_t nWSR = MAXITER; + int nU = NCONTROLINPUTS; + + InputRealPtrsType in_H, in_g, in_A, in_lb, in_ub, in_lbA, in_ubA; + + SQProblem * problem; + real_t *H, *g, *A, *lb, *ub, *lbA, *ubA; + + real_t * xOpt; + + real_T *out_uOpt, *out_objVal, *out_status, *out_nWSR; + + /* get pointers to block inputs ... */ + in_H = ssGetInputPortRealSignalPtrs(S, 0); + in_g = ssGetInputPortRealSignalPtrs(S, 1); + in_A = ssGetInputPortRealSignalPtrs(S, 2); + in_lb = ssGetInputPortRealSignalPtrs(S, 3); + in_ub = ssGetInputPortRealSignalPtrs(S, 4); + in_lbA = ssGetInputPortRealSignalPtrs(S, 5); + in_ubA = ssGetInputPortRealSignalPtrs(S, 6); + + /* ... and to the QP data */ + problem = (SQProblem *)ssGetPWork(S)[0]; + + H = (real_t *)ssGetPWork(S)[1]; + g = (real_t *)ssGetPWork(S)[2]; + A = (real_t *)ssGetPWork(S)[3]; + lb = (real_t *)ssGetPWork(S)[4]; + ub = (real_t *)ssGetPWork(S)[5]; + lbA = (real_t *)ssGetPWork(S)[6]; + ubA = (real_t *)ssGetPWork(S)[7]; + + /* setup QP data */ + nV = ssGetInputPortWidth(S, 1); /* nV = size_g */ + nC = (int)(((real_t)ssGetInputPortWidth(S, 2)) / ((real_t)nV)); /* nC = size_A / size_g */ + + if (H != 0) { + /* no conversion from FORTRAN to C as Hessian is symmetric! */ + for (ii = 0; ii < nV * nV; ++ii) + H[ii] = (*in_H)[ii]; + } + + convertFortranToC(*in_A, nV, nC, A); + + for (ii = 0; ii < nV; ++ii) + g[ii] = (*in_g)[ii]; + + if (lb != 0) { + for (ii = 0; ii < nV; ++ii) + lb[ii] = (*in_lb)[ii]; + } + + if (ub != 0) { + for (ii = 0; ii < nV; ++ii) + ub[ii] = (*in_ub)[ii]; + } + + if (lbA != 0) { + for (ii = 0; ii < nC; ++ii) + lbA[ii] = (*in_lbA)[ii]; + } + + if (ubA != 0) { + for (ii = 0; ii < nC; ++ii) + ubA[ii] = (*in_ubA)[ii]; + } + + xOpt = new real_t[nV]; + + if (problem->getCount() == 0) { + /* initialise and solve first QP */ + status = problem->init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + problem->getPrimalSolution(xOpt); + } else { + /* solve neighbouring QP using hotstart technique */ + status = problem->hotstart(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + if ((status != SUCCESSFUL_RETURN) && (status != RET_MAX_NWSR_REACHED)) { + /* if an error occurs, reset problem data structures ... */ + problem->reset(); + + /* ... and initialise/solve again with remaining number of iterations. */ + int_t nWSR_retry = MAXITER - nWSR; + status = problem->init(H, g, A, lb, ub, lbA, ubA, nWSR_retry, 0); + nWSR += nWSR_retry; + } + + /* obtain optimal solution */ + problem->getPrimalSolution(xOpt); + } + + /* generate block output: status information ... */ + out_uOpt = ssGetOutputPortRealSignal(S, 0); + out_objVal = ssGetOutputPortRealSignal(S, 1); + out_status = ssGetOutputPortRealSignal(S, 2); + out_nWSR = ssGetOutputPortRealSignal(S, 3); + + for (ii = 0; ii < nU; ++ii) + out_uOpt[ii] = (real_T)(xOpt[ii]); + + out_objVal[0] = (real_T)(problem->getObjVal()); + out_status[0] = (real_t)(getSimpleStatus(status)); + out_nWSR[0] = (real_T)(nWSR); + + removeNaNs(out_uOpt, nU); + removeInfs(out_uOpt, nU); + removeNaNs(out_objVal, 1); + removeInfs(out_objVal, 1); + + delete[] xOpt; + } + + static void mdlTerminate(SimStruct * S) + { + USING_NAMESPACE_QPOASES + + int ii; + + /* reset global message handler */ + getGlobalMessageHandler()->reset(); + + if (ssGetPWork(S)[0] != 0) + delete ((SQProblem *)(ssGetPWork(S)[0])); + + for (ii = 1; ii < 8; ++ii) { + if (ssGetPWork(S)[ii] != 0) + free(ssGetPWork(S)[ii]); + } + } + +#ifdef MATLAB_MEX_FILE +#include "simulink.c" +#else +#include "cg_sfun.h" +#endif + +#ifdef __cplusplus +} +#endif + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/qpOASES_simulink_utils.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/qpOASES_simulink_utils.cpp new file mode 100644 index 0000000..d3bfd47 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/interfaces/simulink/qpOASES_simulink_utils.cpp @@ -0,0 +1,112 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file interfaces/simulink/qpOASES_simulink_utils.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + * + * Collects utility functions for Interface to Simulink(R) that + * enables to call qpOASES as a C S function. + * + */ + +#ifndef __SINGLE_OBJECT__ +#include +#endif + +USING_NAMESPACE_QPOASES + +/* + * i s N a N + */ +BooleanType isNaN(real_t val) +{ + if (((val <= 0.0) || (val >= 0.0)) == 0) + return BT_TRUE; + else + return BT_FALSE; +} + +/* + * r e m o v e N a N s + */ +returnValue removeNaNs(real_t * const data, unsigned int dim) +{ + unsigned int i; + + if (data == 0) + return RET_INVALID_ARGUMENTS; + + for (i = 0; i < dim; ++i) + if (isNaN(data[i]) == BT_TRUE) + data[i] = INFTY; + + return SUCCESSFUL_RETURN; +} + +/* + * r e m o v e I n f s + */ +returnValue removeInfs(real_t * const data, unsigned int dim) +{ + unsigned int i; + + if (data == 0) + return RET_INVALID_ARGUMENTS; + + for (i = 0; i < dim; ++i) { + if (data[i] < -INFTY) + data[i] = -INFTY; + + if (data[i] > INFTY) + data[i] = INFTY; + } + + return SUCCESSFUL_RETURN; +} + +/* + * c o n v e r t F o r t r a n T o C + */ +returnValue convertFortranToC(const real_t * const M_for, int nV, int nC, real_t * const M) +{ + int i, j; + + if ((M_for == 0) || (M == 0)) + return RET_INVALID_ARGUMENTS; + + if ((nV < 0) || (nC < 0)) + return RET_INVALID_ARGUMENTS; + + for (i = 0; i < nC; ++i) + for (j = 0; j < nV; ++j) + M[i * nV + j] = M_for[j * nC + i]; + + return SUCCESSFUL_RETURN; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/make.mk b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/make.mk new file mode 100755 index 0000000..d4b4c12 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/make.mk @@ -0,0 +1,38 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: make.mk +## Author: Hans Joachim Ferreau, Andreas Potschka, Christian Kirches +## Version: 3.2 +## Date: 2007-2017 +## + + +TOP = $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) + +include ${TOP}/make_linux.mk +#include ${TOP}/make_cygwin.mk +#include ${TOP}/make_windows.mk +#include ${TOP}/make_osx.mk diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/make_cygwin.mk b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/make_cygwin.mk new file mode 100755 index 0000000..daf2b51 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/make_cygwin.mk @@ -0,0 +1,119 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: make_cygwin.mk +## Author: Hans Joachim Ferreau, Andreas Potschka, Christian Kirches +## Version: 3.2 +## Date: 2007-2017 +## + +################################################################################ +# user configuration + +# include directories, relative +IDIR = ${TOP}/include +SRCDIR = ${TOP}/src +BINDIR = ${TOP}/bin + +# Matlab include directory (ADAPT TO YOUR LOCAL SETTINGS!) +MATLAB_IDIR = /cygdrive/c/progra~2/matlab/r2009b/extern/include/ +MATLAB_LIBDIR = /cygdrive/c/progra~2/matlab/r2009b/extern/lib/win32/microsoft + +# system or replacement BLAS/LAPACK +REPLACE_LINALG = 1 + +ifeq ($(REPLACE_LINALG), 1) + LIB_BLAS = ${SRCDIR}/BLASReplacement.o + LIB_LAPACK = ${SRCDIR}/LAPACKReplacement.o +else + LIB_BLAS = /usr/lib/lapack/cygblas-0.dll + LIB_LAPACK = /usr/lib/lapack/cyglapack-0.dll +endif + +# choice of sparse solver: NONE, MA27, or MA57 +# If choice is not 'NONE', BLAS and LAPACK replacements must not be used +USE_SOLVER = NONE + +ifeq ($(USE_SOLVER), MA57) + LIB_SOLVER = /usr/local/lib/libhsl_ma57.a /usr/local/lib/libfakemetis.a + DEF_SOLVER = SOLVER_MA57 +else ifeq ($(USE_SOLVER), MA27) + LIB_SOLVER = /usr/local/lib/libhsl_ma27.a + DEF_SOLVER = SOLVER_MA27 +else + LIB_SOLVER = + DEF_SOLVER = SOLVER_NONE +endif + +################################################################################ +# do not touch this + +CPP = g++ +CC = gcc +AR = ar +RM = rm +F77 = gfortran +ECHO = echo +CD = cd +CP = cp + +# file extensions +OBJEXT = o +LIBEXT = a +DLLEXT = so +EXE = .exe +MEXOCTEXT = mex +DEF_TARGET = -o $@ +SHARED = -shared + +# 32 or 64 depending on target platform +BITS = $(shell getconf LONG_BIT) + +# decide on MEX interface extension +ifeq ($(BITS), 32) + MEXEXT = mexw32 +else + MEXEXT = mexw64 +endif + +CPPFLAGS = -Wall -pedantic -Wshadow -Wfloat-equal -O3 -Wconversion -Wsign-conversion -DWIN32 -D${DEF_SOLVER} -D__NO_COPYRIGHT__ +# -g -D__DEBUG__ -D__NO_COPYRIGHT__ -D__SUPPRESSANYOUTPUT__ -D__USE_SINGLE_PRECISION__ + +# libraries to link against when building qpOASES .so files +LINK_LIBRARIES = ${LIB_LAPACK} ${LIB_BLAS} -lm ${LIB_SOLVER} +LINK_LIBRARIES_WRAPPER = -lm ${LIB_SOLVER} -lstdc++ + +# how to link against the qpOASES shared library +QPOASES_LINK = -L${BINDIR} -Wl,-rpath=${BINDIR} -lqpOASES +QPOASES_LINK_WRAPPER = -L${BINDIR} -Wl,-rpath=${BINDIR} -lqpOASES_wrapper + +# link dependencies when creating executables +LINK_DEPENDS = ${LIB_LAPACK} ${LIB_BLAS} ${BINDIR}/libqpOASES.${LIBEXT} ${BINDIR}/libqpOASES.${DLLEXT} +LINK_DEPENDS_WRAPPER = ${BINDIR}/libqpOASES_wrapper.${LIBEXT} ${BINDIR}/libqpOASES_wrapper.${DLLEXT} + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/make_linux.mk b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/make_linux.mk new file mode 100755 index 0000000..4820cff --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/make_linux.mk @@ -0,0 +1,133 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: make_linux.mk +## Author: Hans Joachim Ferreau, Andreas Potschka, Christian Kirches +## Version: 3.2 +## Date: 2007-2017 +## + +################################################################################ +# user configuration + +# include directories, relative +IDIR = ${TOP}/include +SRCDIR = ${TOP}/src +BINDIR = ${TOP}/bin +MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) +MKFILE_DIR := $(dir $(MKFILE_PATH)) +EXT_IDIR = + +# Matlab include directory (ADAPT TO YOUR LOCAL SETTINGS!) +#MATLAB_IDIR = ${HOME}/Programs/matlab/extern/include/ + +# system or replacement BLAS/LAPACK +REPLACE_LINALG = 1 + +ifeq ($(REPLACE_LINALG), 1) + LIB_BLAS = ${SRCDIR}/BLASReplacement.o + LIB_LAPACK = ${SRCDIR}/LAPACKReplacement.o +else +# LIB_BLAS = ${MATLAB_LIBDIR}/libmwblas.so +# LIB_LAPACK = ${MATLAB_LIBDIR}/libmwlapack.so +endif + +# choice of sparse solver: NONE, MA27, or MA57 +# If choice is not 'NONE', BLAS and LAPACK replacements must not be used +USE_SOLVER = NONE +# USE_SOLVER = MUMPS + + +ifeq ($(USE_SOLVER), MA57) + LIB_SOLVER = ${MATLAB_LIBDIR}/libmwma57.so + DEF_SOLVER = SOLVER_MA57 + LINKHSL = -Wl,-rpath=${MATLAB_LIBDIR} +else ifeq ($(USE_SOLVER), MA27) + LIB_SOLVER = /usr/local/lib/libhsl_ma27.a + DEF_SOLVER = SOLVER_MA27 + LINKHSL = +else ifeq ($(USE_SOLVER), MUMPS) + LIB_SOLVER = $(MKFILE_DIR)external/mumps_installation/lib/libcoinmumps.so + DEF_SOLVER = SOLVER_MUMPS + LINKHSL = + EXT_IDIR += -I$(MKFILE_DIR)external/mumps_installation/include/coin-or/mumps/ +else + LIB_SOLVER = + DEF_SOLVER = SOLVER_NONE + LINKHSL = +endif + +################################################################################ +# do not touch this + +CPP = g++ +CC = gcc +AR = ar +RM = rm +F77 = gfortran +ECHO = echo +CD = cd +CP = cp + +# file extensions +OBJEXT = o +LIBEXT = a +DLLEXT = so +EXE = +MEXOCTEXT = mex +DEF_TARGET = -o $@ +SHARED = -shared + +# 32 or 64 depending on target platform +BITS = $(shell getconf LONG_BIT) + +# decide on MEX interface extension +ifeq ($(BITS), 32) + MEXEXT = mexglx +else + MEXEXT = mexa64 +endif + + +# CPPFLAGS = -Wall $(EXT_IDIR) -pedantic -Wshadow -Wfloat-equal -O3 -Wconversion -Wsign-conversion -fPIC -DLINUX -D__USE_LONG_INTEGERS__ -D__USE_LONG_FINTS__ -D${DEF_SOLVER} -D__NO_COPYRIGHT__ +CPPFLAGS = -Wall $(EXT_IDIR) -pedantic -Wshadow -Wfloat-equal -O3 -Wconversion -Wsign-conversion -fPIC -DLINUX -D${DEF_SOLVER} -D__NO_COPYRIGHT__ +# -g -D__DEBUG__ -D__NO_COPYRIGHT__ -D__SUPPRESSANYOUTPUT__ -D__USE_SINGLE_PRECISION__ + +# libraries to link against when building qpOASES .so files +LINK_LIBRARIES = ${LIB_LAPACK} ${LIB_BLAS} -lm ${LIB_SOLVER} -ldl +LINK_LIBRARIES_WRAPPER = -lm ${LIB_SOLVER} -lstdc++ + +# how to link against the qpOASES shared library +QPOASES_LINK = -L${BINDIR} -Wl,-rpath=${BINDIR} ${LINKHSL} -lqpOASES +QPOASES_LINK_WRAPPER = -L${BINDIR} -Wl,-rpath=${BINDIR} ${LINKHSL} -lqpOASES_wrapper + +# link dependencies when creating executables +LINK_DEPENDS = ${LIB_LAPACK} ${LIB_BLAS} ${BINDIR}/libqpOASES.${LIBEXT} ${BINDIR}/libqpOASES.${DLLEXT} +LINK_DEPENDS_WRAPPER = ${BINDIR}/libqpOASES_wrapper.${LIBEXT} ${BINDIR}/libqpOASES_wrapper.${DLLEXT} + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/make_osx.mk b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/make_osx.mk new file mode 100755 index 0000000..cca2505 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/make_osx.mk @@ -0,0 +1,124 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: make_osx.mk +## Author: Hans Joachim Ferreau, Andreas Potschka, Christian Kirches +## Version: 3.2 +## Date: 2007-2017 +## + +################################################################################ +# user configuration + +# include directories, relative +IDIR = ${TOP}/include +SRCDIR = ${TOP}/src +BINDIR = ${TOP}/bin + +# MacOSX SDK +SYSROOT = /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk +SDK = -isysroot ${SYSROOT} -stdlib=libc++ + +# Matlab include directory (ADAPT TO YOUR LOCAL SETTINGS!) +MATLAB_IDIR = /Applications/MATLAB_R2013a.app/extern/include/ +MATLAB_LIBDIR = + +# system or replacement BLAS/LAPACK +REPLACE_LINALG = 0 + +ifeq ($(REPLACE_LINALG), 1) + LIB_BLAS = ${SRCDIR}/BLASReplacement.o + LIB_LAPACK = ${SRCDIR}/LAPACKReplacement.o + LA_DEPENDS = ${LIB_LAPACK} ${LIB_BLAS} +else + LIB_BLAS = -framework Accelerate + LIB_LAPACK = + LA_DEPENDS = +endif + +# choice of sparse solver: NONE, MA27, or MA57 +# If choice is not 'NONE', BLAS and LAPACK replacements must not be used +USE_SOLVER = NONE + +ifeq ($(USE_SOLVER), MA57) + LIB_SOLVER = /usr/local/lib/libhsl_ma57.a /usr/local/lib/libfakemetis.a + DEF_SOLVER = SOLVER_MA57 +else ifeq ($(USE_SOLVER), MA27) + LIB_SOLVER = /usr/local/lib/libhsl_ma27.a + DEF_SOLVER = SOLVER_MA27 +else + LIB_SOLVER = + DEF_SOLVER = SOLVER_NONE +endif + +################################################################################ +# do not touch this + +CPP = clang++ +CC = clang +AR = ar +RM = rm +F77 = gfortran +ECHO = echo +CD = cd + +# file extensions +OBJEXT = o +LIBEXT = a +DLLEXT = dylib +EXE = +MEXOCTEXT = mex +DEF_TARGET = -o $@ +SHARED = -dynamiclib ${SDK} + +# 32 or 64 depending on target platform +BITS = $(shell getconf LONG_BIT) + +# decide on MEX interface extension +ifeq ($(BITS), 32) + MEXEXT = mexglx +else + MEXEXT = mexa64 +endif + +CPPFLAGS = ${SDK} -Wall -pedantic -Wshadow -Wfloat-equal -Wconversion -Wsign-conversion -O3 -fPIC -D__USE_LONG_INTEGERS__ -D__USE_LONG_FINTS__ -D__NO_COPYRIGHT__ +# -g -D__DEBUG__ -D__NO_COPYRIGHT__ -D__SUPPRESSANYOUTPUT__ -D__USE_SINGLE_PRECISION__ + +# libraries to link against when building qpOASES .so files +LINK_LIBRARIES = ${LIB_LAPACK} ${LIB_BLAS} -lm ${LIB_SOLVER} +LINK_LIBRARIES_WRAPPER = -lm ${LIB_SOLVER} + +# how to link against the qpOASES shared library +QPOASES_LINK = -L${BINDIR} -lqpOASES -L${SYSROOT}/usr/lib/System +QPOASES_LINK_WRAPPER = -L${BINDIR} -lqpOASES_wrapper + +# link dependencies when creating executables +LINK_DEPENDS = ${LA_DEPENDS} ${BINDIR}/libqpOASES.${LIBEXT} ${BINDIR}/libqpOASES.${DLLEXT} +LINK_DEPENDS_WRAPPER = ${BINDIR}/libqpOASES_wrapper.${LIBEXT} ${BINDIR}/libqpOASES_wrapper.${DLLEXT} + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/qpOASESConfig.cmake.in b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/qpOASESConfig.cmake.in new file mode 100755 index 0000000..d0dadc2 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/qpOASESConfig.cmake.in @@ -0,0 +1,29 @@ +# CMake qpOASES module +# +# It defines the following variables: +# qpOASES_FOUND - TRUE +# qpOASES_INCLUDE_DIR - The qpOASES include directory +# qpOASES_LIBRARY_DIR - The qpOASES library directory +# qpOASES_LIBRARY - The qpOASES library +# qpOASES_VERSION - The qpOASES version in the form . + + + +@PACKAGE_INIT@ + +set(qpOASES_VERSION @PACKAGE_VERSION@) + + +set_and_check(qpOASES_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") + + +set(qpOASES_INCLUDE_DIR "${qpOASES_INCLUDE_DIR}" CACHE STRING "Include path for qpOASES and its dependencies") +set_and_check(qpOASES_LIBRARY_DIR @PACKAGE_LIB_INSTALL_DIR@) +set(qpOASES_LIBRARY_DIR "${qpOASES_LIBRARY_DIR}" CACHE STRING "Library path for qpOASES and its dependencies") + +find_library(qpOASES_LIBRARY NAMES qpOASES + PATHS ${qpOASES_LIBRARY_DIR} NO_DEFAULT_PATH) + + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(qpOASES DEFAULT_MSG qpOASES_INCLUDE_DIR qpOASES_LIBRARY_DIR qpOASES_LIBRARY qpOASES_VERSION) \ No newline at end of file diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/BLASReplacement.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/BLASReplacement.cpp new file mode 100644 index 0000000..1919b8a --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/BLASReplacement.cpp @@ -0,0 +1,162 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/BLASReplacement.cpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * BLAS Level 3 replacement routines. + */ + +#include +#include + +extern "C" void DGEMM(const char * TRANSA, + const char * TRANSB, + const la_uint_t * M, + const la_uint_t * N, + const la_uint_t * K, + const double * ALPHA, + const double * A, + const la_uint_t * LDA, + const double * B, + const la_uint_t * LDB, + const double * BETA, + double * C, + const la_uint_t * LDC) +{ + la_uint_t i, j, k; + + if (REFER_NAMESPACE_QPOASES isZero(*BETA) == REFER_NAMESPACE_QPOASES BT_TRUE) + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + C[j + (*LDC) * k] = 0.0; + else if (REFER_NAMESPACE_QPOASES isEqual(*BETA, -1.0) == REFER_NAMESPACE_QPOASES BT_TRUE) + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + C[j + (*LDC) * k] = -C[j + (*LDC) * k]; + else if (REFER_NAMESPACE_QPOASES isEqual(*BETA, 1.0) == REFER_NAMESPACE_QPOASES BT_FALSE) + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + C[j + (*LDC) * k] *= *BETA; + + if (TRANSA[0] == 'N') + if (REFER_NAMESPACE_QPOASES isEqual(*ALPHA, 1.0) == REFER_NAMESPACE_QPOASES BT_TRUE) + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + for (i = 0; i < *K; i++) + C[j + (*LDC) * k] += A[j + (*LDA) * i] * B[i + (*LDB) * k]; + else if (REFER_NAMESPACE_QPOASES isEqual(*ALPHA, -1.0) == REFER_NAMESPACE_QPOASES BT_TRUE) + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + for (i = 0; i < *K; i++) + C[j + (*LDC) * k] -= A[j + (*LDA) * i] * B[i + (*LDB) * k]; + else + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + for (i = 0; i < *K; i++) + C[j + (*LDC) * k] += *ALPHA * A[j + (*LDA) * i] * B[i + (*LDB) * k]; + else if (REFER_NAMESPACE_QPOASES isEqual(*ALPHA, 1.0) == REFER_NAMESPACE_QPOASES BT_TRUE) + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + for (i = 0; i < *K; i++) + C[j + (*LDC) * k] += A[i + (*LDA) * j] * B[i + (*LDB) * k]; + else if (REFER_NAMESPACE_QPOASES isEqual(*ALPHA, -1.0) == REFER_NAMESPACE_QPOASES BT_TRUE) + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + for (i = 0; i < *K; i++) + C[j + (*LDC) * k] -= A[i + (*LDA) * j] * B[i + (*LDB) * k]; + else + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + for (i = 0; i < *K; i++) + C[j + (*LDC) * k] += *ALPHA * A[i + (*LDA) * j] * B[i + (*LDB) * k]; +} + +extern "C" void SGEMM(const char * TRANSA, + const char * TRANSB, + const la_uint_t * M, + const la_uint_t * N, + const la_uint_t * K, + const float * ALPHA, + const float * A, + const la_uint_t * LDA, + const float * B, + const la_uint_t * LDB, + const float * BETA, + float * C, + const la_uint_t * LDC) +{ + la_uint_t i, j, k; + + if (REFER_NAMESPACE_QPOASES isZero(*BETA) == REFER_NAMESPACE_QPOASES BT_TRUE) + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + C[j + (*LDC) * k] = 0.0; + else if (REFER_NAMESPACE_QPOASES isEqual(*BETA, -1.0) == REFER_NAMESPACE_QPOASES BT_TRUE) + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + C[j + (*LDC) * k] = -C[j + (*LDC) * k]; + else if (REFER_NAMESPACE_QPOASES isEqual(*BETA, 1.0) == REFER_NAMESPACE_QPOASES BT_FALSE) + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + C[j + (*LDC) * k] *= *BETA; + + if (TRANSA[0] == 'N') + if (REFER_NAMESPACE_QPOASES isEqual(*ALPHA, 1.0) == REFER_NAMESPACE_QPOASES BT_TRUE) + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + for (i = 0; i < *K; i++) + C[j + (*LDC) * k] += A[j + (*LDA) * i] * B[i + (*LDB) * k]; + else if (REFER_NAMESPACE_QPOASES isEqual(*ALPHA, -1.0) == REFER_NAMESPACE_QPOASES BT_TRUE) + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + for (i = 0; i < *K; i++) + C[j + (*LDC) * k] -= A[j + (*LDA) * i] * B[i + (*LDB) * k]; + else + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + for (i = 0; i < *K; i++) + C[j + (*LDC) * k] += *ALPHA * A[j + (*LDA) * i] * B[i + (*LDB) * k]; + else if (REFER_NAMESPACE_QPOASES isEqual(*ALPHA, 1.0) == REFER_NAMESPACE_QPOASES BT_TRUE) + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + for (i = 0; i < *K; i++) + C[j + (*LDC) * k] += A[i + (*LDA) * j] * B[i + (*LDB) * k]; + else if (REFER_NAMESPACE_QPOASES isEqual(*ALPHA, -1.0) == REFER_NAMESPACE_QPOASES BT_TRUE) + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + for (i = 0; i < *K; i++) + C[j + (*LDC) * k] -= A[i + (*LDA) * j] * B[i + (*LDB) * k]; + else + for (k = 0; k < *N; k++) + for (j = 0; j < *M; j++) + for (i = 0; i < *K; i++) + C[j + (*LDC) * k] += *ALPHA * A[i + (*LDA) * j] * B[i + (*LDB) * k]; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Bounds.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Bounds.cpp new file mode 100644 index 0000000..8e901c2 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Bounds.cpp @@ -0,0 +1,468 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/Bounds.cpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of the Bounds class designed to manage working sets of + * bounds within a QProblem. + */ + +#include + +BEGIN_NAMESPACE_QPOASES + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +/* + * B o u n d s + */ +Bounds::Bounds() : SubjectTo() +{ +} + +/* + * B o u n d s + */ +Bounds::Bounds(int_t _n) : SubjectTo(_n) +{ + init(_n); +} + +/* + * B o u n d s + */ +Bounds::Bounds(const Bounds & rhs) : SubjectTo(rhs) +{ + copy(rhs); +} + +/* + * ~ B o u n d s + */ +Bounds::~Bounds() +{ + clear(); +} + +/* + * o p e r a t o r = + */ +Bounds & Bounds::operator=(const Bounds & rhs) +{ + if (this != &rhs) { + clear(); + SubjectTo::operator=(rhs); + copy(rhs); + } + + return *this; +} + +/* + * i n i t + */ +returnValue Bounds::init(int_t _n) +{ + if (_n < 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + clear(); + + if (_n >= 0) { + freee.init(_n); + fixed.init(_n); + } + + return SubjectTo::init(_n); +} + +/* + * s e t u p B o u n d + */ +returnValue Bounds::setupBound(int_t number, SubjectToStatus _status) +{ + /* consistency check */ + if ((number < 0) || (number >= n)) + return THROWERROR(RET_INDEX_OUT_OF_BOUNDS); + + /* Add bound index to respective index list. */ + switch (_status) { + case ST_INACTIVE: + if (this->addIndex(this->getFree(), number, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_BOUND_FAILED); + break; + + case ST_LOWER: + if (this->addIndex(this->getFixed(), number, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_BOUND_FAILED); + break; + + case ST_UPPER: + if (this->addIndex(this->getFixed(), number, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_BOUND_FAILED); + break; + + default: + return THROWERROR(RET_INVALID_ARGUMENTS); + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A l l F r e e + */ +returnValue Bounds::setupAllFree() +{ + return setupAll(ST_INACTIVE); +} + +/* + * s e t u p A l l L o w e r + */ +returnValue Bounds::setupAllLower() +{ + return setupAll(ST_LOWER); +} + +/* + * s e t u p A l l U p p e r + */ +returnValue Bounds::setupAllUpper() +{ + return setupAll(ST_UPPER); +} + +/* + * m o v e F i x e d T o F r e e + */ +returnValue Bounds::moveFixedToFree(int_t number) +{ + /* consistency check */ + if ((number < 0) || (number >= n)) + return THROWERROR(RET_INDEX_OUT_OF_BOUNDS); + + /* Move index from indexlist of fixed variables to that of free ones. */ + if (this->removeIndex(this->getFixed(), number) != SUCCESSFUL_RETURN) + return THROWERROR(RET_MOVING_BOUND_FAILED); + + if (this->addIndex(this->getFree(), number, ST_INACTIVE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_MOVING_BOUND_FAILED); + + return SUCCESSFUL_RETURN; +} + +/* + * m o v e F r e e T o F i x e d + */ +returnValue Bounds::moveFreeToFixed(int_t number, SubjectToStatus _status) +{ + /* consistency check */ + if ((number < 0) || (number >= n)) + return THROWERROR(RET_INDEX_OUT_OF_BOUNDS); + + /* Move index from indexlist of free variables to that of fixed ones. */ + if (this->removeIndex(this->getFree(), number) != SUCCESSFUL_RETURN) + return THROWERROR(RET_MOVING_BOUND_FAILED); + + if (this->addIndex(this->getFixed(), number, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_MOVING_BOUND_FAILED); + + return SUCCESSFUL_RETURN; +} + +/* + * f l i p F i x e d + */ +returnValue Bounds::flipFixed(int_t number) +{ + /* consistency check */ + if ((number < 0) || (number >= n)) + return THROWERROR(RET_INDEX_OUT_OF_BOUNDS); + + if (status != 0) + switch (status[number]) { + case ST_LOWER: + status[number] = ST_UPPER; + break; + case ST_UPPER: + status[number] = ST_LOWER; + break; + default: + return THROWERROR(RET_MOVING_BOUND_FAILED); + } + + return SUCCESSFUL_RETURN; +} + +/* + * s w a p F r e e + */ +returnValue Bounds::swapFree(int_t number1, int_t number2) +{ + /* consistency check */ + if ((number1 < 0) || (number1 >= n) || (number2 < 0) || (number2 >= n)) + return THROWERROR(RET_INDEX_OUT_OF_BOUNDS); + + /* Swap index within indexlist of free variables. */ + return this->swapIndex(this->getFree(), number1, number2); +} + +/* + * s h i f t + */ +returnValue Bounds::shift(int_t offset) +{ + int_t i; + + /* consistency check */ + if ((offset == 0) || (n <= 1)) + return SUCCESSFUL_RETURN; + + if ((offset < 0) || (offset > n / 2)) + return THROWERROR(RET_INDEX_OUT_OF_BOUNDS); + + if ((n % offset) != 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + /* 1) Shift types and status. */ + for (i = 0; i < n - offset; ++i) { + setType(i, getType(i + offset)); + setStatus(i, getStatus(i + offset)); + } + + /* 2) Construct shifted index lists of free and fixed variables. */ + Indexlist shiftedFreee(n); + Indexlist shiftedFixed(n); + + for (i = 0; i < n; ++i) { + switch (getStatus(i)) { + case ST_INACTIVE: + if (shiftedFreee.addNumber(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SHIFTING_FAILED); + break; + + case ST_LOWER: + if (shiftedFixed.addNumber(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SHIFTING_FAILED); + break; + + case ST_UPPER: + if (shiftedFixed.addNumber(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SHIFTING_FAILED); + break; + + default: + return THROWERROR(RET_SHIFTING_FAILED); + } + } + + /* 3) Assign shifted index list. */ + freee = shiftedFreee; + fixed = shiftedFixed; + + return SUCCESSFUL_RETURN; +} + +/* + * r o t a t e + */ +returnValue Bounds::rotate(int_t offset) +{ + int_t i; + + /* consistency check */ + if ((offset == 0) || (offset == n) || (n <= 1)) + return SUCCESSFUL_RETURN; + + if ((offset < 0) || (offset > n)) + return THROWERROR(RET_INDEX_OUT_OF_BOUNDS); + + /* 1) Rotate types and status. */ + SubjectToType * typeTmp = new SubjectToType[offset]; + SubjectToStatus * statusTmp = new SubjectToStatus[offset]; + + for (i = 0; i < offset; ++i) { + typeTmp[i] = getType(i); + statusTmp[i] = getStatus(i); + } + + for (i = 0; i < n - offset; ++i) { + setType(i, getType(i + offset)); + setStatus(i, getStatus(i + offset)); + } + + for (i = n - offset; i < n; ++i) { + setType(i, typeTmp[i - n + offset]); + setStatus(i, statusTmp[i - n + offset]); + } + + delete[] statusTmp; + delete[] typeTmp; + + /* 2) Construct shifted index lists of free and fixed variables. */ + Indexlist rotatedFreee(n); + Indexlist rotatedFixed(n); + + for (i = 0; i < n; ++i) { + switch (getStatus(i)) { + case ST_INACTIVE: + if (rotatedFreee.addNumber(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ROTATING_FAILED); + break; + + case ST_LOWER: + if (rotatedFixed.addNumber(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ROTATING_FAILED); + break; + + case ST_UPPER: + if (rotatedFixed.addNumber(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ROTATING_FAILED); + break; + + default: + return THROWERROR(RET_ROTATING_FAILED); + } + } + + /* 3) Assign shifted index list. */ + freee = rotatedFreee; + fixed = rotatedFixed; + + return SUCCESSFUL_RETURN; +} + +/* + * p r i n t + */ +returnValue Bounds::print() +{ + if (n == 0) + return SUCCESSFUL_RETURN; + +#ifndef __SUPPRESSANYOUTPUT__ + + char myPrintfString[MAX_STRING_LENGTH]; + + int_t nFR = getNFR(); + int_t nFX = getNFX(); + + int_t * FR_idx; + getFree()->getNumberArray(&FR_idx); + + int_t * FX_idx; + getFixed()->getNumberArray(&FX_idx); + + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "Bounds object comprising %d variables (%d free, %d fixed):\n", + (int)n, + (int)nFR, + (int)nFX); + myPrintf(myPrintfString); + + REFER_NAMESPACE_QPOASES print(FR_idx, nFR, "free "); + REFER_NAMESPACE_QPOASES print(FX_idx, nFX, "fixed"); + +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + +/* + * c l e a r + */ +returnValue Bounds::clear() +{ + return SUCCESSFUL_RETURN; +} + +/* + * c o p y + */ +returnValue Bounds::copy(const Bounds & rhs) +{ + freee = rhs.freee; + fixed = rhs.fixed; + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A l l + */ +returnValue Bounds::setupAll(SubjectToStatus _status) +{ + int_t i; + + /* 1) Place unbounded variables at the beginning of the index list of free variables. */ + for (i = 0; i < n; ++i) { + if (getType(i) == ST_UNBOUNDED) { + if (setupBound(i, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_BOUND_FAILED); + } + } + + /* 2) Add remaining (i.e. bounded but possibly free) variables to the index list of free variables. */ + for (i = 0; i < n; ++i) { + if (getType(i) == ST_BOUNDED) { + if (setupBound(i, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_BOUND_FAILED); + } + } + + /* 3) Place implicitly fixed variables at the end of the index list of free variables. */ + for (i = 0; i < n; ++i) { + if (getType(i) == ST_EQUALITY) { + if (setupBound(i, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_BOUND_FAILED); + } + } + + /* 4) Moreover, add all bounds of unknown type. */ + for (i = 0; i < n; ++i) { + if (getType(i) == ST_UNKNOWN || getType(i) == ST_DISABLED) { + if (setupBound(i, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_BOUND_FAILED); + } + } + + return SUCCESSFUL_RETURN; +} + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Constraints.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Constraints.cpp new file mode 100644 index 0000000..a94c150 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Constraints.cpp @@ -0,0 +1,455 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/Constraints.cpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of the Constraints class designed to manage working sets of + * constraints within a QProblem. + */ + +#include + +BEGIN_NAMESPACE_QPOASES + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +/* + * C o n s t r a i n t s + */ +Constraints::Constraints() : SubjectTo() +{ +} + +/* + * C o n s t r a i n t s + */ +Constraints::Constraints(int_t _n) : SubjectTo(_n) +{ + init(_n); +} + +/* + * C o n s t r a i n t s + */ +Constraints::Constraints(const Constraints & rhs) : SubjectTo(rhs) +{ + copy(rhs); +} + +/* + * ~ C o n s t r a i n t s + */ +Constraints::~Constraints() +{ + clear(); +} + +/* + * o p e r a t o r = + */ +Constraints & Constraints::operator=(const Constraints & rhs) +{ + if (this != &rhs) { + clear(); + SubjectTo::operator=(rhs); + copy(rhs); + } + + return *this; +} + +/* + * i n i t + */ +returnValue Constraints::init(int_t _n) +{ + if (_n < 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + clear(); + + if (_n >= 0) { + active.init(_n); + inactive.init(_n); + } + + return SubjectTo::init(_n); +} + +/* + * s e t u p C o n s t r a i n t + */ +returnValue Constraints::setupConstraint(int_t number, SubjectToStatus _status) +{ + /* consistency check */ + if ((number < 0) || (number >= n)) + return THROWERROR(RET_INDEX_OUT_OF_BOUNDS); + + /* Add constraint index to respective index list. */ + switch (_status) { + case ST_INACTIVE: + if (this->addIndex(this->getInactive(), number, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_CONSTRAINT_FAILED); + break; + + case ST_LOWER: + if (this->addIndex(this->getActive(), number, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_CONSTRAINT_FAILED); + break; + + case ST_UPPER: + if (this->addIndex(this->getActive(), number, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_CONSTRAINT_FAILED); + break; + + default: + return THROWERROR(RET_INVALID_ARGUMENTS); + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A l l I n a c t i v e + */ +returnValue Constraints::setupAllInactive() +{ + return setupAll(ST_INACTIVE); +} + +/* + * s e t u p A l l L o w e r + */ +returnValue Constraints::setupAllLower() +{ + return setupAll(ST_LOWER); +} + +/* + * s e t u p A l l U p p e r + */ +returnValue Constraints::setupAllUpper() +{ + return setupAll(ST_UPPER); +} + +/* + * m o v e A c t i v e T o I n a c t i v e + */ +returnValue Constraints::moveActiveToInactive(int_t number) +{ + /* consistency check */ + if ((number < 0) || (number >= n)) + return THROWERROR(RET_INDEX_OUT_OF_BOUNDS); + + /* Move index from indexlist of active constraints to that of inactive ones. */ + if (this->removeIndex(this->getActive(), number) != SUCCESSFUL_RETURN) + return THROWERROR(RET_MOVING_BOUND_FAILED); + + if (this->addIndex(this->getInactive(), number, ST_INACTIVE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_MOVING_BOUND_FAILED); + + return SUCCESSFUL_RETURN; +} + +/* + * m o v e I n a c t i v e T o A c t i v e + */ +returnValue Constraints::moveInactiveToActive(int_t number, SubjectToStatus _status) +{ + /* consistency check */ + if ((number < 0) || (number >= n)) + return THROWERROR(RET_INDEX_OUT_OF_BOUNDS); + + /* Move index from indexlist of inactive constraints to that of active ones. */ + if (this->removeIndex(this->getInactive(), number) != SUCCESSFUL_RETURN) + return THROWERROR(RET_MOVING_BOUND_FAILED); + + if (this->addIndex(this->getActive(), number, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_MOVING_BOUND_FAILED); + + return SUCCESSFUL_RETURN; +} + +/* + * f l i p F i x e d + */ +returnValue Constraints::flipFixed(int_t number) +{ + /* consistency check */ + if ((number < 0) || (number >= n)) + return THROWERROR(RET_INDEX_OUT_OF_BOUNDS); + + if (status != 0) + switch (status[number]) { + case ST_LOWER: + status[number] = ST_UPPER; + break; + case ST_UPPER: + status[number] = ST_LOWER; + break; + default: + return THROWERROR(RET_MOVING_CONSTRAINT_FAILED); + } + + return SUCCESSFUL_RETURN; +} + +/* + * s h i f t + */ +returnValue Constraints::shift(int_t offset) +{ + int_t i; + + /* consistency check */ + if ((offset == 0) || (n <= 1)) + return SUCCESSFUL_RETURN; + + if ((offset < 0) || (offset > n / 2)) + return THROWERROR(RET_INDEX_OUT_OF_BOUNDS); + + if ((n % offset) != 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + /* 1) Shift types and status. */ + for (i = 0; i < n - offset; ++i) { + setType(i, getType(i + offset)); + setStatus(i, getStatus(i + offset)); + } + + /* 2) Construct shifted index lists of free and fixed variables. */ + Indexlist shiftedActive(n); + Indexlist shiftedInactive(n); + + for (i = 0; i < n; ++i) { + switch (getStatus(i)) { + case ST_INACTIVE: + if (shiftedInactive.addNumber(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SHIFTING_FAILED); + break; + + case ST_LOWER: + if (shiftedActive.addNumber(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SHIFTING_FAILED); + break; + + case ST_UPPER: + if (shiftedActive.addNumber(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SHIFTING_FAILED); + break; + + default: + return THROWERROR(RET_SHIFTING_FAILED); + } + } + + /* 3) Assign shifted index list. */ + active = shiftedActive; + inactive = shiftedInactive; + + return SUCCESSFUL_RETURN; +} + +/* + * r o t a t e + */ +returnValue Constraints::rotate(int_t offset) +{ + int_t i; + + /* consistency check */ + if ((offset == 0) || (offset == n) || (n <= 1)) + return SUCCESSFUL_RETURN; + + if ((offset < 0) || (offset > n)) + return THROWERROR(RET_INDEX_OUT_OF_BOUNDS); + + /* 1) Rotate types and status. */ + SubjectToType * typeTmp = new SubjectToType[offset]; + SubjectToStatus * statusTmp = new SubjectToStatus[offset]; + + for (i = 0; i < offset; ++i) { + typeTmp[i] = getType(i); + statusTmp[i] = getStatus(i); + } + + for (i = 0; i < n - offset; ++i) { + setType(i, getType(i + offset)); + setStatus(i, getStatus(i + offset)); + } + + for (i = n - offset; i < n; ++i) { + setType(i, typeTmp[i - n + offset]); + setStatus(i, statusTmp[i - n + offset]); + } + + delete[] statusTmp; + delete[] typeTmp; + + /* 2) Construct shifted index lists of free and fixed variables. */ + Indexlist rotatedActive(n); + Indexlist rotatedInactive(n); + + for (i = 0; i < n; ++i) { + switch (getStatus(i)) { + case ST_INACTIVE: + if (rotatedInactive.addNumber(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ROTATING_FAILED); + break; + + case ST_LOWER: + if (rotatedActive.addNumber(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ROTATING_FAILED); + break; + + case ST_UPPER: + if (rotatedActive.addNumber(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ROTATING_FAILED); + break; + + default: + return THROWERROR(RET_ROTATING_FAILED); + } + } + + /* 3) Assign shifted index list. */ + active = rotatedActive; + inactive = rotatedInactive; + + return SUCCESSFUL_RETURN; +} + +/* + * p r i n t + */ +returnValue Constraints::print() +{ + if (n == 0) + return SUCCESSFUL_RETURN; + +#ifndef __SUPPRESSANYOUTPUT__ + + char myPrintfString[MAX_STRING_LENGTH]; + + int_t nIAC = getNIAC(); + int_t nAC = getNAC(); + + int_t * IAC_idx; + getInactive()->getNumberArray(&IAC_idx); + + int_t * AC_idx; + getActive()->getNumberArray(&AC_idx); + + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "Constraints object comprising %d constraints (%d inactive, %d active):\n", + (int)n, + (int)nIAC, + (int)nAC); + myPrintf(myPrintfString); + + REFER_NAMESPACE_QPOASES print(IAC_idx, nIAC, "inactive"); + REFER_NAMESPACE_QPOASES print(AC_idx, nAC, "active "); + +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + +/* + * c l e a r + */ +returnValue Constraints::clear() +{ + return SUCCESSFUL_RETURN; +} + +/* + * c o p y + */ +returnValue Constraints::copy(const Constraints & rhs) +{ + active = rhs.active; + inactive = rhs.inactive; + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A l l + */ +returnValue Constraints::setupAll(SubjectToStatus _status) +{ + int_t i; + + /* 1) Place unbounded constraints at the beginning of the index list of inactive constraints. */ + for (i = 0; i < n; ++i) { + if (getType(i) == ST_UNBOUNDED) { + if (setupConstraint(i, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_CONSTRAINT_FAILED); + } + } + + /* 2) Add remaining (i.e. "real" inequality) constraints to the index list of inactive constraints. */ + for (i = 0; i < n; ++i) { + if (getType(i) == ST_BOUNDED) { + if (setupConstraint(i, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_CONSTRAINT_FAILED); + } + } + + /* 3) Place implicit equality constraints at the end of the index list of inactive constraints. */ + for (i = 0; i < n; ++i) { + if (getType(i) == ST_EQUALITY) { + if (setupConstraint(i, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_CONSTRAINT_FAILED); + } + } + + /* 4) Moreover, add all constraints of unknown type. */ + for (i = 0; i < n; ++i) { + if (getType(i) == ST_UNKNOWN || getType(i) == ST_DISABLED) { + if (setupConstraint(i, _status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_CONSTRAINT_FAILED); + } + } + + return SUCCESSFUL_RETURN; +} + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Flipper.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Flipper.cpp new file mode 100644 index 0000000..3e20d35 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Flipper.cpp @@ -0,0 +1,225 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/Flipper.cpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of the Flipper class designed to manage working sets of + * constraints and bounds within a QProblem. + */ + +#include + +BEGIN_NAMESPACE_QPOASES + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +/* + * F l i p p e r + */ +Flipper::Flipper() +{ + R = 0; + Q = 0; + T = 0; + + init(); +} + +/* + * F l i p p e r + */ +Flipper::Flipper(uint_t _nV, uint_t _nC) +{ + R = 0; + Q = 0; + T = 0; + + init(_nV, _nC); +} + +/* + * F l i p p e r + */ +Flipper::Flipper(const Flipper & rhs) +{ + R = 0; + Q = 0; + T = 0; + + copy(rhs); +} + +/* + * ~ F l i p p e r + */ +Flipper::~Flipper() +{ + clear(); +} + +/* + * o p e r a t o r = + */ +Flipper & Flipper::operator=(const Flipper & rhs) +{ + if (this != &rhs) { + clear(); + copy(rhs); + } + + return *this; +} + +/* + * i n i t + */ +returnValue Flipper::init(uint_t _nV, uint_t _nC) +{ + clear(); + + nV = _nV; + nC = _nC; + + return SUCCESSFUL_RETURN; +} + +/* + * g e t + */ +returnValue Flipper::get(Bounds * const _bounds, + real_t * const _R, + Constraints * const _constraints, + real_t * const _Q, + real_t * const _T) const +{ + if (_bounds != 0) + *_bounds = bounds; + + if (_constraints != 0) + *_constraints = constraints; + + if ((_R != 0) && (R != 0)) + memcpy(_R, R, nV * nV * sizeof(real_t)); + + if ((_Q != 0) && (Q != 0)) + memcpy(_Q, Q, nV * nV * sizeof(real_t)); + + if ((_T != 0) && (T != 0)) + memcpy(_T, T, getDimT() * sizeof(real_t)); + + return SUCCESSFUL_RETURN; +} + +/* + * s e t + */ +returnValue Flipper::set(const Bounds * const _bounds, + const real_t * const _R, + const Constraints * const _constraints, + const real_t * const _Q, + const real_t * const _T) +{ + if (_bounds != 0) + bounds = *_bounds; + + if (_constraints != 0) + constraints = *_constraints; + + if (_R != 0) { + if (R == 0) + R = new real_t[nV * nV]; + + memcpy(R, _R, nV * nV * sizeof(real_t)); + } + + if (_Q != 0) { + if (Q == 0) + Q = new real_t[nV * nV]; + + memcpy(Q, _Q, nV * nV * sizeof(real_t)); + } + + if (_T != 0) { + if (T == 0) + T = new real_t[getDimT()]; + + memcpy(T, _T, getDimT() * sizeof(real_t)); + } + + return SUCCESSFUL_RETURN; +} + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + +/* + * c l e a r + */ +returnValue Flipper::clear() +{ + if (R != 0) { + delete[] R; + R = 0; + } + + if (Q != 0) { + delete[] Q; + Q = 0; + } + + if (T != 0) { + delete[] T; + T = 0; + } + + return SUCCESSFUL_RETURN; +} + +/* + * c o p y + */ +returnValue Flipper::copy(const Flipper & rhs) +{ + return set(&(rhs.bounds), rhs.R, &(rhs.constraints), rhs.Q, rhs.T); +} + +uint_t Flipper::getDimT() const +{ + if (nV > nC) + return nC * nC; + else + return nV * nV; +} + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Indexlist.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Indexlist.cpp new file mode 100644 index 0000000..84059cf --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Indexlist.cpp @@ -0,0 +1,293 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/Indexlist.cpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of the Indexlist class designed to manage index lists of + * constraints and bounds within a QProblem_SubjectTo. + */ + +#include + +BEGIN_NAMESPACE_QPOASES + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +/* + * I n d e x l i s t + */ +Indexlist::Indexlist() +{ + number = 0; + iSort = 0; + + init(); +} + +/* + * I n d e x l i s t + */ +Indexlist::Indexlist(int_t n) +{ + number = 0; + iSort = 0; + + init(n); +} + +/* + * I n d e x l i s t + */ +Indexlist::Indexlist(const Indexlist & rhs) +{ + copy(rhs); +} + +/* + * ~ I n d e x l i s t + */ +Indexlist::~Indexlist() +{ + clear(); +} + +/* + * o p e r a t o r = + */ +Indexlist & Indexlist::operator=(const Indexlist & rhs) +{ + if (this != &rhs) { + clear(); + copy(rhs); + } + + return *this; +} + +/* + * i n i t + */ +returnValue Indexlist::init(int_t n) +{ + if (n < 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + clear(); + + length = 0; + physicallength = n; + + if (n > 0) { + number = new int_t[n]; + iSort = new int_t[n]; + } + + return SUCCESSFUL_RETURN; +} + +/* + * g e t N u m b e r A r r a y + */ +returnValue Indexlist::getNumberArray(int_t ** const numberarray) const +{ + if (numberarray == 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + *numberarray = number; + + return SUCCESSFUL_RETURN; +} + +/* + * g e t I S o r t A r r a y + */ +returnValue Indexlist::getISortArray(int_t ** const iSortArray) const +{ + *iSortArray = iSort; + + return SUCCESSFUL_RETURN; +} + +/* + * g e t I n d e x + */ +int_t Indexlist::getIndex(int_t givennumber) const +{ + int_t index = findInsert(givennumber); + return number[iSort[index]] == givennumber ? iSort[index] : -1; +} + +/* + * a d d N u m b e r + */ +returnValue Indexlist::addNumber(int_t addnumber) +{ + if (length >= physicallength) + return THROWERROR(RET_INDEXLIST_EXCEEDS_MAX_LENGTH); + + int_t i, j; + number[length] = addnumber; + j = findInsert(addnumber); + for (i = length; i > j + 1; i--) + iSort[i] = iSort[i - 1]; + iSort[j + 1] = length; + ++length; + + return SUCCESSFUL_RETURN; +} + +/* + * r e m o v e N u m b e r + */ +returnValue Indexlist::removeNumber(int_t removenumber) +{ + int_t i; + int_t idx = findInsert(removenumber); + int_t iSidx = iSort[idx]; + + /* nothing to be done if number is not contained in index set */ + if (number[iSidx] != removenumber) + return SUCCESSFUL_RETURN; + + /* update sorted indices iSort first */ + for (i = 0; i < length; i++) + if (iSort[i] > iSidx) + iSort[i]--; + for (i = idx + 1; i < length; i++) + iSort[i - 1] = iSort[i]; + + /* remove from numbers list */ + for (i = iSidx; i < length - 1; ++i) + number[i] = number[i + 1]; + number[length - 1] = -1; + + --length; + + return SUCCESSFUL_RETURN; +} + +/* + * s w a p N u m b e r s + */ +returnValue Indexlist::swapNumbers(int_t number1, int_t number2) +{ + int_t index1 = findInsert(number1); + int_t index2 = findInsert(number2); + + /* consistency check */ + if ((number[iSort[index1]] != number1) || (number[iSort[index2]] != number2)) + return THROWERROR(RET_INDEXLIST_CORRUPTED); + + int_t tmp; + /* swap numbers */ + tmp = number[iSort[index1]]; + number[iSort[index1]] = number[iSort[index2]]; + number[iSort[index2]] = tmp; + /* swap sorting indices */ + tmp = iSort[index1]; + iSort[index1] = iSort[index2]; + iSort[index2] = tmp; + + return SUCCESSFUL_RETURN; +} + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + +/* + * c l e a r + */ +returnValue Indexlist::clear() +{ + if (iSort != 0) { + delete[] iSort; + iSort = 0; + } + + if (number != 0) { + delete[] number; + number = 0; + } + + return SUCCESSFUL_RETURN; +} + +/* + * c o p y + */ +returnValue Indexlist::copy(const Indexlist & rhs) +{ + int_t i; + + length = rhs.length; + physicallength = rhs.physicallength; + + if (rhs.number != 0) { + number = new int_t[physicallength]; + for (i = 0; i < physicallength; ++i) + number[i] = rhs.number[i]; + iSort = new int_t[physicallength]; + for (i = 0; i < physicallength; ++i) + iSort[i] = rhs.iSort[i]; + } else { + number = 0; + iSort = 0; + } + + return SUCCESSFUL_RETURN; +} + +int_t Indexlist::findInsert(int_t i) const +{ + /* quick check if index can be appended */ + if (length == 0 || i < number[iSort[0]]) + return -1; + if (i >= number[iSort[length - 1]]) + return length - 1; + + /* otherwise, perform bisection search */ + int_t fst = 0, lst = length - 1, mid; + + while (fst < lst - 1) { + mid = (fst + lst) / 2; + if (i >= number[iSort[mid]]) + fst = mid; + else + lst = mid; + } + + return fst; +} + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/LAPACKReplacement.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/LAPACKReplacement.cpp new file mode 100644 index 0000000..5bc1136 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/LAPACKReplacement.cpp @@ -0,0 +1,168 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/LAPACKReplacement.cpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * LAPACK replacement routines. + */ + +#include +#include + +extern "C" void DPOTRF( + const char * uplo, const la_uint_t * _n, double * a, const la_uint_t * _lda, la_int_t * info) +{ + double sum; + la_int_t i, j, k; + la_int_t n = (la_int_t)(*_n); + la_int_t lda = (la_int_t)(*_lda); + + for (i = 0; i < n; ++i) { + /* j == i */ + sum = a[i + lda * i]; + + for (k = (i - 1); k >= 0; --k) + sum -= a[k + lda * i] * a[k + lda * i]; + + if (sum > 0.0) + a[i + lda * i] = REFER_NAMESPACE_QPOASES getSqrt(sum); + else { + a[0] = sum; /* tunnel negative diagonal element to caller */ + if (info != 0) + *info = (la_int_t)i + 1; + return; + } + + for (j = (i + 1); j < n; ++j) { + sum = a[j * lda + i]; + + for (k = (i - 1); k >= 0; --k) + sum -= a[k + lda * i] * a[k + lda * j]; + + a[i + lda * j] = sum / a[i + lda * i]; + } + } + if (info != 0) + *info = 0; +} + +extern "C" void SPOTRF( + const char * uplo, const la_uint_t * _n, float * a, const la_uint_t * _lda, la_int_t * info) +{ + float sum; + la_int_t i, j, k; + la_int_t n = (la_int_t)(*_n); + la_int_t lda = (la_int_t)(*_lda); + + for (i = 0; i < n; ++i) { + /* j == i */ + sum = a[i + lda * i]; + + for (k = (i - 1); k >= 0; --k) + sum -= a[k + lda * i] * a[k + lda * i]; + + if (sum > 0.0) + a[i + lda * i] = (float)(REFER_NAMESPACE_QPOASES getSqrt(sum)); + else { + a[0] = sum; /* tunnel negative diagonal element to caller */ + if (info != 0) + *info = (la_int_t)i + 1; + return; + } + + for (j = (i + 1); j < n; ++j) { + sum = a[j * lda + i]; + + for (k = (i - 1); k >= 0; --k) + sum -= a[k + lda * i] * a[k + lda * j]; + + a[i + lda * j] = sum / a[i + lda * i]; + } + } + if (info != 0) + *info = 0; +} + +extern "C" void DTRTRS(const char * UPLO, + const char * TRANS, + const char * DIAG, + const la_uint_t * N, + const la_uint_t * NRHS, + double * A, + const la_uint_t * LDA, + double * B, + const la_uint_t * LDB, + la_int_t * INFO) +{ + INFO[0] = ((la_int_t)0xDEADBEEF); /* Dummy. If SQProblemSchur is to be used, system LAPACK must be used */ +} + +extern "C" void STRTRS(const char * UPLO, + const char * TRANS, + const char * DIAG, + const la_uint_t * N, + const la_uint_t * NRHS, + float * A, + const la_uint_t * LDA, + float * B, + const la_uint_t * LDB, + la_int_t * INFO) +{ + INFO[0] = ((la_int_t)0xDEADBEEF); /* Dummy. If SQProblemSchur is to be used, system LAPACK must be used */ +} + +extern "C" void DTRCON(const char * NORM, + const char * UPLO, + const char * DIAG, + const la_uint_t * N, + double * A, + const la_uint_t * LDA, + double * RCOND, + double * WORK, + const la_uint_t * IWORK, + la_int_t * INFO) +{ + INFO[0] = ((la_int_t)0xDEADBEEF); /* Dummy. If SQProblemSchur is to be used, system LAPACK must be used */ +} + +extern "C" void STRCON(const char * NORM, + const char * UPLO, + const char * DIAG, + const la_uint_t * N, + float * A, + const la_uint_t * LDA, + float * RCOND, + float * WORK, + const la_uint_t * IWORK, + la_int_t * INFO) +{ + INFO[0] = ((la_int_t)0xDEADBEEF); /* Dummy. If SQProblemSchur is to be used, system LAPACK must be used */ +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Makefile b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Makefile new file mode 100755 index 0000000..69b9503 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Makefile @@ -0,0 +1,111 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: src/Makefile +## Author: Hans Joachim Ferreau, Andreas Potschka, Christian Kirches +## Version: 3.2 +## Date: 2007-2017 +## + +include ../make.mk + +## +## flags +## + +IFLAGS = -I. \ + -I${IDIR} + +QPOASES_OBJECTS = \ + SQProblem.${OBJEXT} \ + QProblem.${OBJEXT} \ + QProblemB.${OBJEXT} \ + SQProblemSchur.${OBJEXT} \ + Bounds.${OBJEXT} \ + Constraints.${OBJEXT} \ + SubjectTo.${OBJEXT} \ + Indexlist.${OBJEXT} \ + Flipper.${OBJEXT} \ + Utils.${OBJEXT} \ + Options.${OBJEXT} \ + Matrices.${OBJEXT} \ + MessageHandling.${OBJEXT} \ + SparseSolver.${OBJEXT} + + +QPOASES_EXTRAS_OBJECTS = \ + SolutionAnalysis.${OBJEXT} \ + OQPinterface.${OBJEXT} + +QPOASES_DEPENDS = \ + ${IDIR}/qpOASES.hpp \ + ${IDIR}/qpOASES/LapackBlasReplacement.hpp \ + ${IDIR}/qpOASES/SQProblem.hpp \ + ${IDIR}/qpOASES/QProblem.hpp \ + ${IDIR}/qpOASES/Flipper.hpp \ + ${IDIR}/qpOASES/QProblemB.hpp \ + ${IDIR}/qpOASES/Bounds.hpp \ + ${IDIR}/qpOASES/Constraints.hpp \ + ${IDIR}/qpOASES/SubjectTo.hpp \ + ${IDIR}/qpOASES/Indexlist.hpp \ + ${IDIR}/qpOASES/Utils.hpp \ + ${IDIR}/qpOASES/Constants.hpp \ + ${IDIR}/qpOASES/Types.hpp \ + ${IDIR}/qpOASES/Options.hpp \ + ${IDIR}/qpOASES/Matrices.hpp \ + ${IDIR}/qpOASES/MessageHandling.hpp \ + ${IDIR}/qpOASES/UnitTesting.hpp + + +## +## targets +## + +all: ${LINK_DEPENDS} + + +${BINDIR}/libqpOASES.${LIBEXT}: ${QPOASES_OBJECTS} ${QPOASES_EXTRAS_OBJECTS} + @${ECHO} "Creating static lib" $@ + @${AR} r $@ $^ + +${BINDIR}/libqpOASES.${DLLEXT}: ${QPOASES_OBJECTS} ${QPOASES_EXTRAS_OBJECTS} + @${ECHO} "Creating shared lib" $@ + @${CPP} ${DEF_TARGET} ${SHARED} $^ ${LINK_LIBRARIES} + +clean: + @${ECHO} "Cleaning up (src)" + @${RM} -f *.${OBJEXT} *.${LIBEXT} *.${DLLEXT} + +clobber: clean + + +%.${OBJEXT}: %.cpp ${QPOASES_DEPENDS} + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} -c ${IFLAGS} ${CPPFLAGS} $< + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Matrices.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Matrices.cpp new file mode 100644 index 0000000..c7ffcc6 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Matrices.cpp @@ -0,0 +1,2113 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/Matrices.cpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of the matrix classes. + */ + +#include +#include + +BEGIN_NAMESPACE_QPOASES + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +returnValue Matrix::getSparseSubmatrix(const Indexlist * const irows, + const Indexlist * const icols, + int_t rowoffset, + int_t coloffset, + int_t & numNonzeros, + int_t * irn, + int_t * jcn, + real_t * avals, + BooleanType only_lower_triangular) const +{ + int_t * rowsNumbers; + irows->getNumberArray(&rowsNumbers); + int_t * colsNumbers; + icols->getNumberArray(&colsNumbers); + + return getSparseSubmatrix(irows->getLength(), + rowsNumbers, + icols->getLength(), + colsNumbers, + rowoffset, + coloffset, + numNonzeros, + irn, + jcn, + avals, + only_lower_triangular); +} + +returnValue Matrix::getSparseSubmatrix(const Indexlist * const irows, + int_t idx_icol, + int_t rowoffset, + int_t coloffset, + int_t & numNonzeros, + int_t * irn, + int_t * jcn, + real_t * avals, + BooleanType only_lower_triangular) const +{ + int_t * rowsNumbers; + irows->getNumberArray(&rowsNumbers); + + return getSparseSubmatrix(irows->getLength(), + rowsNumbers, + 1, + &idx_icol, + rowoffset, + coloffset, + numNonzeros, + irn, + jcn, + avals, + only_lower_triangular); +} + +returnValue Matrix::getSparseSubmatrix(int_t idx_row, + const Indexlist * const icols, + int_t rowoffset, + int_t coloffset, + int_t & numNonzeros, + int_t * irn, + int_t * jcn, + real_t * avals, + BooleanType only_lower_triangular) const +{ + int_t * colsNumbers; + icols->getNumberArray(&colsNumbers); + + return getSparseSubmatrix(1, + &idx_row, + icols->getLength(), + colsNumbers, + rowoffset, + coloffset, + numNonzeros, + irn, + jcn, + avals, + only_lower_triangular); +} + +DenseMatrix::~DenseMatrix() +{ + if (needToFreeMemory() == BT_TRUE) + free(); +} + +void DenseMatrix::free() +{ + if (val != 0) + delete[] val; + val = 0; +} + +Matrix * DenseMatrix::duplicate() const +{ + DenseMatrix * dupl = 0; + + if (needToFreeMemory() == BT_TRUE) { + real_t * val_new = new real_t[nRows * nCols]; + memcpy(val_new, val, ((uint_t)(nRows * nCols)) * sizeof(real_t)); + dupl = new DenseMatrix(nRows, nCols, nCols, val_new); + dupl->doFreeMemory(); + } else { + dupl = new DenseMatrix(nRows, nCols, nCols, val); + } + + return dupl; +} + +real_t DenseMatrix::diag(int_t i) const +{ + return val[i * (leaDim + 1)]; +} + +BooleanType DenseMatrix::isDiag() const +{ + int_t i, j; + + if (nRows != nCols) + return BT_FALSE; + + for (i = 0; i < nRows; ++i) + for (j = 0; j < i; ++j) + if ((getAbs(val[i * leaDim + j]) > EPS) || (getAbs(val[j * leaDim + i]) > EPS)) + return BT_FALSE; + + return BT_TRUE; +} + +real_t DenseMatrix::getNorm(int_t type) const +{ + return REFER_NAMESPACE_QPOASES getNorm(val, nCols * nRows, type); +} + +real_t DenseMatrix::getRowNorm(int_t rNum, int_t type) const +{ + return REFER_NAMESPACE_QPOASES getNorm(&(val[rNum * leaDim]), nCols, type); +} + +returnValue DenseMatrix::getRowNorm(real_t * norm, int_t type) const +{ + int_t i; + for (i = 0; i < nRows; ++i) { + norm[i] = REFER_NAMESPACE_QPOASES getNorm(&(val[i * leaDim]), nCols, type); + } + return SUCCESSFUL_RETURN; +} + +returnValue DenseMatrix::getRow(int_t rNum, const Indexlist * const icols, real_t alpha, real_t * row) const +{ + int_t i; + if (icols != 0) { + if (isEqual(alpha, 1.0) == BT_TRUE) + for (i = 0; i < icols->length; i++) + row[i] = val[rNum * leaDim + icols->number[i]]; + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (i = 0; i < icols->length; i++) + row[i] = -val[rNum * leaDim + icols->number[i]]; + else + for (i = 0; i < icols->length; i++) + row[i] = alpha * val[rNum * leaDim + icols->number[i]]; + } else { + if (isEqual(alpha, 1.0) == BT_TRUE) + for (i = 0; i < nCols; i++) + row[i] = val[rNum * leaDim + i]; + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (i = 0; i < nCols; i++) + row[i] = -val[rNum * leaDim + i]; + else + for (i = 0; i < nCols; i++) + row[i] = alpha * val[rNum * leaDim + i]; + } + return SUCCESSFUL_RETURN; +} + +returnValue DenseMatrix::getCol(int_t cNum, const Indexlist * const irows, real_t alpha, real_t * col) const +{ + int_t i; + + if (isEqual(alpha, 1.0) == BT_TRUE) + for (i = 0; i < irows->length; i++) + col[i] = val[irows->number[i] * leaDim + cNum]; + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (i = 0; i < irows->length; i++) + col[i] = -val[irows->number[i] * leaDim + cNum]; + else + for (i = 0; i < irows->length; i++) + col[i] = alpha * val[irows->number[i] * leaDim + cNum]; + + return SUCCESSFUL_RETURN; +} + +returnValue DenseMatrix::getSparseSubmatrix(int_t irowsLength, + const int_t * const irowsNumber, + int_t icolsLength, + const int_t * const icolsNumber, + int_t rowoffset, + int_t coloffset, + int_t & numNonzeros, + int_t * irn, + int_t * jcn, + real_t * avals, + BooleanType only_lower_triangular /*= BT_FALSE */) const +{ + int_t i, j, irA; + real_t v; + numNonzeros = 0; + if (only_lower_triangular == BT_FALSE) { + if (irn == 0) { + if (jcn != 0 || avals != 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + for (j = 0; j < irowsLength; j++) { + irA = irowsNumber[j] * leaDim; + for (i = 0; i < icolsLength; i++) + if (isZero(val[irA + icolsNumber[i]]) == BT_FALSE) + numNonzeros++; + } + } else { + for (j = 0; j < irowsLength; j++) { + irA = irowsNumber[j] * leaDim; + for (i = 0; i < icolsLength; i++) { + v = val[irA + icolsNumber[i]]; + if (isZero(v) == BT_FALSE) { + irn[numNonzeros] = j + rowoffset; + jcn[numNonzeros] = i + coloffset; + avals[numNonzeros] = v; + numNonzeros++; + } + } + } + } + } else { + if (irn == 0) { + if (jcn != 0 || avals != 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + for (j = 0; j < irowsLength; j++) { + irA = irowsNumber[j] * leaDim; + for (i = 0; i <= j; i++) + if (isZero(val[irA + irowsNumber[i]]) == BT_FALSE) + numNonzeros++; + } + } else { + for (j = 0; j < irowsLength; j++) { + irA = irowsNumber[j] * leaDim; + for (i = 0; i <= j; i++) { + v = val[irA + irowsNumber[i]]; + if (isZero(v) == BT_FALSE) { + irn[numNonzeros] = j + rowoffset; + jcn[numNonzeros] = i + coloffset; + avals[numNonzeros] = v; + numNonzeros++; + } + } + } + } + } + + return SUCCESSFUL_RETURN; +} + +returnValue DenseMatrix::times( + int_t xN, real_t alpha, const real_t * x, int_t xLD, real_t beta, real_t * y, int_t yLD) const +{ + la_uint_t _xN = (la_uint_t)xN; + la_uint_t _nRows = (la_uint_t)nRows; + la_uint_t _nCols = (la_uint_t)nCols; + la_uint_t _leaDim = (la_uint_t)getMax(1, nCols); + la_uint_t _xLD = (la_uint_t)getMax(1, xLD); + la_uint_t _yLD = (la_uint_t)getMax(1, yLD); + + /* Call BLAS. Mind row major format! */ + GEMM("TRANS", "NOTRANS", &_nRows, &_xN, &_nCols, &alpha, val, &_leaDim, x, &_xLD, &beta, y, &_yLD); + return SUCCESSFUL_RETURN; +} + +returnValue DenseMatrix::transTimes( + int_t xN, real_t alpha, const real_t * x, int_t xLD, real_t beta, real_t * y, int_t yLD) const +{ + la_uint_t _xN = (la_uint_t)xN; + la_uint_t _nRows = (la_uint_t)nRows; + la_uint_t _nCols = (la_uint_t)nCols; + la_uint_t _leaDim = (la_uint_t)getMax(1, nCols); + la_uint_t _xLD = (la_uint_t)getMax(1, xLD); + la_uint_t _yLD = (la_uint_t)getMax(1, yLD); + + /* Call BLAS. Mind row major format! */ + GEMM("NOTRANS", "NOTRANS", &_nCols, &_xN, &_nRows, &alpha, val, &_leaDim, x, &_xLD, &beta, y, &_yLD); + return SUCCESSFUL_RETURN; +} + +returnValue DenseMatrix::times(const Indexlist * const irows, + const Indexlist * const icols, + int_t xN, + real_t alpha, + const real_t * x, + int_t xLD, + real_t beta, + real_t * y, + int_t yLD, + BooleanType yCompr) const +{ + int_t i, j, k, row, col, iy, irA; + + if (yCompr == BT_TRUE) { + if (isZero(beta) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[j + k * yLD] = 0.0; + else if (isEqual(beta, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[j + k * yLD] = -y[j + k * yLD]; + else if (isEqual(beta, 1.0) == BT_FALSE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[j + k * yLD] *= beta; + + if (icols == 0) + if (isEqual(alpha, 1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) { + row = irows->iSort[j]; + iy = row + k * yLD; + irA = irows->number[row] * leaDim; + for (i = 0; i < nCols; i++) + y[iy] += val[irA + i] * x[k * xLD + i]; + } + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) { + row = irows->iSort[j]; + iy = row + k * yLD; + irA = irows->number[row] * leaDim; + for (i = 0; i < nCols; i++) + y[iy] -= val[irA + i] * x[k * xLD + i]; + } + else + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) { + row = irows->iSort[j]; + iy = row + k * yLD; + irA = irows->number[row] * leaDim; + for (i = 0; i < nCols; i++) + y[iy] += alpha * val[irA + i] * x[k * xLD + i]; + } + else /* icols != 0 */ + if (isEqual(alpha, 1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) { + row = irows->iSort[j]; + iy = row + k * yLD; + irA = irows->number[row] * leaDim; + for (i = 0; i < icols->length; i++) { + col = icols->iSort[i]; + y[iy] += val[irA + icols->number[col]] * x[k * xLD + col]; + } + } + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) { + row = irows->iSort[j]; + iy = row + k * yLD; + irA = irows->number[row] * leaDim; + for (i = 0; i < icols->length; i++) { + col = icols->iSort[i]; + y[iy] -= val[irA + icols->number[col]] * x[k * xLD + col]; + } + } + else + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) { + row = irows->iSort[j]; + iy = row + k * yLD; + irA = irows->number[row] * leaDim; + for (i = 0; i < icols->length; i++) { + col = icols->iSort[i]; + y[iy] += alpha * val[irA + icols->number[col]] * x[k * xLD + col]; + } + } + } else /* y not compressed */ + { + if (isZero(beta) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[irows->number[j] + k * yLD] = 0.0; + else if (isEqual(beta, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[irows->number[j] + k * yLD] = -y[j + k * yLD]; + else if (isEqual(beta, 1.0) == BT_FALSE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[irows->number[j] + k * yLD] *= beta; + + if (icols == 0) + if (isEqual(alpha, 1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) { + row = irows->number[irows->iSort[j]]; + iy = row + k * yLD; + irA = row * leaDim; + for (i = 0; i < nCols; i++) + y[iy] += val[irA + i] * x[k * xLD + i]; + } + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) { + row = irows->number[irows->iSort[j]]; + iy = row + k * yLD; + irA = row * leaDim; + for (i = 0; i < nCols; i++) + y[iy] -= val[irA + i] * x[k * xLD + i]; + } + else + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) { + row = irows->number[irows->iSort[j]]; + iy = row + k * yLD; + irA = row * leaDim; + for (i = 0; i < nCols; i++) + y[iy] += alpha * val[irA + i] * x[k * xLD + i]; + } + else /* icols != 0 */ + if (isEqual(alpha, 1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) { + row = irows->number[irows->iSort[j]]; + iy = row + k * yLD; + irA = row * leaDim; + for (i = 0; i < icols->length; i++) { + col = icols->iSort[i]; + y[iy] += val[irA + icols->number[col]] * x[k * xLD + col]; + } + } + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) { + row = irows->number[irows->iSort[j]]; + iy = row + k * yLD; + irA = row * leaDim; + for (i = 0; i < icols->length; i++) { + col = icols->iSort[i]; + y[iy] -= val[irA + icols->number[col]] * x[k * xLD + col]; + } + } + else + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) { + row = irows->number[irows->iSort[j]]; + iy = row + k * yLD; + irA = row * leaDim; + for (i = 0; i < icols->length; i++) { + col = icols->iSort[i]; + y[iy] += alpha * val[irA + icols->number[col]] * x[k * xLD + col]; + } + } + } + + return SUCCESSFUL_RETURN; +} + +returnValue DenseMatrix::transTimes(const Indexlist * const irows, + const Indexlist * const icols, + int_t xN, + real_t alpha, + const real_t * x, + int_t xLD, + real_t beta, + real_t * y, + int_t yLD) const +{ + int_t i, j, k, row, col; + + if (isZero(beta) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < icols->length; j++) + y[j + k * yLD] = 0.0; + else if (isEqual(beta, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < icols->length; j++) + y[j + k * yLD] = -y[j + k * yLD]; + else if (isEqual(beta, 1.0) == BT_FALSE) + for (k = 0; k < xN; k++) + for (j = 0; j < icols->length; j++) + y[j + k * yLD] *= beta; + + if (isEqual(alpha, 1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) { + row = irows->iSort[j]; + for (i = 0; i < icols->length; i++) { + col = icols->iSort[i]; + y[col + k * yLD] += val[irows->number[row] * leaDim + icols->number[col]] * x[row + k * xLD]; + } + } + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) { + row = irows->iSort[j]; + for (i = 0; i < icols->length; i++) { + col = icols->iSort[i]; + y[col + k * yLD] -= val[irows->number[row] * leaDim + icols->number[col]] * x[row + k * xLD]; + } + } + else + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) { + row = irows->iSort[j]; + for (i = 0; i < icols->length; i++) { + col = icols->iSort[i]; + y[col + k * yLD] += + alpha * val[irows->number[row] * leaDim + icols->number[col]] * x[row + k * xLD]; + } + } + + return SUCCESSFUL_RETURN; +} + +returnValue DenseMatrix::addToDiag(real_t alpha) +{ + int_t i; + for (i = 0; i < nRows && i < nCols; i++) + val[i * (leaDim + 1)] += alpha; + + return SUCCESSFUL_RETURN; +} + +returnValue DenseMatrix::writeToFile(FILE * output_file, const char * prefix) const +{ + return THROWERROR(RET_NOT_YET_IMPLEMENTED); +} + +real_t * DenseMatrix::full() const +{ + real_t * v = new real_t[nRows * nCols]; + memcpy(v, val, ((uint_t)(nRows * nCols)) * sizeof(real_t)); + return v; +} + +returnValue DenseMatrix::print(const char * name) const +{ + return REFER_NAMESPACE_QPOASES print(val, nRows, nCols, name); +} + +Matrix * SymDenseMat::duplicate() const +{ + return duplicateSym(); +} + +SymmetricMatrix * SymDenseMat::duplicateSym() const +{ + /* "same" as duplicate() in DenseMatrix */ + SymDenseMat * dupl = 0; + + if (needToFreeMemory() == BT_TRUE) { + real_t * val_new = new real_t[nRows * nCols]; + memcpy(val_new, val, ((uint_t)(nRows * nCols)) * sizeof(real_t)); + dupl = new SymDenseMat(nRows, nCols, nCols, val_new); + dupl->doFreeMemory(); + } else { + dupl = new SymDenseMat(nRows, nCols, nCols, val); + } + + return dupl; +} + +returnValue SymDenseMat::bilinear( + const Indexlist * const icols, int_t xN, const real_t * x, int_t xLD, real_t * y, int_t yLD) const +{ + int_t ii, jj, kk, col; + int_t i, j, k, irA; + + for (ii = 0; ii < xN; ii++) + for (jj = 0; jj < xN; jj++) + y[ii * yLD + jj] = 0.0; + + real_t * Ax = new real_t[icols->length * xN]; + + for (i = 0; i < icols->length * xN; ++i) + Ax[i] = 0.0; + + /* exploit symmetry of A ! */ + for (j = 0; j < icols->length; j++) { + irA = icols->number[j] * leaDim; + for (i = 0; i < icols->length; i++) { + real_t h = val[irA + icols->number[i]]; + for (k = 0; k < xN; k++) + Ax[j + k * icols->length] += h * x[k * xLD + icols->number[i]]; + } + } + + for (ii = 0; ii < icols->length; ++ii) { + col = icols->number[ii]; + for (jj = 0; jj < xN; ++jj) { + for (kk = 0; kk < xN; ++kk) { + y[kk + jj * yLD] += x[col + jj * xLD] * Ax[ii + kk * icols->length]; + } + } + } + delete[] Ax; + + return SUCCESSFUL_RETURN; +} + +SparseMatrix::SparseMatrix() : nRows(0), nCols(0), ir(0), jc(0), jd(0), val(0) +{ +} + +SparseMatrix::SparseMatrix(int_t nr, int_t nc, sparse_int_t * r, sparse_int_t * c, real_t * v) +: nRows(nr), nCols(nc), ir(r), jc(c), jd(0), val(v) +{ + doNotFreeMemory(); +} + +SparseMatrix::SparseMatrix(int_t nr, int_t nc, int_t ld, const real_t * const v) +: nRows(nr), nCols(nc), jd(0) +{ + int_t i, j, nnz; + + jc = new sparse_int_t[nc + 1]; + ir = new sparse_int_t[nr * nc]; + val = new real_t[nr * nc]; + + nnz = 0; + for (j = 0; j < nCols; j++) { + jc[j] = nnz; + for (i = 0; i < nRows; i++) + if ((isZero(v[i * ld + j], 0.0) == BT_FALSE) || (i == j)) /* also include zero diagonal elements! */ + { + ir[nnz] = i; + val[nnz++] = v[i * ld + j]; + } + } + jc[nCols] = nnz; + + doFreeMemory(); +} + +SparseMatrix::~SparseMatrix() +{ + if (jd != 0) { + delete[] jd; + jd = 0; + } + + if (needToFreeMemory() == BT_TRUE) + free(); +} + +void SparseMatrix::free() +{ + if (ir != 0) + delete[] ir; + ir = 0; + if (jc != 0) + delete[] jc; + jc = 0; + if (val != 0) + delete[] val; + val = 0; + + doNotFreeMemory(); +} + +Matrix * SparseMatrix::duplicate() const +{ + long i, length = jc[nCols]; + SparseMatrix * dupl = new SparseMatrix; + + dupl->nRows = nRows; + dupl->nCols = nCols; + dupl->ir = new sparse_int_t[length]; + dupl->jc = new sparse_int_t[nCols + 1]; + dupl->val = new real_t[length]; + + for (i = 0; i < length; i++) + dupl->ir[i] = ir[i]; + for (i = 0; i <= nCols; i++) + dupl->jc[i] = jc[i]; + for (i = 0; i < length; i++) + dupl->val[i] = val[i]; + + if (jd != 0) { + dupl->jd = new sparse_int_t[nCols]; + for (i = 0; i < nCols; i++) + dupl->jd[i] = jd[i]; + } else + dupl->jd = 0; + + dupl->doFreeMemory(); + + return dupl; +} + +void SparseMatrix::setVal(const real_t * newVal) +{ + long length = jc[nCols]; /* [nCols+1] ?? */ + for (long index = 0; index < length; ++index) { + val[index] = newVal[index]; + } +} + +real_t SparseMatrix::diag(int_t i) const +{ + if (jd == 0) { + THROWERROR(RET_DIAGONAL_NOT_INITIALISED); + return INFTY; + } + + int_t entry = jd[i]; + return (entry < jc[i + 1] && ir[entry] == i) ? val[entry] : 0.0; +} + +BooleanType SparseMatrix::isDiag() const +{ + int_t j; + + if (nCols != nRows) + return BT_FALSE; + + for (j = 0; j < nCols; ++j) { + if (jc[j + 1] > jc[j] + 1) + return BT_FALSE; + + if ((jc[j + 1] == jc[j] + 1) && (ir[jc[j]] != j)) + return BT_FALSE; + } + + return BT_TRUE; +} + +real_t SparseMatrix::getNorm(int_t type) const +{ + int_t length = jc[nCols]; + return REFER_NAMESPACE_QPOASES getNorm(val, length, type); +} + +real_t SparseMatrix::getRowNorm(int_t rNum, int_t type) const +{ + int_t i, j; + real_t norm = 0.0; + + switch (type) { + case 2: + for (j = 0; j < nCols; ++j) { + for (i = jc[j]; i < jc[j + 1] && ir[i] < rNum; i++) {}; + if (i < jc[j + 1] && ir[i] == rNum) + norm += val[i] * val[i]; + } + return getSqrt(norm); + + case 1: + for (j = 0; j < nCols; ++j) { + for (i = jc[j]; i < jc[j + 1] && ir[i] < rNum; i++) {}; + if (i < jc[j + 1] && ir[i] == rNum) + norm += getAbs(val[i]); + } + return norm; + + default: + THROWERROR(RET_INVALID_ARGUMENTS); + return -INFTY; + } +} + +returnValue SparseMatrix::getRowNorm(real_t * norm, int_t type) const +{ + int_t i, j; + + for (j = 0; j < nRows; ++j) + norm[j] = 0.0; + + switch (type) { + case 2: + for (j = 0; j < nCols; ++j) { + for (i = jc[j]; i < jc[j + 1]; i++) + norm[ir[i]] += val[i] * val[i]; + } + for (j = 0; j < nRows; ++j) + norm[j] = getSqrt(norm[j]); + break; + case 1: + for (j = 0; j < nCols; ++j) { + for (i = jc[j]; i < jc[j + 1]; i++) + ; + norm[ir[i]] += getAbs(val[i]); + } + break; + default: + return RET_INVALID_ARGUMENTS; + } + return SUCCESSFUL_RETURN; +} + +returnValue SparseMatrix::getRow( + int_t rNum, const Indexlist * const icols, real_t alpha, real_t * row) const +{ + long i, j, k; + + if (icols != 0) { + if (isEqual(alpha, 1.0) == BT_TRUE) + for (k = 0; k < icols->length; k++) { + j = icols->number[icols->iSort[k]]; + for (i = jc[j]; i < jc[j + 1] && ir[i] < rNum; i++) + ; + row[icols->iSort[k]] = (i < jc[j + 1] && ir[i] == rNum) ? val[i] : 0.0; + } + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (k = 0; k < icols->length; k++) { + j = icols->number[icols->iSort[k]]; + for (i = jc[j]; i < jc[j + 1] && ir[i] < rNum; i++) + ; + row[icols->iSort[k]] = (i < jc[j + 1] && ir[i] == rNum) ? -val[i] : 0.0; + } + else + for (k = 0; k < icols->length; k++) { + j = icols->number[icols->iSort[k]]; + for (i = jc[j]; i < jc[j + 1] && ir[i] < rNum; i++) + ; + row[icols->iSort[k]] = (i < jc[j + 1] && ir[i] == rNum) ? alpha * val[i] : 0.0; + } + } else { + if (isEqual(alpha, 1.0) == BT_TRUE) + for (j = 0; j < nCols; j++) { + for (i = jc[j]; i < jc[j + 1] && ir[i] < rNum; i++) + ; + row[j] = (i < jc[j + 1] && ir[i] == rNum) ? val[i] : 0.0; + } + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (j = 0; j < icols->length; j++) { + for (i = jc[j]; i < jc[j + 1] && ir[i] < rNum; i++) + ; + row[j] = (i < jc[j + 1] && ir[i] == rNum) ? -val[i] : 0.0; + } + else + for (j = 0; j < icols->length; j++) { + for (i = jc[j]; i < jc[j + 1] && ir[i] < rNum; i++) + ; + row[j] = (i < jc[j + 1] && ir[i] == rNum) ? alpha * val[i] : 0.0; + } + } + return SUCCESSFUL_RETURN; +} + +returnValue SparseMatrix::getCol( + int_t cNum, const Indexlist * const irows, real_t alpha, real_t * col) const +{ + long i, j; + + i = jc[cNum]; + j = 0; + if (isEqual(alpha, 1.0) == BT_TRUE) + while (i < jc[cNum + 1] && j < irows->length) + if (ir[i] == irows->number[irows->iSort[j]]) + col[irows->iSort[j++]] = val[i++]; + else if (ir[i] > irows->number[irows->iSort[j]]) + col[irows->iSort[j++]] = 0.0; + else + i++; + else if (isEqual(alpha, -1.0) == BT_TRUE) + while (i < jc[cNum + 1] && j < irows->length) + if (ir[i] == irows->number[irows->iSort[j]]) + col[irows->iSort[j++]] = -val[i++]; + else if (ir[i] > irows->number[irows->iSort[j]]) + col[irows->iSort[j++]] = 0.0; + else + i++; + else + while (i < jc[cNum + 1] && j < irows->length) + if (ir[i] == irows->number[irows->iSort[j]]) + col[irows->iSort[j++]] = alpha * val[i++]; + else if (ir[i] > irows->number[irows->iSort[j]]) + col[irows->iSort[j++]] = 0.0; + else + i++; + + /* fill in remaining zeros */ + while (j < irows->length) + col[irows->iSort[j++]] = 0.0; + + return SUCCESSFUL_RETURN; +} + +returnValue SparseMatrix::getSparseSubmatrix(int_t irowsLength, + const int_t * const irowsNumber, + int_t icolsLength, + const int_t * const icolsNumber, + int_t rowoffset, + int_t coloffset, + int_t & numNonzeros, + int_t * irn, + int_t * jcn, + real_t * avals, + BooleanType only_lower_triangular /*= BT_FALSE */) const +{ + int_t i, j, k, l; + + // Compute the "inverse" of the irows->number array + // TODO: Ideally this should be a part of Indexlist + int_t * rowNumberInv = new int_t[nRows]; + for (i = 0; i < nRows; i++) + rowNumberInv[i] = -1; + for (i = 0; i < irowsLength; i++) + rowNumberInv[irowsNumber[i]] = i; + + numNonzeros = 0; + if (only_lower_triangular == BT_FALSE) { + if (irn == 0) { + if (jcn != 0 || avals != 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + for (k = 0; k < icolsLength; k++) { + j = icolsNumber[k]; + for (i = jc[j]; i < jc[j + 1]; i++) { + l = rowNumberInv[ir[i]]; + if (l >= 0) + numNonzeros++; + } + } + } else { + for (k = 0; k < icolsLength; k++) { + j = icolsNumber[k]; + for (i = jc[j]; i < jc[j + 1]; i++) { + l = rowNumberInv[ir[i]]; + if (l >= 0) { + irn[numNonzeros] = l + rowoffset; + jcn[numNonzeros] = k + coloffset; + avals[numNonzeros] = val[i]; + numNonzeros++; + } + } + } + } + } else { + if (irn == 0) { + if (jcn != 0 || avals != 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + for (k = 0; k < icolsLength; k++) { + j = icolsNumber[k]; + for (i = jc[j]; i < jc[j + 1]; i++) { + l = rowNumberInv[ir[i]]; + if (l >= k) + numNonzeros++; + } + } + } else { + for (k = 0; k < icolsLength; k++) { + j = icolsNumber[k]; + for (i = jc[j]; i < jc[j + 1]; i++) { + l = rowNumberInv[ir[i]]; + if (l >= k) { + irn[numNonzeros] = l + rowoffset; + jcn[numNonzeros] = k + coloffset; + avals[numNonzeros] = val[i]; + numNonzeros++; + } + } + } + } + } + delete[] rowNumberInv; + + return SUCCESSFUL_RETURN; +} + +returnValue SparseMatrix::times( + int_t xN, real_t alpha, const real_t * x, int_t xLD, real_t beta, real_t * y, int_t yLD) const +{ + long i, j, k; + + if (isZero(beta) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < nRows; j++) + y[j + k * yLD] = 0.0; + else if (isEqual(beta, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < nRows; j++) + y[j + k * yLD] = -y[j + k * yLD]; + else if (isEqual(beta, 1.0) == BT_FALSE) + for (k = 0; k < xN; k++) + for (j = 0; j < nRows; j++) + y[j + k * yLD] *= beta; + + if (isEqual(alpha, 1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < nCols; j++) + for (i = jc[j]; i < jc[j + 1]; i++) + y[ir[i] + k * yLD] += val[i] * x[j + k * xLD]; + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < nCols; j++) + for (i = jc[j]; i < jc[j + 1]; i++) + y[ir[i] + k * yLD] -= val[i] * x[j + k * xLD]; + else + for (k = 0; k < xN; k++) + for (j = 0; j < nCols; j++) + for (i = jc[j]; i < jc[j + 1]; i++) + y[ir[i] + k * yLD] += alpha * val[i] * x[j + k * xLD]; + + return SUCCESSFUL_RETURN; +} + +returnValue SparseMatrix::transTimes( + int_t xN, real_t alpha, const real_t * x, int_t xLD, real_t beta, real_t * y, int_t yLD) const +{ + long i, j, k; + + if (isZero(beta) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < nCols; j++) + y[j + k * yLD] = 0.0; + else if (isEqual(beta, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < nCols; j++) + y[j + k * yLD] = -y[j + k * yLD]; + else if (isEqual(beta, 1.0) == BT_FALSE) + for (k = 0; k < xN; k++) + for (j = 0; j < nCols; j++) + y[j + k * yLD] *= beta; + + if (isEqual(alpha, 1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < nCols; j++) + for (i = jc[j]; i < jc[j + 1]; i++) + y[j + k * yLD] += val[i] * x[ir[i] + k * xLD]; + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < nCols; j++) + for (i = jc[j]; i < jc[j + 1]; i++) + y[j + k * yLD] -= val[i] * x[ir[i] + k * xLD]; + else + for (k = 0; k < xN; k++) + for (j = 0; j < nCols; j++) + for (i = jc[j]; i < jc[j + 1]; i++) + y[j + k * yLD] += alpha * val[i] * x[ir[i] + k * xLD]; + + return SUCCESSFUL_RETURN; +} + +returnValue SparseMatrix::times(const Indexlist * const irows, + const Indexlist * const icols, + int_t xN, + real_t alpha, + const real_t * x, + int_t xLD, + real_t beta, + real_t * y, + int_t yLD, + BooleanType yCompr) const +{ + long i, j, k, l, col; + real_t xcol; + + if (isEqual(alpha, 0.0) == BT_TRUE) { + if (yCompr == BT_TRUE) { + if (isZero(beta) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[j + k * yLD] = 0.0; + else if (isEqual(beta, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[j + k * yLD] = -y[j + k * yLD]; + else if (isEqual(beta, 1.0) == BT_FALSE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[j + k * yLD] *= beta; + } else { + if (isZero(beta) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[irows->number[j] + k * yLD] = 0.0; + else if (isEqual(beta, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[irows->number[j] + k * yLD] = -y[irows->number[j] + k * yLD]; + else if (isEqual(beta, 1.0) == BT_FALSE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[irows->number[j] + k * yLD] *= beta; + } + return SUCCESSFUL_RETURN; + } + + // First, work with full, unordered copy of y and store matrix times x in there + const int_t yfullLength = nRows; + real_t * ytmp = new real_t[xN * yfullLength]; + for (k = 0; k < xN * yfullLength; k++) + ytmp[k] = 0.0; + + if (icols != 0) { + if (xN == 1) { + for (l = 0; l < icols->length; l++) { + col = icols->iSort[l]; + xcol = x[col]; + if (isZero(xcol) == BT_FALSE) { + j = icols->number[col]; + for (i = jc[j]; i < jc[j + 1]; i++) + ytmp[ir[i]] += val[i] * xcol; + } + } + } else { + // AW: I didn't test the case xN>1, but I hope it is working + real_t * xcols = new real_t[xN]; + for (l = 0; l < icols->length; l++) { + col = icols->iSort[l]; + real_t xmax = 0.0; + for (k = 0; k < xN; k++) { + xcols[k] = x[k * xLD + col]; + xmax = getMax(xmax, getAbs(xcols[k])); + } + if (isZero(xmax) == BT_FALSE) { + j = icols->number[col]; + for (i = jc[j]; i < jc[j + 1]; i++) + for (k = 0; k < xN; k++) + // AW: Maybe it makes more sense to order ytmp by vectors, not vector entries, for better + // cache peformance? + ytmp[k * yfullLength + ir[i]] += val[i] * xcols[k]; + } + } + delete[] xcols; + } + } else /* icols == 0 */ + { + if (xN == 1) { + for (col = 0; col < nCols; col++) { + xcol = x[col]; + if (isZero(xcol) == BT_FALSE) + for (i = jc[col]; i < jc[col + 1]; i++) + ytmp[ir[i]] += val[i] * xcol; + } + } else { + // AW: I didn't test the case xN>1, but I hope it is working + real_t * xcols = new real_t[xN]; + for (col = 0; col < nCols; col++) { + real_t xmax = 0.0; + for (k = 0; k < xN; k++) { + xcols[k] = x[k * xLD + col]; + xmax = getMax(xmax, getAbs(xcols[k])); + } + if (isZero(xmax) == BT_FALSE) + for (i = jc[col]; i < jc[col + 1]; i++) + for (k = 0; k < xN; k++) + ytmp[k * yfullLength + ir[i]] += val[i] * xcols[k]; + delete[] xcols; + } + } + } + + if (yCompr == BT_TRUE) { + if (isZero(beta) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[j + k * yLD] = alpha * ytmp[irows->number[j] + k * yfullLength]; + else if (isEqual(beta, 1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[j + k * yLD] += alpha * ytmp[irows->number[j] + k * yfullLength]; + else if (isEqual(beta, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[j + k * yLD] = alpha * ytmp[irows->number[j] + k * yfullLength] - y[j + k * yLD]; + else if (isEqual(beta, 1.0) == BT_FALSE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[j + k * yLD] = alpha * ytmp[irows->number[j] + k * yfullLength] + beta * y[j + k * yLD]; + } else { + if (isZero(beta) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[irows->number[j] + k * yLD] = alpha * ytmp[irows->number[j] + k * yfullLength]; + else if (isEqual(beta, 1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[irows->number[j] + k * yLD] = alpha * ytmp[irows->number[j] + k * yfullLength] + y[j + k * yLD]; + else if (isEqual(beta, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[irows->number[j] + k * yLD] = alpha * ytmp[irows->number[j] + k * yfullLength] - y[j + k * yLD]; + else if (isEqual(beta, 1.0) == BT_FALSE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[irows->number[j] + k * yLD] = + alpha * ytmp[irows->number[j] + k * yfullLength] + beta * y[j + k * yLD]; + } + + delete[] ytmp; + return SUCCESSFUL_RETURN; +} + +returnValue SparseMatrix::transTimes(const Indexlist * const irows, + const Indexlist * const icols, + int_t xN, + real_t alpha, + const real_t * x, + int_t xLD, + real_t beta, + real_t * y, + int_t yLD) const +{ + long i, j, k, l, col; + real_t yadd; + + if (isZero(beta) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < icols->length; j++) + y[j + k * yLD] = 0.0; + else if (isEqual(beta, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < icols->length; j++) + y[j + k * yLD] = -y[j + k * yLD]; + else if (isEqual(beta, 1.0) == BT_FALSE) + for (k = 0; k < xN; k++) + for (j = 0; j < icols->length; j++) + y[j + k * yLD] *= beta; + if (isEqual(alpha, 0.0) == BT_TRUE) + return SUCCESSFUL_RETURN; + + // work with full, unordered copy of x + const int_t xfullLength = nRows; + real_t * xtmp = new real_t[xfullLength]; + for (k = 0; k < xN; k++) { + for (i = 0; i < xfullLength; i++) + xtmp[i] = 0.0; + for (i = 0; i < irows->length; i++) + xtmp[irows->number[i]] = x[k * xLD + i]; + for (l = 0; l < icols->length; l++) { + col = icols->iSort[l]; + yadd = 0.0; + j = icols->number[col]; + for (i = jc[j]; i < jc[j + 1]; i++) + yadd += val[i] * xtmp[ir[i]]; + y[col] += alpha * yadd; + } + y += yLD; // move on to next RHS + } + + delete[] xtmp; + + return SUCCESSFUL_RETURN; +} + +returnValue SparseMatrix::addToDiag(real_t alpha) +{ + long i; + + if (jd == 0) + return THROWERROR(RET_DIAGONAL_NOT_INITIALISED); + + if (isZero(alpha) == BT_FALSE) { + for (i = 0; i < nRows && i < nCols; i++) { + if (ir[jd[i]] == i) + val[jd[i]] += alpha; + else + return RET_NO_DIAGONAL_AVAILABLE; + } + } + + return SUCCESSFUL_RETURN; +} + +sparse_int_t * SparseMatrix::createDiagInfo() +{ + sparse_int_t i, j; + + if (jd == 0) { + jd = new sparse_int_t[nCols]; + + for (j = 0; j < nCols; j++) { + for (i = jc[j]; i < jc[j + 1] && ir[i] < j; i++) + ; + jd[j] = i; + } + } + + return jd; +} + +real_t * SparseMatrix::full() const +{ + sparse_int_t i, j; + real_t * v = new real_t[nRows * nCols]; + + for (i = 0; i < nCols * nRows; i++) + v[i] = 0.0; + + for (j = 0; j < nCols; j++) + for (i = jc[j]; i < jc[j + 1]; i++) + v[ir[i] * nCols + j] = val[i]; + + return v; +} + +returnValue SparseMatrix::print(const char * name) const +{ + real_t * tmp = this->full(); + returnValue retVal = REFER_NAMESPACE_QPOASES print(tmp, nRows, nCols, name); + delete[] tmp; + + return retVal; +} + +returnValue SparseMatrix::writeToFile(FILE * output_file, const char * prefix) const +{ + for (int_t i = 0; i <= nCols; i++) { + fprintf(output_file, "%sjc[%d] = %d\n", prefix, (int)i, (int)(jc[i])); + } + for (int_t i = 0; i < jc[nCols]; i++) { + fprintf(output_file, "%sir[%d] = %d\n", prefix, (int)i, (int)(ir[i])); + } + for (int_t i = 0; i < jc[nCols]; i++) { + fprintf(output_file, "%sval[%d] = %23.16e\n", prefix, (int)i, val[i]); + } + + return SUCCESSFUL_RETURN; +} + +SparseMatrixRow::SparseMatrixRow() : nRows(0), nCols(0), jr(0), ic(0), jd(0), val(0) +{ +} + +SparseMatrixRow::SparseMatrixRow(int_t nr, int_t nc, sparse_int_t * r, sparse_int_t * c, real_t * v) +: nRows(nr), nCols(nc), jr(r), ic(c), jd(0), val(v) +{ + doNotFreeMemory(); +} + +SparseMatrixRow::SparseMatrixRow(int_t nr, int_t nc, int_t ld, const real_t * const v) +: nRows(nr), nCols(nc), jd(0) +{ + int_t i, j, nnz; + + jr = new sparse_int_t[nr + 1]; + ic = new sparse_int_t[nr * nc]; + val = new real_t[nr * nc]; + + nnz = 0; + for (j = 0; j < nRows; j++) { + jr[j] = nnz; + for (i = 0; i < nCols; i++) + if ((isZero(v[j * ld + i], 0.0) == BT_FALSE) || (j == i)) { + ic[nnz] = i; + val[nnz++] = v[j * ld + i]; + } + } + jr[nRows] = nnz; + + doFreeMemory(); +} + +SparseMatrixRow::~SparseMatrixRow() +{ + if (jd != 0) { + delete[] jd; + jd = 0; + } + + if (needToFreeMemory() == BT_TRUE) + free(); +} + +void SparseMatrixRow::free() +{ + if (jr != 0) + delete[] jr; + jr = 0; + if (ic != 0) + delete[] ic; + ic = 0; + if (val != 0) + delete[] val; + val = 0; + + doNotFreeMemory(); +} + +Matrix * SparseMatrixRow::duplicate() const +{ + long i, length = jr[nRows]; + SparseMatrixRow * dupl = new SparseMatrixRow; + + dupl->nRows = nRows; + dupl->nCols = nCols; + dupl->jr = new sparse_int_t[nRows + 1]; + dupl->ic = new sparse_int_t[length]; + dupl->val = new real_t[length]; + + for (i = 0; i < length; i++) + dupl->jr[i] = jr[i]; + for (i = 0; i <= nCols; i++) + dupl->ic[i] = ic[i]; + for (i = 0; i < length; i++) + dupl->val[i] = val[i]; + + if (jd != 0) { + dupl->jd = new sparse_int_t[nRows]; + for (i = 0; i < nCols; i++) + dupl->jd[i] = jd[i]; + } else + dupl->jd = 0; + + dupl->doFreeMemory(); + + return dupl; +} + +real_t SparseMatrixRow::diag(int_t i) const +{ + if (jd == 0) { + THROWERROR(RET_DIAGONAL_NOT_INITIALISED); + return INFTY; + } + + int_t entry = jd[i]; + return (entry < jr[i + 1] && ic[entry] == i) ? val[entry] : 0.0; +} + +BooleanType SparseMatrixRow::isDiag() const +{ + int_t i; + + if (nCols != nRows) + return BT_FALSE; + + for (i = 0; i < nRows; ++i) { + if (jr[i + 1] > jr[i] + 1) + return BT_FALSE; + + if ((jr[i + 1] == jr[i] + 1) && (ic[jr[i]] != i)) + return BT_FALSE; + } + + return BT_TRUE; +} + +real_t SparseMatrixRow::getNorm(int_t type) const +{ + int_t length = jr[nRows]; + return REFER_NAMESPACE_QPOASES getNorm(val, length, type); +} + +real_t SparseMatrixRow::getRowNorm(int_t rNum, int_t type) const +{ + int_t length = jr[rNum + 1] - jr[rNum]; + return REFER_NAMESPACE_QPOASES getNorm(&(val[jr[rNum]]), length, type); +} + +returnValue SparseMatrixRow::getRowNorm(real_t * norm, int_t type) const +{ + int_t i; + for (i = 0; i < nRows; ++i) { + int_t length = jr[i + 1] - jr[i]; + norm[i] = REFER_NAMESPACE_QPOASES getNorm(&(val[jr[i]]), length, type); + } + return SUCCESSFUL_RETURN; +} + +returnValue SparseMatrixRow::getRow( + int_t rNum, const Indexlist * const icols, real_t alpha, real_t * row) const +{ + long i, j; + + if (icols != 0) { + j = jr[rNum]; + i = 0; + if (isEqual(alpha, 1.0) == BT_TRUE) + while (j < jr[rNum + 1] && i < icols->length) + if (ic[j] == icols->number[icols->iSort[i]]) + row[icols->iSort[i++]] = val[j++]; + else if (ic[j] > icols->number[icols->iSort[i]]) + row[icols->iSort[i++]] = 0.0; + else + j++; + else if (isEqual(alpha, -1.0) == BT_TRUE) + while (j < jr[rNum + 1] && i < icols->length) + if (ic[j] == icols->number[icols->iSort[i]]) + row[icols->iSort[i++]] = -val[j++]; + else if (ic[j] > icols->number[icols->iSort[i]]) + row[icols->iSort[i++]] = 0.0; + else + j++; + else + while (j < jr[rNum + 1] && i < icols->length) + if (ic[j] == icols->number[icols->iSort[i]]) + row[icols->iSort[i++]] = alpha * val[j++]; + else if (ic[j] > icols->number[icols->iSort[i]]) + row[icols->iSort[i++]] = 0.0; + else + j++; + + /* fill in remaining zeros */ + while (i < icols->length) + row[icols->iSort[i++]] = 0.0; + } else { + for (i = 0; i < nCols; i++) + row[i] = 0; + + if (isEqual(alpha, 1.0) == BT_TRUE) + for (j = jr[rNum]; j < jr[rNum + 1]; j++) + row[ic[j]] = val[j]; + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (j = jr[rNum]; j < jr[rNum + 1]; j++) + row[ic[j]] = -val[j]; + else + for (j = jr[rNum]; j < jr[rNum + 1]; j++) + row[ic[j]] = alpha * val[j]; + } + + return SUCCESSFUL_RETURN; +} + +returnValue SparseMatrixRow::getCol( + int_t cNum, const Indexlist * const irows, real_t alpha, real_t * col) const +{ + long i, j, k, srt; + + if (irows != 0) { + if (isEqual(alpha, 1.0) == BT_TRUE) + for (k = 0; k < irows->length; k++) { + srt = irows->iSort[k]; + j = irows->number[srt]; + for (i = jr[j]; i < jr[j + 1] && ic[i] < cNum; i++) + ; + col[srt] = (i < jr[j + 1] && ic[i] == cNum) ? val[i] : 0.0; + } + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (k = 0; k < irows->length; k++) { + srt = irows->iSort[k]; + j = irows->number[srt]; + for (i = jr[j]; i < jr[j + 1] && ic[i] < cNum; i++) + ; + col[srt] = (i < jr[j + 1] && ic[i] == cNum) ? -val[i] : 0.0; + } + else + for (k = 0; k < irows->length; k++) { + srt = irows->iSort[k]; + j = irows->number[srt]; + for (i = jr[j]; i < jr[j + 1] && ic[i] < cNum; i++) + ; + col[srt] = (i < jr[j + 1] && ic[i] == cNum) ? alpha * val[i] : 0.0; + } + } else { + if (isEqual(alpha, 1.0) == BT_TRUE) + for (j = 0; j < nCols; j++) { + for (i = jr[j]; i < jr[j + 1] && ic[i] < cNum; i++) + ; + col[j] = (i < jr[j + 1] && ic[i] == cNum) ? val[i] : 0.0; + } + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (j = 0; j < irows->length; j++) { + for (i = jr[j]; i < jr[j + 1] && ic[i] < cNum; i++) + ; + col[j] = (i < jr[j + 1] && ic[i] == cNum) ? -val[i] : 0.0; + } + else + for (j = 0; j < irows->length; j++) { + for (i = jr[j]; i < jr[j + 1] && ic[i] < cNum; i++) + ; + col[j] = (i < jr[j + 1] && ic[i] == cNum) ? alpha * val[i] : 0.0; + } + } + return SUCCESSFUL_RETURN; +} + +returnValue SparseMatrixRow::getSparseSubmatrix(int_t irowsLength, + const int_t * const irowsNumber, + int_t icolsLength, + const int_t * const icolsNumber, + int_t rowoffset, + int_t coloffset, + int_t & numNonzeros, + int_t * irn, + int_t * jcn, + real_t * avals, + BooleanType only_lower_triangular /*= BT_FALSE */) const +{ + fprintf(stderr, "SparseMatrixRow::getSparseSubmatrix not implemented!\n"); + + return THROWERROR(RET_NOT_YET_IMPLEMENTED); +} + +returnValue SparseMatrixRow::times( + int_t xN, real_t alpha, const real_t * x, int_t xLD, real_t beta, real_t * y, int_t yLD) const +{ + long i, j, k; + + if (isZero(beta) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < nRows; j++) + y[j + k * yLD] = 0.0; + else if (isEqual(beta, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < nRows; j++) + y[j + k * yLD] = -y[j + k * yLD]; + else if (isEqual(beta, 1.0) == BT_FALSE) + for (k = 0; k < xN; k++) + for (j = 0; j < nRows; j++) + y[j + k * yLD] *= beta; + + if (isEqual(alpha, 1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < nRows; j++) + for (i = jr[j]; i < jr[j + 1]; i++) + y[j + k * yLD] += val[i] * x[ic[i] + k * xLD]; + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < nRows; j++) + for (i = jr[j]; i < jr[j + 1]; i++) + y[j + k * yLD] -= val[i] * x[ic[i] + k * xLD]; + else + for (k = 0; k < xN; k++) + for (j = 0; j < nRows; j++) + for (i = jr[j]; i < jr[j + 1]; i++) + y[j + k * yLD] += alpha * val[i] * x[ic[i] + k * xLD]; + + return SUCCESSFUL_RETURN; +} + +returnValue SparseMatrixRow::transTimes( + int_t xN, real_t alpha, const real_t * x, int_t xLD, real_t beta, real_t * y, int_t yLD) const +{ + long i, j, k; + + if (isZero(beta) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < nCols; j++) + y[j + k * yLD] = 0.0; + else if (isEqual(beta, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < nCols; j++) + y[j + k * yLD] = -y[j + k * yLD]; + else if (isEqual(beta, 1.0) == BT_FALSE) + for (k = 0; k < xN; k++) + for (j = 0; j < nCols; j++) + y[j + k * yLD] *= beta; + + if (isEqual(alpha, 1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (i = 0; i < nRows; i++) + for (j = jr[i]; j < jr[i + 1]; j++) + y[ic[j] + k * yLD] += val[j] * x[i + k * xLD]; + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (i = 0; i < nRows; i++) + for (j = jr[i]; j < jr[i + 1]; j++) + y[ic[j] + k * yLD] -= val[j] * x[i + k * xLD]; + else + for (k = 0; k < xN; k++) + for (i = 0; i < nRows; i++) + for (j = jr[i]; j < jr[i + 1]; j++) + y[ic[j] + k * yLD] += alpha * val[j] * x[i + k * xLD]; + + return SUCCESSFUL_RETURN; +} + +returnValue SparseMatrixRow::times(const Indexlist * const irows, + const Indexlist * const icols, + int_t xN, + real_t alpha, + const real_t * x, + int_t xLD, + real_t beta, + real_t * y, + int_t yLD, + BooleanType yCompr) const +{ + long i, j, k, l, srt, row; + + if (yCompr == BT_TRUE) { + if (isZero(beta) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[j + k * yLD] = 0.0; + else if (isEqual(beta, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[j + k * yLD] = -y[j + k * yLD]; + else if (isEqual(beta, 1.0) == BT_FALSE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[j + k * yLD] *= beta; + + if (icols == 0) + if (isEqual(alpha, 1.0) == BT_TRUE) + for (l = 0; l < irows->length; l++) { + srt = irows->iSort[l]; + row = irows->number[srt]; + for (j = jr[row]; j < jr[row + 1]; j++) + for (k = 0; k < xN; k++) + y[k * yLD + srt] += val[j] * x[k * xLD + ic[j]]; + } + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (l = 0; l < irows->length; l++) { + srt = irows->iSort[l]; + row = irows->number[srt]; + for (j = jr[row]; j < jr[row + 1]; j++) + for (k = 0; k < xN; k++) + y[k * yLD + srt] -= val[j] * x[k * xLD + ic[j]]; + } + else + for (l = 0; l < irows->length; l++) { + srt = irows->iSort[l]; + row = irows->number[srt]; + for (j = jr[row]; j < jr[row + 1]; j++) + for (k = 0; k < xN; k++) + y[k * yLD + srt] += alpha * val[j] * x[k * xLD + ic[j]]; + } + else /* icols != 0 */ + if (isEqual(alpha, 1.0) == BT_TRUE) + for (l = 0; l < irows->length; l++) { + srt = irows->iSort[l]; + row = irows->number[srt]; + j = jr[row]; + i = 0; + while (j < jr[row + 1] && i < icols->length) + if (ic[j] == icols->number[icols->iSort[i]]) { + for (k = 0; k < xN; k++) + y[k * yLD + srt] += val[j] * x[k * xLD + icols->iSort[i]]; + j++, i++; + } else if (ic[j] > icols->number[icols->iSort[i]]) + i++; + else + j++; + } + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (l = 0; l < irows->length; l++) { + srt = irows->iSort[l]; + row = irows->number[srt]; + j = jr[row]; + i = 0; + while (j < jr[row + 1] && i < icols->length) + if (ic[j] == icols->number[icols->iSort[i]]) { + for (k = 0; k < xN; k++) + y[k * yLD + srt] -= val[j] * x[k * xLD + icols->iSort[i]]; + j++, i++; + } else if (ic[j] > icols->number[icols->iSort[i]]) + i++; + else + j++; + } + else + for (l = 0; l < irows->length; l++) { + srt = irows->iSort[l]; + row = irows->number[srt]; + j = jr[row]; + i = 0; + while (j < jr[row + 1] && i < icols->length) + if (ic[j] == icols->number[icols->iSort[i]]) { + for (k = 0; k < xN; k++) + y[k * yLD + srt] += alpha * val[j] * x[k * xLD + icols->iSort[i]]; + j++, i++; + } else if (ic[j] > icols->number[icols->iSort[i]]) + i++; + else + j++; + } + } else /* y not compressed */ + { + if (isZero(beta) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[irows->number[j] + k * yLD] = 0.0; + else if (isEqual(beta, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[irows->number[j] + k * yLD] = -y[j + k * yLD]; + else if (isEqual(beta, 1.0) == BT_FALSE) + for (k = 0; k < xN; k++) + for (j = 0; j < irows->length; j++) + y[irows->number[j] + k * yLD] *= beta; + + if (icols == 0) + if (isEqual(alpha, 1.0) == BT_TRUE) + for (l = 0; l < irows->length; l++) { + row = irows->number[irows->iSort[l]]; + for (j = jr[row]; j < jr[row + 1]; j++) + for (k = 0; k < xN; k++) + y[k * yLD + row] += val[j] * x[k * xLD + ic[j]]; + } + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (l = 0; l < irows->length; l++) { + row = irows->number[irows->iSort[l]]; + for (j = jr[row]; j < jr[row + 1]; j++) + for (k = 0; k < xN; k++) + y[k * yLD + row] -= val[j] * x[k * xLD + ic[j]]; + } + else + for (l = 0; l < irows->length; l++) { + row = irows->number[irows->iSort[l]]; + for (j = jr[row]; j < jr[row + 1]; j++) + for (k = 0; k < xN; k++) + y[k * yLD + row] += alpha * val[j] * x[k * xLD + ic[j]]; + } + else /* icols != 0 */ + if (isEqual(alpha, 1.0) == BT_TRUE) + for (l = 0; l < irows->length; l++) { + row = irows->iSort[l]; + j = jr[irows->number[row]]; + i = 0; + while (j < jr[irows->number[row] + 1] && i < icols->length) + if (ic[j] == icols->number[icols->iSort[i]]) { + for (k = 0; k < xN; k++) + y[k * yLD + row] += val[j] * x[k * xLD + icols->iSort[i]]; + j++, i++; + } else if (ic[j] > icols->number[icols->iSort[i]]) + i++; + else + j++; + } + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (l = 0; l < irows->length; l++) { + row = irows->iSort[l]; + j = jr[irows->number[row]]; + i = 0; + while (j < jr[irows->number[row] + 1] && i < icols->length) + if (ic[j] == icols->number[icols->iSort[i]]) { + for (k = 0; k < xN; k++) + y[k * yLD + row] -= val[j] * x[k * xLD + icols->iSort[i]]; + j++, i++; + } else if (ic[j] > icols->number[icols->iSort[i]]) + i++; + else + j++; + } + else + for (l = 0; l < irows->length; l++) { + row = irows->iSort[l]; + j = jr[irows->number[row]]; + i = 0; + while (j < jr[irows->number[row] + 1] && i < icols->length) + if (ic[j] == icols->number[icols->iSort[i]]) { + for (k = 0; k < xN; k++) + y[k * yLD + row] += alpha * val[j] * x[k * xLD + icols->iSort[i]]; + j++, i++; + } else if (ic[j] > icols->number[icols->iSort[i]]) + i++; + else + j++; + } + } + return SUCCESSFUL_RETURN; +} + +returnValue SparseMatrixRow::transTimes(const Indexlist * const irows, + const Indexlist * const icols, + int_t xN, + real_t alpha, + const real_t * x, + int_t xLD, + real_t beta, + real_t * y, + int_t yLD) const +{ + long i, j, k, l, row, srt; + + if (isZero(beta) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < icols->length; j++) + y[j + k * yLD] = 0.0; + else if (isEqual(beta, -1.0) == BT_TRUE) + for (k = 0; k < xN; k++) + for (j = 0; j < icols->length; j++) + y[j + k * yLD] = -y[j + k * yLD]; + else if (isEqual(beta, 1.0) == BT_FALSE) + for (k = 0; k < xN; k++) + for (j = 0; j < icols->length; j++) + y[j + k * yLD] *= beta; + + if (isEqual(alpha, 1.0) == BT_TRUE) + for (l = 0; l < irows->length; l++) { + srt = irows->iSort[l]; + row = irows->number[srt]; + j = jr[row]; + i = 0; + while (j < jr[row + 1] && i < icols->length) + if (ic[j] == icols->number[icols->iSort[i]]) { + for (k = 0; k < xN; k++) + y[k * yLD + icols->iSort[i]] += val[j] * x[k * xLD + srt]; + j++, i++; + } else if (ic[j] > icols->number[icols->iSort[i]]) + i++; + else + j++; + } + else if (isEqual(alpha, -1.0) == BT_TRUE) + for (l = 0; l < irows->length; l++) { + srt = irows->iSort[l]; + row = irows->number[srt]; + j = jr[row]; + i = 0; + while (j < jr[row + 1] && i < icols->length) + if (ic[j] == icols->number[icols->iSort[i]]) { + for (k = 0; k < xN; k++) + y[k * yLD + icols->iSort[i]] -= val[j] * x[k * xLD + srt]; + j++, i++; + } else if (ic[j] > icols->number[icols->iSort[i]]) + i++; + else + j++; + } + else + for (l = 0; l < irows->length; l++) { + srt = irows->iSort[l]; + row = irows->number[srt]; + j = jr[row]; + i = 0; + while (j < jr[row + 1] && i < icols->length) + if (ic[j] == icols->number[icols->iSort[i]]) { + for (k = 0; k < xN; k++) + y[k * yLD + icols->iSort[i]] += alpha * val[j] * x[k * xLD + srt]; + j++, i++; + } else if (ic[j] > icols->number[icols->iSort[i]]) + i++; + else + j++; + } + + return SUCCESSFUL_RETURN; +} + +returnValue SparseMatrixRow::addToDiag(real_t alpha) +{ + long i; + + if (jd == 0) + return THROWERROR(RET_DIAGONAL_NOT_INITIALISED); + + if (isZero(alpha) == BT_FALSE) { + for (i = 0; i < nRows && i < nCols; i++) { + if (ic[jd[i]] == i) + val[jd[i]] += alpha; + else + return RET_NO_DIAGONAL_AVAILABLE; + } + } + + return SUCCESSFUL_RETURN; +} + +sparse_int_t * SparseMatrixRow::createDiagInfo() +{ + sparse_int_t i, j; + + if (jd == 0) { + jd = new sparse_int_t[nRows]; + + for (i = 0; i < nRows; i++) { + for (j = jr[i]; j < jr[i + 1] && ic[j] < i; j++) + ; + jd[i] = j; + } + } + + return jd; +} + +real_t * SparseMatrixRow::full() const +{ + sparse_int_t i, j; + real_t * v = new real_t[nRows * nCols]; + + for (i = 0; i < nCols * nRows; i++) + v[i] = 0.0; + + for (i = 0; i < nRows; i++) + for (j = jr[i]; j < jr[i + 1]; j++) + v[ic[j] + i * nCols] = val[j]; + + return v; +} + +returnValue SparseMatrixRow::print(const char * name) const +{ + real_t * tmp = this->full(); + returnValue retVal = REFER_NAMESPACE_QPOASES print(tmp, nRows, nCols, name); + delete[] tmp; + + return retVal; +} + +returnValue SparseMatrixRow::writeToFile(FILE * output_file, const char * prefix) const +{ + return THROWERROR(RET_NOT_YET_IMPLEMENTED); +} + +Matrix * SymSparseMat::duplicate() const +{ + return duplicateSym(); +} + +SymmetricMatrix * SymSparseMat::duplicateSym() const +{ + /* "same" as duplicate() in SparseMatrix */ + long i, length = jc[nCols]; + SymSparseMat * dupl = new SymSparseMat; + + dupl->nRows = nRows; + dupl->nCols = nCols; + dupl->ir = new sparse_int_t[length]; + dupl->jc = new sparse_int_t[nCols + 1]; + dupl->val = new real_t[length]; + + for (i = 0; i < length; i++) + dupl->ir[i] = ir[i]; + for (i = 0; i <= nCols; i++) + dupl->jc[i] = jc[i]; + for (i = 0; i < length; i++) + dupl->val[i] = val[i]; + + if (jd != 0) { + dupl->jd = new sparse_int_t[nCols]; + for (i = 0; i < nCols; i++) + dupl->jd[i] = jd[i]; + } else + dupl->jd = 0; + + dupl->doFreeMemory(); + + return dupl; +} + +returnValue SymSparseMat::bilinear( + const Indexlist * const icols, int_t xN, const real_t * x, int_t xLD, real_t * y, int_t yLD) const +{ + int_t i, j, k, l, idx, row, col; + + if (jd == 0) + return THROWERROR(RET_DIAGONAL_NOT_INITIALISED); + + /* clear output */ + for (i = 0; i < xN * xN; i++) + y[i] = 0.0; + + /* compute lower triangle */ + for (l = 0; l < icols->length; l++) { + col = icols->number[icols->iSort[l]]; + idx = jd[col]; + k = 0; + while (idx < jc[col + 1] && k < icols->length) { + row = icols->number[icols->iSort[k]]; + if (ir[idx] == row) { + /* TODO: It is possible to formulate this as DSYR and DSYR2 + * operations. */ + if (row == col) /* diagonal element */ + for (i = 0; i < xN; i++) + for (j = i; j < xN; j++) + y[i * yLD + j] += val[idx] * x[i * xLD + col] * x[j * xLD + col]; + else /* subdiagonal elements */ + for (i = 0; i < xN; i++) + for (j = i; j < xN; j++) + y[i * yLD + j] += + val[idx] * (x[i * xLD + col] * x[j * xLD + row] + x[i * xLD + row] * x[j * xLD + col]); + idx++, k++; + } else if (ir[idx] > row) + k++; + else + idx++; + } + } + + /* fill upper triangle */ + for (i = 0; i < xN; i++) + for (j = i; j < xN; j++) + y[j * yLD + i] = y[i * yLD + j]; + + return SUCCESSFUL_RETURN; +} + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/MessageHandling.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/MessageHandling.cpp new file mode 100644 index 0000000..3fe6b1f --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/MessageHandling.cpp @@ -0,0 +1,630 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/MessageHandling.cpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of the MessageHandling class including global return values. + * + */ + +#include + +#ifdef __MATLAB__ +#include "mex.h" +#endif + +#include +#include + +BEGIN_NAMESPACE_QPOASES + +/** Default file to display messages. */ +FILE * stdFile = stdout; + +#ifndef __SUPPRESSANYOUTPUT__ + +/** Defines pairs of global return values and messages. */ +MessageHandling::ReturnValueList returnValueList[] = { + /* miscellaneous */ + {SUCCESSFUL_RETURN, "Successful return", VS_VISIBLE}, + {RET_DIV_BY_ZERO, "Division by zero", VS_VISIBLE}, + {RET_INDEX_OUT_OF_BOUNDS, "Index out of bounds", VS_VISIBLE}, + {RET_INVALID_ARGUMENTS, "At least one of the arguments is invalid", VS_VISIBLE}, + {RET_ERROR_UNDEFINED, "Error number undefined", VS_VISIBLE}, + {RET_WARNING_UNDEFINED, "Warning number undefined", VS_VISIBLE}, + {RET_INFO_UNDEFINED, "Info number undefined", VS_VISIBLE}, + {RET_EWI_UNDEFINED, "Error/warning/info number undefined", VS_VISIBLE}, + {RET_AVAILABLE_WITH_LINUX_ONLY, "This function is available under Linux only", VS_HIDDEN}, + {RET_UNKNOWN_BUG, "The error occurred is not yet known", VS_VISIBLE}, + {RET_PRINTLEVEL_CHANGED, "Print level changed", VS_VISIBLE}, + {RET_NOT_YET_IMPLEMENTED, "Requested function is not yet implemented.", VS_VISIBLE}, + /* Indexlist */ + {RET_INDEXLIST_MUST_BE_REORDERD, "Index list has to be reordered", VS_VISIBLE}, + {RET_INDEXLIST_EXCEEDS_MAX_LENGTH, "Index list exceeds its maximal physical length", VS_VISIBLE}, + {RET_INDEXLIST_CORRUPTED, "Index list corrupted", VS_VISIBLE}, + {RET_INDEXLIST_OUTOFBOUNDS, "Physical index is out of bounds", VS_VISIBLE}, + {RET_INDEXLIST_ADD_FAILED, "Adding indices from another index set failed", VS_VISIBLE}, + {RET_INDEXLIST_INTERSECT_FAILED, "Intersection with another index set failed", VS_VISIBLE}, + /* SubjectTo / Bounds / Constraints */ + {RET_INDEX_ALREADY_OF_DESIRED_STATUS, "Index is already of desired status", VS_VISIBLE}, + {RET_ADDINDEX_FAILED, "Adding index to index set failed", VS_VISIBLE}, + {RET_REMOVEINDEX_FAILED, "Removing index from index set failed", VS_VISIBLE}, + {RET_SWAPINDEX_FAILED, "Cannot swap between different indexsets", VS_VISIBLE}, + {RET_NOTHING_TO_DO, "Nothing to do", VS_VISIBLE}, + {RET_SETUP_BOUND_FAILED, "Setting up bound index failed", VS_VISIBLE}, + {RET_SETUP_CONSTRAINT_FAILED, "Setting up constraint index failed", VS_VISIBLE}, + {RET_MOVING_BOUND_FAILED, "Moving bound between index sets failed", VS_VISIBLE}, + {RET_MOVING_CONSTRAINT_FAILED, "Moving constraint between index sets failed", VS_VISIBLE}, + {RET_SHIFTING_FAILED, "Shifting of bounds/constraints failed", VS_VISIBLE}, + {RET_ROTATING_FAILED, "Rotating of bounds/constraints failed", VS_VISIBLE}, + /* QProblem */ + {RET_QPOBJECT_NOT_SETUP, + "The QP object has not been setup correctly, use another constructor", + VS_VISIBLE}, + {RET_QP_ALREADY_INITIALISED, "QProblem has already been initialised", VS_VISIBLE}, + {RET_NO_INIT_WITH_STANDARD_SOLVER, + "Initialisation via extern QP solver is not yet implemented", + VS_VISIBLE}, + {RET_RESET_FAILED, "Reset failed", VS_VISIBLE}, + {RET_INIT_FAILED, "Initialisation failed", VS_VISIBLE}, + {RET_INIT_FAILED_TQ, "Initialisation failed due to TQ factorisation", VS_VISIBLE}, + {RET_INIT_FAILED_CHOLESKY, "Initialisation failed due to Cholesky decomposition", VS_VISIBLE}, + {RET_INIT_FAILED_HOTSTART, "Initialisation failed! QP could not be solved!", VS_VISIBLE}, + {RET_INIT_FAILED_INFEASIBILITY, "Initial QP could not be solved due to infeasibility!", VS_VISIBLE}, + {RET_INIT_FAILED_UNBOUNDEDNESS, "Initial QP could not be solved due to unboundedness!", VS_VISIBLE}, + {RET_INIT_FAILED_REGULARISATION, + "Initialisation failed as Hessian matrix could not be regularised", + VS_VISIBLE}, + {RET_INIT_SUCCESSFUL, "Initialisation done", VS_VISIBLE}, + {RET_OBTAINING_WORKINGSET_FAILED, "Failed to obtain working set for auxiliary QP", VS_VISIBLE}, + {RET_SETUP_WORKINGSET_FAILED, "Failed to setup working set for auxiliary QP", VS_VISIBLE}, + {RET_SETUP_AUXILIARYQP_FAILED, "Failed to setup auxiliary QP for initialised homotopy", VS_VISIBLE}, + {RET_NO_CHOLESKY_WITH_INITIAL_GUESS, + "Externally computed Cholesky factor cannot be combined with an initial guess", + VS_VISIBLE}, + {RET_NO_EXTERN_SOLVER, "No extern QP solver available", VS_VISIBLE}, + {RET_QP_UNBOUNDED, "QP is unbounded", VS_VISIBLE}, + {RET_QP_INFEASIBLE, "QP is infeasible", VS_VISIBLE}, + {RET_QP_NOT_SOLVED, "Problems occurred while solving QP with standard solver", VS_VISIBLE}, + {RET_QP_SOLVED, "QP successfully solved", VS_VISIBLE}, + {RET_UNABLE_TO_SOLVE_QP, "Problems occurred while solving QP", VS_VISIBLE}, + {RET_INITIALISATION_STARTED, "Starting problem initialisation...", VS_VISIBLE}, + {RET_HOTSTART_FAILED, "Unable to perform homotopy due to internal error", VS_VISIBLE}, + {RET_HOTSTART_FAILED_TO_INIT, "Unable to initialise problem", VS_VISIBLE}, + {RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED, + "Unable to perform homotopy as previous QP is not solved", + VS_VISIBLE}, + {RET_ITERATION_STARTED, "Iteration", VS_VISIBLE}, + {RET_SHIFT_DETERMINATION_FAILED, "Determination of shift of the QP data failed", VS_VISIBLE}, + {RET_STEPDIRECTION_DETERMINATION_FAILED, "Determination of step direction failed", VS_VISIBLE}, + {RET_STEPLENGTH_DETERMINATION_FAILED, "Determination of step direction failed", VS_VISIBLE}, + {RET_OPTIMAL_SOLUTION_FOUND, "Optimal solution of neighbouring QP found", VS_VISIBLE}, + {RET_HOMOTOPY_STEP_FAILED, "Unable to perform homotopy step", VS_VISIBLE}, + {RET_HOTSTART_STOPPED_INFEASIBILITY, + "Premature homotopy termination because QP is infeasible", + VS_VISIBLE}, + {RET_HOTSTART_STOPPED_UNBOUNDEDNESS, + "Premature homotopy termination because QP is unbounded", + VS_VISIBLE}, + {RET_WORKINGSET_UPDATE_FAILED, "Unable to update working sets according to initial guesses", VS_VISIBLE}, + {RET_MAX_NWSR_REACHED, "Maximum number of working set recalculations performed", VS_VISIBLE}, + {RET_CONSTRAINTS_NOT_SPECIFIED, + "Problem does comprise constraints! You have to specify new constraints' bounds", + VS_VISIBLE}, + {RET_INVALID_FACTORISATION_FLAG, "Invalid factorisation flag", VS_VISIBLE}, + {RET_UNABLE_TO_SAVE_QPDATA, "Unable to save QP data", VS_VISIBLE}, + {RET_STEPDIRECTION_FAILED_TQ, "Abnormal termination due to TQ factorisation", VS_VISIBLE}, + {RET_STEPDIRECTION_FAILED_CHOLESKY, "Abnormal termination due to Cholesky factorisation", VS_VISIBLE}, + {RET_CYCLING_DETECTED, "Cycling detected", VS_VISIBLE}, + {RET_CYCLING_NOT_RESOLVED, "Cycling cannot be resolved, QP is probably infeasible", VS_VISIBLE}, + {RET_CYCLING_RESOLVED, "Cycling probably resolved", VS_VISIBLE}, + {RET_STEPSIZE, "", VS_VISIBLE}, + {RET_STEPSIZE_NONPOSITIVE, "", VS_VISIBLE}, + {RET_SETUPSUBJECTTOTYPE_FAILED, "Setup of SubjectToTypes failed", VS_VISIBLE}, + {RET_ADDCONSTRAINT_FAILED, "Addition of constraint to working set failed", VS_VISIBLE}, + {RET_ADDCONSTRAINT_FAILED_INFEASIBILITY, "Addition of constraint to working set failed", VS_VISIBLE}, + {RET_ADDBOUND_FAILED, "Addition of bound to working set failed", VS_VISIBLE}, + {RET_ADDBOUND_FAILED_INFEASIBILITY, "Addition of bound to working set failed", VS_VISIBLE}, + {RET_REMOVECONSTRAINT_FAILED, "Removal of constraint from working set failed", VS_VISIBLE}, + {RET_REMOVEBOUND_FAILED, "Removal of bound from working set failed", VS_VISIBLE}, + {RET_REMOVE_FROM_ACTIVESET, "Removing from active set:", VS_VISIBLE}, + {RET_ADD_TO_ACTIVESET, "Adding to active set:", VS_VISIBLE}, + {RET_REMOVE_FROM_ACTIVESET_FAILED, "Removing from active set failed", VS_VISIBLE}, + {RET_ADD_TO_ACTIVESET_FAILED, "Adding to active set failed", VS_VISIBLE}, + {RET_CONSTRAINT_ALREADY_ACTIVE, "Constraint is already active", VS_VISIBLE}, + {RET_ALL_CONSTRAINTS_ACTIVE, + "All constraints are active, no further constraint can be added", + VS_VISIBLE}, + {RET_LINEARLY_DEPENDENT, "New bound/constraint is linearly dependent", VS_VISIBLE}, + {RET_LINEARLY_INDEPENDENT, "New bound/constraint is linearly independent", VS_VISIBLE}, + {RET_LI_RESOLVED, "Linear independence of active constraint matrix successfully resolved", VS_VISIBLE}, + {RET_ENSURELI_FAILED, "Failed to ensure linear independence of active constraint matrix", VS_VISIBLE}, + {RET_ENSURELI_FAILED_TQ, "Abnormal termination due to TQ factorisation", VS_VISIBLE}, + {RET_ENSURELI_FAILED_NOINDEX, "QP is infeasible", VS_VISIBLE}, + {RET_ENSURELI_FAILED_CYCLING, "QP is infeasible", VS_VISIBLE}, + {RET_BOUND_ALREADY_ACTIVE, "Bound is already active", VS_VISIBLE}, + {RET_ALL_BOUNDS_ACTIVE, "All bounds are active, no further bound can be added", VS_VISIBLE}, + {RET_CONSTRAINT_NOT_ACTIVE, "Constraint is not active", VS_VISIBLE}, + {RET_BOUND_NOT_ACTIVE, "Bound is not active", VS_VISIBLE}, + {RET_HESSIAN_NOT_SPD, "Projected Hessian matrix not positive definite", VS_VISIBLE}, + {RET_HESSIAN_INDEFINITE, "Hessian matrix is indefinite", VS_VISIBLE}, + {RET_MATRIX_SHIFT_FAILED, "Unable to update matrices or to transform vectors", VS_VISIBLE}, + {RET_MATRIX_FACTORISATION_FAILED, "Unable to calculate new matrix factorisations", VS_VISIBLE}, + {RET_PRINT_ITERATION_FAILED, "Unable to print information on current iteration", VS_VISIBLE}, + {RET_NO_GLOBAL_MESSAGE_OUTPUTFILE, "No global message output file initialised", VS_VISIBLE}, + {RET_DISABLECONSTRAINTS_FAILED, "Unable to disable constraints", VS_VISIBLE}, + {RET_ENABLECONSTRAINTS_FAILED, "Unable to enable constraints", VS_VISIBLE}, + {RET_ALREADY_ENABLED, "Bound or constraint is already enabled", VS_VISIBLE}, + {RET_ALREADY_DISABLED, "Bound or constraint is already disabled", VS_VISIBLE}, + {RET_NO_HESSIAN_SPECIFIED, "No Hessian matrix has been specified", VS_VISIBLE}, + {RET_USING_REGULARISATION, "Using regularisation as Hessian matrix is not positive definite", VS_VISIBLE}, + {RET_EPS_MUST_BE_POSITVE, "Eps for regularisation must be sufficiently positive", VS_VISIBLE}, + {RET_REGSTEPS_MUST_BE_POSITVE, "Maximum number of regularisation steps must be non-negative", VS_VISIBLE}, + {RET_HESSIAN_ALREADY_REGULARISED, "Hessian has been already regularised", VS_VISIBLE}, + {RET_CANNOT_REGULARISE_IDENTITY, "Identity Hessian matrix cannot be regularised", VS_VISIBLE}, + {RET_CANNOT_REGULARISE_SPARSE, + "Sparse matrix cannot be regularised as diagonal entry is missing", + VS_VISIBLE}, + {RET_NO_REGSTEP_NWSR, "No additional regularisation step could be performed due to limits", VS_VISIBLE}, + {RET_FEWER_REGSTEPS_NWSR, + "Fewer additional regularisation steps have been performed due to limits", + VS_VISIBLE}, + {RET_CHOLESKY_OF_ZERO_HESSIAN, + "Cholesky decomposition of (unregularised) zero Hessian matrix", + VS_VISIBLE}, + {RET_ZERO_HESSIAN_ASSUMED, + "Zero Hessian matrix assumed as null pointer passed without specifying hessianType", + VS_VISIBLE}, + {RET_CONSTRAINTS_ARE_NOT_SCALED, "(should not be thrown, no longer in use)", VS_VISIBLE}, + {RET_INITIAL_BOUNDS_STATUS_NYI, "(should not be thrown, no longer in use)", VS_VISIBLE}, + {RET_ERROR_IN_CONSTRAINTPRODUCT, "Error in user-defined constraint product function", VS_VISIBLE}, + {RET_FIX_BOUNDS_FOR_LP, + "All initial bounds must be fixed when solving an (unregularised) LP", + VS_VISIBLE}, + {RET_USE_REGULARISATION_FOR_LP, "Set options.enableRegularisation=BT_TRUE for solving LPs", VS_VISIBLE}, + /* SQProblem */ + {RET_UPDATEMATRICES_FAILED, "Unable to update QP matrices", VS_VISIBLE}, + {RET_UPDATEMATRICES_FAILED_AS_QP_NOT_SOLVED, + "Unable to update matrices as previous QP is not solved", + VS_VISIBLE}, + /* Utils */ + {RET_UNABLE_TO_OPEN_FILE, "Unable to open file", VS_VISIBLE}, + {RET_UNABLE_TO_WRITE_FILE, "Unable to write into file", VS_VISIBLE}, + {RET_UNABLE_TO_READ_FILE, "Unable to read from file", VS_VISIBLE}, + {RET_FILEDATA_INCONSISTENT, "File contains inconsistent data", VS_VISIBLE}, + /* Options */ + {RET_OPTIONS_ADJUSTED, "Options needed to be adjusted for consistency reasons", VS_VISIBLE}, + /* SolutionAnalysis */ + {RET_UNABLE_TO_ANALYSE_QPROBLEM, "Unable to analyse (S)QProblem(B) object", VS_VISIBLE}, + /* Benchmark */ + {RET_NWSR_SET_TO_ONE, "Maximum number of working set changes was set to 1", VS_VISIBLE}, + {RET_UNABLE_TO_READ_BENCHMARK, "Unable to read benchmark data", VS_VISIBLE}, + {RET_BENCHMARK_ABORTED, "Benchmark aborted", VS_VISIBLE}, + {RET_INITIAL_QP_SOLVED, "Initial QP solved", VS_VISIBLE}, + {RET_QP_SOLUTION_STARTED, "Solving QP no.", VS_VISIBLE}, + {RET_BENCHMARK_SUCCESSFUL, "Benchmark terminated successfully", VS_VISIBLE}, + /* Sparse matrices */ + {RET_NO_DIAGONAL_AVAILABLE, "Sparse matrix does not have entries on full diagonal", VS_VISIBLE}, + {RET_DIAGONAL_NOT_INITIALISED, "Diagonal data of sparse matrix has not been initialised", VS_VISIBLE}, + /* Dropping of infeasible constraints */ + {RET_ENSURELI_DROPPED, "Linear independence resolved by dropping blocking constraint", VS_VISIBLE}, + /* Schur complement computations */ + {RET_KKT_MATRIX_SINGULAR, "KKT matrix is singular", VS_VISIBLE}, + {RET_QR_FACTORISATION_FAILED, "QR factorization of Schur complement failed", VS_VISIBLE}, + {RET_INERTIA_CORRECTION_FAILED, "Inertia correction of KKT matrix failed", VS_VISIBLE}, + {RET_NO_SPARSE_SOLVER, "No Sparse Solver installed", VS_VISIBLE}, + /* Simple exitflags */ + {RET_SIMPLE_STATUS_P1, "QP problem could not be solved within given number of iterations", VS_VISIBLE}, + {RET_SIMPLE_STATUS_P0, "QP problem solved", VS_VISIBLE}, + {RET_SIMPLE_STATUS_M1, "QP problem could not be solved due to an internal error", VS_VISIBLE}, + {RET_SIMPLE_STATUS_M2, "QP problem is infeasible (and thus could not be solved)", VS_VISIBLE}, + {RET_SIMPLE_STATUS_M3, "QP problem is unbounded (and thus could not be solved)", VS_VISIBLE}, + /* IMPORTANT: Terminal list element! */ + {TERMINAL_LIST_ELEMENT, "", VS_HIDDEN}}; + +#else /* __SUPPRESSANYOUTPUT__ */ + +MessageHandling::ReturnValueList returnValueList[1]; /* Do not use messages for embedded platforms! */ + +#endif /* __SUPPRESSANYOUTPUT__ */ + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +/* + * M e s s a g e H a n d l i n g + */ +MessageHandling::MessageHandling() +{ + errorVisibility = VS_VISIBLE; + warningVisibility = VS_VISIBLE; + infoVisibility = VS_VISIBLE; + + outputFile = stdFile; + errorCount = 0; +} + +/* + * M e s s a g e H a n d l i n g + */ +MessageHandling::MessageHandling(FILE * _outputFile) +{ + errorVisibility = VS_VISIBLE; + warningVisibility = VS_HIDDEN; + infoVisibility = VS_HIDDEN; + + outputFile = _outputFile; + errorCount = 0; +} + +/* + * M e s s a g e H a n d l i n g + */ +MessageHandling::MessageHandling( + VisibilityStatus _errorVisibility, VisibilityStatus _warningVisibility, VisibilityStatus _infoVisibility) +{ + errorVisibility = _errorVisibility; + warningVisibility = _warningVisibility; + infoVisibility = _infoVisibility; + + outputFile = stdFile; + errorCount = 0; +} + +/* + * M e s s a g e H a n d l i n g + */ +MessageHandling::MessageHandling(FILE * _outputFile, + VisibilityStatus _errorVisibility, + VisibilityStatus _warningVisibility, + VisibilityStatus _infoVisibility) +{ + errorVisibility = _errorVisibility; + warningVisibility = _warningVisibility; + infoVisibility = _infoVisibility; + + outputFile = _outputFile; + errorCount = 0; +} + +/* + * M e s s a g e H a n d l i n g + */ +MessageHandling::MessageHandling(const MessageHandling & rhs) +{ + errorVisibility = rhs.errorVisibility; + warningVisibility = rhs.warningVisibility; + infoVisibility = rhs.infoVisibility; + + outputFile = rhs.outputFile; + errorCount = rhs.errorCount; +} + +/* + * ~ M e s s a g e H a n d l i n g + */ +MessageHandling::~MessageHandling() +{ +#ifndef __SUPPRESSANYOUTPUT__ + if ((outputFile != 0) && (outputFile != stdout) && (outputFile != stderr)) + fclose(outputFile); +#endif /* __SUPPRESSANYOUTPUT__ */ +} + +/* + * o p e r a t o r = + */ +MessageHandling & MessageHandling::operator=(const MessageHandling & rhs) +{ + if (this != &rhs) { + errorVisibility = rhs.errorVisibility; + warningVisibility = rhs.warningVisibility; + infoVisibility = rhs.infoVisibility; + + outputFile = rhs.outputFile; + errorCount = rhs.errorCount; + } + + return *this; +} + +/* + * t h r o w E r r o r + */ +returnValue MessageHandling::throwError(returnValue Enumber, + const char * additionaltext, + const char * functionname, + const char * filename, + const unsigned long linenumber, + VisibilityStatus localVisibilityStatus) +{ + /* consistency check */ + if (Enumber <= SUCCESSFUL_RETURN) + return throwError(RET_ERROR_UNDEFINED, 0, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); + + /* Call to common throwMessage function if error shall be displayed. */ + if (errorVisibility == VS_VISIBLE) + return throwMessage( + Enumber, additionaltext, functionname, filename, linenumber, localVisibilityStatus, "ERROR"); + else + return Enumber; +} + +/* + * t h r o w W a r n i n g + */ +returnValue MessageHandling::throwWarning(returnValue Wnumber, + const char * additionaltext, + const char * functionname, + const char * filename, + const unsigned long linenumber, + VisibilityStatus localVisibilityStatus) +{ + /* consistency check */ + if (Wnumber <= SUCCESSFUL_RETURN) + return throwError(RET_WARNING_UNDEFINED, 0, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); + + /* Call to common throwMessage function if warning shall be displayed. */ + if (warningVisibility == VS_VISIBLE) + return throwMessage( + Wnumber, additionaltext, functionname, filename, linenumber, localVisibilityStatus, "WARNING"); + else + return Wnumber; +} + +/* + * t h r o w I n f o + */ +returnValue MessageHandling::throwInfo(returnValue Inumber, + const char * additionaltext, + const char * functionname, + const char * filename, + const unsigned long linenumber, + VisibilityStatus localVisibilityStatus) +{ + /* consistency check */ + if (Inumber < SUCCESSFUL_RETURN) + return throwError(RET_INFO_UNDEFINED, 0, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); + + /* Call to common throwMessage function if info shall be displayed. */ + if (infoVisibility == VS_VISIBLE) + return throwMessage( + Inumber, additionaltext, functionname, filename, linenumber, localVisibilityStatus, "INFO"); + else + return Inumber; +} + +/* + * r e s e t + */ +returnValue MessageHandling::reset() +{ + setErrorVisibilityStatus(VS_VISIBLE); + setWarningVisibilityStatus(VS_HIDDEN); + setInfoVisibilityStatus(VS_HIDDEN); + + setOutputFile(stdFile); + setErrorCount(0); + + return SUCCESSFUL_RETURN; +} + +/* + * l i s t A l l M e s s a g e s + */ +returnValue MessageHandling::listAllMessages() +{ +#ifndef __SUPPRESSANYOUTPUT__ + int_t keypos = 0; + char myPrintfString[MAX_STRING_LENGTH]; + + /* Run through whole returnValueList and print each item. */ + while (returnValueList[keypos].key != TERMINAL_LIST_ELEMENT) { + snprintf(myPrintfString, MAX_STRING_LENGTH, " %d - %s \n", (int)keypos, returnValueList[keypos].data); + myPrintf(myPrintfString); + + ++keypos; + } +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + +/* + * t h r o w M e s s a g e + */ +returnValue MessageHandling::throwMessage(returnValue RETnumber, + const char * additionaltext, + const char * functionname, + const char * filename, + const unsigned long linenumber, + VisibilityStatus localVisibilityStatus, + const char * RETstring) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + int_t keypos = 0; + char myPrintfString[MAX_STRING_LENGTH]; + + /* 1) Determine number of whitespace for output. */ + char whitespaces[MAX_STRING_LENGTH]; + int_t numberOfWhitespaces = (errorCount - 1) * 2; + + if (numberOfWhitespaces < 0) + numberOfWhitespaces = 0; + + if (numberOfWhitespaces > 40) + numberOfWhitespaces = 40; + + if (numberOfWhitespaces >= (int_t)MAX_STRING_LENGTH) + numberOfWhitespaces = (int_t)MAX_STRING_LENGTH - 1; + + memset(whitespaces, ' ', (size_t)numberOfWhitespaces); + whitespaces[numberOfWhitespaces] = '\0'; + + /* 2) Find error/warning/info in list. */ + while (returnValueList[keypos].key != TERMINAL_LIST_ELEMENT) { + if (returnValueList[keypos].key == RETnumber) + break; + else + ++keypos; + } + + if (returnValueList[keypos].key == TERMINAL_LIST_ELEMENT) { + throwError(RET_EWI_UNDEFINED, 0, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); + return RETnumber; + } + + /* 3) Print error/warning/info. */ + if ((returnValueList[keypos].globalVisibilityStatus == VS_VISIBLE) && + (localVisibilityStatus == VS_VISIBLE)) { + if (errorCount < 0) { + myPrintf("\n"); + errorCount = 0; + } + + if (errorCount > 0) { + snprintf(myPrintfString, MAX_STRING_LENGTH, "%s->", whitespaces); + myPrintf(myPrintfString); + } + + if (additionaltext == 0) { +#ifdef __DEBUG__ + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "%s (%s, %s:%d): \t%s\n", + RETstring, + functionname, + filename, + (int_t)linenumber, + returnValueList[keypos].data); +#else + snprintf(myPrintfString, MAX_STRING_LENGTH, "%s: %s\n", RETstring, returnValueList[keypos].data); +#endif + myPrintf(myPrintfString); + } else { +#ifdef __DEBUG__ + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "%s (%s, %s:%d): \t%s %s\n", + RETstring, + functionname, + filename, + (int_t)linenumber, + returnValueList[keypos].data, + additionaltext); +#else + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "%s: %s %s\n", + RETstring, + returnValueList[keypos].data, + additionaltext); +#endif + myPrintf(myPrintfString); + } + + /* take care of proper indention for subsequent error messages */ + if (RETstring[0] == 'E') { + ++errorCount; + } else { + if (errorCount > 0) + myPrintf("\n"); + errorCount = 0; + } + } + +#endif /* __SUPPRESSANYOUTPUT__ */ + + return RETnumber; +} + +/****************************************************************************/ +/* S T A T I C P U B L I C */ +/****************************************************************************/ + +const char * MessageHandling::getErrorCodeMessage(const returnValue _returnValue) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + int_t keypos = 0; + + /* 2) Find error/warning/info in list. */ + while (returnValueList[keypos].key != TERMINAL_LIST_ELEMENT) { + if (returnValueList[keypos].key == _returnValue) + break; + else + ++keypos; + } + + if (returnValueList[keypos].key == TERMINAL_LIST_ELEMENT) { + return "Unknown error code"; + } + + return (returnValueList[keypos].data != 0) ? returnValueList[keypos].data + : "No message for this error code"; + +#else /* __SUPPRESSANYOUTPUT__ */ + + return "No message for this error code"; + +#endif /* __SUPPRESSANYOUTPUT__ */ +} + +/***************************************************************************** + * G L O B A L M E S S A G E H A N D L E R * + *****************************************************************************/ + +/** Global message handler for all qpOASES modules.*/ +#if defined(__DSPACE__) || defined(__XPCTARGET__) +static MessageHandling globalMessageHandler(stdFile, VS_VISIBLE, VS_HIDDEN, VS_HIDDEN); +#endif + +/* + * g e t G l o b a l M e s s a g e H a n d l e r + */ +MessageHandling * getGlobalMessageHandler() +{ +#ifndef __DSPACE__ +#ifndef __XPCTARGET__ + static MessageHandling globalMessageHandler(stdFile, VS_VISIBLE, VS_VISIBLE, VS_VISIBLE); +#endif /* __DSPACE__ */ +#endif /* __XPCTARGET__ */ + + return &globalMessageHandler; +} + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/OQPinterface.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/OQPinterface.cpp new file mode 100644 index 0000000..c200b3a --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/OQPinterface.cpp @@ -0,0 +1,819 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/OQPinterface.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2008-2017 + * + * Implementation of an interface comprising several utility functions + * for solving test problems from the Online QP Benchmark Collection + * (This collection is no longer maintained, see + * http://www.qpOASES.org/onlineQP for a backup). + * + */ + +#include +#include + +BEGIN_NAMESPACE_QPOASES + +/* + * r e a d O q p D i m e n s i o n s + */ +returnValue readOqpDimensions(const char * path, int_t & nQP, int_t & nV, int_t & nC, int_t & nEC) +{ + /* 1) Setup file name where dimensions are stored. */ + char filename[MAX_STRING_LENGTH]; + snprintf(filename, MAX_STRING_LENGTH, "%sdims.oqp", path); + + /* 2) Load dimensions from file. */ + int_t dims[4]; + if (readFromFile(dims, 4, filename) != SUCCESSFUL_RETURN) + return THROWERROR(RET_UNABLE_TO_READ_FILE); + + nQP = dims[0]; + nV = dims[1]; + nC = dims[2]; + nEC = dims[3]; + + /* consistency check */ + if ((nQP <= 0) || (nV <= 0) || (nC < 0) || (nEC < 0)) + return THROWERROR(RET_FILEDATA_INCONSISTENT); + + return SUCCESSFUL_RETURN; +} + +/* + * r e a d O q p D a t a + */ +returnValue readOqpData(const char * path, + int_t & nQP, + int_t & nV, + int_t & nC, + int_t & nEC, + real_t ** H, + real_t ** g, + real_t ** A, + real_t ** lb, + real_t ** ub, + real_t ** lbA, + real_t ** ubA, + real_t ** xOpt, + real_t ** yOpt, + real_t ** objOpt) +{ + char filename[MAX_STRING_LENGTH]; + + /* consistency check */ + if ((H == 0) || (g == 0) || (lb == 0) || (ub == 0)) + return THROWERROR(RET_INVALID_ARGUMENTS); + + /* 1) Obtain OQP dimensions. */ + if (readOqpDimensions(path, nQP, nV, nC, nEC) != SUCCESSFUL_RETURN) + return THROWERROR(RET_UNABLE_TO_READ_FILE); + + /* another consistency check */ + if ((nC > 0) && ((A == 0) || (lbA == 0) || (ubA == 0))) + return THROWERROR(RET_FILEDATA_INCONSISTENT); + + /* 2) Allocate memory and load OQP data: */ + /* Hessian matrix */ + *H = new real_t[nV * nV]; + snprintf(filename, MAX_STRING_LENGTH, "%sH.oqp", path); + if (readFromFile(*H, nV, nV, filename) != SUCCESSFUL_RETURN) { + delete[] * H; + return THROWERROR(RET_UNABLE_TO_READ_FILE); + } + + /* gradient vector sequence */ + *g = new real_t[nQP * nV]; + snprintf(filename, MAX_STRING_LENGTH, "%sg.oqp", path); + if (readFromFile(*g, nQP, nV, filename) != SUCCESSFUL_RETURN) { + delete[] * g; + delete[] * H; + return THROWERROR(RET_UNABLE_TO_READ_FILE); + } + + /* lower bound vector sequence */ + *lb = new real_t[nQP * nV]; + snprintf(filename, MAX_STRING_LENGTH, "%slb.oqp", path); + if (readFromFile(*lb, nQP, nV, filename) != SUCCESSFUL_RETURN) { + delete[] * lb; + delete[] * g; + delete[] * H; + return THROWERROR(RET_UNABLE_TO_READ_FILE); + } + + /* upper bound vector sequence */ + *ub = new real_t[nQP * nV]; + snprintf(filename, MAX_STRING_LENGTH, "%sub.oqp", path); + if (readFromFile(*ub, nQP, nV, filename) != SUCCESSFUL_RETURN) { + delete[] * ub; + delete[] * lb; + delete[] * g; + delete[] * H; + return THROWERROR(RET_UNABLE_TO_READ_FILE); + } + + if (nC > 0) { + /* Constraint matrix */ + *A = new real_t[nC * nV]; + snprintf(filename, MAX_STRING_LENGTH, "%sA.oqp", path); + if (readFromFile(*A, nC, nV, filename) != SUCCESSFUL_RETURN) { + delete[] * A; + delete[] * ub; + delete[] * lb; + delete[] * g; + delete[] * H; + return THROWERROR(RET_UNABLE_TO_READ_FILE); + } + + /* lower constraints' bound vector sequence */ + *lbA = new real_t[nQP * nC]; + snprintf(filename, MAX_STRING_LENGTH, "%slbA.oqp", path); + if (readFromFile(*lbA, nQP, nC, filename) != SUCCESSFUL_RETURN) { + delete[] * lbA; + delete[] * A; + delete[] * ub; + delete[] * lb; + delete[] * g; + delete[] * H; + return THROWERROR(RET_UNABLE_TO_READ_FILE); + } + + /* upper constraints' bound vector sequence */ + *ubA = new real_t[nQP * nC]; + snprintf(filename, MAX_STRING_LENGTH, "%subA.oqp", path); + if (readFromFile(*ubA, nQP, nC, filename) != SUCCESSFUL_RETURN) { + delete[] * ubA; + delete[] * lbA; + delete[] * A; + delete[] * ub; + delete[] * lb; + delete[] * g; + delete[] * H; + return THROWERROR(RET_UNABLE_TO_READ_FILE); + } + } else { + *A = 0; + *lbA = 0; + *ubA = 0; + } + + if (xOpt != 0) { + /* primal solution vector sequence */ + *xOpt = new real_t[nQP * nV]; + snprintf(filename, MAX_STRING_LENGTH, "%sx_opt.oqp", path); + if (readFromFile(*xOpt, nQP, nV, filename) != SUCCESSFUL_RETURN) { + delete[] xOpt; + if (nC > 0) { + delete[] * ubA; + delete[] * lbA; + delete[] * A; + }; + delete[] * ub; + delete[] * lb; + delete[] * g; + delete[] * H; + return THROWERROR(RET_UNABLE_TO_READ_FILE); + } + } + + if (yOpt != 0) { + /* dual solution vector sequence */ + *yOpt = new real_t[nQP * (nV + nC)]; + snprintf(filename, MAX_STRING_LENGTH, "%sy_opt.oqp", path); + if (readFromFile(*yOpt, nQP, nV + nC, filename) != SUCCESSFUL_RETURN) { + delete[] yOpt; + if (xOpt != 0) { + delete[] xOpt; + }; + if (nC > 0) { + delete[] * ubA; + delete[] * lbA; + delete[] * A; + }; + delete[] * ub; + delete[] * lb; + delete[] * g; + delete[] * H; + return THROWERROR(RET_UNABLE_TO_READ_FILE); + } + } + + if (objOpt != 0) { + /* dual solution vector sequence */ + *objOpt = new real_t[nQP]; + snprintf(filename, MAX_STRING_LENGTH, "%sobj_opt.oqp", path); + if (readFromFile(*objOpt, nQP, 1, filename) != SUCCESSFUL_RETURN) { + delete[] objOpt; + if (yOpt != 0) { + delete[] yOpt; + }; + if (xOpt != 0) { + delete[] xOpt; + }; + if (nC > 0) { + delete[] * ubA; + delete[] * lbA; + delete[] * A; + }; + delete[] * ub; + delete[] * lb; + delete[] * g; + delete[] * H; + return THROWERROR(RET_UNABLE_TO_READ_FILE); + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * s o l v e O q p B e n c h m a r k + */ +returnValue solveOqpBenchmark(int_t nQP, + int_t nV, + int_t nC, + int_t nEC, + const real_t * const _H, + const real_t * const g, + const real_t * const _A, + const real_t * const lb, + const real_t * const ub, + const real_t * const lbA, + const real_t * const ubA, + BooleanType isSparse, + const Options & options, + int_t & nWSR, + real_t & maxCPUtime, + real_t & maxStationarity, + real_t & maxFeasibility, + real_t & maxComplementarity) +{ + real_t maxNWSR = 0.0; + real_t avgNWSR = 0.0; + real_t avgCPUtime = 0.0; + + returnValue returnvalue = solveOqpBenchmark(nQP, + nV, + nC, + nEC, + _H, + g, + _A, + lb, + ub, + lbA, + ubA, + isSparse, + BT_TRUE, + options, + nWSR, + maxNWSR, + avgNWSR, + maxCPUtime, + avgCPUtime, + maxStationarity, + maxFeasibility, + maxComplementarity); + nWSR = (int_t)maxNWSR; + + return returnvalue; +} + +/* + * s o l v e O q p B e n c h m a r k + */ +returnValue solveOqpBenchmark(int_t nQP, + int_t nV, + int_t nC, + int_t nEC, + const real_t * const _H, + const real_t * const g, + const real_t * const _A, + const real_t * const lb, + const real_t * const ub, + const real_t * const lbA, + const real_t * const ubA, + BooleanType isSparse, + BooleanType useHotstarts, + const Options & options, + int_t maxAllowedNWSR, + real_t & maxNWSR, + real_t & avgNWSR, + real_t & maxCPUtime, + real_t & avgCPUtime, + real_t & maxStationarity, + real_t & maxFeasibility, + real_t & maxComplementarity) +{ + int_t k; + + /* I) SETUP AUXILIARY VARIABLES: */ + /* 1) Keep nWSR and store current and maximum number of + * working set recalculations in temporary variables */ + int_t nWSRcur; + + real_t CPUtimeLimit = maxCPUtime; + real_t CPUtimeCur = CPUtimeLimit; + maxNWSR = 0.0; + avgNWSR = 0.0; + maxCPUtime = 0.0; + avgCPUtime = 0.0; + maxStationarity = 0.0; + maxFeasibility = 0.0; + maxComplementarity = 0.0; + real_t stat, feas, cmpl; + + /* 2) Pointers to data of current QP ... */ + const real_t * gCur; + const real_t * lbCur; + const real_t * ubCur; + const real_t * lbACur; + const real_t * ubACur; + + /* 3) Vectors for solution obtained by qpOASES. */ + real_t * x = new real_t[nV]; + real_t * y = new real_t[nV + nC]; + // real_t obj; + + /* 4) Prepare matrix objects */ + SymmetricMatrix * H; + Matrix * A; + + real_t * H_cpy = new real_t[nV * nV]; + memcpy(H_cpy, _H, ((uint_t)(nV * nV)) * sizeof(real_t)); + real_t * A_cpy = new real_t[nC * nV]; + memcpy(A_cpy, _A, ((uint_t)(nC * nV)) * sizeof(real_t)); + + if (isSparse == BT_TRUE) { + SymSparseMat * Hs; + H = Hs = new SymSparseMat(nV, nV, nV, H_cpy); + A = new SparseMatrixRow(nC, nV, nV, A_cpy); + Hs->createDiagInfo(); + delete[] A_cpy; + delete[] H_cpy; + } else { + H = new SymDenseMat(nV, nV, nV, const_cast(H_cpy)); + A = new DenseMatrix(nC, nV, nV, const_cast(A_cpy)); + } + + H->doFreeMemory(); + A->doFreeMemory(); + + /* II) SETUP QPROBLEM OBJECT */ + QProblem qp(nV, nC); + qp.setOptions(options); + // qp.setPrintLevel( PL_LOW ); + + // qp.printOptions(); + + /* III) RUN BENCHMARK SEQUENCE: */ + returnValue returnvalue; + + for (k = 0; k < nQP; ++k) { + // if ( k%50 == 0 ) + // printf( "%d\n",k ); + + /* 1) Update pointers to current QP data. */ + gCur = &(g[k * nV]); + lbCur = &(lb[k * nV]); + ubCur = &(ub[k * nV]); + lbACur = &(lbA[k * nC]); + ubACur = &(ubA[k * nC]); + + /* 2) Set nWSR and maximum CPU time. */ + nWSRcur = maxAllowedNWSR; + CPUtimeCur = CPUtimeLimit; + + /* 3) Solve current QP. */ + if ((k == 0) || (useHotstarts == BT_FALSE)) { + /* initialise */ + returnvalue = qp.init(H, gCur, A, lbCur, ubCur, lbACur, ubACur, nWSRcur, &CPUtimeCur); + if ((returnvalue != SUCCESSFUL_RETURN) && (returnvalue != RET_MAX_NWSR_REACHED)) { + delete A; + delete H; + delete[] y; + delete[] x; + return THROWERROR(returnvalue); + } + } else { + /* hotstart */ + returnvalue = qp.hotstart(gCur, lbCur, ubCur, lbACur, ubACur, nWSRcur, &CPUtimeCur); + if ((returnvalue != SUCCESSFUL_RETURN) && (returnvalue != RET_MAX_NWSR_REACHED)) { + delete A; + delete H; + delete[] y; + delete[] x; + return THROWERROR(returnvalue); + } + } + + /* 4) Obtain solution vectors and objective function value */ + qp.getPrimalSolution(x); + qp.getDualSolution(y); + // obj = qp.getObjVal( ); + + /* 5) Compute KKT residuals */ + getKktViolation(nV, nC, _H, gCur, _A, lbCur, ubCur, lbACur, ubACur, x, y, stat, feas, cmpl); + + /* 6) Update maximum and average values. */ + if (((double)nWSRcur) > maxNWSR) + maxNWSR = ((double)nWSRcur); + if (stat > maxStationarity) + maxStationarity = stat; + if (feas > maxFeasibility) + maxFeasibility = feas; + if (cmpl > maxComplementarity) + maxComplementarity = cmpl; + + if (CPUtimeCur > maxCPUtime) + maxCPUtime = CPUtimeCur; + + avgNWSR += ((double)nWSRcur); + avgCPUtime += CPUtimeCur; + } + avgNWSR /= ((double)nQP); + avgCPUtime /= ((double)nQP); + + delete A; + delete H; + delete[] y; + delete[] x; + + return SUCCESSFUL_RETURN; +} + +/* + * s o l v e O q p B e n c h m a r k + */ +returnValue solveOqpBenchmark(int_t nQP, + int_t nV, + const real_t * const _H, + const real_t * const g, + const real_t * const lb, + const real_t * const ub, + BooleanType isSparse, + const Options & options, + int_t & nWSR, + real_t & maxCPUtime, + real_t & maxStationarity, + real_t & maxFeasibility, + real_t & maxComplementarity) +{ + real_t maxNWSR = 0.0; + real_t avgNWSR = 0.0; + real_t avgCPUtime = 0.0; + + returnValue returnvalue = solveOqpBenchmark(nQP, + nV, + _H, + g, + lb, + ub, + isSparse, + BT_TRUE, + options, + nWSR, + maxNWSR, + avgNWSR, + maxCPUtime, + avgCPUtime, + maxStationarity, + maxFeasibility, + maxComplementarity); + nWSR = (int_t)maxNWSR; + + return returnvalue; +} + +/* + * s o l v e O q p B e n c h m a r k + */ +returnValue solveOqpBenchmark(int_t nQP, + int_t nV, + const real_t * const _H, + const real_t * const g, + const real_t * const lb, + const real_t * const ub, + BooleanType isSparse, + BooleanType useHotstarts, + const Options & options, + int_t maxAllowedNWSR, + real_t & maxNWSR, + real_t & avgNWSR, + real_t & maxCPUtime, + real_t & avgCPUtime, + real_t & maxStationarity, + real_t & maxFeasibility, + real_t & maxComplementarity) +{ + int_t k; + + /* I) SETUP AUXILIARY VARIABLES: */ + /* 1) Keep nWSR and store current and maximum number of + * working set recalculations in temporary variables */ + int_t nWSRcur; + + real_t CPUtimeLimit = maxCPUtime; + real_t CPUtimeCur = CPUtimeLimit; + real_t stat, feas, cmpl; + maxNWSR = 0; + avgNWSR = 0; + maxCPUtime = 0.0; + avgCPUtime = 0.0; + maxStationarity = 0.0; + maxFeasibility = 0.0; + maxComplementarity = 0.0; + + /* 2) Pointers to data of current QP ... */ + const real_t * gCur; + const real_t * lbCur; + const real_t * ubCur; + + /* 3) Vectors for solution obtained by qpOASES. */ + real_t * x = new real_t[nV]; + real_t * y = new real_t[nV]; + // real_t obj; + + /* 4) Prepare matrix objects */ + SymmetricMatrix * H; + real_t * H_cpy = new real_t[nV * nV]; + memcpy(H_cpy, _H, ((uint_t)(nV * nV)) * sizeof(real_t)); + + if (isSparse == BT_TRUE) { + SymSparseMat * Hs; + H = Hs = new SymSparseMat(nV, nV, nV, H_cpy); + Hs->createDiagInfo(); + delete[] H_cpy; + } else { + H = new SymDenseMat(nV, nV, nV, const_cast(H_cpy)); + } + + H->doFreeMemory(); + + /* II) SETUP QPROBLEM OBJECT */ + QProblemB qp(nV); + qp.setOptions(options); + // qp.setPrintLevel( PL_LOW ); + + /* III) RUN BENCHMARK SEQUENCE: */ + returnValue returnvalue; + + for (k = 0; k < nQP; ++k) { + // if ( k%50 == 0 ) + // printf( "%d\n",k ); + + /* 1) Update pointers to current QP data. */ + gCur = &(g[k * nV]); + lbCur = &(lb[k * nV]); + ubCur = &(ub[k * nV]); + + /* 2) Set nWSR and maximum CPU time. */ + nWSRcur = maxAllowedNWSR; + CPUtimeCur = CPUtimeLimit; + + /* 3) Solve current QP. */ + if ((k == 0) || (useHotstarts == BT_FALSE)) { + /* initialise */ + returnvalue = qp.init(H, gCur, lbCur, ubCur, nWSRcur, &CPUtimeCur); + if ((returnvalue != SUCCESSFUL_RETURN) && (returnvalue != RET_MAX_NWSR_REACHED)) { + delete H; + delete[] y; + delete[] x; + return THROWERROR(returnvalue); + } + } else { + /* hotstart */ + returnvalue = qp.hotstart(gCur, lbCur, ubCur, nWSRcur, &CPUtimeCur); + if ((returnvalue != SUCCESSFUL_RETURN) && (returnvalue != RET_MAX_NWSR_REACHED)) { + delete H; + delete[] y; + delete[] x; + return THROWERROR(returnvalue); + } + } + + /* 4) Obtain solution vectors and objective function value ... */ + qp.getPrimalSolution(x); + qp.getDualSolution(y); + // obj = qp.getObjVal( ); + + /* 5) Compute KKT residuals */ + getKktViolation(nV, _H, gCur, lbCur, ubCur, x, y, stat, feas, cmpl); + + /* 6) update maximum values. */ + if (((real_t)nWSRcur) > maxNWSR) + maxNWSR = ((real_t)nWSRcur); + if (stat > maxStationarity) + maxStationarity = stat; + if (feas > maxFeasibility) + maxFeasibility = feas; + if (cmpl > maxComplementarity) + maxComplementarity = cmpl; + + if (CPUtimeCur > maxCPUtime) + maxCPUtime = CPUtimeCur; + + avgNWSR += (real_t)nWSRcur; + avgCPUtime += CPUtimeCur; + } + avgNWSR /= ((real_t)nQP); + avgCPUtime /= ((real_t)nQP); + + delete H; + delete[] y; + delete[] x; + + return SUCCESSFUL_RETURN; +} + +/* + * r u n O q p B e n c h m a r k + */ +returnValue runOqpBenchmark(const char * path, + BooleanType isSparse, + const Options & options, + int_t & nWSR, + real_t & maxCPUtime, + real_t & maxStationarity, + real_t & maxFeasibility, + real_t & maxComplementarity) +{ + real_t maxNWSR = 0.0; + real_t avgNWSR = 0.0; + real_t avgCPUtime = 0.0; + + returnValue returnvalue = runOqpBenchmark(path, + isSparse, + BT_TRUE, + options, + nWSR, + maxNWSR, + avgNWSR, + maxCPUtime, + avgCPUtime, + maxStationarity, + maxFeasibility, + maxComplementarity); + nWSR = (int_t)maxNWSR; + + return returnvalue; +} + +/* + * r u n O q p B e n c h m a r k + */ +returnValue runOqpBenchmark(const char * path, + BooleanType isSparse, + BooleanType useHotstarts, + const Options & options, + int_t maxAllowedNWSR, + real_t & maxNWSR, + real_t & avgNWSR, + real_t & maxCPUtime, + real_t & avgCPUtime, + real_t & maxStationarity, + real_t & maxFeasibility, + real_t & maxComplementarity) +{ + int_t nQP = 0, nV = 0, nC = 0, nEC = 0; + + real_t *H = 0, *g = 0, *A = 0, *lb = 0, *ub = 0, *lbA = 0, *ubA = 0; + + returnValue returnvalue; + + /* I) SETUP BENCHMARK: */ + /* 1) Obtain QP sequence dimensions. */ + if (readOqpDimensions(path, nQP, nV, nC, nEC) != SUCCESSFUL_RETURN) + return THROWERROR(RET_UNABLE_TO_READ_BENCHMARK); + + /* 2) Read OQP benchmark data. */ + if (readOqpData(path, nQP, nV, nC, nEC, &H, &g, &A, &lb, &ub, &lbA, &ubA, 0, 0, 0) != SUCCESSFUL_RETURN) { + return THROWERROR(RET_UNABLE_TO_READ_BENCHMARK); + } + + // normaliseConstraints( nV,nC,A,lbA,ubA ); //only works when nP==1 + + /* II) SOLVE BENCHMARK */ + if (nC > 0) { + returnvalue = solveOqpBenchmark(nQP, + nV, + nC, + nEC, + H, + g, + A, + lb, + ub, + lbA, + ubA, + isSparse, + useHotstarts, + options, + maxAllowedNWSR, + maxNWSR, + avgNWSR, + maxCPUtime, + avgCPUtime, + maxStationarity, + maxFeasibility, + maxComplementarity); + + if (returnvalue != SUCCESSFUL_RETURN) { + if (H != 0) + delete[] H; + if (g != 0) + delete[] g; + if (A != 0) + delete[] A; + if (lb != 0) + delete[] lb; + if (ub != 0) + delete[] ub; + if (lbA != 0) + delete[] lbA; + if (ubA != 0) + delete[] ubA; + return THROWERROR(returnvalue); + } + } else { + returnvalue = solveOqpBenchmark(nQP, + nV, + H, + g, + lb, + ub, + isSparse, + useHotstarts, + options, + maxAllowedNWSR, + maxNWSR, + avgNWSR, + maxCPUtime, + avgCPUtime, + maxStationarity, + maxFeasibility, + maxComplementarity); + + if (returnvalue != SUCCESSFUL_RETURN) { + if (H != 0) + delete[] H; + if (g != 0) + delete[] g; + if (A != 0) + delete[] A; + if (lb != 0) + delete[] lb; + if (ub != 0) + delete[] ub; + return THROWERROR(returnvalue); + } + } + + if (H != 0) + delete[] H; + if (g != 0) + delete[] g; + if (A != 0) + delete[] A; + if (lb != 0) + delete[] lb; + if (ub != 0) + delete[] ub; + if (lbA != 0) + delete[] lbA; + if (ubA != 0) + delete[] ubA; + + return SUCCESSFUL_RETURN; +} + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Options.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Options.cpp new file mode 100644 index 0000000..275616d --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Options.cpp @@ -0,0 +1,531 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/Options.cpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of the Options class designed to manage working sets of + * constraints and bounds within a QProblem. + */ + +#include + +BEGIN_NAMESPACE_QPOASES + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +/* + * O p t i o n s + */ +Options::Options() +{ + setToDefault(); +} + +/* + * O p t i o n s + */ +Options::Options(const Options & rhs) +{ + copy(rhs); +} + +/* + * ~ O p t i o n s + */ +Options::~Options() +{ +} + +/* + * o p e r a t o r = + */ +Options & Options::operator=(const Options & rhs) +{ + if (this != &rhs) { + copy(rhs); + } + + return *this; +} + +/* + * s e t T o D e f a u l t + */ +returnValue Options::setToDefault() +{ + printLevel = PL_MEDIUM; +#ifdef __DEBUG__ + printLevel = PL_HIGH; +#endif +#ifdef __SUPPRESSANYOUTPUT__ + printLevel = PL_NONE; +#endif + + enableRamping = BT_TRUE; + enableFarBounds = BT_TRUE; + enableFlippingBounds = BT_TRUE; + enableRegularisation = BT_FALSE; + enableFullLITests = BT_FALSE; + enableNZCTests = BT_TRUE; + enableDriftCorrection = 1; + enableCholeskyRefactorisation = 0; + enableEqualities = BT_FALSE; + +#ifdef __USE_SINGLE_PRECISION__ + terminationTolerance = 1.0e2 * EPS; + boundTolerance = 1.0e2 * EPS; +#else + terminationTolerance = 5.0e6 * EPS; + boundTolerance = 1.0e6 * EPS; +#endif + boundRelaxation = 1.0e4; +#ifdef __USE_SINGLE_PRECISION__ + epsNum = -1.0e2 * EPS; + epsDen = 1.0e2 * EPS; +#else + epsNum = -1.0e3 * EPS; + epsDen = 1.0e3 * EPS; +#endif + maxPrimalJump = 1.0e8; + maxDualJump = 1.0e8; + + initialRamping = 0.5; + finalRamping = 1.0; + initialFarBounds = 1.0e6; + growFarBounds = 1.0e3; + initialStatusBounds = ST_LOWER; +#ifdef __USE_SINGLE_PRECISION__ + epsFlipping = 5.0e1 * EPS; +#else + epsFlipping = 1.0e3 * EPS; +#endif + numRegularisationSteps = 0; +#ifdef __USE_SINGLE_PRECISION__ + epsRegularisation = 2.0e1 * EPS; + numRefinementSteps = 2; +#else + epsRegularisation = 1.0e3 * EPS; + numRefinementSteps = 1; +#endif + epsIterRef = 1.0e2 * EPS; +#ifdef __USE_SINGLE_PRECISION__ + epsLITests = 5.0e1 * EPS; + epsNZCTests = 1.0e2 * EPS; +#else + epsLITests = 1.0e5 * EPS; + epsNZCTests = 3.0e3 * EPS; +#endif + + enableDropInfeasibles = BT_FALSE; + dropBoundPriority = 1; + dropEqConPriority = 1; + dropIneqConPriority = 1; + + enableInertiaCorrection = BT_TRUE; + rcondSMin = 1.0e-14; + + return SUCCESSFUL_RETURN; +} + +/* + * s e t T o R e l i a b l e + */ +returnValue Options::setToReliable() +{ + setToDefault(); + + enableFullLITests = BT_TRUE; + enableCholeskyRefactorisation = 1; + +#ifdef __USE_SINGLE_PRECISION__ + numRefinementSteps = 3; +#else + numRefinementSteps = 2; +#endif + + return SUCCESSFUL_RETURN; +} + +/* + * s e t T o M P C + */ +returnValue Options::setToMPC() +{ + setToDefault(); + + enableRamping = BT_FALSE; + enableFarBounds = BT_TRUE; + enableFlippingBounds = BT_FALSE; + enableRegularisation = BT_TRUE; + enableNZCTests = BT_FALSE; + enableDriftCorrection = 0; + enableEqualities = BT_TRUE; + +#ifdef __USE_SINGLE_PRECISION__ + terminationTolerance = 1.0e3 * EPS; +#else + terminationTolerance = 1.0e9 * EPS; +#endif + + initialStatusBounds = ST_INACTIVE; + numRegularisationSteps = 1; +#ifdef __USE_SINGLE_PRECISION__ + numRefinementSteps = 2; +#else + numRefinementSteps = 0; +#endif + + return SUCCESSFUL_RETURN; +} + +/* + * s e t T o F a s t + */ +returnValue Options::setToFast() +{ + return setToMPC(); +} + +/* + * e n s u r e C o n s i s t e n c y + */ +returnValue Options::ensureConsistency() +{ + BooleanType needToAdjust = BT_FALSE; + + /* flipping bounds require far bounds */ + /* (ckirches) Removed this as per filter's trust region +if( enableFlippingBounds == BT_TRUE ) + enableFarBounds = BT_TRUE; + */ + + if (enableDriftCorrection < 0) { + enableDriftCorrection = 0; + needToAdjust = BT_TRUE; + } + + if (enableCholeskyRefactorisation < 0) { + enableCholeskyRefactorisation = 0; + needToAdjust = BT_TRUE; + } + + if (terminationTolerance <= 0.0) { + terminationTolerance = EPS; + needToAdjust = BT_TRUE; + } + + if (epsIterRef <= 0.0) { + epsIterRef = EPS; + needToAdjust = BT_TRUE; + } + + if (epsRegularisation <= 0.0) { + epsRegularisation = EPS; + needToAdjust = BT_TRUE; + } + + if (boundTolerance <= 0.0) { + boundTolerance = EPS; + needToAdjust = BT_TRUE; + } + + if (boundRelaxation <= 0.0) { + boundRelaxation = EPS; + needToAdjust = BT_TRUE; + } + + if (maxPrimalJump <= 0.0) { + maxPrimalJump = EPS; + needToAdjust = BT_TRUE; + } + + if (maxDualJump <= 0.0) { + maxDualJump = EPS; + needToAdjust = BT_TRUE; + } + + if (initialRamping < 0.0) { + initialRamping = 0.0; + needToAdjust = BT_TRUE; + } + + if (finalRamping < 0.0) { + finalRamping = 0.0; + needToAdjust = BT_TRUE; + } + + if (initialFarBounds <= boundRelaxation) { + initialFarBounds = boundRelaxation + EPS; + needToAdjust = BT_TRUE; + } + + if (growFarBounds < 1.1) { + growFarBounds = 1.1; + needToAdjust = BT_TRUE; + } + + if (epsFlipping <= 0.0) { + epsFlipping = EPS; + needToAdjust = BT_TRUE; + } + + if (numRegularisationSteps < 0) { + numRegularisationSteps = 0; + needToAdjust = BT_TRUE; + } + + if (epsRegularisation < 0.0) { + epsRegularisation = EPS; + needToAdjust = BT_TRUE; + } + + if (numRefinementSteps < 0) { + numRefinementSteps = 0; + needToAdjust = BT_TRUE; + } + + if (epsIterRef < 0.0) { + epsIterRef = EPS; + needToAdjust = BT_TRUE; + } + + if (epsLITests < 0.0) { + epsLITests = EPS; + needToAdjust = BT_TRUE; + } + + if (epsNZCTests < 0.0) { + epsNZCTests = EPS; + needToAdjust = BT_TRUE; + } + + if (needToAdjust == BT_TRUE) + return THROWWARNING(RET_OPTIONS_ADJUSTED); + + return SUCCESSFUL_RETURN; +} + +/* + * p r i n t + */ +returnValue Options::print() const +{ +#ifndef __SUPPRESSANYOUTPUT__ + + char myPrintfString[MAX_STRING_LENGTH]; + char info[MAX_STRING_LENGTH]; + + myPrintf("\n################### qpOASES -- QP OPTIONS ##################\n"); + myPrintf("\n"); + + convertPrintLevelToString(printLevel, info); + snprintf(myPrintfString, MAX_STRING_LENGTH, "printLevel = %s\n", info); + myPrintf(myPrintfString); + + myPrintf("\n"); + + convertBooleanTypeToString(enableRamping, info); + snprintf(myPrintfString, MAX_STRING_LENGTH, "enableRamping = %s\n", info); + myPrintf(myPrintfString); + + convertBooleanTypeToString(enableFarBounds, info); + snprintf(myPrintfString, MAX_STRING_LENGTH, "enableFarBounds = %s\n", info); + myPrintf(myPrintfString); + + convertBooleanTypeToString(enableFlippingBounds, info); + snprintf(myPrintfString, MAX_STRING_LENGTH, "enableFlippingBounds = %s\n", info); + myPrintf(myPrintfString); + + convertBooleanTypeToString(enableRegularisation, info); + snprintf(myPrintfString, MAX_STRING_LENGTH, "enableRegularisation = %s\n", info); + myPrintf(myPrintfString); + + convertBooleanTypeToString(enableFullLITests, info); + snprintf(myPrintfString, MAX_STRING_LENGTH, "enableFullLITests = %s\n", info); + myPrintf(myPrintfString); + + convertBooleanTypeToString(enableNZCTests, info); + snprintf(myPrintfString, MAX_STRING_LENGTH, "enableNZCTests = %s\n", info); + myPrintf(myPrintfString); + + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "enableDriftCorrection = %d\n", + (int)enableDriftCorrection); + myPrintf(myPrintfString); + + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "enableCholeskyRefactorisation = %d\n", + (int)enableCholeskyRefactorisation); + myPrintf(myPrintfString); + + convertBooleanTypeToString(enableEqualities, info); + snprintf(myPrintfString, MAX_STRING_LENGTH, "enableEqualities = %s\n", info); + myPrintf(myPrintfString); + + convertBooleanTypeToString(enableInertiaCorrection, info); + snprintf(myPrintfString, MAX_STRING_LENGTH, "enableInertiaCorrection = %s\n", info); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "rcondSMin = %e\n", rcondSMin); + myPrintf(myPrintfString); + + myPrintf("\n"); + + snprintf( + myPrintfString, MAX_STRING_LENGTH, "terminationTolerance = %e\n", terminationTolerance); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "boundTolerance = %e\n", boundTolerance); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "boundRelaxation = %e\n", boundRelaxation); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "epsNum = %e\n", epsNum); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "epsDen = %e\n", epsDen); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "maxPrimalJump = %e\n", maxPrimalJump); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "maxDualJump = %e\n", maxDualJump); + myPrintf(myPrintfString); + + myPrintf("\n"); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "initialRamping = %e\n", initialRamping); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "finalRamping = %e\n", finalRamping); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "initialFarBounds = %e\n", initialFarBounds); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "growFarBounds = %e\n", growFarBounds); + myPrintf(myPrintfString); + + convertSubjectToStatusToString(initialStatusBounds, info); + snprintf(myPrintfString, MAX_STRING_LENGTH, "initialStatusBounds = %s\n", info); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "epsFlipping = %e\n", epsFlipping); + myPrintf(myPrintfString); + + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "numRegularisationSteps = %d\n", + (int)numRegularisationSteps); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "epsRegularisation = %e\n", epsRegularisation); + myPrintf(myPrintfString); + + snprintf( + myPrintfString, MAX_STRING_LENGTH, "numRefinementSteps = %d\n", (int)numRefinementSteps); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "epsIterRef = %e\n", epsIterRef); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "epsLITests = %e\n", epsLITests); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "epsNZCTests = %e\n", epsNZCTests); + myPrintf(myPrintfString); + + myPrintf("\n\n"); + +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + +/* + * c o p y + */ +returnValue Options::copy(const Options & rhs) +{ + printLevel = rhs.printLevel; + + enableRamping = rhs.enableRamping; + enableFarBounds = rhs.enableFarBounds; + enableFlippingBounds = rhs.enableFlippingBounds; + enableRegularisation = rhs.enableRegularisation; + enableFullLITests = rhs.enableFullLITests; + enableNZCTests = rhs.enableNZCTests; + enableDriftCorrection = rhs.enableDriftCorrection; + enableCholeskyRefactorisation = rhs.enableCholeskyRefactorisation; + enableEqualities = rhs.enableEqualities; + + terminationTolerance = rhs.terminationTolerance; + boundTolerance = rhs.boundTolerance; + boundRelaxation = rhs.boundRelaxation; + epsNum = rhs.epsNum; + epsDen = rhs.epsDen; + maxPrimalJump = rhs.maxPrimalJump; + maxDualJump = rhs.maxDualJump; + + initialRamping = rhs.initialRamping; + finalRamping = rhs.finalRamping; + initialFarBounds = rhs.initialFarBounds; + growFarBounds = rhs.growFarBounds; + initialStatusBounds = rhs.initialStatusBounds; + epsFlipping = rhs.epsFlipping; + numRegularisationSteps = rhs.numRegularisationSteps; + epsRegularisation = rhs.epsRegularisation; + numRefinementSteps = rhs.numRefinementSteps; + epsIterRef = rhs.epsIterRef; + epsLITests = rhs.epsLITests; + epsNZCTests = rhs.epsNZCTests; + + enableInertiaCorrection = rhs.enableInertiaCorrection; + rcondSMin = rhs.rcondSMin; + + enableDropInfeasibles = rhs.enableDropInfeasibles; + dropBoundPriority = rhs.dropBoundPriority; + dropEqConPriority = rhs.dropEqConPriority; + dropIneqConPriority = rhs.dropIneqConPriority; + + return SUCCESSFUL_RETURN; +} + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/QProblem.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/QProblem.cpp new file mode 100644 index 0000000..6e5b280 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/QProblem.cpp @@ -0,0 +1,6099 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/QProblem.cpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of the QProblem class which is able to use the newly + * developed online active set strategy for parametric quadratic programming. + */ + +#include +#include + +BEGIN_NAMESPACE_QPOASES + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +/* + * Q P r o b l e m + */ +QProblem::QProblem() : QProblemB() +{ + freeConstraintMatrix = BT_FALSE; + A = 0; + + lbA = 0; + ubA = 0; + + sizeT = 0; + T = 0; + Q = 0; + + Ax = 0; + Ax_l = 0; + Ax_u = 0; + + constraintProduct = 0; + + tempA = 0; + ZFR_delta_xFRz = 0; + delta_xFRy = 0; + delta_xFRz = 0; + tempB = 0; + delta_yAC_TMP = 0; + tempC = 0; +} + +/* + * Q P r o b l e m + */ +QProblem::QProblem(int_t _nV, int_t _nC, HessianType _hessianType, BooleanType allocDenseMats) +: QProblemB(_nV, _hessianType, allocDenseMats) +{ + int_t i; + + /* consistency checks */ + if (_nV <= 0) { + _nV = 1; + THROWERROR(RET_INVALID_ARGUMENTS); + } + + if (_nC < 0) { + _nC = 0; + THROWERROR(RET_INVALID_ARGUMENTS); + } + + if (_nC > 0) { + freeConstraintMatrix = BT_FALSE; + A = 0; + + lbA = new real_t[_nC]; + for (i = 0; i < _nC; ++i) + lbA[i] = 0.0; + + ubA = new real_t[_nC]; + for (i = 0; i < _nC; ++i) + ubA[i] = 0.0; + } else { + /* prevent segmentation faults in case nC == 0 + * (avoiding checks for A!=0 around all calls to A->... */ + freeConstraintMatrix = BT_TRUE; + A = new DenseMatrix(); + + lbA = 0; + ubA = 0; + } + + constraints.init(_nC); + + delete[] y; /* y of no constraints version too short! */ + y = new real_t[_nV + _nC]; + for (i = 0; i < _nV + _nC; ++i) + y[i] = 0.0; + + if (allocDenseMats == BT_TRUE) { + sizeT = getMin(_nV, _nC); + T = new real_t[sizeT * sizeT]; + Q = new real_t[_nV * _nV]; + } else { + sizeT = 0; + T = 0; + Q = 0; + } + + if (_nC > 0) { + Ax = new real_t[_nC]; + Ax_l = new real_t[_nC]; + Ax_u = new real_t[_nC]; + } else { + Ax = 0; + Ax_l = 0; + Ax_u = 0; + } + + constraintProduct = 0; + + tempA = new real_t[_nV]; /* nFR */ + ZFR_delta_xFRz = new real_t[_nV]; /* nFR */ + delta_xFRz = new real_t[_nV]; /* nZ */ + + if (_nC > 0) { + tempB = new real_t[_nC]; /* nAC */ + delta_xFRy = new real_t[_nC]; /* nAC */ + delta_yAC_TMP = new real_t[_nC]; /* nAC */ + tempC = new real_t[_nC]; /* nAC */ + } else { + tempB = 0; + delta_xFRy = 0; + delta_yAC_TMP = 0; + tempC = 0; + } + + flipper.init((uint_t)_nV, (uint_t)_nC); +} + +/* + * Q P r o b l e m + */ +QProblem::QProblem(const QProblem & rhs) : QProblemB(rhs) +{ + freeConstraintMatrix = BT_FALSE; + A = 0; + + copy(rhs); +} + +/* + * ~ Q P r o b l e m + */ +QProblem::~QProblem() +{ + clear(); +} + +/* + * o p e r a t o r = + */ +QProblem & QProblem::operator=(const QProblem & rhs) +{ + if (this != &rhs) { + clear(); + QProblemB::operator=(rhs); + copy(rhs); + } + + return *this; +} + +/* + * r e s e t + */ +returnValue QProblem::reset() +{ + int_t i; + int_t nV = getNV(); + int_t nC = getNC(); + + if (nV == 0) + return THROWERROR(RET_QPOBJECT_NOT_SETUP); + + /* 1) Reset bounds, Cholesky decomposition and status flags. */ + if (QProblemB::reset() != SUCCESSFUL_RETURN) + return THROWERROR(RET_RESET_FAILED); + + /* 2) Reset constraints. */ + constraints.init(nC); + + /* 3) Reset TQ factorisation. */ + if (T != 0) + for (i = 0; i < sizeT * sizeT; ++i) + T[i] = 0.0; + + if (Q != 0) + for (i = 0; i < nV * nV; ++i) + Q[i] = 0.0; + + /* 4) Reset constraint product pointer. */ + constraintProduct = 0; + + /* 5) Reset flipper object */ + flipper.init((uint_t)nV, (uint_t)nC); + + return SUCCESSFUL_RETURN; +} + +/* + * i n i t + */ +returnValue QProblem::init(SymmetricMatrix * _H, + const real_t * const _g, + Matrix * _A, + const real_t * const _lb, + const real_t * const _ub, + const real_t * const _lbA, + const real_t * const _ubA, + int_t & nWSR, + real_t * const cputime, + const real_t * const xOpt, + const real_t * const yOpt, + const Bounds * const guessedBounds, + const Constraints * const guessedConstraints, + const real_t * const _R) +{ + int_t i; + int_t nV = getNV(); + int_t nC = getNC(); + + if (nV == 0) + return THROWERROR(RET_QPOBJECT_NOT_SETUP); + + /* 1) Consistency checks. */ + if (isInitialised() == BT_TRUE) { + THROWWARNING(RET_QP_ALREADY_INITIALISED); + reset(); + } + + if (guessedBounds != 0) { + for (i = 0; i < nV; ++i) { + if (guessedBounds->getStatus(i) == ST_UNDEFINED) + return THROWERROR(RET_INVALID_ARGUMENTS); + } + } + + if (guessedConstraints != 0) { + for (i = 0; i < nC; ++i) + if (guessedConstraints->getStatus(i) == ST_UNDEFINED) + return THROWERROR(RET_INVALID_ARGUMENTS); + } + + /* exclude these possibilities in order to avoid inconsistencies */ + if ((xOpt == 0) && (yOpt != 0) && ((guessedBounds != 0) || (guessedConstraints != 0))) + return THROWERROR(RET_INVALID_ARGUMENTS); + + if ((_R != 0) && ((xOpt != 0) || (yOpt != 0) || (guessedBounds != 0) || (guessedConstraints != 0))) + return THROWERROR(RET_NO_CHOLESKY_WITH_INITIAL_GUESS); + + /* 2) Setup QP data. */ + if (setupQPdata(_H, _g, _A, _lb, _ub, _lbA, _ubA) != SUCCESSFUL_RETURN) + return THROWERROR(RET_INVALID_ARGUMENTS); + + /* 3) Call to main initialisation routine. */ + return solveInitialQP(xOpt, yOpt, guessedBounds, guessedConstraints, _R, nWSR, cputime); +} + +/* + * i n i t + */ +returnValue QProblem::init(const real_t * const _H, + const real_t * const _g, + const real_t * const _A, + const real_t * const _lb, + const real_t * const _ub, + const real_t * const _lbA, + const real_t * const _ubA, + int_t & nWSR, + real_t * const cputime, + const real_t * const xOpt, + const real_t * const yOpt, + const Bounds * const guessedBounds, + const Constraints * const guessedConstraints, + const real_t * const _R) +{ + int_t i; + int_t nV = getNV(); + int_t nC = getNC(); + + if (nV == 0) + return THROWERROR(RET_QPOBJECT_NOT_SETUP); + + /* 1) Consistency checks. */ + if (isInitialised() == BT_TRUE) { + THROWWARNING(RET_QP_ALREADY_INITIALISED); + reset(); + } + + if (guessedBounds != 0) { + for (i = 0; i < nV; ++i) { + if (guessedBounds->getStatus(i) == ST_UNDEFINED) + return THROWERROR(RET_INVALID_ARGUMENTS); + } + } + + if (guessedConstraints != 0) { + for (i = 0; i < nC; ++i) + if (guessedConstraints->getStatus(i) == ST_UNDEFINED) + return THROWERROR(RET_INVALID_ARGUMENTS); + } + + /* exclude these possibilities in order to avoid inconsistencies */ + if ((xOpt == 0) && (yOpt != 0) && ((guessedBounds != 0) || (guessedConstraints != 0))) + return THROWERROR(RET_INVALID_ARGUMENTS); + + if ((_R != 0) && ((xOpt != 0) || (yOpt != 0) || (guessedBounds != 0) || (guessedConstraints != 0))) + return THROWERROR(RET_NO_CHOLESKY_WITH_INITIAL_GUESS); + + /* 2) Setup QP data. */ + if (setupQPdata(_H, _g, _A, _lb, _ub, _lbA, _ubA) != SUCCESSFUL_RETURN) + return THROWERROR(RET_INVALID_ARGUMENTS); + + /* 3) Call to main initialisation routine. */ + return solveInitialQP(xOpt, yOpt, guessedBounds, guessedConstraints, _R, nWSR, cputime); +} + +/* + * i n i t + */ +returnValue QProblem::init(const char * const H_file, + const char * const g_file, + const char * const A_file, + const char * const lb_file, + const char * const ub_file, + const char * const lbA_file, + const char * const ubA_file, + int_t & nWSR, + real_t * const cputime, + const real_t * const xOpt, + const real_t * const yOpt, + const Bounds * const guessedBounds, + const Constraints * const guessedConstraints, + const char * const R_file) +{ + int_t i; + int_t nV = getNV(); + int_t nC = getNC(); + + if (nV == 0) + return THROWERROR(RET_QPOBJECT_NOT_SETUP); + + /* 1) Consistency checks. */ + if (isInitialised() == BT_TRUE) { + THROWWARNING(RET_QP_ALREADY_INITIALISED); + reset(); + } + + if (guessedBounds != 0) { + for (i = 0; i < nV; ++i) { + if (guessedBounds->getStatus(i) == ST_UNDEFINED) + return THROWERROR(RET_INVALID_ARGUMENTS); + } + } + + if (guessedConstraints != 0) { + for (i = 0; i < nC; ++i) + if (guessedConstraints->getStatus(i) == ST_UNDEFINED) + return THROWERROR(RET_INVALID_ARGUMENTS); + } + + /* exclude these possibilities in order to avoid inconsistencies */ + if ((xOpt == 0) && (yOpt != 0) && ((guessedBounds != 0) || (guessedConstraints != 0))) + return THROWERROR(RET_INVALID_ARGUMENTS); + + if ((R_file != 0) && ((xOpt != 0) || (yOpt != 0) || (guessedBounds != 0) || (guessedConstraints != 0))) + return THROWERROR(RET_NO_CHOLESKY_WITH_INITIAL_GUESS); + + /* 2) Setup QP data from files. */ + if (setupQPdataFromFile(H_file, g_file, A_file, lb_file, ub_file, lbA_file, ubA_file) != + SUCCESSFUL_RETURN) + return THROWERROR(RET_UNABLE_TO_READ_FILE); + + if (R_file == 0) { + /* 3) Call to main initialisation routine. */ + return solveInitialQP(xOpt, yOpt, guessedBounds, guessedConstraints, 0, nWSR, cputime); + } else { + /* Also read Cholesky factor from file and store it directly into R [thus... */ + returnValue returnvalue = readFromFile(R, nV, nV, R_file); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWWARNING(returnvalue); + + /* 3) Call to main initialisation routine. ...passing R here!] */ + return solveInitialQP(xOpt, yOpt, guessedBounds, guessedConstraints, R, nWSR, cputime); + } +} + +/* + * h o t s t a r t + */ +returnValue QProblem::hotstart(const real_t * const g_new, + const real_t * const lb_new, + const real_t * const ub_new, + const real_t * const lbA_new, + const real_t * const ubA_new, + int_t & nWSR, + real_t * const cputime, + const Bounds * const guessedBounds, + const Constraints * const guessedConstraints) +{ + int_t i, nActiveFar; + int_t nV = getNV(); + int_t nC = getNC(); + real_t starttime = 0.0; + real_t auxTime = 0.0; + + if (nV == 0) + return THROWERROR(RET_QPOBJECT_NOT_SETUP); + + /* Possibly update working sets according to guesses for working sets of bounds and constraints. */ + if ((guessedBounds != 0) || (guessedConstraints != 0)) { + if (cputime != 0) + starttime = getCPUtime(); + + const Bounds * actualGuessedBounds = (guessedBounds != 0) ? guessedBounds : &bounds; + const Constraints * actualGuessedConstraints = + (guessedConstraints != 0) ? guessedConstraints : &constraints; + + if (setupAuxiliaryQP(actualGuessedBounds, actualGuessedConstraints) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + status = QPS_AUXILIARYQPSOLVED; + + /* Allow only remaining CPU time for usual hotstart. */ + if (cputime != 0) { + auxTime = getCPUtime() - starttime; + *cputime -= auxTime; + } + } + + returnValue returnvalue = SUCCESSFUL_RETURN; + + /* Simple check for consistency of bounds and constraints. */ + if (areBoundsConsistent(lb_new, ub_new, lbA_new, ubA_new) != SUCCESSFUL_RETURN) + return setInfeasibilityFlag(returnvalue, BT_TRUE); + + ++count; + + int_t nWSR_max = nWSR; + int_t nWSR_performed = 0; + + real_t cputime_remaining = INFTY, *pcputime_rem; + real_t cputime_needed = 0.0; + + real_t farbound = options.initialFarBounds; + + /* writeQpDataIntoMatFile( "qpData.mat" ); */ + /* writeQpWorkspaceIntoMatFile( "qpWorkspace.mat" ); */ + + if (haveCholesky == BT_FALSE) { + returnvalue = setupInitialCholesky(); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(returnvalue); + } + + BooleanType isFirstCall = BT_TRUE; + + if (options.enableFarBounds == BT_FALSE) { + /* Automatically call standard solveQP if regularisation is not active. */ + returnvalue = + solveRegularisedQP(g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR, cputime, 0, isFirstCall); + } else { + real_t * ub_new_far = new real_t[nV]; + real_t * lb_new_far = new real_t[nV]; + real_t * ubA_new_far = new real_t[nC]; + real_t * lbA_new_far = new real_t[nC]; + + /* possibly extend initial far bounds to largest bound/constraint data */ + if (ub_new) + for (i = 0; i < nV; i++) + if ((ub_new[i] < INFTY) && (ub_new[i] > farbound)) + farbound = ub_new[i]; + if (lb_new) + for (i = 0; i < nV; i++) + if ((lb_new[i] > -INFTY) && (lb_new[i] < -farbound)) + farbound = -lb_new[i]; + if (ubA_new) + for (i = 0; i < nC; i++) + if ((ubA_new[i] < INFTY) && (ubA_new[i] > farbound)) + farbound = ubA_new[i]; + if (lbA_new) + for (i = 0; i < nC; i++) + if ((lbA_new[i] > -INFTY) && (lbA_new[i] < -farbound)) + farbound = -lbA_new[i]; + + updateFarBounds(farbound, + nV + nC, + lb_new, + lb_new_far, + ub_new, + ub_new_far, + lbA_new, + lbA_new_far, + ubA_new, + ubA_new_far); + + for (;;) { + nWSR = nWSR_max; + if (cputime != 0) { + cputime_remaining = *cputime - cputime_needed; + pcputime_rem = &cputime_remaining; + } else + pcputime_rem = 0; + + /* Automatically call standard solveQP if regularisation is not active. */ + returnvalue = solveRegularisedQP(g_new, + lb_new_far, + ub_new_far, + lbA_new_far, + ubA_new_far, + nWSR, + pcputime_rem, + nWSR_performed, + isFirstCall); + + nWSR_performed = nWSR; + cputime_needed += cputime_remaining; + isFirstCall = BT_FALSE; + + /* Check for active far-bounds and move them away */ + nActiveFar = 0; + farbound *= options.growFarBounds; + + if (infeasible == BT_TRUE) { + if (farbound >= INFTY) { + returnvalue = RET_HOTSTART_STOPPED_INFEASIBILITY; + break; // goto farewell; + } + + updateFarBounds(farbound, + nV + nC, + lb_new, + lb_new_far, + ub_new, + ub_new_far, + lbA_new, + lbA_new_far, + ubA_new, + ubA_new_far); + } else if (status == QPS_SOLVED) { + real_t tol = farbound / options.growFarBounds * options.boundTolerance; + + for (i = 0; i < nV; ++i) { + if (((lb_new == 0) || (lb_new_far[i] > lb_new[i])) && (getAbs(lb_new_far[i] - x[i]) < tol)) + ++nActiveFar; + if (((ub_new == 0) || (ub_new_far[i] < ub_new[i])) && (getAbs(ub_new_far[i] - x[i]) < tol)) + ++nActiveFar; + } + for (i = 0; i < nC; ++i) { + if (((lbA_new == 0) || (lbA_new_far[i] > lbA_new[i])) && (getAbs(lbA_new_far[i] - Ax[i]) < tol)) + ++nActiveFar; + if (((ubA_new == 0) || (ubA_new_far[i] < ubA_new[i])) && (getAbs(ubA_new_far[i] - Ax[i]) < tol)) + ++nActiveFar; + } + + if (nActiveFar == 0) + break; + + status = QPS_HOMOTOPYQPSOLVED; + + if (farbound >= INFTY) { + unbounded = BT_TRUE; + returnvalue = RET_HOTSTART_STOPPED_UNBOUNDEDNESS; + goto farewell; + } + + updateFarBounds(farbound, + nV + nC, + lb_new, + lb_new_far, + ub_new, + ub_new_far, + lbA_new, + lbA_new_far, + ubA_new, + ubA_new_far); + } else { + /* some other error when solving QP */ + break; + } + + /* advance ramp offset to avoid Ramping cycles */ + rampOffset++; + } + + farewell: + /* add time to setup auxiliary QP */ + if (cputime != 0) + *cputime = cputime_needed + auxTime; + delete[] lbA_new_far; + delete[] ubA_new_far; + delete[] lb_new_far; + delete[] ub_new_far; + } + + return (returnvalue != SUCCESSFUL_RETURN) ? THROWERROR(returnvalue) : returnvalue; +} + +/* + * h o t s t a r t + */ +returnValue QProblem::hotstart(const char * const g_file, + const char * const lb_file, + const char * const ub_file, + const char * const lbA_file, + const char * const ubA_file, + int_t & nWSR, + real_t * const cputime, + const Bounds * const guessedBounds, + const Constraints * const guessedConstraints) +{ + int_t nV = getNV(); + int_t nC = getNC(); + + if (nV == 0) + return THROWERROR(RET_QPOBJECT_NOT_SETUP); + + /* consistency check */ + if (g_file == 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + /* 1) Allocate memory (if bounds exist). */ + real_t * g_new = new real_t[nV]; + real_t * lb_new = (lb_file != 0) ? new real_t[nV] : 0; + real_t * ub_new = (ub_file != 0) ? new real_t[nV] : 0; + real_t * lbA_new = (lbA_file != 0) ? new real_t[nC] : 0; + real_t * ubA_new = (ubA_file != 0) ? new real_t[nC] : 0; + + /* 2) Load new QP vectors from file. */ + returnValue returnvalue; + returnvalue = loadQPvectorsFromFile( + g_file, lb_file, ub_file, lbA_file, ubA_file, g_new, lb_new, ub_new, lbA_new, ubA_new); + if (returnvalue != SUCCESSFUL_RETURN) { + if (ubA_file != 0) + delete[] ubA_new; + if (lbA_file != 0) + delete[] lbA_new; + if (ub_file != 0) + delete[] ub_new; + if (lb_file != 0) + delete[] lb_new; + delete[] g_new; + + return THROWERROR(RET_UNABLE_TO_READ_FILE); + } + + /* 3) Actually perform hotstart. */ + returnvalue = + hotstart(g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR, cputime, guessedBounds, guessedConstraints); + + /* 4) Free memory. */ + if (ubA_file != 0) + delete[] ubA_new; + if (lbA_file != 0) + delete[] lbA_new; + if (ub_file != 0) + delete[] ub_new; + if (lb_file != 0) + delete[] lb_new; + delete[] g_new; + + return returnvalue; +} + +/* + * s o l v e C u r r e n t E Q P + */ +returnValue QProblem::solveCurrentEQP(const int_t n_rhs, + const real_t * g_in, + const real_t * lb_in, + const real_t * ub_in, + const real_t * lbA_in, + const real_t * ubA_in, + real_t * x_out, + real_t * y_out) +{ + if ((x_out == 0) || (y_out == 0)) + return THROWERROR(RET_INVALID_ARGUMENTS); + + returnValue returnvalue = SUCCESSFUL_RETURN; + int_t ii, jj; + int_t nV = getNV(); + int_t nC = getNC(); + int_t nFR = getNFR(); + int_t nFX = getNFX(); + int_t nAC = getNAC(); + + real_t * delta_xFX = new real_t[nFX]; + real_t * delta_xFR = new real_t[nFR]; + real_t * delta_yAC = new real_t[nAC]; + real_t * delta_yFX = new real_t[nFX]; + + /* 1) Determine index arrays. */ + int_t * FR_idx; + int_t * FX_idx; + int_t * AC_idx; + + bounds.getFree()->getNumberArray(&FR_idx); + bounds.getFixed()->getNumberArray(&FX_idx); + constraints.getActive()->getNumberArray(&AC_idx); + + for (ii = 0; ii < (nV + nC) * n_rhs; ++ii) + y_out[ii] = 0.0; + + for (ii = 0; ii < n_rhs; ++ii) { + returnvalue = determineStepDirection( + g_in, lbA_in, ubA_in, lb_in, ub_in, BT_FALSE, BT_FALSE, delta_xFX, delta_xFR, delta_yAC, delta_yFX); + + for (jj = 0; jj < nFX; ++jj) + x_out[FX_idx[jj]] = delta_xFX[jj]; + for (jj = 0; jj < nFR; ++jj) + x_out[FR_idx[jj]] = delta_xFR[jj]; + for (jj = 0; jj < nFX; ++jj) + y_out[FX_idx[jj]] = delta_yFX[jj]; + for (jj = 0; jj < nAC; ++jj) + y_out[nV + AC_idx[jj]] = delta_yAC[jj]; + + g_in += nV; + lb_in += nV; + ub_in += nV; + lbA_in += nC; + ubA_in += nC; + x_out += nV; + y_out += nV + nC; + } + + delete[] delta_yFX; + delete[] delta_yAC; + delete[] delta_xFR; + delete[] delta_xFX; + + return returnvalue; +} + +/* + * g e t W o r k i n g S e t + */ +returnValue QProblem::getWorkingSet(real_t * workingSet) +{ + int_t nV = this->getNV(); + + if (workingSet == 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + /* At which limit are the bounds active? */ + getWorkingSetBounds(workingSet); + + /* At which limit are the contraints active? */ + getWorkingSetConstraints(&(workingSet[nV])); + + return SUCCESSFUL_RETURN; +} + +/* + * g e t W o r k i n g S e t B o u n d s + */ +returnValue QProblem::getWorkingSetBounds(real_t * workingSetB) +{ + return QProblemB::getWorkingSetBounds(workingSetB); +} + +/* + * g e t W o r k i n g S e t C o n s t r a i n t s + */ +returnValue QProblem::getWorkingSetConstraints(real_t * workingSetC) +{ + int_t i; + int_t nC = this->getNC(); + + if (workingSetC == 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + for (i = 0; i < nC; ++i) { + switch (constraints.getStatus(i)) { + case ST_LOWER: + workingSetC[i] = -1.0; + break; + case ST_UPPER: + workingSetC[i] = +1.0; + break; + default: + workingSetC[i] = 0.0; + break; + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * g e t N Z + */ +int_t QProblem::getNZ() const +{ + /* nZ = nFR - nAC */ + return getNFR() - getNAC(); +} + +/* + * g e t D u a l S o l u t i o n + */ +returnValue QProblem::getDualSolution(real_t * const yOpt) const +{ + int_t i; + + for (i = 0; i < getNV() + getNC(); ++i) + yOpt[i] = y[i]; + + /* return optimal dual solution vector + * only if current QP has been solved */ + if ((getStatus() == QPS_AUXILIARYQPSOLVED) || (getStatus() == QPS_HOMOTOPYQPSOLVED) || + (getStatus() == QPS_SOLVED)) { + return SUCCESSFUL_RETURN; + } else { + return RET_QP_NOT_SOLVED; + } +} + +/* + * s e t C o n s t r a i n t P r o d u c t + */ +returnValue QProblem::setConstraintProduct(ConstraintProduct * const _constraintProduct) +{ + constraintProduct = _constraintProduct; + + return SUCCESSFUL_RETURN; +} + +/* + * p r i n t P r o p e r t i e s + */ +returnValue QProblem::printProperties() +{ +#ifndef __SUPPRESSANYOUTPUT__ + + /* Do not print properties if print level is set to none! */ + if (options.printLevel == PL_NONE) + return SUCCESSFUL_RETURN; + + char myPrintfString[MAX_STRING_LENGTH]; + + myPrintf("\n################# qpOASES -- QP PROPERTIES #################\n"); + myPrintf("\n"); + + /* 1) Variables properties. */ + snprintf(myPrintfString, MAX_STRING_LENGTH, "Number of Variables: %4.1d\n", (int)getNV()); + myPrintf(myPrintfString); + + if (bounds.hasNoLower() == BT_TRUE) + myPrintf("Variables are not bounded from below.\n"); + else + myPrintf("Variables are bounded from below.\n"); + + if (bounds.hasNoUpper() == BT_TRUE) + myPrintf("Variables are not bounded from above.\n"); + else + myPrintf("Variables are bounded from above.\n"); + + myPrintf("\n"); + + /* 2) Constraints properties. */ + snprintf(myPrintfString, MAX_STRING_LENGTH, "Total number of Constraints: %4.1d\n", (int)getNC()); + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "Number of Equality Constraints: %4.1d\n", (int)getNEC()); + myPrintf(myPrintfString); + + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "Number of Inequality Constraints: %4.1d\n", + (int)(getNC() - getNEC())); + myPrintf(myPrintfString); + + if (getNC() > 0) { + if (constraints.hasNoLower() == BT_TRUE) + myPrintf("Constraints are not bounded from below.\n"); + else + myPrintf("Constraints are bounded from below.\n"); + + if (constraints.hasNoUpper() == BT_TRUE) + myPrintf("Constraints are not bounded from above.\n"); + else + myPrintf("Constraints are bounded from above.\n"); + } + + myPrintf("\n"); + + /* 3) Further properties. */ + switch (hessianType) { + case HST_ZERO: + myPrintf("Hessian is zero matrix (i.e. actually an LP is solved).\n"); + break; + + case HST_IDENTITY: + myPrintf("Hessian is identity matrix.\n"); + break; + + case HST_POSDEF: + myPrintf("Hessian matrix is (strictly) positive definite.\n"); + break; + + case HST_POSDEF_NULLSPACE: + myPrintf("Hessian matrix is positive definite on null space of active constraints.\n"); + break; + + case HST_SEMIDEF: + myPrintf("Hessian matrix is positive semi-definite.\n"); + break; + + case HST_INDEF: + myPrintf("Hessian matrix is indefinite.\n"); + break; + + default: + myPrintf("Hessian matrix has unknown type.\n"); + break; + } + + if (infeasible == BT_TRUE) + myPrintf("QP was found to be infeasible.\n"); + else + myPrintf("QP seems to be feasible.\n"); + + if (unbounded == BT_TRUE) + myPrintf("QP was found to be unbounded from below.\n"); + else + myPrintf("QP seems to be bounded from below.\n"); + + myPrintf("\n"); + + /* 4) QP object properties. */ + switch (status) { + case QPS_NOTINITIALISED: + myPrintf("Status of QP object: freshly instantiated or reset.\n"); + break; + + case QPS_PREPARINGAUXILIARYQP: + myPrintf("Status of QP object: an auxiliary QP is currently setup.\n"); + break; + + case QPS_AUXILIARYQPSOLVED: + myPrintf("Status of QP object: an auxilary QP was solved.\n"); + break; + + case QPS_PERFORMINGHOMOTOPY: + myPrintf("Status of QP object: a homotopy step is performed.\n"); + break; + + case QPS_HOMOTOPYQPSOLVED: + myPrintf("Status of QP object: an intermediate QP along the homotopy path was solved.\n"); + break; + + case QPS_SOLVED: + myPrintf("Status of QP object: solution of the actual QP was found.\n"); + break; + } + + switch (options.printLevel) { + case PL_DEBUG_ITER: + myPrintf("Print level of QP object is set to display a tabular output for debugging.\n"); + break; + + case PL_TABULAR: + myPrintf("Print level of QP object is set to display a tabular output.\n"); + break; + + case PL_LOW: + myPrintf("Print level of QP object is low, i.e. only error are printed.\n"); + break; + + case PL_MEDIUM: + myPrintf("Print level of QP object is medium, i.e. error and warnings are printed.\n"); + break; + + case PL_HIGH: + myPrintf("Print level of QP object is high, i.e. all available output is printed.\n"); + break; + + default: + break; + } + + myPrintf("\n"); + +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +returnValue QProblem::getFreeVariablesFlags(BooleanType * varIsFree) +{ + int_t nV = getNV(); + for (int_t i = 0; i < nV; i++) + varIsFree[i] = BT_FALSE; + + int_t nFR = getNFR(); + int_t * FR_idx; + bounds.getFree()->getNumberArray(&FR_idx); + + for (int_t i = 0; i < nFR; i++) + varIsFree[FR_idx[i]] = BT_TRUE; + + return SUCCESSFUL_RETURN; +} + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + +/* + * c l e a r + */ +returnValue QProblem::clear() +{ + if ((freeConstraintMatrix == BT_TRUE) && (A != 0)) { + delete A; + A = 0; + } + + if (lbA != 0) { + delete[] lbA; + lbA = 0; + } + + if (ubA != 0) { + delete[] ubA; + ubA = 0; + } + + if (T != 0) { + delete[] T; + T = 0; + } + + if (Q != 0) { + delete[] Q; + Q = 0; + } + + if (Ax != 0) { + delete[] Ax; + Ax = 0; + } + + if (Ax_l != 0) { + delete[] Ax_l; + Ax_l = 0; + } + + if (Ax_u != 0) { + delete[] Ax_u; + Ax_u = 0; + } + + if (tempA != 0) { + delete[] tempA; + tempA = 0; + } + + if (ZFR_delta_xFRz != 0) { + delete[] ZFR_delta_xFRz; + ZFR_delta_xFRz = 0; + } + + if (delta_xFRy != 0) { + delete[] delta_xFRy; + delta_xFRy = 0; + } + + if (delta_xFRz != 0) { + delete[] delta_xFRz; + delta_xFRz = 0; + } + + if (tempB != 0) { + delete[] tempB; + tempB = 0; + } + + if (delta_yAC_TMP != 0) { + delete[] delta_yAC_TMP; + delta_yAC_TMP = 0; + } + + if (tempC != 0) { + delete[] tempC; + tempC = 0; + } + + return SUCCESSFUL_RETURN; +} + +/* + * c o p y + */ +returnValue QProblem::copy(const QProblem & rhs) +{ + uint_t _nV = (uint_t)rhs.getNV(); + uint_t _nC = (uint_t)rhs.getNC(); + + constraints = rhs.constraints; + + if ((freeConstraintMatrix == BT_TRUE) && (A != 0)) { + delete A; + A = 0; + } + + freeConstraintMatrix = rhs.freeConstraintMatrix; + + if (freeConstraintMatrix == BT_TRUE) + A = rhs.A->duplicate(); + else + A = rhs.A; + + if (rhs.lbA != 0) { + lbA = new real_t[_nC]; + setLBA(rhs.lbA); + } else + lbA = 0; + + if (rhs.ubA != 0) { + ubA = new real_t[_nC]; + setUBA(rhs.ubA); + } else + ubA = 0; + + if (rhs.y != 0) { + delete[] y; /* y of no constraints version too short! */ + y = new real_t[_nV + _nC]; + memcpy(y, rhs.y, (_nV + _nC) * sizeof(real_t)); + } else + y = 0; + + sizeT = rhs.sizeT; + + if (rhs.T != 0) { + T = new real_t[sizeT * sizeT]; + memcpy(T, rhs.T, ((uint_t)(sizeT * sizeT)) * sizeof(real_t)); + } else + T = 0; + + if (rhs.Q != 0) { + Q = new real_t[_nV * _nV]; + memcpy(Q, rhs.Q, _nV * _nV * sizeof(real_t)); + } else + Q = 0; + + if (rhs.Ax != 0) { + Ax = new real_t[_nC]; + memcpy(Ax, rhs.Ax, _nC * sizeof(real_t)); + } else + Ax = 0; + + if (rhs.Ax_l != 0) { + Ax_l = new real_t[_nC]; + memcpy(Ax_l, rhs.Ax_l, _nC * sizeof(real_t)); + } else + Ax_l = 0; + + if (rhs.Ax_u != 0) { + Ax_u = new real_t[_nC]; + memcpy(Ax_u, rhs.Ax_u, _nC * sizeof(real_t)); + } else + Ax_u = 0; + + if (rhs.constraintProduct != 0) + constraintProduct = rhs.constraintProduct; + else + constraintProduct = 0; + + tempA = new real_t[_nV]; /* nFR */ + ZFR_delta_xFRz = new real_t[_nV]; /* nFR */ + delta_xFRz = new real_t[_nV]; /* nZ */ + + if (_nC > 0) { + delta_xFRy = new real_t[_nC]; /* nAC */ + tempB = new real_t[_nC]; /* nAC */ + delta_yAC_TMP = new real_t[_nC]; /* nAC */ + tempC = new real_t[_nC]; /* nAC */ + } else { + delta_xFRy = 0; + tempB = 0; + delta_yAC_TMP = 0; + tempC = 0; + } + + return SUCCESSFUL_RETURN; +} + +/* + * s o l v e I n i t i a l Q P + */ +returnValue QProblem::solveInitialQP(const real_t * const xOpt, + const real_t * const yOpt, + const Bounds * const guessedBounds, + const Constraints * const guessedConstraints, + const real_t * const _R, + int_t & nWSR, + real_t * const cputime) +{ + int_t i, j; + + /* some definitions */ + int_t nV = getNV(); + int_t nC = getNC(); + + // writeQpDataIntoMatFile( "qpData.mat" ); + + /* start runtime measurement */ + real_t starttime = 0.0; + if (cputime != 0) + starttime = getCPUtime(); + + status = QPS_NOTINITIALISED; + + /* I) ANALYSE QP DATA: */ + /* 1) Check if Hessian happens to be the identity matrix. */ + if (determineHessianType() != SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED); + + /* 2) Setup type of bounds and constraints (i.e. unbounded, implicitly fixed etc.). */ + if (setupSubjectToType() != SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED); + + status = QPS_PREPARINGAUXILIARYQP; + + /* II) SETUP AUXILIARY QP WITH GIVEN OPTIMAL SOLUTION: */ + /* 1) Setup bounds and constraints data structure. */ + if (bounds.setupAllFree() != SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED); + + if (constraints.setupAllInactive() != SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED); + + /* 2) Setup optimal primal/dual solution for auxiliary QP. */ + if (setupAuxiliaryQPsolution(xOpt, yOpt) != SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED); + + /* 3) Obtain linear independent working set for auxiliary QP. */ + Bounds auxiliaryBounds(nV); + Constraints auxiliaryConstraints(nC); + + if (obtainAuxiliaryWorkingSet( + xOpt, yOpt, guessedBounds, guessedConstraints, &auxiliaryBounds, &auxiliaryConstraints) != + SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED); + + /* 4) Setup working set of auxiliary QP and setup matrix factorisations. */ + /* a) Regularise Hessian if necessary. */ + if ((hessianType == HST_ZERO) || (hessianType == HST_SEMIDEF)) { + if (regulariseHessian() != SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED_REGULARISATION); + } + + /* b) TQ factorisation. */ + if (setupTQfactorisation() != SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED_TQ); + + /* c) Working set of auxiliary QP. */ + if (setupAuxiliaryWorkingSet(&auxiliaryBounds, &auxiliaryConstraints, BT_TRUE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED); + + /* d) Copy external Cholesky factor if provided */ + haveCholesky = BT_FALSE; + + if (_R != 0) { + if (options.initialStatusBounds != ST_INACTIVE) { + THROWWARNING(RET_NO_CHOLESKY_WITH_INITIAL_GUESS); + } else { + if (_R == R) { + /* Cholesky factor read from file and already loaded into R. */ + haveCholesky = BT_TRUE; + } else if ((xOpt == 0) && (yOpt == 0) && (guessedBounds == 0) && (guessedConstraints == 0)) { + for (i = 0; i < nV; ++i) + for (j = i; j < nV; ++j) + RR(i, j) = _R[i * nV + j]; + haveCholesky = BT_TRUE; + } else { + THROWWARNING(RET_NO_CHOLESKY_WITH_INITIAL_GUESS); + } + } + } + + /* 5) Store original QP formulation... */ + real_t * g_original = new real_t[nV]; + real_t * lb_original = new real_t[nV]; + real_t * ub_original = new real_t[nV]; + real_t * lbA_original = new real_t[nC]; + real_t * ubA_original = new real_t[nC]; + + for (i = 0; i < nV; ++i) { + g_original[i] = g[i]; + lb_original[i] = lb[i]; + ub_original[i] = ub[i]; + } + + for (i = 0; i < nC; ++i) { + lbA_original[i] = lbA[i]; + ubA_original[i] = ubA[i]; + } + + /* ... and setup QP data of an auxiliary QP having an optimal solution + * as specified by the user (or xOpt = yOpt = 0, by default). */ + if (setupAuxiliaryQPgradient() != SUCCESSFUL_RETURN) { + delete[] ubA_original; + delete[] lbA_original; + delete[] ub_original; + delete[] lb_original; + delete[] g_original; + return THROWERROR(RET_INIT_FAILED); + } + + if (setupAuxiliaryQPbounds(&auxiliaryBounds, &auxiliaryConstraints, BT_TRUE) != SUCCESSFUL_RETURN) { + delete[] ubA_original; + delete[] lbA_original; + delete[] ub_original; + delete[] lb_original; + delete[] g_original; + return THROWERROR(RET_INIT_FAILED); + } + + status = QPS_AUXILIARYQPSOLVED; + + if (options.enableRamping == BT_TRUE) + performRamping(); + + /* III) SOLVE ACTUAL INITIAL QP: */ + /* Allow only remaining CPU time for usual hotstart. */ + if (cputime != 0) + *cputime -= getCPUtime() - starttime; + + /* Use hotstart method to find the solution of the original initial QP,... */ + returnValue returnvalue = + hotstart(g_original, lb_original, ub_original, lbA_original, ubA_original, nWSR, cputime); + + /* ... deallocate memory,... */ + delete[] ubA_original; + delete[] lbA_original; + delete[] ub_original; + delete[] lb_original; + delete[] g_original; + + /* ... check for infeasibility and unboundedness... */ + if (isInfeasible() == BT_TRUE) + return THROWERROR(RET_INIT_FAILED_INFEASIBILITY); + + if (isUnbounded() == BT_TRUE) + return THROWERROR(RET_INIT_FAILED_UNBOUNDEDNESS); + + /* ... and internal errors. */ + if ((returnvalue != SUCCESSFUL_RETURN) && (returnvalue != RET_MAX_NWSR_REACHED)) + return THROWERROR(RET_INIT_FAILED_HOTSTART); + + /* stop runtime measurement */ + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + THROWINFO(RET_INIT_SUCCESSFUL); + + return returnvalue; +} + +/* + * s o l v e Q P + */ +returnValue QProblem::solveQP(const real_t * const g_new, + const real_t * const lb_new, + const real_t * const ub_new, + const real_t * const lbA_new, + const real_t * const ubA_new, + int_t & nWSR, + real_t * const cputime, + int_t nWSRperformed, + BooleanType isFirstCall) +{ + int_t iter; + int_t nV = getNV(); + int_t nC = getNC(); + + returnValue returnvalue; + + /* consistency check */ + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_PREPARINGAUXILIARYQP) || + (getStatus() == QPS_PERFORMINGHOMOTOPY)) { + return THROWERROR(RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED); + } + + /* start runtime measurement */ + real_t starttime = 0.0; + if (cputime != 0) + starttime = getCPUtime(); + + /* AW: Remove bounds if they were active before but are now infinity */ + status = QPS_PERFORMINGHOMOTOPY; // AW TODO: Not sure if this is too early, but otherwise removeBounds + // will complain + returnvalue = updateActivitiesForHotstart(lb_new, ub_new, lbA_new, ubA_new); + if (returnvalue != SUCCESSFUL_RETURN) { + THROWERROR(RET_HOTSTART_FAILED); + return returnvalue; + } + + /* I) PREPARATIONS */ + /* 1) Allocate delta vectors of gradient and (constraints') bounds, + * index arrays and step direction arrays. */ + real_t * delta_xFR = new real_t[nV]; + real_t * delta_xFX = new real_t[nV]; + real_t * delta_yAC = new real_t[nC]; + real_t * delta_yFX = new real_t[nV]; + + real_t * delta_g = new real_t[nV]; + real_t * delta_lb = new real_t[nV]; + real_t * delta_ub = new real_t[nV]; + real_t * delta_lbA = new real_t[nC]; + real_t * delta_ubA = new real_t[nC]; + + BooleanType Delta_bC_isZero, Delta_bB_isZero; + + int_t BC_idx; + SubjectToStatus BC_status; + BooleanType BC_isBound; + + real_t homotopyLength; + +#ifndef __SUPPRESSANYOUTPUT__ + char messageString[MAX_STRING_LENGTH]; +#endif + + /* 2) Update type of bounds and constraints, e.g. + * a former equality constraint might have become a normal one etc. */ + + // (ckirches) disabled this, as inactive but tight bounds may become inactive equalities + // which would then never become active again! + /* + if ( setupSubjectToType( lb_new,ub_new,lbA_new,ubA_new ) != SUCCESSFUL_RETURN ) + return THROWERROR( RET_HOTSTART_FAILED ); + */ + + /* 3) Reset status flags. */ + infeasible = BT_FALSE; + unbounded = BT_FALSE; + + /* II) MAIN HOMOTOPY LOOP */ + for (iter = nWSRperformed; iter < nWSR; ++iter) { + tabularOutput.idxAddB = tabularOutput.idxRemB = tabularOutput.idxAddC = tabularOutput.idxRemC = -1; + tabularOutput.excAddB = tabularOutput.excRemB = tabularOutput.excAddC = tabularOutput.excRemC = 0; + + if (isCPUtimeLimitExceeded(cputime, starttime, iter - nWSRperformed) == BT_TRUE) { + /* If CPU time limit is exceeded, stop homotopy loop immediately! + * Assign number of working set recalculations (runtime measurement is stopped later). */ + nWSR = iter; + break; + } + + status = QPS_PERFORMINGHOMOTOPY; + +#ifndef __SUPPRESSANYOUTPUT__ + if (isFirstCall == BT_TRUE) + snprintf(messageString, MAX_STRING_LENGTH, "%d ...", (int)iter); + else + snprintf(messageString, MAX_STRING_LENGTH, "%d* ...", (int)iter); + getGlobalMessageHandler()->throwInfo( + RET_ITERATION_STARTED, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + /* 2) Determination of shift direction of the gradient and the (constraints') bounds. */ + returnvalue = determineDataShift(g_new, + lbA_new, + ubA_new, + lb_new, + ub_new, + delta_g, + delta_lbA, + delta_ubA, + delta_lb, + delta_ub, + Delta_bC_isZero, + Delta_bB_isZero); + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] delta_yAC; + delete[] delta_yFX; + delete[] delta_xFX; + delete[] delta_xFR; + delete[] delta_ub; + delete[] delta_lb; + delete[] delta_ubA; + delete[] delta_lbA; + delete[] delta_g; + + /* Assign number of working set recalculations and stop runtime measurement. */ + nWSR = iter; + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + THROWERROR(RET_SHIFT_DETERMINATION_FAILED); + return returnvalue; + } + + /* 3) Determination of step direction of X and Y. */ + returnvalue = determineStepDirection(delta_g, + delta_lbA, + delta_ubA, + delta_lb, + delta_ub, + Delta_bC_isZero, + Delta_bB_isZero, + delta_xFX, + delta_xFR, + delta_yAC, + delta_yFX); + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] delta_yAC; + delete[] delta_yFX; + delete[] delta_xFX; + delete[] delta_xFR; + delete[] delta_ub; + delete[] delta_lb; + delete[] delta_ubA; + delete[] delta_lbA; + delete[] delta_g; + + /* Assign number of working set recalculations and stop runtime measurement. */ + nWSR = iter; + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + THROWERROR(RET_STEPDIRECTION_DETERMINATION_FAILED); + return returnvalue; + } + + /* 4) Determination of step length TAU. + * This step along the homotopy path is also taken (without changing working set). */ + returnvalue = performStep(delta_g, + delta_lbA, + delta_ubA, + delta_lb, + delta_ub, + delta_xFX, + delta_xFR, + delta_yAC, + delta_yFX, + BC_idx, + BC_status, + BC_isBound); + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] delta_yAC; + delete[] delta_yFX; + delete[] delta_xFX; + delete[] delta_xFR; + delete[] delta_ub; + delete[] delta_lb; + delete[] delta_ubA; + delete[] delta_lbA; + delete[] delta_g; + + /* Assign number of working set recalculations and stop runtime measurement. */ + nWSR = iter; + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + THROWERROR(RET_STEPLENGTH_DETERMINATION_FAILED); + return returnvalue; + } + + /* 5) Termination criterion. */ + nV = getNV(); + nC = getNC(); + + homotopyLength = getRelativeHomotopyLength(g_new, lb_new, ub_new, lbA_new, ubA_new); + if (homotopyLength <= options.terminationTolerance) { + status = QPS_SOLVED; + + THROWINFO(RET_OPTIMAL_SOLUTION_FOUND); + + if (printIteration(iter, BC_idx, BC_status, BC_isBound, homotopyLength, isFirstCall) != + SUCCESSFUL_RETURN) + THROWERROR(RET_PRINT_ITERATION_FAILED); /* do not pass this as return value! */ + + nWSR = iter; + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + delete[] delta_yAC; + delete[] delta_yFX; + delete[] delta_xFX; + delete[] delta_xFR; + delete[] delta_ub; + delete[] delta_lb; + delete[] delta_ubA; + delete[] delta_lbA; + delete[] delta_g; + + return SUCCESSFUL_RETURN; + } + + /* 6) Change active set. */ + returnvalue = changeActiveSet(BC_idx, BC_status, BC_isBound); + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] delta_yAC; + delete[] delta_yFX; + delete[] delta_xFX; + delete[] delta_xFR; + delete[] delta_ub; + delete[] delta_lb; + delete[] delta_ubA; + delete[] delta_lbA; + delete[] delta_g; + + /* Assign number of working set recalculations and stop runtime measurement. */ + nWSR = iter; + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + /* Checks for infeasibility... */ + if (isInfeasible() == BT_TRUE) { + status = QPS_HOMOTOPYQPSOLVED; + return setInfeasibilityFlag(RET_HOTSTART_STOPPED_INFEASIBILITY); + } + + /* ...unboundedness... */ + if (unbounded == BT_TRUE) /* not necessary since objective function convex! */ + return THROWERROR(RET_HOTSTART_STOPPED_UNBOUNDEDNESS); + + /* ... and throw unspecific error otherwise */ + THROWERROR(RET_HOMOTOPY_STEP_FAILED); + return returnvalue; + } + + /* 6a) Possibly refactorise projected Hessian from scratch. */ + if ((options.enableCholeskyRefactorisation > 0) && + ((iter % options.enableCholeskyRefactorisation) == 0)) { + returnvalue = computeProjectedCholesky(); + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] delta_yAC; + delete[] delta_yFX; + delete[] delta_xFX; + delete[] delta_xFR; + delete[] delta_ub; + delete[] delta_lb; + delete[] delta_ubA; + delete[] delta_lbA; + delete[] delta_g; + return returnvalue; + } + } + + /* 7) Output information of successful QP iteration. */ + status = QPS_HOMOTOPYQPSOLVED; + + if (printIteration(iter, BC_idx, BC_status, BC_isBound, homotopyLength, isFirstCall) != + SUCCESSFUL_RETURN) + THROWERROR(RET_PRINT_ITERATION_FAILED); /* do not pass this as return value! */ + + /* 8) Perform Ramping Strategy on zero homotopy step or drift correction (if desired). */ + if (BC_status != ST_UNDEFINED) { + if ((tau <= EPS) && (options.enableRamping == BT_TRUE)) + performRamping(); + else if ((options.enableDriftCorrection > 0) && ((iter + 1) % options.enableDriftCorrection == 0)) + performDriftCorrection(); /* always returns SUCCESSFUL_RETURN */ + } else // AW: Added this. Otherwise, I observed that the gradient might become incorrect + { + if ((options.enableDriftCorrection > 0) && ((iter + 1) % options.enableDriftCorrection == 0)) + performDriftCorrection(); /* always returns SUCCESSFUL_RETURN */ + } + } + + delete[] delta_yAC; + delete[] delta_yFX; + delete[] delta_xFX; + delete[] delta_xFR; + delete[] delta_ub; + delete[] delta_lb; + delete[] delta_ubA; + delete[] delta_lbA; + delete[] delta_g; + + /* stop runtime measurement */ + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + /* if program gets to here, output information that QP could not be solved + * within the given maximum numbers of working set changes */ + if (options.printLevel == PL_HIGH) { +#ifndef __SUPPRESSANYOUTPUT__ + snprintf(messageString, MAX_STRING_LENGTH, "(nWSR = %d)", (int)iter); + return getGlobalMessageHandler()->throwWarning( + RET_MAX_NWSR_REACHED, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#else + return RET_MAX_NWSR_REACHED; +#endif + } else { + return RET_MAX_NWSR_REACHED; + } +} + +/* + * s o l v e R e g u l a r i s e d Q P + */ +returnValue QProblem::solveRegularisedQP(const real_t * const g_new, + const real_t * const lb_new, + const real_t * const ub_new, + const real_t * const lbA_new, + const real_t * const ubA_new, + int_t & nWSR, + real_t * const cputime, + int_t nWSRperformed, + BooleanType isFirstCall) +{ + int_t i, step; + int_t nV = getNV(); + + /* Perform normal QP solution if QP has not been regularised. */ + if (usingRegularisation() == BT_FALSE) + return solveQP(g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR, cputime, nWSRperformed, isFirstCall); + + /* I) SOLVE USUAL REGULARISED QP */ + returnValue returnvalue; + + int_t nWSR_max = nWSR; + int_t nWSR_total = nWSRperformed; + + real_t cputime_total = 0.0; + real_t cputime_cur = 0.0; + + if (cputime == 0) { + returnvalue = solveQP(g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR, 0, nWSRperformed, isFirstCall); + } else { + cputime_cur = *cputime; + returnvalue = + solveQP(g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR, &cputime_cur, nWSRperformed, isFirstCall); + } + nWSR_total = nWSR; + cputime_total += cputime_cur; + isFirstCall = BT_FALSE; + + /* Only continue if QP solution has been successful. */ + if (returnvalue != SUCCESSFUL_RETURN) { + if (cputime != 0) + *cputime = cputime_total; + + if (returnvalue == RET_MAX_NWSR_REACHED) + THROWWARNING(RET_NO_REGSTEP_NWSR); + + return returnvalue; + } + + /* II) PERFORM SUCCESSIVE REGULARISATION STEPS */ + real_t * gMod = new real_t[nV]; + + for (step = 0; step < options.numRegularisationSteps; ++step) { + /* 1) Modify gradient: gMod = g - eps*xOpt + * (assuming regularisation matrix to be regVal*Id). */ + for (i = 0; i < nV; ++i) + gMod[i] = g_new[i] - regVal * x[i]; + + /* 2) Solve regularised QP with modified gradient allowing + * only as many working set recalculations and CPU time + * as have been left from previous QP solutions. */ + nWSR = nWSR_max; + + if (cputime == 0) { + returnvalue = solveQP(gMod, lb_new, ub_new, lbA_new, ubA_new, nWSR, 0, nWSR_total, isFirstCall); + } else { + cputime_cur = *cputime - cputime_total; + returnvalue = + solveQP(gMod, lb_new, ub_new, lbA_new, ubA_new, nWSR, &cputime_cur, nWSR_total, isFirstCall); + } + + nWSR_total = nWSR; + cputime_total += cputime_cur; + + /* Only continue if QP solution has been successful. */ + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] gMod; + + if (cputime != 0) + *cputime = cputime_total; + + if (returnvalue == RET_MAX_NWSR_REACHED) + THROWWARNING(RET_FEWER_REGSTEPS_NWSR); + + return returnvalue; + } + } + + for (i = 0; i < nV; ++i) + g[i] = g_new[i]; + + delete[] gMod; + + if (cputime != 0) + *cputime = cputime_total; + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p S u b j e c t T o T y p e + */ +returnValue QProblem::updateActivitiesForHotstart(const real_t * const lb_new, + const real_t * const ub_new, + const real_t * const lbA_new, + const real_t * const ubA_new) +{ + int_t i; + int_t nV = getNV(); + + returnValue returnvalue; + + if (QProblemB::setupSubjectToType(lb_new, ub_new) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUPSUBJECTTOTYPE_FAILED); + + for (i = 0; i < nV; i++) { + if (lb_new[i] <= -INFTY && bounds.getStatus(i) == ST_LOWER) { + returnvalue = removeBound(i, BT_TRUE, BT_FALSE, options.enableNZCTests); + if (returnvalue != SUCCESSFUL_RETURN) + return returnvalue; + g[i] -= y[i]; + y[i] = 0.0; + } + if (ub_new[i] >= INFTY && bounds.getStatus(i) == ST_UPPER) { + returnvalue = removeBound(i, BT_TRUE, BT_FALSE, options.enableNZCTests); + if (returnvalue != SUCCESSFUL_RETURN) + return returnvalue; + g[i] -= y[i]; + y[i] = 0.0; + } + if (lb_new[i] > -INFTY && lb[i] <= -INFTY) { + /* Now a lower bound has become finite. To avoid numerical issues, adjust lb */ + lb[i] = x[i] - options.boundRelaxation; + } + if (ub_new[i] < INFTY && ub[i] >= INFTY) { + /* Now a lower bound has become finite. To avoid numerical issues, adjust lb */ + ub[i] = x[i] + options.boundRelaxation; + } + } + + for (i = 0; i < nV; i++) { + if (bounds.getType(i) == ST_EQUALITY) // ?? && lb[i] != ub[i] + { + /* AW: Are the following two lines OK? */ + lb[i] = x[i]; + ub[i] = x[i]; + if (bounds.getStatus(i) == ST_INACTIVE) { + returnvalue = addBound_checkLI(i); + if (returnvalue == RET_LINEARLY_INDEPENDENT) { + returnvalue = addBound(i, ST_LOWER, BT_TRUE); + if (returnvalue != SUCCESSFUL_RETURN) + return returnvalue; + } + /* AW: Check: This allows to have variables that are + equalities to be in the set of free variables. */ + } + } + } + + // AW TODO: We could also implement something here for the constraints + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p S u b j e c t T o T y p e + */ +returnValue QProblem::setupSubjectToType() +{ + return setupSubjectToType(lb, ub, lbA, ubA); +} + +/* + * s e t u p S u b j e c t T o T y p e + */ +returnValue QProblem::setupSubjectToType(const real_t * const lb_new, + const real_t * const ub_new, + const real_t * const lbA_new, + const real_t * const ubA_new) +{ + int_t i; + int_t nC = getNC(); + + /* I) SETUP SUBJECTTOTYPE FOR BOUNDS */ + if (QProblemB::setupSubjectToType(lb_new, ub_new) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUPSUBJECTTOTYPE_FAILED); + + /* II) SETUP SUBJECTTOTYPE FOR CONSTRAINTS */ + /* 1) Check if lower constraints' bounds are present. */ + constraints.setNoLower(BT_TRUE); + if (lbA_new != 0) { + for (i = 0; i < nC; ++i) { + if (lbA_new[i] > -INFTY) { + constraints.setNoLower(BT_FALSE); + break; + } + } + } + + /* 2) Check if upper constraints' bounds are present. */ + constraints.setNoUpper(BT_TRUE); + if (ubA_new != 0) { + for (i = 0; i < nC; ++i) { + if (ubA_new[i] < INFTY) { + constraints.setNoUpper(BT_FALSE); + break; + } + } + } + + /* 3) Determine implicit equality constraints and unbounded constraints. */ + if ((lbA_new != 0) && (ubA_new != 0)) { + for (i = 0; i < nC; ++i) { + if (constraints.getType(i) == ST_DISABLED) + continue; + + if ((lbA_new[i] < -INFTY + options.boundTolerance) && (ubA_new[i] > INFTY - options.boundTolerance) && + (options.enableFarBounds == BT_FALSE)) { + constraints.setType(i, ST_UNBOUNDED); + } else { + if (options.enableEqualities && lbA[i] > ubA[i] - options.boundTolerance && + lbA_new[i] > ubA_new[i] - options.boundTolerance) + constraints.setType(i, ST_EQUALITY); + else + constraints.setType(i, ST_BOUNDED); + } + } + } else { + if ((lbA_new == 0) && (ubA_new == 0)) { + for (i = 0; i < nC; ++i) { + if (constraints.getType(i) != ST_DISABLED) + constraints.setType(i, ST_UNBOUNDED); + } + } else { + for (i = 0; i < nC; ++i) { + if (constraints.getType(i) != ST_DISABLED) + constraints.setType(i, ST_BOUNDED); + } + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * c o m p u t e P r o j e c t e d C h o l e s k y + */ +returnValue QProblem::computeProjectedCholesky() +{ + int_t i, j; + int_t nV = getNV(); + int_t nZ = getNZ(); + + SymSparseMat * Id; + + /* Revert to unprotected Cholesky decomposition */ + if (getNFX() + getNAC() == 0) + return QProblemB::computeCholesky(); + + /* 1) Initialises R with all zeros. */ + for (i = 0; i < nV * nV; ++i) + R[i] = 0.0; + + /* Do not do anything for empty null spaces (important for LP case, HST_ZERO !)*/ + if (nZ == 0) // nZ == nV - getNFX() - getNAC() + return SUCCESSFUL_RETURN; + + /* 2) Calculate Cholesky decomposition of projected Hessian Z'*H*Z. */ + int_t * FR_idx; + bounds.getFree()->getNumberArray(&FR_idx); + + int_t * AC_idx; + constraints.getActive()->getNumberArray(&AC_idx); + + /* calculate Z'*H*Z */ + switch (hessianType) { + case HST_ZERO: + if (usingRegularisation() == BT_TRUE) { + Id = createDiagSparseMat(nV, regVal); + Id->bilinear(bounds.getFree(), nZ, Q, nV, R, nV); + delete Id; + } else { + /* Code should not get here, as nZ == 0 always holds for an LP (without regularisation)! */ + if (nZ > 0) + return THROWERROR(RET_UNKNOWN_BUG); + } + break; + + case HST_IDENTITY: + Id = createDiagSparseMat(nV, 1.0); + Id->bilinear(bounds.getFree(), nZ, Q, nV, R, nV); + delete Id; + break; + + default: + if (getNAC() == 0) { + /* make Z trivial */ + for (j = 0; j < nZ; ++j) { + for (i = 0; i < nV; ++i) + QQ(i, j) = 0.0; + QQ(FR_idx[j], j) = 1.0; + } + /* now Z is trivial, and so is Z'HZ */ + int_t nFR = getNFR(); + for (j = 0; j < nFR; ++j) + H->getCol(FR_idx[j], bounds.getFree(), 1.0, &R[j * nV]); + } else { + /* this is expensive if Z is large! */ + H->bilinear(bounds.getFree(), nZ, Q, nV, R, nV); + } + } + + /* R'*R = Z'*H*Z */ + la_int_t info = 0; + la_uint_t _nZ = (la_uint_t)nZ, _nV = (la_uint_t)nV; + + POTRF("U", &_nZ, R, &_nV, &info); + + /* <0 = invalid call, =0 ok, >0 not spd */ + if (info > 0) { + if (R[0] < 0.0) { + /* Cholesky decomposition has tunneled a negative + * diagonal element. */ + options.epsRegularisation = + getMin(-R[0] + options.epsRegularisation, getSqrt(getAbs(options.epsRegularisation))); + } + + hessianType = HST_SEMIDEF; + return RET_HESSIAN_NOT_SPD; + } + + /* zero first subdiagonal to make givens updates work */ + for (i = 0; i < nZ - 1; ++i) + RR(i + 1, i) = 0.0; + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p I n i t i a l C h o l e s k y + */ +returnValue QProblem::setupInitialCholesky() +{ + returnValue returnvalueCholesky; + + /* If regularisation shall be used, always regularise at beginning + * if initial working set is not empty. */ + if ((getNV() != getNFR() - getNFV()) && (options.enableRegularisation == BT_TRUE)) + if (regulariseHessian() != SUCCESSFUL_RETURN) + return RET_INIT_FAILED_REGULARISATION; + + /* Factorise projected Hessian + * now handles all special cases (no active bounds/constraints, no nullspace) */ + returnvalueCholesky = computeProjectedCholesky(); + + /* If Hessian is not positive definite, regularise and try again. */ + if (returnvalueCholesky == RET_HESSIAN_NOT_SPD) { + if (regulariseHessian() != SUCCESSFUL_RETURN) + return RET_INIT_FAILED_REGULARISATION; + + returnvalueCholesky = computeProjectedCholesky(); + } + + if (returnvalueCholesky != SUCCESSFUL_RETURN) + return RET_INIT_FAILED_CHOLESKY; + + haveCholesky = BT_TRUE; + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p T Q f a c t o r i s a t i o n + */ +returnValue QProblem::setupTQfactorisation() +{ + int_t i, ii; + int_t nV = getNV(); + int_t nFR = getNFR(); + + int_t * FR_idx; + bounds.getFree()->getNumberArray(&FR_idx); + + /* 1) Set Q to unity matrix. */ + for (i = 0; i < nV * nV; ++i) + Q[i] = 0.0; + + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + QQ(ii, i) = 1.0; + } + + /* 2) Set T to zero matrix. */ + for (i = 0; i < sizeT * sizeT; ++i) + T[i] = 0.0; + + return SUCCESSFUL_RETURN; +} + +/* + * o b t a i n A u x i l i a r y W o r k i n g S e t + */ +returnValue QProblem::obtainAuxiliaryWorkingSet(const real_t * const xOpt, + const real_t * const yOpt, + const Bounds * const guessedBounds, + const Constraints * const guessedConstraints, + Bounds * auxiliaryBounds, + Constraints * auxiliaryConstraints) const +{ + int_t i = 0; + int_t nV = getNV(); + int_t nC = getNC(); + + /* 1) Ensure that desiredBounds is allocated (and different from guessedBounds). */ + if ((auxiliaryBounds == 0) || (auxiliaryBounds == guessedBounds)) + return THROWERROR(RET_INVALID_ARGUMENTS); + + if ((auxiliaryConstraints == 0) || (auxiliaryConstraints == guessedConstraints)) + return THROWERROR(RET_INVALID_ARGUMENTS); + + SubjectToStatus guessedStatus; + + /* 2) Setup working set of bounds for auxiliary initial QP. */ + if (QProblemB::obtainAuxiliaryWorkingSet(xOpt, yOpt, guessedBounds, auxiliaryBounds) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + + /* 3) Setup working set of constraints for auxiliary initial QP. */ + if (guessedConstraints != 0) { + /* If an initial working set is specific, use it! + * Moreover, add all equality constraints if specified. */ + for (i = 0; i < nC; ++i) { + /* Add constraint only if it is not (going to be) disabled! */ + guessedStatus = guessedConstraints->getStatus(i); + +#ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ + if (constraints.getType(i) == ST_EQUALITY) { + if (auxiliaryConstraints->setupConstraint(i, ST_LOWER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + } else +#endif + { + if (auxiliaryConstraints->setupConstraint(i, guessedStatus) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + } + } + } else /* No initial working set specified. */ + { + /* Obtain initial working set by "clipping". */ + if ((xOpt != 0) && (yOpt == 0)) { + for (i = 0; i < nC; ++i) { + if (Ax[i] - lbA[i] <= options.boundTolerance) { + if (auxiliaryConstraints->setupConstraint(i, ST_LOWER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + continue; + } + + if (ubA[i] - Ax_u[i] <= options.boundTolerance) { + if (auxiliaryConstraints->setupConstraint(i, ST_UPPER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + continue; + } + +/* Moreover, add all equality constraints if specified. */ +#ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ + if (constraints.getType(i) == ST_EQUALITY) { + if (auxiliaryConstraints->setupConstraint(i, ST_LOWER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + } else +#endif + { + if (auxiliaryConstraints->setupConstraint(i, ST_INACTIVE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + } + } + } + + /* Obtain initial working set in accordance to sign of dual solution vector. */ + if (yOpt != 0) { + for (i = 0; i < nC; ++i) { + if (yOpt[nV + i] > EPS) { + if (auxiliaryConstraints->setupConstraint(i, ST_LOWER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + continue; + } + + if (yOpt[nV + i] < -EPS) { + if (auxiliaryConstraints->setupConstraint(i, ST_UPPER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + continue; + } + +/* Moreover, add all equality constraints if specified. */ +#ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ + if (constraints.getType(i) == ST_EQUALITY) { + if (auxiliaryConstraints->setupConstraint(i, ST_LOWER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + } else +#endif + { + if (auxiliaryConstraints->setupConstraint(i, ST_INACTIVE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + } + } + } + + /* If xOpt and yOpt are null pointer and no initial working is specified, + * start with empty working set (or implicitly fixed bounds and equality constraints only) + * for auxiliary QP. */ + if ((xOpt == 0) && (yOpt == 0)) { + for (i = 0; i < nC; ++i) { +/* Only add all equality constraints if specified. */ +#ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ + if (constraints.getType(i) == ST_EQUALITY) { + if (auxiliaryConstraints->setupConstraint(i, ST_LOWER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + } else +#endif + { + if (auxiliaryConstraints->setupConstraint(i, ST_INACTIVE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + } + } + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A u x i l i a r y W o r k i n g S e t + */ +returnValue QProblem::setupAuxiliaryWorkingSet(const Bounds * const auxiliaryBounds, + const Constraints * const auxiliaryConstraints, + BooleanType setupAfresh) +{ + int_t i; + int_t nV = getNV(); + int_t nC = getNC(); + BooleanType WSisTrivial = BT_TRUE; + + /* consistency checks */ + if (auxiliaryBounds != 0) { + for (i = 0; i < nV; ++i) + if ((bounds.getStatus(i) == ST_UNDEFINED) || (auxiliaryBounds->getStatus(i) == ST_UNDEFINED)) + return THROWERROR(RET_UNKNOWN_BUG); + } else { + return THROWERROR(RET_INVALID_ARGUMENTS); + } + + if (auxiliaryConstraints != 0) { + for (i = 0; i < nC; ++i) + if ((constraints.getStatus(i) == ST_UNDEFINED) || + (auxiliaryConstraints->getStatus(i) == ST_UNDEFINED)) + return THROWERROR(RET_UNKNOWN_BUG); + } else { + return THROWERROR(RET_INVALID_ARGUMENTS); + } + + /* Check for trivial working set (all and only bounds active) */ + for (i = 0; i < nV; i++) + if (auxiliaryBounds->getStatus(i) == ST_INACTIVE) { + WSisTrivial = BT_FALSE; + break; + } + for (i = 0; i < nC; i++) + // (ckirches) here we chose to ignore an invalid ST_INACTIVE on + // constraints that are ST_EQUALITies or may just have become equalities + if ((constraints.getType(i) == ST_EQUALITY) // NOT auxiliaryConstraints here + || (auxiliaryConstraints->getStatus(i) != ST_INACTIVE)) { + WSisTrivial = BT_FALSE; + break; + } + + if (WSisTrivial == BT_TRUE) { + for (i = 0; i < nV; i++) + if (bounds.getStatus(i) == ST_INACTIVE) + bounds.moveFreeToFixed(i, auxiliaryBounds->getStatus(i)); + + return SUCCESSFUL_RETURN; + } + + /* I) SETUP CHOLESKY FLAG: + * Cholesky decomposition shall only be updated if working set + * shall be updated (i.e. NOT setup afresh!) */ + BooleanType updateCholesky; + if (setupAfresh == BT_TRUE) + updateCholesky = BT_FALSE; + else + updateCholesky = BT_TRUE; + + BooleanType was_fulli = options.enableFullLITests; + real_t backupEpsLITests = options.epsLITests; + + options.enableFullLITests = BT_FALSE; + /* options.epsLITests = 1e-1; */ + + /* II) REMOVE FORMERLY ACTIVE (CONSTRAINTS') BOUNDS (IF NECESSARY): */ + if (setupAfresh == BT_FALSE) { + /* 1) Remove all active constraints that shall be inactive or disabled AND + * all active constraints that are active at the wrong bound. */ + for (i = 0; i < nC; ++i) { + if ((constraints.getStatus(i) == ST_LOWER) && (auxiliaryConstraints->getStatus(i) != ST_LOWER)) + if (removeConstraint(i, updateCholesky, BT_FALSE, options.enableNZCTests) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + + if ((constraints.getStatus(i) == ST_UPPER) && (auxiliaryConstraints->getStatus(i) != ST_UPPER)) + if (removeConstraint(i, updateCholesky, BT_FALSE, options.enableNZCTests) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + } + + /* 2) Remove all active bounds that shall be inactive AND + * all active bounds that are active at the wrong bound. */ + for (i = 0; i < nV; ++i) { + if ((bounds.getStatus(i) == ST_LOWER) && (auxiliaryBounds->getStatus(i) != ST_LOWER)) + if (removeBound(i, updateCholesky, BT_FALSE, options.enableNZCTests) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + + if ((bounds.getStatus(i) == ST_UPPER) && (auxiliaryBounds->getStatus(i) != ST_UPPER)) + if (removeBound(i, updateCholesky, BT_FALSE, options.enableNZCTests) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + } + } + + /* III) ADD NEWLY ACTIVE (CONSTRAINTS') BOUNDS: */ + + /* 1) Add all equality bounds. */ + for (i = 0; i < nV; ++i) { + // if ( ( bounds.getType( i ) == ST_EQUALITY ) && ( ( bounds.getStatus( i ) == ST_INACTIVE ) && ( + // auxiliaryBounds->getStatus( i ) != ST_INACTIVE ) ) ) + + // (ckirches) force equalities active + + if ((bounds.getType(i) == ST_EQUALITY) && (bounds.getStatus(i) == ST_INACTIVE)) { + // assert ( auxiliaryBounds->getStatus( i ) != ST_INACTIVE ); + /* No check for linear independence necessary. */ + if (addBound(i, ST_LOWER, updateCholesky) != + SUCCESSFUL_RETURN) // was auxiliaryBounds->getStatus( i ) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + } + } + + /* 2) Add all equality constraints. */ + for (i = 0; i < nC; ++i) { + // if ( ( constraints.getType( i ) == ST_EQUALITY ) && ( ( constraints.getStatus( i ) == ST_INACTIVE ) + // && ( auxiliaryConstraints->getStatus( i ) != ST_INACTIVE ) ) ) + + // (ckirches) force equalities active + + if ((constraints.getType(i) == ST_EQUALITY) && (constraints.getStatus(i) == ST_INACTIVE)) { + // assert ( auxiliaryConstraints->getStatus( i ) != ST_INACTIVE ); + /* Add constraint only if it is linearly independent from the current working set. */ + if (addConstraint_checkLI(i) == RET_LINEARLY_INDEPENDENT) { + if (addConstraint(i, ST_LOWER, updateCholesky) != + SUCCESSFUL_RETURN) // was auxiliaryConstraints->getStatus( i ) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + } else { + /* Equalities are not linearly independent! */ + constraints.setType(i, ST_BOUNDED); + } + } + } + + /* 3) Add all inactive bounds that shall be active AND + * all formerly active bounds that have been active at the wrong bound. */ + for (i = 0; i < nV; ++i) { + if ((bounds.getType(i) != ST_EQUALITY) && + ((bounds.getStatus(i) == ST_INACTIVE) && (auxiliaryBounds->getStatus(i) != ST_INACTIVE))) { + /* Add bound only if it is linearly independent from the current working set. */ + if (addBound_checkLI(i) == RET_LINEARLY_INDEPENDENT) { + if (addBound(i, auxiliaryBounds->getStatus(i), updateCholesky) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + } + } + } + + /* 4) Add all inactive constraints that shall be active AND + * all formerly active constraints that have been active at the wrong bound. */ + for (i = 0; i < nC; ++i) { + if ((constraints.getType(i) != ST_EQUALITY) && (auxiliaryConstraints->getStatus(i) != ST_INACTIVE)) { + /* formerly inactive */ + if (constraints.getStatus(i) == ST_INACTIVE) { + /* Add constraint only if it is linearly independent from the current working set. */ + if (addConstraint_checkLI(i) == RET_LINEARLY_INDEPENDENT) { + if (addConstraint(i, auxiliaryConstraints->getStatus(i), updateCholesky) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + } + } + } + } + + options.enableFullLITests = was_fulli; + options.epsLITests = backupEpsLITests; + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A u x i l i a r y Q P s o l u t i o n + */ +returnValue QProblem::setupAuxiliaryQPsolution(const real_t * const xOpt, const real_t * const yOpt) +{ + int_t i, j; + int_t nV = getNV(); + int_t nC = getNC(); + + /* Setup primal/dual solution vector for auxiliary initial QP: + * if a null pointer is passed, a zero vector is assigned; + * old solution vector is kept if pointer to internal solution vector is passed. */ + if (xOpt != 0) { + if (xOpt != x) + for (i = 0; i < nV; ++i) + x[i] = xOpt[i]; + + A->times(1, 1.0, x, nV, 0.0, Ax, nC); + + for (j = 0; j < nC; ++j) { + Ax_l[j] = Ax[j]; + Ax_u[j] = Ax[j]; + } + } else { + for (i = 0; i < nV; ++i) + x[i] = 0.0; + + for (j = 0; j < nC; ++j) { + Ax[j] = 0.0; + Ax_l[j] = 0.0; + Ax_u[j] = 0.0; + } + } + + if (yOpt != 0) { + if (yOpt != y) + for (i = 0; i < nV + nC; ++i) + y[i] = yOpt[i]; + } else { + for (i = 0; i < nV + nC; ++i) + y[i] = 0.0; + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A u x i l i a r y Q P g r a d i e n t + */ +returnValue QProblem::setupAuxiliaryQPgradient() +{ + int_t i; + int_t nV = getNV(); + int_t nC = getNC(); + + /* Setup gradient vector: g = -H*x + [Id A]'*[yB yC] + * = yB - H*x + A'*yC. */ + switch (hessianType) { + case HST_ZERO: + if (usingRegularisation() == BT_FALSE) + for (i = 0; i < nV; ++i) + g[i] = y[i]; + else + for (i = 0; i < nV; ++i) + g[i] = y[i] - regVal * x[i]; + break; + + case HST_IDENTITY: + for (i = 0; i < nV; ++i) + g[i] = y[i] - x[i]; + break; + + default: + /* y'*Id */ + for (i = 0; i < nV; ++i) + g[i] = y[i]; + + /* - H*x */ + H->times(1, -1.0, x, nV, 1.0, g, nV); + break; + } + + /* + A'*yC */ + A->transTimes(1, 1.0, y + nV, nC, 1.0, g, nV); + + return SUCCESSFUL_RETURN; +} + +/* + * a r e B o u n d s C o n s i s t e n t + */ +returnValue QProblem::areBoundsConsistent(const real_t * const lb_new, + const real_t * const ub_new, + const real_t * const lbA_new, + const real_t * const ubA_new) const +{ + if (QProblemB::areBoundsConsistent(lb_new, ub_new) == RET_QP_INFEASIBLE) + return RET_QP_INFEASIBLE; + + if (lbA_new && ubA_new) { + for (int_t i = 0; i < getNC(); ++i) { + if (lbA_new[i] > ubA_new[i] + EPS) { + return RET_QP_INFEASIBLE; + } + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A u x i l i a r y Q P b o u n d s + */ +returnValue QProblem::setupAuxiliaryQPbounds(const Bounds * const auxiliaryBounds, + const Constraints * const auxiliaryConstraints, + BooleanType useRelaxation) +{ + int_t i; + int_t nV = getNV(); + int_t nC = getNC(); + + /* 1) Setup bound vectors. */ + for (i = 0; i < nV; ++i) { + switch (bounds.getStatus(i)) { + case ST_INACTIVE: + if (useRelaxation == BT_TRUE) { + if (bounds.getType(i) == ST_EQUALITY) { + lb[i] = x[i]; + ub[i] = x[i]; + } else { + /* If a bound is inactive although it was supposed to be + * active by the auxiliaryBounds, it could not be added + * due to linear dependence. Thus set it "strongly inactive". */ + if (auxiliaryBounds->getStatus(i) == ST_LOWER) + lb[i] = x[i]; + else + lb[i] = x[i] - options.boundRelaxation; + + if (auxiliaryBounds->getStatus(i) == ST_UPPER) + ub[i] = x[i]; + else + ub[i] = x[i] + options.boundRelaxation; + } + } + break; + + case ST_LOWER: + lb[i] = x[i]; + if (bounds.getType(i) == ST_EQUALITY) { + ub[i] = x[i]; + } else { + if (useRelaxation == BT_TRUE) + ub[i] = x[i] + options.boundRelaxation; + } + break; + + case ST_UPPER: + ub[i] = x[i]; + if (bounds.getType(i) == ST_EQUALITY) { + lb[i] = x[i]; + } else { + if (useRelaxation == BT_TRUE) + lb[i] = x[i] - options.boundRelaxation; + } + break; + + case ST_INFEASIBLE_LOWER: + case ST_INFEASIBLE_UPPER: + break; + + default: + return THROWERROR(RET_UNKNOWN_BUG); + } + } + + /* 2) Setup constraints vectors. */ + for (i = 0; i < nC; ++i) { + switch (constraints.getStatus(i)) { + case ST_INACTIVE: + if (useRelaxation == BT_TRUE) { + if (constraints.getType(i) == ST_EQUALITY) { + lbA[i] = Ax_l[i]; + ubA[i] = Ax_u[i]; + } else { + /* If a constraint is inactive although it was supposed to be + * active by the auxiliaryConstraints, it could not be added + * due to linear dependence. Thus set it "strongly inactive". */ + if (auxiliaryConstraints->getStatus(i) == ST_LOWER) + lbA[i] = Ax_l[i]; + else + lbA[i] = Ax_l[i] - options.boundRelaxation; + + if (auxiliaryConstraints->getStatus(i) == ST_UPPER) + ubA[i] = Ax_u[i]; + else + ubA[i] = Ax_u[i] + options.boundRelaxation; + } + } + break; + + case ST_LOWER: + lbA[i] = Ax_l[i]; + if (constraints.getType(i) == ST_EQUALITY) { + ubA[i] = Ax_l[i]; + } else { + if (useRelaxation == BT_TRUE) + ubA[i] = Ax_l[i] + options.boundRelaxation; + } + break; + + case ST_UPPER: + ubA[i] = Ax_u[i]; + if (constraints.getType(i) == ST_EQUALITY) { + lbA[i] = Ax_u[i]; + } else { + if (useRelaxation == BT_TRUE) + lbA[i] = Ax_u[i] - options.boundRelaxation; + } + break; + + case ST_INFEASIBLE_LOWER: + case ST_INFEASIBLE_UPPER: + break; + + default: + return THROWERROR(RET_UNKNOWN_BUG); + } + Ax_l[i] = Ax_l[i] - lbA[i]; + Ax_u[i] = ubA[i] - Ax_u[i]; + } + + return SUCCESSFUL_RETURN; +} + +/* + * a d d C o n s t r a i n t + */ +returnValue QProblem::addConstraint( + int_t number, SubjectToStatus C_status, BooleanType updateCholesky, BooleanType ensureLI) +{ + int_t i, j, ii; + + /* consistency checks */ + if (constraints.getStatus(number) != ST_INACTIVE) + return THROWERROR(RET_CONSTRAINT_ALREADY_ACTIVE); + + if ((constraints.getNC() - getNAC()) == constraints.getNUC()) + return THROWERROR(RET_ALL_CONSTRAINTS_ACTIVE); + + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_AUXILIARYQPSOLVED) || + (getStatus() == QPS_HOMOTOPYQPSOLVED) || (getStatus() == QPS_SOLVED)) { + return THROWERROR(RET_UNKNOWN_BUG); + } + + /* I) ENSURE LINEAR INDEPENDENCE OF THE WORKING SET, + * i.e. remove a constraint or bound if linear dependence occurs. */ + /* check for LI only if Cholesky decomposition shall be updated! */ + if (updateCholesky == BT_TRUE && ensureLI == BT_TRUE) { + returnValue ensureLIreturnvalue = addConstraint_ensureLI(number, C_status); + + switch (ensureLIreturnvalue) { + case SUCCESSFUL_RETURN: + break; + + case RET_LI_RESOLVED: + break; + + case RET_ENSURELI_FAILED_NOINDEX: + return RET_ADDCONSTRAINT_FAILED_INFEASIBILITY; + + case RET_ENSURELI_FAILED_CYCLING: + return RET_ADDCONSTRAINT_FAILED_INFEASIBILITY; + + case RET_ENSURELI_DROPPED: + return SUCCESSFUL_RETURN; + + default: + return THROWERROR(RET_ENSURELI_FAILED); + } + } + + /* some definitions */ + int_t nV = getNV(); + int_t nFR = getNFR(); + int_t nAC = getNAC(); + int_t nZ = getNZ(); + + int_t tcol = sizeT - nAC; + + int_t * FR_idx; + bounds.getFree()->getNumberArray(&FR_idx); + + real_t * aFR = new real_t[nFR]; + real_t * wZ = new real_t[nZ]; + for (i = 0; i < nZ; ++i) + wZ[i] = 0.0; + + /* II) ADD NEW ACTIVE CONSTRAINT TO MATRIX T: */ + /* 1) Add row [wZ wY] = aFR'*[Z Y] to the end of T: assign aFR. */ + A->getRow(number, bounds.getFree(), 1.0, aFR); + + /* calculate wZ */ + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + for (j = 0; j < nZ; ++j) + wZ[j] += aFR[i] * QQ(ii, j); + } + + /* 2) Calculate wY and store it directly into T. */ + if (nAC > 0) { + for (j = 0; j < nAC; ++j) + TT(nAC, tcol + j) = 0.0; + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + for (j = 0; j < nAC; ++j) + TT(nAC, tcol + j) += aFR[i] * QQ(ii, nZ + j); + } + } + + delete[] aFR; + + real_t c, s, nu; + + if (nZ > 0) { + /* II) RESTORE TRIANGULAR FORM OF T: */ + /* Use column-wise Givens rotations to restore reverse triangular form + * of T, simultanenous change of Q (i.e. Z) and R. */ + for (j = 0; j < nZ - 1; ++j) { + computeGivens(wZ[j + 1], wZ[j], wZ[j + 1], wZ[j], c, s); + nu = s / (1.0 + c); + + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + applyGivens(c, s, nu, QQ(ii, 1 + j), QQ(ii, j), QQ(ii, 1 + j), QQ(ii, j)); + } + + if ((updateCholesky == BT_TRUE) && (hessianType != HST_ZERO) && (hessianType != HST_IDENTITY)) { + for (i = 0; i <= j + 1; ++i) + applyGivens(c, s, nu, RR(i, 1 + j), RR(i, j), RR(i, 1 + j), RR(i, j)); + } + } + + TT(nAC, tcol - 1) = wZ[nZ - 1]; + + if ((updateCholesky == BT_TRUE) && (hessianType != HST_ZERO) && (hessianType != HST_IDENTITY)) { + /* III) RESTORE TRIANGULAR FORM OF R: + * Use row-wise Givens rotations to restore upper triangular form of R. */ + for (i = 0; i < nZ - 1; ++i) { + computeGivens(RR(i, i), RR(1 + i, i), RR(i, i), RR(1 + i, i), c, s); + nu = s / (1.0 + c); + + for (j = (1 + i); j < (nZ - 1); ++j) /* last column of R is thrown away */ + applyGivens(c, s, nu, RR(i, j), RR(1 + i, j), RR(i, j), RR(1 + i, j)); + } + /* last column of R is thrown away */ + for (i = 0; i < nZ; ++i) + RR(i, nZ - 1) = 0.0; + } + } + + delete[] wZ; + + /* IV) UPDATE INDICES */ + tabularOutput.idxAddC = number; + if (constraints.moveInactiveToActive(number, C_status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ADDCONSTRAINT_FAILED); + + return SUCCESSFUL_RETURN; +} + +/* + * a d d C o n s t r a i n t _ c h e c k L I + */ +returnValue QProblem::addConstraint_checkLI(int_t number) +{ + returnValue returnvalue = RET_LINEARLY_DEPENDENT; + + int_t i, j, ii; + int_t nV = getNV(); + int_t nFR = getNFR(); + int_t nZ = getNZ(); + int_t nC = getNC(); + int_t nAC = getNAC(); + int_t nFX = getNFX(); + int_t * FR_idx; + + bounds.getFree()->getNumberArray(&FR_idx); + + if (options.enableFullLITests) { + /* + * expensive LI test. Backsolve with refinement using special right + * hand side. This gives an estimate for what should be considered + * "zero". We then check linear independence relative to this estimate. + */ + + int_t *FX_idx, *AC_idx, *IAC_idx; + + real_t * delta_g = new real_t[nV]; + real_t * delta_xFX = new real_t[nFX]; + real_t * delta_xFR = new real_t[nFR]; + real_t * delta_yAC = new real_t[nAC]; + real_t * delta_yFX = new real_t[nFX]; + + bounds.getFixed()->getNumberArray(&FX_idx); + constraints.getActive()->getNumberArray(&AC_idx); + constraints.getInactive()->getNumberArray(&IAC_idx); + + int_t dim = (nC > nV) ? nC : nV; + real_t * nul = new real_t[dim]; + for (ii = 0; ii < dim; ++ii) + nul[ii] = 0.0; + + A->getRow(number, 0, 1.0, delta_g); + + // AW: I think original line overwrote correct return value + // original: returnvalue = determineStepDirection ( delta_g, + returnValue dsdreturnvalue = determineStepDirection( + delta_g, nul, nul, nul, nul, BT_FALSE, BT_FALSE, delta_xFX, delta_xFR, delta_yAC, delta_yFX); + if (dsdreturnvalue != SUCCESSFUL_RETURN) + returnvalue = dsdreturnvalue; + + delete[] nul; + + /* compute the weight in inf-norm */ + real_t weight = 0.0; + for (ii = 0; ii < nAC; ++ii) { + real_t a = getAbs(delta_yAC[ii]); + if (weight < a) + weight = a; + } + for (ii = 0; ii < nFX; ++ii) { + real_t a = getAbs(delta_yFX[ii]); + if (weight < a) + weight = a; + } + + /* look at the "zero" in a relative inf-norm */ + real_t zero = 0.0; + for (ii = 0; ii < nFX; ++ii) { + real_t a = getAbs(delta_xFX[ii]); + if (zero < a) + zero = a; + } + for (ii = 0; ii < nFR; ++ii) { + real_t a = getAbs(delta_xFR[ii]); + if (zero < a) + zero = a; + } + + /* relative test against zero in inf-norm */ + if (zero > options.epsLITests * weight) + returnvalue = RET_LINEARLY_INDEPENDENT; + + delete[] delta_yFX; + delete[] delta_yAC; + delete[] delta_xFR; + delete[] delta_xFX; + delete[] delta_g; + + } else { + /* + * cheap LI test for constraint. Check if constraint is + * linearly independent from the the active ones (<=> is element of null + * space of Afr). + */ + + real_t * Arow = new real_t[nFR]; + A->getRow(number, bounds.getFree(), 1.0, Arow); + + real_t sum, l2; + + l2 = 0.0; + for (i = 0; i < nFR; i++) + l2 += Arow[i] * Arow[i]; + + for (j = 0; j < nZ; ++j) { + sum = 0.0; + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + sum += Arow[i] * QQ(ii, j); + } + + if (getAbs(sum) > options.epsLITests * l2) { + /*fprintf(stdFile, "LI test: |sum| = %9.2e, l2 = %9.2e, var = %d\n", getAbs(sum), l2, jj+1); */ + returnvalue = RET_LINEARLY_INDEPENDENT; + break; + } + } + + delete[] Arow; + } + + return THROWINFO(returnvalue); +} + +/* + * a d d C o n s t r a i n t _ e n s u r e L I + */ +returnValue QProblem::addConstraint_ensureLI(int_t number, SubjectToStatus C_status) +{ + int_t i, j, ii, jj; + int_t nV = getNV(); + int_t nFR = getNFR(); + int_t nFX = getNFX(); + int_t nAC = getNAC(); + int_t nZ = getNZ(); + + /* I) Check if new constraint is linearly independent from the active ones. */ + returnValue returnvalueCheckLI = addConstraint_checkLI(number); + + if (returnvalueCheckLI == RET_INDEXLIST_CORRUPTED) + return THROWERROR(RET_ENSURELI_FAILED); + + if (returnvalueCheckLI == RET_LINEARLY_INDEPENDENT) + return SUCCESSFUL_RETURN; + + /* II) NEW CONSTRAINT IS LINEARLY DEPENDENT: */ + /* 1) Determine coefficients of linear combination, + * cf. M.J. Best. Applied Mathematics and Parallel Computing, chapter: + * An Algorithm for the Solution of the Parametric Quadratic Programming + * Problem, pages 57-76. Physica-Verlag, Heidelberg, 1996. */ + int_t * FR_idx; + bounds.getFree()->getNumberArray(&FR_idx); + + int_t * FX_idx; + bounds.getFixed()->getNumberArray(&FX_idx); + + real_t * xiC = new real_t[nAC]; + real_t * xiC_TMP = new real_t[nAC]; + real_t * xiB = new real_t[nFX]; + real_t * Arow = new real_t[nFR]; + real_t * num = new real_t[nV]; + + returnValue returnvalue = SUCCESSFUL_RETURN; + + real_t y_min = options.maxDualJump; + int_t y_min_number = -1; + int_t y_min_number_bound = -1; + BooleanType y_min_isBound = BT_FALSE; + + A->getRow(number, bounds.getFree(), C_status == ST_LOWER ? 1.0 : -1.0, Arow); + + /* 2) Calculate xiC */ + if (nAC > 0) { + for (i = 0; i < nAC; ++i) { + xiC_TMP[i] = 0.0; + for (j = 0; j < nFR; ++j) { + jj = FR_idx[j]; + xiC_TMP[i] += QQ(jj, nZ + i) * Arow[j]; + } + } + + if (backsolveT(xiC_TMP, BT_TRUE, xiC) != SUCCESSFUL_RETURN) { + returnvalue = RET_ENSURELI_FAILED_TQ; + goto farewell; + } + } + + /* 3) Calculate xiB. */ + int_t * AC_idx; + constraints.getActive()->getNumberArray(&AC_idx); + + A->getRow(number, bounds.getFixed(), C_status == ST_LOWER ? 1.0 : -1.0, xiB); + A->transTimes(constraints.getActive(), bounds.getFixed(), 1, -1.0, xiC, nAC, 1.0, xiB, nFX); + + /* III) DETERMINE CONSTRAINT/BOUND TO BE REMOVED. */ + + /* 1) Constraints. */ + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + num[i] = y[nV + ii]; + } + + performRatioTest( + nAC, AC_idx, &constraints, num, xiC, options.epsNum, options.epsDen, y_min, y_min_number); + + /* 2) Bounds. */ + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + num[i] = y[ii]; + } + + performRatioTest( + nFX, FX_idx, &bounds, num, xiB, options.epsNum, options.epsDen, y_min, y_min_number_bound); + + if (y_min_number_bound >= 0) { + y_min_number = y_min_number_bound; + y_min_isBound = BT_TRUE; + } + +#ifndef __SUPPRESSANYOUTPUT__ + /* setup output preferences */ + char messageString[MAX_STRING_LENGTH]; +#endif + + /* IV) REMOVE CONSTRAINT/BOUND FOR RESOLVING LINEAR DEPENDENCE: */ + if (y_min_number >= 0) { + /* Update Lagrange multiplier... */ + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + y[nV + ii] -= y_min * xiC[i]; + } + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + y[ii] -= y_min * xiB[i]; + } + + /* ... also for newly active constraint... */ + if (C_status == ST_LOWER) + y[nV + number] = y_min; + else + y[nV + number] = -y_min; + + /* ... and for constraint to be removed. */ + if (y_min_isBound == BT_TRUE) { +#ifndef __SUPPRESSANYOUTPUT__ + snprintf(messageString, MAX_STRING_LENGTH, "bound no. %d.", (int)y_min_number); + getGlobalMessageHandler()->throwInfo( + RET_REMOVE_FROM_ACTIVESET, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + if (removeBound(y_min_number, BT_TRUE, BT_FALSE, BT_FALSE) != SUCCESSFUL_RETURN) { + returnvalue = RET_REMOVE_FROM_ACTIVESET_FAILED; + goto farewell; + } + tabularOutput.excRemB = 1; + + y[y_min_number] = 0.0; + } else { +#ifndef __SUPPRESSANYOUTPUT__ + snprintf(messageString, MAX_STRING_LENGTH, "constraint no. %d.", (int)y_min_number); + getGlobalMessageHandler()->throwInfo( + RET_REMOVE_FROM_ACTIVESET, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + if (removeConstraint(y_min_number, BT_TRUE, BT_FALSE, BT_FALSE) != SUCCESSFUL_RETURN) { + returnvalue = RET_REMOVE_FROM_ACTIVESET_FAILED; + goto farewell; + } + tabularOutput.excRemC = 1; + + y[nV + y_min_number] = 0.0; + } + } else { + if (options.enableDropInfeasibles == BT_TRUE) { + /* dropping of infeasible constraints according to drop priorities */ + returnvalue = dropInfeasibles(number, C_status, BT_FALSE, xiB, xiC); + } else { + /* no constraint/bound can be removed => QP is infeasible! */ + returnvalue = RET_ENSURELI_FAILED_NOINDEX; + setInfeasibilityFlag(returnvalue); + } + } + +farewell: + delete[] num; + delete[] Arow; + delete[] xiB; + delete[] xiC_TMP; + delete[] xiC; + + getGlobalMessageHandler()->throwInfo(RET_LI_RESOLVED, 0, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); + + return ((returnvalue != SUCCESSFUL_RETURN) && (returnvalue != RET_ENSURELI_FAILED_NOINDEX)) + ? THROWERROR(returnvalue) + : returnvalue; +} + +/* + * a d d B o u n d + */ +returnValue QProblem::addBound( + int_t number, SubjectToStatus B_status, BooleanType updateCholesky, BooleanType ensureLI) +{ + int_t i, j, ii; + + /* consistency checks */ + if (bounds.getStatus(number) != ST_INACTIVE) + return THROWERROR(RET_BOUND_ALREADY_ACTIVE); + + if (getNFR() == bounds.getNUV()) + return THROWERROR(RET_ALL_BOUNDS_ACTIVE); + + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_AUXILIARYQPSOLVED) || + (getStatus() == QPS_HOMOTOPYQPSOLVED) || (getStatus() == QPS_SOLVED)) { + return THROWERROR(RET_UNKNOWN_BUG); + } + + /* I) ENSURE LINEAR INDEPENDENCE OF THE WORKING SET, + * i.e. remove a constraint or bound if linear dependence occurs. */ + /* check for LI only if Cholesky decomposition shall be updated! */ + if ((updateCholesky == BT_TRUE) && (ensureLI == BT_TRUE)) { + returnValue ensureLIreturnvalue = addBound_ensureLI(number, B_status); + + switch (ensureLIreturnvalue) { + case SUCCESSFUL_RETURN: + break; + + case RET_LI_RESOLVED: + break; + + case RET_ENSURELI_FAILED_NOINDEX: + return RET_ADDBOUND_FAILED_INFEASIBILITY; + + case RET_ENSURELI_FAILED_CYCLING: + return RET_ADDBOUND_FAILED_INFEASIBILITY; + + case RET_ENSURELI_DROPPED: + return SUCCESSFUL_RETURN; + + default: + return THROWERROR(RET_ENSURELI_FAILED); + } + } + + /* some definitions */ + int_t nV = getNV(); + int_t nFR = getNFR(); + int_t nAC = getNAC(); + int_t nZ = getNZ(); + + int_t tcol = sizeT - nAC; + + /* II) SWAP INDEXLIST OF FREE VARIABLES: + * move the variable to be fixed to the end of the list of free variables. */ + int_t lastfreenumber = bounds.getFree()->getLastNumber(); + if (lastfreenumber != number) + if (bounds.swapFree(number, lastfreenumber) != SUCCESSFUL_RETURN) + THROWERROR(RET_ADDBOUND_FAILED); + + int_t * FR_idx; + bounds.getFree()->getNumberArray(&FR_idx); + + real_t * w = new real_t[nFR]; + + /* III) ADD NEW ACTIVE BOUND TO TOP OF MATRIX T: */ + /* 1) add row [wZ wY] = [Z Y](number) at the top of T: assign w */ + for (i = 0; i < nFR; ++i) + w[i] = QQ(FR_idx[nFR - 1], i); + + /* 2) Use column-wise Givens rotations to restore reverse triangular form + * of the first row of T, simultanenous change of Q (i.e. Z) and R. */ + real_t c, s, nu; + + for (j = 0; j < nZ - 1; ++j) { + computeGivens(w[j + 1], w[j], w[j + 1], w[j], c, s); + nu = s / (1.0 + c); + + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + applyGivens(c, s, nu, QQ(ii, 1 + j), QQ(ii, j), QQ(ii, 1 + j), QQ(ii, j)); + } + + if ((updateCholesky == BT_TRUE) && (hessianType != HST_ZERO) && (hessianType != HST_IDENTITY)) { + for (i = 0; i <= j + 1; ++i) + applyGivens(c, s, nu, RR(i, 1 + j), RR(i, j), RR(i, 1 + j), RR(i, j)); + } + } + + if (nAC > 0) /* ( nAC == 0 ) <=> ( nZ == nFR ) <=> Y and T are empty => nothing to do */ + { + /* store new column a in a temporary vector instead of shifting T one column to the left */ + real_t * tmp = new real_t[nAC]; + for (i = 0; i < nAC; ++i) + tmp[i] = 0.0; + + { + j = nZ - 1; + + computeGivens(w[j + 1], w[j], w[j + 1], w[j], c, s); + nu = s / (1.0 + c); + + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + applyGivens(c, s, nu, QQ(ii, 1 + j), QQ(ii, j), QQ(ii, 1 + j), QQ(ii, j)); + } + + applyGivens(c, s, nu, TT(nAC - 1, tcol), tmp[nAC - 1], tmp[nAC - 1], TT(nAC - 1, tcol)); + } + + for (j = nZ; j < nFR - 1; ++j) { + computeGivens(w[j + 1], w[j], w[j + 1], w[j], c, s); + nu = s / (1.0 + c); + + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + applyGivens(c, s, nu, QQ(ii, 1 + j), QQ(ii, j), QQ(ii, 1 + j), QQ(ii, j)); + } + + for (i = (nFR - 2 - j); i < nAC; ++i) + applyGivens(c, s, nu, TT(i, 1 + tcol - nZ + j), tmp[i], tmp[i], TT(i, 1 + tcol - nZ + j)); + } + + delete[] tmp; + } + + delete[] w; + + if ((updateCholesky == BT_TRUE) && (hessianType != HST_ZERO) && (hessianType != HST_IDENTITY)) { + /* IV) RESTORE TRIANGULAR FORM OF R: + * use row-wise Givens rotations to restore upper triangular form of R */ + for (i = 0; i < nZ - 1; ++i) { + computeGivens(RR(i, i), RR(1 + i, i), RR(i, i), RR(1 + i, i), c, s); + nu = s / (1.0 + c); + + for (j = (1 + i); j < nZ - 1; ++j) /* last column of R is thrown away */ + applyGivens(c, s, nu, RR(i, j), RR(1 + i, j), RR(i, j), RR(1 + i, j)); + } + /* last column of R is thrown away */ + for (i = 0; i < nZ; ++i) + RR(i, nZ - 1) = 0.0; + } + + /* V) UPDATE INDICES */ + tabularOutput.idxAddB = number; + if (bounds.moveFreeToFixed(number, B_status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ADDBOUND_FAILED); + + return SUCCESSFUL_RETURN; +} + +/* + * a d d B o u n d _ c h e c k L I + */ +returnValue QProblem::addBound_checkLI(int_t number) +{ + int_t i, ii; + int_t nV = getNV(); /* for QQ() macro */ + int_t nFR = getNFR(); + int_t nAC = getNAC(); + int_t nFX = getNFX(); + int_t nC = getNC(); + returnValue returnvalue = RET_LINEARLY_DEPENDENT; + + if (options.enableFullLITests) { + /* + * expensive LI test. Backsolve with refinement using special right + * hand side. This gives an estimate for what should be considered + * "zero". We then check linear independence relative to this estimate. + */ + + /* + * expensive LI test. Backsolve with refinement using special right + * hand side. This gives an estimate for what should be considered + * "zero". We then check linear independence relative to this estimate. + */ + + real_t * delta_g = new real_t[nV]; + real_t * delta_xFX = new real_t[nFX]; + real_t * delta_xFR = new real_t[nFR]; + real_t * delta_yAC = new real_t[nAC]; + real_t * delta_yFX = new real_t[nFX]; + + for (ii = 0; ii < nV; ++ii) + delta_g[ii] = 0.0; + delta_g[number] = 1.0; /* sign doesn't matter here */ + + int_t dim = (nC > nV) ? nC : nV; + real_t * nul = new real_t[dim]; + for (ii = 0; ii < dim; ++ii) + nul[ii] = 0.0; + + returnValue dsdReturnValue = determineStepDirection( + delta_g, nul, nul, nul, nul, BT_FALSE, BT_FALSE, delta_xFX, delta_xFR, delta_yAC, delta_yFX); + if (dsdReturnValue != SUCCESSFUL_RETURN) + returnvalue = dsdReturnValue; + + /* compute the weight in inf-norm */ + real_t weight = 0.0; + for (ii = 0; ii < nAC; ++ii) { + real_t a = getAbs(delta_yAC[ii]); + if (weight < a) + weight = a; + } + for (ii = 0; ii < nFX; ++ii) { + real_t a = getAbs(delta_yFX[ii]); + if (weight < a) + weight = a; + } + + /* look at the "zero" in a relative inf-norm */ + real_t zero = 0.0; + for (ii = 0; ii < nFX; ++ii) { + real_t a = getAbs(delta_xFX[ii]); + if (zero < a) + zero = a; + } + for (ii = 0; ii < nFR; ++ii) { + real_t a = getAbs(delta_xFR[ii]); + if (zero < a) + zero = a; + } + + /* relative test against zero in inf-norm */ + if (zero > options.epsLITests * weight) + returnvalue = RET_LINEARLY_INDEPENDENT; + + delete[] nul; + delete[] delta_yFX; + delete[] delta_yAC; + delete[] delta_xFR; + delete[] delta_xFX; + delete[] delta_g; + + } else { + /* + * cheap LI test for simple bound. Check if constraint is + * linearly independent from the the active ones (<=> is element of null + * space of Afr). + */ + + /* some definitions */ + int_t nZ = getNZ(); + + for (i = 0; i < nZ; ++i) + if (getAbs(QQ(number, i)) > options.epsLITests) { + returnvalue = RET_LINEARLY_INDEPENDENT; + break; + } + } + + return THROWINFO(returnvalue); +} + +/* + * a d d B o u n d _ e n s u r e L I + */ +returnValue QProblem::addBound_ensureLI(int_t number, SubjectToStatus B_status) +{ + int_t i, ii; + int_t nV = getNV(); + int_t nFX = getNFX(); + int_t nAC = getNAC(); + int_t nZ = getNZ(); + + /* I) Check if new constraint is linearly independent from the active ones. */ + returnValue returnvalueCheckLI = addBound_checkLI(number); + + if (returnvalueCheckLI == RET_INDEXLIST_CORRUPTED) + return THROWERROR(RET_ENSURELI_FAILED); + + if (returnvalueCheckLI == RET_LINEARLY_INDEPENDENT) + return SUCCESSFUL_RETURN; + + /* II) NEW BOUND IS LINEARLY DEPENDENT: */ + /* 1) Determine coefficients of linear combination, + * cf. M.J. Best. Applied Mathematics and Parallel Computing, chapter: + * An Algorithm for the Solution of the Parametric Quadratic Programming + * Problem, pages 57-76. Physica-Verlag, Heidelberg, 1996. */ + int_t * FR_idx; + bounds.getFree()->getNumberArray(&FR_idx); + + int_t * FX_idx; + bounds.getFixed()->getNumberArray(&FX_idx); + + int_t * AC_idx; + constraints.getActive()->getNumberArray(&AC_idx); + + real_t * xiC = new real_t[nAC]; + real_t * xiC_TMP = new real_t[nAC]; + real_t * xiB = new real_t[nFX]; + real_t * num = new real_t[nV]; + + real_t y_min = options.maxDualJump; + int_t y_min_number = -1; + int_t y_min_number_bound = -1; + BooleanType y_min_isBound = BT_FALSE; + + returnValue returnvalue = SUCCESSFUL_RETURN; + + /* 2) Calculate xiC. */ + if (nAC > 0) { + if (B_status == ST_LOWER) { + for (i = 0; i < nAC; ++i) + xiC_TMP[i] = QQ(number, nZ + i); + } else { + for (i = 0; i < nAC; ++i) + xiC_TMP[i] = -QQ(number, nZ + i); + } + + if (backsolveT(xiC_TMP, BT_TRUE, xiC) != SUCCESSFUL_RETURN) { + returnvalue = RET_ENSURELI_FAILED_TQ; + goto farewell; + } + } + + /* 3) Calculate xiB. */ + A->transTimes(constraints.getActive(), bounds.getFixed(), 1, -1.0, xiC, nAC, 0.0, xiB, nFX); + + /* III) DETERMINE CONSTRAINT/BOUND TO BE REMOVED. */ + + /* 1) Constraints. */ + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + num[i] = y[nV + ii]; + } + + performRatioTest( + nAC, AC_idx, &constraints, num, xiC, options.epsNum, options.epsDen, y_min, y_min_number); + + /* 2) Bounds. */ + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + num[i] = y[ii]; + } + + performRatioTest( + nFX, FX_idx, &bounds, num, xiB, options.epsNum, options.epsDen, y_min, y_min_number_bound); + + if (y_min_number_bound >= 0) { + y_min_number = y_min_number_bound; + y_min_isBound = BT_TRUE; + } + +/* IV) REMOVE CONSTRAINT/BOUND FOR RESOLVING LINEAR DEPENDENCE: */ +#ifndef __SUPPRESSANYOUTPUT__ + char messageString[MAX_STRING_LENGTH]; +#endif + + if (y_min_number >= 0) { + /* Update Lagrange multiplier... */ + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + y[nV + ii] -= y_min * xiC[i]; + } + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + y[ii] -= y_min * xiB[i]; + } + + /* ... also for newly active bound ... */ + if (B_status == ST_LOWER) + y[number] = y_min; + else + y[number] = -y_min; + + /* ... and for bound to be removed. */ + if (y_min_isBound == BT_TRUE) { +#ifndef __SUPPRESSANYOUTPUT__ + snprintf(messageString, MAX_STRING_LENGTH, "bound no. %d.", (int)y_min_number); + getGlobalMessageHandler()->throwInfo( + RET_REMOVE_FROM_ACTIVESET, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + if (removeBound(y_min_number, BT_TRUE, BT_FALSE, BT_FALSE) != SUCCESSFUL_RETURN) { + returnvalue = RET_REMOVE_FROM_ACTIVESET_FAILED; + goto farewell; + } + tabularOutput.excRemB = 1; + + y[y_min_number] = 0.0; + } else { +#ifndef __SUPPRESSANYOUTPUT__ + snprintf(messageString, MAX_STRING_LENGTH, "constraint no. %d.", (int)y_min_number); + getGlobalMessageHandler()->throwInfo( + RET_REMOVE_FROM_ACTIVESET, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + if (removeConstraint(y_min_number, BT_TRUE, BT_FALSE, BT_FALSE) != SUCCESSFUL_RETURN) { + returnvalue = RET_REMOVE_FROM_ACTIVESET_FAILED; + goto farewell; + } + tabularOutput.excRemC = 1; + + y[nV + y_min_number] = 0.0; + } + } else { + if (options.enableDropInfeasibles == BT_TRUE) { + /* dropping of infeasible constraints according to drop priorities */ + returnvalue = dropInfeasibles(number, B_status, BT_TRUE, xiB, xiC); + } else { + /* no constraint/bound can be removed => QP is infeasible! */ + returnvalue = RET_ENSURELI_FAILED_NOINDEX; + setInfeasibilityFlag(returnvalue); + } + } + +farewell: + delete[] num; + delete[] xiB; + delete[] xiC_TMP; + delete[] xiC; + + getGlobalMessageHandler()->throwInfo(RET_LI_RESOLVED, 0, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); + + return ((returnvalue != SUCCESSFUL_RETURN) && (returnvalue != RET_ENSURELI_FAILED_NOINDEX)) + ? THROWERROR(returnvalue) + : returnvalue; +} + +/* + * r e m o v e C o n s t r a i n t + */ +returnValue QProblem::removeConstraint( + int_t number, BooleanType updateCholesky, BooleanType allowFlipping, BooleanType ensureNZC) +{ + int_t i, j, ii, jj; + returnValue returnvalue = SUCCESSFUL_RETURN; + BooleanType hasFlipped = BT_FALSE; + + /* consistency check */ + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_AUXILIARYQPSOLVED) || + (getStatus() == QPS_HOMOTOPYQPSOLVED) || (getStatus() == QPS_SOLVED)) { + return THROWERROR(RET_UNKNOWN_BUG); + } + + /* some definitions */ + int_t nV = getNV(); + int_t nFR = getNFR(); + int_t nAC = getNAC(); + int_t nZ = getNZ(); + + int_t tcol = sizeT - nAC; + int_t number_idx = constraints.getActive()->getIndex(number); + + int_t addIdx; + BooleanType addBoundNotConstraint; + SubjectToStatus addStatus; + BooleanType exchangeHappened = BT_FALSE; + + /* consistency checks */ + if (constraints.getStatus(number) == ST_INACTIVE) + return THROWERROR(RET_CONSTRAINT_NOT_ACTIVE); + + if ((number_idx < 0) || (number_idx >= nAC)) + return THROWERROR(RET_CONSTRAINT_NOT_ACTIVE); + + int_t * FR_idx; + bounds.getFree()->getNumberArray(&FR_idx); + + /* N) PERFORM ZERO CURVATURE TEST. */ + if (ensureNZC == BT_TRUE) { + returnvalue = + ensureNonzeroCurvature(BT_FALSE, number, exchangeHappened, addBoundNotConstraint, addIdx, addStatus); + + if (returnvalue != SUCCESSFUL_RETURN) + return returnvalue; + } + + /* save index sets and decompositions for flipping bounds strategy */ + if ((exchangeHappened == BT_FALSE) && (options.enableFlippingBounds == BT_TRUE) && + (allowFlipping == BT_TRUE)) + flipper.set(&bounds, R, &constraints, Q, T); + + /* I) REMOVE th ROW FROM T, + * i.e. shift rows number+1 through nAC upwards (instead of the actual + * constraint number its corresponding index within matrix A is used). */ + if (number_idx < nAC - 1) { + for (i = (number_idx + 1); i < nAC; ++i) + for (j = (nAC - i - 1); j < nAC; ++j) + TT(i - 1, tcol + j) = TT(i, tcol + j); + /* gimmick: write zeros into the last row of T */ + for (j = 0; j < nAC; ++j) + TT(nAC - 1, tcol + j) = 0.0; + + /* II) RESTORE TRIANGULAR FORM OF T, + * use column-wise Givens rotations to restore reverse triangular form + * of T simultanenous change of Q (i.e. Y). */ + real_t c, s, nu; + + for (j = (nAC - 2 - number_idx); j >= 0; --j) { + computeGivens(TT(nAC - 2 - j, tcol + 1 + j), + TT(nAC - 2 - j, tcol + j), + TT(nAC - 2 - j, tcol + 1 + j), + TT(nAC - 2 - j, tcol + j), + c, + s); + nu = s / (1.0 + c); + + for (i = (nAC - j - 1); i < (nAC - 1); ++i) + applyGivens(c, s, nu, TT(i, tcol + 1 + j), TT(i, tcol + j), TT(i, tcol + 1 + j), TT(i, tcol + j)); + + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + applyGivens(c, s, nu, QQ(ii, nZ + 1 + j), QQ(ii, nZ + j), QQ(ii, nZ + 1 + j), QQ(ii, nZ + j)); + } + } + } else { + /* gimmick: write zeros into the last row of T */ + for (j = 0; j < nAC; ++j) + TT(nAC - 1, tcol + j) = 0.0; + } + + if ((updateCholesky == BT_TRUE) && (hessianType != HST_ZERO) && (hessianType != HST_IDENTITY)) { + /* III) UPDATE CHOLESKY DECOMPOSITION, + * calculate new additional column (i.e. [r sqrt(rho2)]') + * of the Cholesky factor R. */ + real_t * Hz = new real_t[nFR]; + real_t * z = new real_t[nFR]; + real_t rho2 = 0.0; + + /* 1) Calculate Hz = H*z, where z is the new rightmost column of Z + * (i.e. the old leftmost column of Y). */ + for (j = 0; j < nFR; ++j) + z[j] = QQ(FR_idx[j], nZ); + H->times(bounds.getFree(), bounds.getFree(), 1, 1.0, z, nFR, 0.0, Hz, nFR); + delete[] z; + + if (nZ > 0) { + real_t * ZHz = new real_t[nZ]; + for (i = 0; i < nZ; ++i) + ZHz[i] = 0.0; + real_t * r = new real_t[nZ]; + + /* 2) Calculate ZHz = Z'*Hz (old Z). */ + for (j = 0; j < nFR; ++j) { + jj = FR_idx[j]; + + for (i = 0; i < nZ; ++i) + ZHz[i] += QQ(jj, i) * Hz[j]; + } + + /* 3) Calculate r = R^-T * ZHz. */ + if (backsolveR(ZHz, BT_TRUE, r) != SUCCESSFUL_RETURN) { + delete[] Hz; + delete[] r; + delete[] ZHz; + return THROWERROR(RET_REMOVECONSTRAINT_FAILED); + } + + /* 4) Calculate rho2 = rho^2 = z'*Hz - r'*r + * and store r into R. */ + for (i = 0; i < nZ; ++i) { + rho2 -= r[i] * r[i]; + RR(i, nZ) = r[i]; + } + + delete[] r; + delete[] ZHz; + } + + /* 5) Store rho into R. */ + for (j = 0; j < nFR; ++j) + rho2 += QQ(FR_idx[j], nZ) * Hz[j]; + + delete[] Hz; + + if ((options.enableFlippingBounds == BT_TRUE) && (allowFlipping == BT_TRUE) && + (exchangeHappened == BT_FALSE)) { + if (rho2 > options.epsFlipping) + RR(nZ, nZ) = getSqrt(rho2); + else { + hessianType = HST_SEMIDEF; + + flipper.get(&bounds, R, &constraints, Q, T); + constraints.flipFixed(number); + tabularOutput.idxAddC = number; + tabularOutput.excAddC = 2; + + switch (constraints.getStatus(number)) { + case ST_LOWER: + lbA[number] = ubA[number]; + Ax_l[number] = -Ax_u[number]; + break; + case ST_UPPER: + ubA[number] = lbA[number]; + Ax_u[number] = -Ax_l[number]; + break; + default: + return THROWERROR(RET_MOVING_BOUND_FAILED); + } + + hasFlipped = BT_TRUE; + } + } else if (exchangeHappened == BT_FALSE) { + if (rho2 > ZERO) + RR(nZ, nZ) = getSqrt(rho2); + else { + if (allowFlipping == BT_FALSE) { + RR(nZ, nZ) = 100.0 * EPS; + } else { + hessianType = HST_SEMIDEF; + return THROWERROR(RET_HESSIAN_NOT_SPD); + } + } + } + } + + /* IV) UPDATE INDICES */ + tabularOutput.idxRemC = number; + if (hasFlipped == BT_FALSE) { + if (constraints.moveActiveToInactive(number) != SUCCESSFUL_RETURN) + return THROWERROR(RET_REMOVECONSTRAINT_FAILED); + } + + if (exchangeHappened == BT_TRUE) { + /* add bound or constraint */ + + /* hessianType = HST_SEMIDEF; */ + RR(nZ, nZ) = 0.0; + + if (addBoundNotConstraint) { + addBound(addIdx, addStatus, BT_TRUE, BT_FALSE); + tabularOutput.excAddB = 1; + } else { + addConstraint(addIdx, addStatus, BT_TRUE, BT_FALSE); + tabularOutput.excAddC = 1; + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * r e m o v e B o u n d + */ +returnValue QProblem::removeBound( + int_t number, BooleanType updateCholesky, BooleanType allowFlipping, BooleanType ensureNZC) +{ + int_t i, j, ii, jj; + returnValue returnvalue = SUCCESSFUL_RETURN; + int_t addIdx; + BooleanType addBoundNotConstraint; + SubjectToStatus addStatus; + BooleanType exchangeHappened = BT_FALSE; + + /* consistency checks */ + if (bounds.getStatus(number) == ST_INACTIVE) + return THROWERROR(RET_BOUND_NOT_ACTIVE); + + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_AUXILIARYQPSOLVED) || + (getStatus() == QPS_HOMOTOPYQPSOLVED) || (getStatus() == QPS_SOLVED)) { + return THROWERROR(RET_UNKNOWN_BUG); + } + + /* some definitions */ + int_t nV = getNV(); + int_t nFR = getNFR(); + int_t nAC = getNAC(); + int_t nZ = getNZ(); + + int_t tcol = sizeT - nAC; + + /* 0) PERFORM ZERO CURVATURE TEST. */ + if (ensureNZC == BT_TRUE) { + returnvalue = + ensureNonzeroCurvature(BT_TRUE, number, exchangeHappened, addBoundNotConstraint, addIdx, addStatus); + + if (returnvalue != SUCCESSFUL_RETURN) + return returnvalue; + } + + /* save index sets and decompositions for flipping bounds strategy */ + if ((options.enableFlippingBounds == BT_TRUE) && (allowFlipping == BT_TRUE) && + (exchangeHappened == BT_FALSE)) + flipper.set(&bounds, R, &constraints, Q, T); + + /* I) UPDATE INDICES */ + tabularOutput.idxRemB = number; + if (bounds.moveFixedToFree(number) != SUCCESSFUL_RETURN) + return THROWERROR(RET_REMOVEBOUND_FAILED); + + int_t * FR_idx; + bounds.getFree()->getNumberArray(&FR_idx); + + /* I) APPEND th UNITY VECTOR TO Q. */ + int_t nnFRp1 = FR_idx[nFR]; + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + QQ(ii, nFR) = 0.0; + QQ(nnFRp1, i) = 0.0; + } + QQ(nnFRp1, nFR) = 1.0; + + if (nAC > 0) { + /* store new column a in a temporary vector instead of shifting T one column to the left and appending a + */ + int_t * AC_idx; + constraints.getActive()->getNumberArray(&AC_idx); + + real_t * tmp = new real_t[nAC]; + A->getCol(number, constraints.getActive(), 1.0, tmp); + + /* II) RESTORE TRIANGULAR FORM OF T, + * use column-wise Givens rotations to restore reverse triangular form + * of T = [T A(:,number)], simultanenous change of Q (i.e. Y and Z). */ + real_t c, s, nu; + + for (j = (nAC - 1); j >= 0; --j) { + computeGivens( + tmp[nAC - 1 - j], TT(nAC - 1 - j, tcol + j), TT(nAC - 1 - j, tcol + j), tmp[nAC - 1 - j], c, s); + nu = s / (1.0 + c); + + for (i = (nAC - j); i < nAC; ++i) + applyGivens(c, s, nu, tmp[i], TT(i, tcol + j), TT(i, tcol + j), tmp[i]); + + for (i = 0; i <= nFR; ++i) { + ii = FR_idx[i]; + /* nZ+1+nAC = nFR+1 / nZ+(1) = nZ+1 */ + applyGivens(c, s, nu, QQ(ii, nZ + 1 + j), QQ(ii, nZ + j), QQ(ii, nZ + 1 + j), QQ(ii, nZ + j)); + } + } + + delete[] tmp; + } + + if ((updateCholesky == BT_TRUE) && (hessianType != HST_ZERO) && (hessianType != HST_IDENTITY)) { + /* III) UPDATE CHOLESKY DECOMPOSITION, + * calculate new additional column (i.e. [r sqrt(rho2)]') + * of the Cholesky factor R: */ + real_t z2 = QQ(nnFRp1, nZ); + real_t rho2 = H->diag(nnFRp1) * z2 * z2; + + if (nFR > 0) { + /* Attention: Index list of free variables has already grown by one! */ + real_t * Hz = new real_t[nFR + 1]; + real_t * z = new real_t[nFR + 1]; + /* 1) Calculate R'*r = Zfr'*Hfr*z1 + z2*Zfr'*h1 =: Zfr'*Hz + z2*Zfr'*h1 =: rhs and + * rho2 = z1'*Hfr*z1 + 2*z2*h1'*z1 + h2*z2^2 - r'*r =: z1'*Hz + 2*z2*h1'*z1 + h2*z2^2 - r'r */ + for (j = 0; j < nFR; ++j) + z[j] = QQ(FR_idx[j], nZ); + z[nFR] = 0.0; + + H->times(bounds.getFree(), bounds.getFree(), 1, 1.0, z, nFR + 1, 0.0, Hz, nFR + 1); + H->getCol(nnFRp1, bounds.getFree(), 1.0, z); + + if (nZ > 0) { + real_t * r = new real_t[nZ]; + real_t * rhs = new real_t[nZ]; + for (i = 0; i < nZ; ++i) + rhs[i] = 0.0; + + /* 2) Calculate rhs. */ + for (j = 0; j < nFR; ++j) { + jj = FR_idx[j]; + for (i = 0; i < nZ; ++i) + /* Zfr' * ( Hz + z2*h1 ) */ + rhs[i] += QQ(jj, i) * (Hz[j] + z2 * z[j]); + } + + /* 3) Calculate r = R^-T * rhs. */ + if (backsolveR(rhs, BT_TRUE, BT_TRUE, r) != SUCCESSFUL_RETURN) { + delete[] z; + delete[] Hz; + delete[] r; + delete[] rhs; + return THROWERROR(RET_REMOVEBOUND_FAILED); + } + + /* 4) Calculate rho2 = rho^2 = z'*Hz - r'*r + * and store r into R. */ + for (i = 0; i < nZ; ++i) { + rho2 -= r[i] * r[i]; + RR(i, nZ) = r[i]; + } + + delete[] rhs; + delete[] r; + } + + for (j = 0; j < nFR; ++j) { + jj = FR_idx[j]; + /* z1' * ( Hz + 2*z2*h1 ) */ + rho2 += QQ(jj, nZ) * (Hz[j] + 2.0 * z2 * z[j]); + } + + delete[] z; + delete[] Hz; + } + + /* 5) Store rho into R. */ + if ((options.enableFlippingBounds == BT_TRUE) && (allowFlipping == BT_TRUE) && + (exchangeHappened == BT_FALSE)) { + if (rho2 > options.epsFlipping) + RR(nZ, nZ) = getSqrt(rho2); + else { + if (hessianType != HST_ZERO) + hessianType = HST_SEMIDEF; + + flipper.get(&bounds, R, &constraints, Q, T); + bounds.flipFixed(number); + tabularOutput.idxAddB = number; + tabularOutput.excAddB = 2; + + switch (bounds.getStatus(number)) { + case ST_LOWER: + lb[number] = ub[number]; + break; + case ST_UPPER: + ub[number] = lb[number]; + break; + default: + return THROWERROR(RET_MOVING_BOUND_FAILED); + } + } + } else if (exchangeHappened == BT_FALSE) { + if (rho2 > ZERO) + RR(nZ, nZ) = getSqrt(rho2); + else { + if (allowFlipping == BT_FALSE) + RR(nZ, nZ) = 100.0 * EPS; + else { + hessianType = HST_SEMIDEF; + return THROWERROR(RET_HESSIAN_NOT_SPD); + } + } + } else { + /* add bound or constraint */ + + /* hessianType = HST_SEMIDEF; */ + RR(nZ, nZ) = 0.0; + + if (addBoundNotConstraint) { + addBound(addIdx, addStatus, BT_TRUE, BT_FALSE); + tabularOutput.excAddB = 1; + } else { + addConstraint(addIdx, addStatus, BT_TRUE, BT_FALSE); + tabularOutput.excAddC = 1; + } + } + } + + return SUCCESSFUL_RETURN; +} + +returnValue QProblem::performPlainRatioTest(int_t nIdx, + const int_t * const idxList, + const real_t * const num, + const real_t * const den, + real_t epsNum, + real_t epsDen, + real_t & t, + int_t & BC_idx) const +{ + int_t i; + for (i = 0; i < nIdx; i++) + if ((num[i] > epsNum) && (den[i] > epsDen) && (t * den[i] > num[i])) { + t = num[i] / den[i]; + BC_idx = idxList[i]; + } + + return SUCCESSFUL_RETURN; +} + +returnValue QProblem::ensureNonzeroCurvature(BooleanType removeBoundNotConstraint, + int_t remIdx, + BooleanType & exchangeHappened, + BooleanType & addBoundNotConstraint, + int_t & addIdx, + SubjectToStatus & addStatus) +{ + int_t i, ii; + int_t addLBndIdx = -1, addLCnstrIdx = -1, addUBndIdx = -1, addUCnstrIdx = -1; /* exchange indices */ + int_t *FX_idx, *AC_idx, *IAC_idx; + returnValue returnvalue = SUCCESSFUL_RETURN; + + int_t nV = getNV(); + int_t nFR = getNFR(); + int_t nAC = getNAC(); + int_t nC = getNC(); + int_t nFX = getNFX(); + int_t nIAC = getNIAC(); + + int_t * FR_idx; + bounds.getFree()->getNumberArray(&FR_idx); + + // real_t *delta_g = new real_t[nV]; + real_t * delta_xFX = new real_t[nFX]; + real_t * delta_xFR = new real_t[nFR]; + real_t * delta_yAC = new real_t[nAC]; + real_t * delta_yFX = new real_t[nFX]; + + bounds.getFixed()->getNumberArray(&FX_idx); + constraints.getActive()->getNumberArray(&AC_idx); + constraints.getInactive()->getNumberArray(&IAC_idx); + + addBoundNotConstraint = BT_TRUE; + addStatus = ST_INACTIVE; + exchangeHappened = BT_FALSE; + + if (removeBoundNotConstraint) { + int_t dim = nV < nC ? nC : nV; + real_t * nul = new real_t[dim]; + real_t * ek = new real_t[nV]; /* minus e_k (bound k is removed) */ + for (ii = 0; ii < dim; ++ii) + nul[ii] = 0.0; + for (ii = 0; ii < nV; ++ii) + ek[ii] = 0.0; + ek[remIdx] = bounds.getStatus(remIdx) == ST_LOWER ? 1.0 : -1.0; + + returnvalue = determineStepDirection( + nul, nul, nul, ek, ek, BT_FALSE, BT_FALSE, delta_xFX, delta_xFR, delta_yAC, delta_yFX); + delete[] ek; + delete[] nul; + } else { + real_t * nul = new real_t[nV]; + real_t * ek = new real_t[nC]; /* minus e_k (constraint k is removed) */ + for (ii = 0; ii < nV; ++ii) + nul[ii] = 0.0; + for (ii = 0; ii < nC; ++ii) + ek[ii] = 0.0; + ek[remIdx] = constraints.getStatus(remIdx) == ST_LOWER ? 1.0 : -1.0; + + returnvalue = determineStepDirection( + nul, ek, ek, nul, nul, BT_FALSE, BT_TRUE, delta_xFX, delta_xFR, delta_yAC, delta_yFX); + delete[] ek; + delete[] nul; + } + + /* compute the weight in inf-norm */ + real_t normXi = 0.0; + for (ii = 0; ii < nAC; ++ii) { + real_t a = getAbs(delta_yAC[ii]); + if (normXi < a) + normXi = a; + } + for (ii = 0; ii < nFX; ++ii) { + real_t a = getAbs(delta_yFX[ii]); + if (normXi < a) + normXi = a; + } + + /* look at the "zero" in a relative inf-norm */ + real_t normS = 0.0; + for (ii = 0; ii < nFX; ++ii) { + real_t a = getAbs(delta_xFX[ii]); + if (normS < a) + normS = a; + } + for (ii = 0; ii < nFR; ++ii) { + real_t a = getAbs(delta_xFR[ii]); + if (normS < a) + normS = a; + } + + /* relative test against zero in inf-norm */ + if (normXi < options.epsNZCTests * normS) { + /* determine jump in x via ratio tests */ + real_t sigmaLBnd, sigmaLCnstr, sigmaUBnd, sigmaUCnstr, sigma; + + /* bounds */ + + /* compress x-u */ + real_t * x_W = new real_t[getMax(1, nFR)]; + for (i = 0; i < nFR; i++) { + ii = FR_idx[i]; + x_W[i] = ub[ii] - x[ii]; + } + /* performRatioTest( nFR,FR_idx,&bounds, x_W,delta_xFR, options.epsNum,options.epsDen, + * sigmaUBnd,addUBndIdx ); */ + sigmaUBnd = options.maxPrimalJump; + addUBndIdx = -1; + performPlainRatioTest( + nFR, FR_idx, x_W, delta_xFR, options.epsNum, options.epsDen, sigmaUBnd, addUBndIdx); + if (removeBoundNotConstraint == BT_TRUE && bounds.getStatus(remIdx) == ST_LOWER) { + /* also consider bound which is to be removed */ + real_t one = 1.0; + x_W[0] = ub[remIdx] - x[remIdx]; + performPlainRatioTest(1, &remIdx, x_W, &one, options.epsNum, options.epsDen, sigmaUBnd, addUBndIdx); + } + + /* compress x-l */ + for (i = 0; i < nFR; i++) { + ii = FR_idx[i]; + x_W[i] = x[ii] - lb[ii]; + } + for (i = 0; i < nFR; i++) + delta_xFR[i] = -delta_xFR[i]; + /* performRatioTest( nFR,FR_idx,&bounds, x_W,delta_xFR, options.epsNum,options.epsDen, + * sigmaLBnd,addLBndIdx ); */ + sigmaLBnd = options.maxPrimalJump; + addLBndIdx = -1; + performPlainRatioTest( + nFR, FR_idx, x_W, delta_xFR, options.epsNum, options.epsDen, sigmaLBnd, addLBndIdx); + if (removeBoundNotConstraint == BT_TRUE && bounds.getStatus(remIdx) == ST_UPPER) { + /* also consider bound which is to be removed */ + real_t one = 1.0; + x_W[0] = x[remIdx] - lb[remIdx]; + performPlainRatioTest(1, &remIdx, x_W, &one, options.epsNum, options.epsDen, sigmaLBnd, addLBndIdx); + } + for (i = 0; i < nFR; i++) + delta_xFR[i] = -delta_xFR[i]; + + delete[] x_W; + + /* constraints */ + + /* compute As (compressed to inactive constraints) */ + real_t * As = new real_t[nIAC]; + A->times(constraints.getInactive(), bounds.getFixed(), 1, 1.0, delta_xFX, nFX, 0.0, As, nIAC); + A->times(constraints.getInactive(), bounds.getFree(), 1, 1.0, delta_xFR, nFR, 1.0, As, nIAC); + + /* compress Ax_u */ + real_t * Ax_W = new real_t[nIAC]; + for (i = 0; i < nIAC; i++) { + ii = IAC_idx[i]; + Ax_W[i] = Ax_u[ii]; + } + /* performRatioTest( nIAC,IAC_idx,&constraints, Ax_W,As, options.epsNum,options.epsDen, + * sigmaUCnstr,addUCnstrIdx ); */ + sigmaUCnstr = options.maxPrimalJump; + addUCnstrIdx = -1; + performPlainRatioTest( + nIAC, IAC_idx, Ax_W, As, options.epsNum, options.epsDen, sigmaUCnstr, addUCnstrIdx); + if (removeBoundNotConstraint == BT_FALSE && constraints.getStatus(remIdx) == ST_LOWER) { + /* also consider constraint which is to be removed */ + real_t one = 1.0; + performPlainRatioTest( + 1, &remIdx, &Ax_u[remIdx], &one, options.epsNum, options.epsDen, sigmaUCnstr, addUCnstrIdx); + } + + /* compress Ax_l */ + for (i = 0; i < nIAC; i++) { + ii = IAC_idx[i]; + Ax_W[i] = Ax_l[ii]; + } + for (i = 0; i < nIAC; i++) + As[i] = -As[i]; + /* performRatioTest( nIAC,IAC_idx,&constraints, Ax_W,As, options.epsNum,options.epsDen, + * sigmaLCnstr,addLCnstrIdx ); */ + sigmaLCnstr = options.maxPrimalJump; + addLCnstrIdx = -1; + performPlainRatioTest( + nIAC, IAC_idx, Ax_W, As, options.epsNum, options.epsDen, sigmaLCnstr, addLCnstrIdx); + if (removeBoundNotConstraint == BT_FALSE && constraints.getStatus(remIdx) == ST_UPPER) { + /* also consider constraint which is to be removed */ + real_t one = 1.0; + performPlainRatioTest( + 1, &remIdx, &Ax_l[remIdx], &one, options.epsNum, options.epsDen, sigmaLCnstr, addLCnstrIdx); + } + + /* perform primal jump */ + sigma = options.maxPrimalJump; + if (sigmaUCnstr < sigma) { + sigma = sigmaUCnstr; + addStatus = ST_UPPER; + addBoundNotConstraint = BT_FALSE; + addIdx = addUCnstrIdx; + } + if (sigmaLCnstr < sigma) { + sigma = sigmaLCnstr; + addStatus = ST_LOWER; + addBoundNotConstraint = BT_FALSE; + addIdx = addLCnstrIdx; + } + if (sigmaUBnd < sigma) { + sigma = sigmaUBnd; + addStatus = ST_UPPER; + addBoundNotConstraint = BT_TRUE; + addIdx = addUBndIdx; + } + if (sigmaLBnd < sigma) { + sigma = sigmaLBnd; + addStatus = ST_LOWER; + addBoundNotConstraint = BT_TRUE; + addIdx = addLBndIdx; + } + + if (sigma >= options.maxPrimalJump) { + unbounded = BT_TRUE; + returnvalue = RET_HOTSTART_STOPPED_UNBOUNDEDNESS; + } else { + for (i = 0; i < nFR; i++) + x[FR_idx[i]] += sigma * delta_xFR[i]; + + for (i = 0; i < nFX; i++) + x[FX_idx[i]] += sigma * delta_xFX[i]; + + /* update Ax, Ax_u, and Ax_l */ + A->times(1, 1.0, x, nV, 0.0, Ax, nC); + for (i = 0; i < nC; i++) + Ax_u[i] = ubA[i] - Ax[i]; + for (i = 0; i < nC; i++) + Ax_l[i] = Ax[i] - lbA[i]; + + /* change working set later */ + exchangeHappened = BT_TRUE; + } + + delete[] Ax_W; + delete[] As; + } + + delete[] delta_yFX; + delete[] delta_yAC; + delete[] delta_xFR; + delete[] delta_xFX; + // delete[] delta_g; + + return returnvalue; +} + +/* + * b a c k s o l v e T + */ +returnValue QProblem::backsolveT(const real_t * const b, BooleanType transposed, real_t * const a) const +{ + int_t i, j; + int_t nT = getNAC(); + int_t tcol = sizeT - nT; + + real_t sum; + + /* nothing to do */ + if (nT <= 0) + return SUCCESSFUL_RETURN; + + /* Solve Ta = b, where T might be transposed. */ + if (transposed == BT_FALSE) { + /* solve Ta = b */ + for (i = 0; i < nT; ++i) { + sum = b[i]; + for (j = 0; j < i; ++j) + sum -= TT(i, sizeT - 1 - j) * a[nT - 1 - j]; + + if (getAbs(TT(i, sizeT - 1 - i)) > EPS) + a[nT - 1 - i] = sum / TT(i, sizeT - 1 - i); + else + return THROWERROR(RET_DIV_BY_ZERO); + } + } else { + /* solve T^T*a = b */ + for (i = 0; i < nT; ++i) { + sum = b[i]; + for (j = 0; j < i; ++j) + sum -= TT(nT - 1 - j, tcol + i) * a[nT - 1 - j]; + + if (getAbs(TT(nT - 1 - i, tcol + i)) > EPS) + a[nT - 1 - i] = sum / TT(nT - 1 - i, tcol + i); + else + return THROWERROR(RET_DIV_BY_ZERO); + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * d e t e r m i n e D a t a S h i f t + */ +returnValue QProblem::determineDataShift(const real_t * const g_new, + const real_t * const lbA_new, + const real_t * const ubA_new, + const real_t * const lb_new, + const real_t * const ub_new, + real_t * const delta_g, + real_t * const delta_lbA, + real_t * const delta_ubA, + real_t * const delta_lb, + real_t * const delta_ub, + BooleanType & Delta_bC_isZero, + BooleanType & Delta_bB_isZero) +{ + int_t i, ii; + int_t nC = getNC(); + int_t nAC = getNAC(); + + int_t * FX_idx; + int_t * AC_idx; + + bounds.getFixed()->getNumberArray(&FX_idx); + constraints.getActive()->getNumberArray(&AC_idx); + + /* I) DETERMINE DATA SHIFT FOR BOUNDS */ + QProblemB::determineDataShift(g_new, lb_new, ub_new, delta_g, delta_lb, delta_ub, Delta_bB_isZero); + + /* II) DETERMINE DATA SHIFT FOR CONSTRAINTS */ + /* 1) Calculate shift directions. */ + for (i = 0; i < nC; ++i) { + /* if lower constraints' bounds are to be disabled or do not exist, shift them to -infinity */ + if (lbA_new != 0) + delta_lbA[i] = lbA_new[i] - lbA[i]; + else + delta_lbA[i] = -INFTY - lbA[i]; + } + + for (i = 0; i < nC; ++i) { + /* if upper constraints' bounds are to be disabled or do not exist, shift them to infinity */ + if (ubA_new != 0) + delta_ubA[i] = ubA_new[i] - ubA[i]; + else + delta_ubA[i] = INFTY - ubA[i]; + } + + /* 2) Determine if active constraints' bounds are to be shifted. */ + Delta_bC_isZero = BT_TRUE; + + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + + if ((getAbs(delta_lbA[ii]) > EPS) || (getAbs(delta_ubA[ii]) > EPS)) { + Delta_bC_isZero = BT_FALSE; + break; + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * d e t e r m i n e S t e p D i r e c t i o n + */ +returnValue QProblem::determineStepDirection(const real_t * const delta_g, + const real_t * const delta_lbA, + const real_t * const delta_ubA, + const real_t * const delta_lb, + const real_t * const delta_ub, + BooleanType Delta_bC_isZero, + BooleanType Delta_bB_isZero, + real_t * const delta_xFX, + real_t * const delta_xFR, + real_t * const delta_yAC, + real_t * const delta_yFX) +{ + int_t i, j, ii, jj, r; + int_t nV = getNV(); + int_t nFR = getNFR(); + int_t nFX = getNFX(); + int_t nAC = getNAC(); + int_t nZ = getNZ(); + + int_t * FR_idx; + int_t * FX_idx; + int_t * AC_idx; + + bounds.getFree()->getNumberArray(&FR_idx); + bounds.getFixed()->getNumberArray(&FX_idx); + constraints.getActive()->getNumberArray(&AC_idx); + + /* I) DETERMINE delta_xFX (this is exact, does not need refinement) */ + if (Delta_bB_isZero == BT_FALSE) { + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + + if (bounds.getStatus(ii) == ST_LOWER) + delta_xFX[i] = delta_lb[ii]; + else + delta_xFX[i] = delta_ub[ii]; + } + } else { + for (i = 0; i < nFX; ++i) + delta_xFX[i] = 0.0; + } + + /* tempA and tempB hold the residuals in gFR and bA (= lbA or ubA) + * delta_xFR, delta_yAC hold the steps that get refined */ + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + tempA[i] = delta_g[ii]; + delta_xFR[i] = 0.0; + } + for (i = 0; i < nAC; ++i) + delta_yAC[i] = 0.0; + if (Delta_bC_isZero == BT_FALSE) { + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + if (constraints.getStatus(ii) == ST_LOWER) + tempB[i] = delta_lbA[ii]; + else + tempB[i] = delta_ubA[ii]; + } + } else { + for (i = 0; i < nAC; ++i) + tempB[i] = 0.0; + } + + /* Iterative refinement loop for delta_xFRz, delta_xFRy, delta_yAC */ + for (r = 0; r <= options.numRefinementSteps; ++r) { + /* II) DETERMINE delta_xFR */ + if (nFR > 0) { + for (i = 0; i < nFR; ++i) + delta_xFR_TMP[i] = 0.0; + + /* 1) Determine delta_xFRy. */ + if (nAC > 0) { + if ((Delta_bC_isZero == BT_TRUE) && (Delta_bB_isZero == BT_TRUE)) { + for (i = 0; i < nAC; ++i) + delta_xFRy[i] = 0.0; + } else { + /* compute bA - A * delta_xFX. tempB already holds bA-> + * in refinements r>=1, delta_xFX is exactly zero */ + if ((Delta_bB_isZero == BT_FALSE) && (r == 0)) + A->times(constraints.getActive(), bounds.getFixed(), 1, -1.0, delta_xFX, nFX, 1.0, tempB, nAC); + + if (backsolveT(tempB, BT_FALSE, delta_xFRy) != SUCCESSFUL_RETURN) + return THROWERROR(RET_STEPDIRECTION_FAILED_TQ); + + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + for (j = 0; j < nAC; ++j) + delta_xFR_TMP[i] += QQ(ii, nZ + j) * delta_xFRy[j]; + } + } + } + + /* 2) Determine delta_xFRz. */ + for (i = 0; i < nZ; ++i) + delta_xFRz[i] = 0.0; + + if ((hessianType == HST_ZERO) || (hessianType == HST_IDENTITY)) { + /* compute Z*delta_gFR [/eps] (delta_gFR is stored in tempA) */ + for (j = 0; j < nFR; ++j) { + jj = FR_idx[j]; + for (i = 0; i < nZ; ++i) + delta_xFRz[i] -= QQ(jj, i) * tempA[j]; + } + + if (hessianType == HST_ZERO) { + if (usingRegularisation() == BT_TRUE) { + for (i = 0; i < nZ; ++i) + delta_xFRz[i] /= regVal; + } else { + /* When solving LPs without regularisation, iterates must always be at a vertex. */ + if (nZ > 0) + return THROWERROR(RET_UNKNOWN_BUG); + } + } + } else { + /* compute HMX*delta_xFX. DESTROY delta_gFR that was in tempA */ + if ((Delta_bB_isZero == BT_FALSE) && (r == 0)) + H->times(bounds.getFree(), bounds.getFixed(), 1, 1.0, delta_xFX, nFX, 1.0, tempA, nFR); + + /* compute HFR*delta_xFRy */ + if ((nAC > 0) && ((Delta_bC_isZero == BT_FALSE) || (Delta_bB_isZero == BT_FALSE))) + H->times(bounds.getFree(), bounds.getFree(), 1, 1.0, delta_xFR_TMP, nFR, 1.0, tempA, nFR); + + /* compute ZFR_delta_xFRz = (Z'*HFR*Z) \ Z * (HFR*delta_xFR + HMX*delta_xFX + delta_gFR) */ + if (nZ > 0) { + for (j = 0; j < nFR; ++j) { + jj = FR_idx[j]; + for (i = 0; i < nZ; ++i) + delta_xFRz[i] -= QQ(jj, i) * tempA[j]; + } + + if (backsolveR(delta_xFRz, BT_TRUE, delta_xFRz) != SUCCESSFUL_RETURN) + return THROWERROR(RET_STEPDIRECTION_FAILED_CHOLESKY); + + if (backsolveR(delta_xFRz, BT_FALSE, delta_xFRz) != SUCCESSFUL_RETURN) + return THROWERROR(RET_STEPDIRECTION_FAILED_CHOLESKY); + } + } + + /* compute Z * ZFR_delta_xFRz */ + if (nZ > 0) { + for (i = 0; i < nFR; ++i) { + ZFR_delta_xFRz[i] = 0.0; + + ii = FR_idx[i]; + for (j = 0; j < nZ; ++j) + ZFR_delta_xFRz[i] += QQ(ii, j) * delta_xFRz[j]; + + delta_xFR_TMP[i] += ZFR_delta_xFRz[i]; + } + } + } + + /* III) DETERMINE delta_yAC */ + if (nAC > 0) /* => ( nFR = nZ + nAC > 0 ) */ + { + if ((hessianType == HST_ZERO) || (hessianType == HST_IDENTITY)) { + /* if zero: delta_yAC = (T')^-1 * ( Yfr*delta_gFR + eps*delta_xFRy ), + * if identity: delta_yAC = (T')^-1 * ( Yfr*delta_gFR + delta_xFRy ) + * + * DESTROY residual_bA that was stored in tempB + * If we come here, residual_gFR in tempA is STILL VALID + */ + if (hessianType == HST_IDENTITY) { + for (j = 0; j < nAC; ++j) + tempB[j] = delta_xFRy[j]; + } else /* hessianType == HST_ZERO */ + { + if (usingRegularisation() == BT_TRUE) { + for (j = 0; j < nAC; ++j) + tempB[j] = regVal * delta_xFRy[j]; + } else { + for (j = 0; j < nAC; ++j) + tempB[j] = 0.0; + } + } + + for (j = 0; j < nAC; ++j) { + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + tempB[j] += QQ(ii, nZ + j) * tempA[i]; + } + } + } else { + /* Compute HFR * delta_xFR + HMX*delta_xFX + * Here, tempA holds (HFR*delta_xFRy + HMX*delta_xFX) */ + if (nZ > 0) + H->times(bounds.getFree(), bounds.getFree(), 1, 1.0, ZFR_delta_xFRz, nFR, 1.0, tempA, nFR); + + for (i = 0; i < nAC; ++i) { + tempB[i] = 0.0; + for (j = 0; j < nFR; ++j) { + jj = FR_idx[j]; + tempB[i] += QQ(jj, nZ + i) * tempA[j]; + } + } + } + + if (backsolveT(tempB, BT_TRUE, delta_yAC_TMP) != SUCCESSFUL_RETURN) + return THROWERROR(RET_STEPDIRECTION_FAILED_TQ); + } + + /* refine the solution found so far */ + for (i = 0; i < nFR; ++i) + delta_xFR[i] += delta_xFR_TMP[i]; + for (i = 0; i < nAC; ++i) + delta_yAC[i] += delta_yAC_TMP[i]; + + if (options.numRefinementSteps > 0) { + /* compute residuals in tempA and tempB, and max-norm */ + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + tempA[i] = delta_g[ii]; + } + + switch (hessianType) { + case HST_ZERO: + if (usingRegularisation() == BT_TRUE) + for (i = 0; i < nFR; ++i) + tempA[i] += regVal * delta_xFR[i]; + break; + + case HST_IDENTITY: + for (i = 0; i < nFR; ++i) + tempA[i] += delta_xFR[i]; + break; + + default: + H->times(bounds.getFree(), bounds.getFree(), 1, 1.0, delta_xFR, nFR, 1.0, tempA, nFR); + H->times(bounds.getFree(), bounds.getFixed(), 1, 1.0, delta_xFX, nFX, 1.0, tempA, nFR); + break; + } + + A->transTimes(constraints.getActive(), bounds.getFree(), 1, -1.0, delta_yAC, nAC, 1.0, tempA, nFR); + real_t rnrm = 0.0; + for (i = 0; i < nFR; ++i) + if (rnrm < getAbs(tempA[i])) + rnrm = getAbs(tempA[i]); + + if (!Delta_bC_isZero) { + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + if (constraints.getStatus(ii) == ST_LOWER) + tempB[i] = delta_lbA[ii]; + else + tempB[i] = delta_ubA[ii]; + } + } else { + for (i = 0; i < nAC; ++i) + tempB[i] = 0.0; + } + A->times(constraints.getActive(), bounds.getFree(), 1, -1.0, delta_xFR, nFR, 1.0, tempB, nAC); + A->times(constraints.getActive(), bounds.getFixed(), 1, -1.0, delta_xFX, nFX, 1.0, tempB, nAC); + for (i = 0; i < nAC; ++i) + if (rnrm < getAbs(tempB[i])) + rnrm = getAbs(tempB[i]); + + /* early termination of residual norm small enough */ + if (rnrm < options.epsIterRef) + break; + } + } /* end of refinement loop for delta_xFRz, delta_xFRy, delta_yAC */ + + /* IV) DETERMINE delta_yFX */ + if (nFX > 0) { + for (i = 0; i < nFX; ++i) + delta_yFX[i] = delta_g[FX_idx[i]]; + + A->transTimes(constraints.getActive(), bounds.getFixed(), 1, -1.0, delta_yAC, nAC, 1.0, delta_yFX, nFX); + + switch (hessianType) { + case HST_ZERO: + if (usingRegularisation() == BT_TRUE) + for (i = 0; i < nFX; ++i) + delta_yFX[i] += regVal * delta_xFX[i]; + break; + + case HST_IDENTITY: + for (i = 0; i < nFX; ++i) + delta_yFX[i] += 1.0 * delta_xFX[i]; + break; + + default: + H->times(bounds.getFixed(), bounds.getFree(), 1, 1.0, delta_xFR, nFR, 1.0, delta_yFX, nFX); + H->times(bounds.getFixed(), bounds.getFixed(), 1, 1.0, delta_xFX, nFX, 1.0, delta_yFX, nFX); + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * p e r f o r m S t e p + */ +returnValue QProblem::performStep(const real_t * const delta_g, + const real_t * const delta_lbA, + const real_t * const delta_ubA, + const real_t * const delta_lb, + const real_t * const delta_ub, + const real_t * const delta_xFX, + const real_t * const delta_xFR, + const real_t * const delta_yAC, + const real_t * const delta_yFX, + int_t & BC_idx, + SubjectToStatus & BC_status, + BooleanType & BC_isBound) +{ + int_t i, j, ii, jj; + int_t nV = getNV(); + int_t nC = getNC(); + int_t nFR = getNFR(); + int_t nFX = getNFX(); + int_t nAC = getNAC(); + int_t nIAC = getNIAC(); + + int_t * FR_idx; + int_t * FX_idx; + int_t * AC_idx; + int_t * IAC_idx; + + bounds.getFree()->getNumberArray(&FR_idx); + bounds.getFixed()->getNumberArray(&FX_idx); + constraints.getActive()->getNumberArray(&AC_idx); + constraints.getInactive()->getNumberArray(&IAC_idx); + + /* initialise maximum steplength array */ + tau = 1.0; + BC_idx = -1; + BC_status = ST_UNDEFINED; + + int_t BC_idx_tmp = -1; + + real_t * num = new real_t[getMax(nV, nC)]; + real_t * den = new real_t[getMax(nV, nC)]; + + real_t * delta_Ax_l = new real_t[nC]; + real_t * delta_Ax_u = new real_t[nC]; + real_t * delta_Ax = new real_t[nC]; + + real_t * delta_x = new real_t[nV]; + for (j = 0; j < nFR; ++j) { + jj = FR_idx[j]; + delta_x[jj] = delta_xFR[j]; + } + for (j = 0; j < nFX; ++j) { + jj = FX_idx[j]; + delta_x[jj] = delta_xFX[j]; + } + + /* I) DETERMINE MAXIMUM DUAL STEPLENGTH: */ + /* 1) Ensure that active dual constraints' bounds remain valid + * (ignoring inequality constraints). */ + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + + num[i] = y[nV + ii]; + den[i] = -delta_yAC[i]; + } + + performRatioTest(nAC, AC_idx, &constraints, num, den, options.epsNum, options.epsDen, tau, BC_idx_tmp); + + if (BC_idx_tmp >= 0) { + BC_idx = BC_idx_tmp; + BC_status = ST_INACTIVE; + BC_isBound = BT_FALSE; + } + + /* 2) Ensure that active dual bounds remain valid + * (ignoring implicitly fixed variables). */ + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + num[i] = y[ii]; + den[i] = -delta_yFX[i]; + } + + performRatioTest(nFX, FX_idx, &bounds, num, den, options.epsNum, options.epsDen, tau, BC_idx_tmp); + + if (BC_idx_tmp >= 0) { + BC_idx = BC_idx_tmp; + BC_status = ST_INACTIVE; + BC_isBound = BT_TRUE; + } + + /* II) DETERMINE MAXIMUM PRIMAL STEPLENGTH */ + /* 1) Ensure that inactive constraints' bounds remain valid + * (ignoring unbounded constraints). */ + + /* calculate product A*x */ + if (constraintProduct == 0) { + A->times(constraints.getInactive(), 0, 1, 1.0, delta_x, nV, 0.0, delta_Ax, nC, BT_FALSE); + } else { + for (i = 0; i < nIAC; ++i) { + ii = IAC_idx[i]; + + if (constraints.getType(ii) != ST_UNBOUNDED) { + if ((*constraintProduct)(ii, delta_x, &(delta_Ax[ii])) != 0) { + delete[] den; + delete[] num; + delete[] delta_Ax; + delete[] delta_Ax_u; + delete[] delta_Ax_l; + delete[] delta_x; + return THROWERROR(RET_ERROR_IN_CONSTRAINTPRODUCT); + } + } + } + } + + if (constraints.hasNoLower() == BT_FALSE) { + for (i = 0; i < nIAC; ++i) { + ii = IAC_idx[i]; + num[i] = getMax(Ax_l[ii], 0.0); + den[i] = delta_lbA[ii] - delta_Ax[ii]; + } + + performRatioTest( + nIAC, IAC_idx, &constraints, num, den, options.epsNum, options.epsDen, tau, BC_idx_tmp); + + if (BC_idx_tmp >= 0) { + BC_idx = BC_idx_tmp; + BC_status = ST_LOWER; + BC_isBound = BT_FALSE; + } + } + + if (constraints.hasNoUpper() == BT_FALSE) { + for (i = 0; i < nIAC; ++i) { + ii = IAC_idx[i]; + num[i] = getMax(Ax_u[ii], 0.0); + den[i] = delta_Ax[ii] - delta_ubA[ii]; + } + + performRatioTest( + nIAC, IAC_idx, &constraints, num, den, options.epsNum, options.epsDen, tau, BC_idx_tmp); + + if (BC_idx_tmp >= 0) { + BC_idx = BC_idx_tmp; + BC_status = ST_UPPER; + BC_isBound = BT_FALSE; + } + } + + for (i = 0; i < nIAC; ++i) { + ii = IAC_idx[i]; + + if (constraints.getType(ii) != ST_UNBOUNDED) { + delta_Ax_l[ii] = delta_Ax[ii] - delta_lbA[ii]; + delta_Ax_u[ii] = delta_ubA[ii] - delta_Ax[ii]; + } + } + + /* 2) Ensure that inactive bounds remain valid + * (ignoring unbounded variables). */ + /* inactive lower bounds */ + if (bounds.hasNoLower() == BT_FALSE) { + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + num[i] = getMax(x[ii] - lb[ii], 0.0); + den[i] = delta_lb[ii] - delta_xFR[i]; + } + + performRatioTest(nFR, FR_idx, &bounds, num, den, options.epsNum, options.epsDen, tau, BC_idx_tmp); + + if (BC_idx_tmp >= 0) { + BC_idx = BC_idx_tmp; + BC_status = ST_LOWER; + BC_isBound = BT_TRUE; + } + } + + /* inactive upper bounds */ + if (bounds.hasNoUpper() == BT_FALSE) { + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + num[i] = getMax(ub[ii] - x[ii], 0.0); + den[i] = delta_xFR[i] - delta_ub[ii]; + } + + performRatioTest(nFR, FR_idx, &bounds, num, den, options.epsNum, options.epsDen, tau, BC_idx_tmp); + + if (BC_idx_tmp >= 0) { + BC_idx = BC_idx_tmp; + BC_status = ST_UPPER; + BC_isBound = BT_TRUE; + } + } + + delete[] den; + delete[] num; + delete[] delta_x; + +#ifndef __SUPPRESSANYOUTPUT__ + char messageString[MAX_STRING_LENGTH]; + + if (BC_status == ST_UNDEFINED) + snprintf(messageString, MAX_STRING_LENGTH, "Stepsize is %.15e!", tau); + else + snprintf(messageString, + MAX_STRING_LENGTH, + "Stepsize is %.15e! (idx = %d, isBound = %d, status = %d)", + tau, + (int)BC_idx, + (int)BC_isBound, + (int)BC_status); + + getGlobalMessageHandler()->throwInfo( + RET_STEPSIZE_NONPOSITIVE, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + /* III) PERFORM STEP ALONG HOMOTOPY PATH */ + if (tau > ZERO) { + /* 1) Perform step in primal and dual space... */ + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + x[ii] += tau * delta_xFR[i]; + } + + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + x[ii] += tau * delta_xFX[i]; + y[ii] += tau * delta_yFX[i]; + } + + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + y[nV + ii] += tau * delta_yAC[i]; + } + + /* 2) Shift QP data. */ + for (i = 0; i < nV; ++i) { + g[i] += tau * delta_g[i]; + lb[i] += tau * delta_lb[i]; + ub[i] += tau * delta_ub[i]; + } + + for (i = 0; i < nC; ++i) { + lbA[i] += tau * delta_lbA[i]; + ubA[i] += tau * delta_ubA[i]; + } + + A->times(constraints.getActive(), 0, 1, 1.0, x, nV, 0.0, Ax, nC, BT_FALSE); + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + Ax_u[ii] = ubA[ii] - Ax[ii]; + Ax_l[ii] = Ax[ii] - lbA[ii]; + } + for (i = 0; i < nIAC; ++i) { + ii = IAC_idx[i]; + if (constraints.getType(ii) != ST_UNBOUNDED) { + Ax[ii] += tau * delta_Ax[ii]; + Ax_l[ii] += tau * delta_Ax_l[ii]; + Ax_u[ii] += tau * delta_Ax_u[ii]; + } + } + } else { +/* print a stepsize warning if stepsize is zero */ +#ifndef __SUPPRESSANYOUTPUT__ + snprintf(messageString, MAX_STRING_LENGTH, "Stepsize is %.15e", tau); + getGlobalMessageHandler()->throwWarning( + RET_STEPSIZE, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + } + + delete[] delta_Ax; + delete[] delta_Ax_u; + delete[] delta_Ax_l; + + return SUCCESSFUL_RETURN; +} + +/* + * c h a n g e A c t i v e S e t + */ +returnValue QProblem::changeActiveSet(int_t BC_idx, SubjectToStatus BC_status, BooleanType BC_isBound) +{ + int_t nV = getNV(); + +#ifndef __SUPPRESSANYOUTPUT__ + char messageString[MAX_STRING_LENGTH]; +#endif + + switch (BC_status) { + /* Optimal solution found as no working set change detected. */ + case ST_UNDEFINED: + return SUCCESSFUL_RETURN; + + /* Remove one variable from active set. */ + case ST_INACTIVE: + if (BC_isBound == BT_TRUE) { +#ifndef __SUPPRESSANYOUTPUT__ + snprintf(messageString, MAX_STRING_LENGTH, "bound no. %d.", (int)BC_idx); + getGlobalMessageHandler()->throwInfo( + RET_REMOVE_FROM_ACTIVESET, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + if (removeBound(BC_idx, BT_TRUE, BT_TRUE, options.enableNZCTests) != SUCCESSFUL_RETURN) + return THROWERROR(RET_REMOVE_FROM_ACTIVESET_FAILED); + + y[BC_idx] = 0.0; + } else { +#ifndef __SUPPRESSANYOUTPUT__ + snprintf(messageString, MAX_STRING_LENGTH, "constraint no. %d.", (int)BC_idx); + getGlobalMessageHandler()->throwInfo( + RET_REMOVE_FROM_ACTIVESET, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + if (removeConstraint(BC_idx, BT_TRUE, BT_TRUE, options.enableNZCTests) != SUCCESSFUL_RETURN) + return THROWERROR(RET_REMOVE_FROM_ACTIVESET_FAILED); + + y[nV + BC_idx] = 0.0; + } + break; + + /* Add one variable to active set. */ + default: + returnValue returnvalue; + if (BC_isBound == BT_TRUE) { +#ifndef __SUPPRESSANYOUTPUT__ + if (BC_status == ST_LOWER) + snprintf(messageString, MAX_STRING_LENGTH, "lower bound no. %d.", (int)BC_idx); + else + snprintf(messageString, MAX_STRING_LENGTH, "upper bound no. %d.", (int)BC_idx); + getGlobalMessageHandler()->throwInfo( + RET_ADD_TO_ACTIVESET, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + returnvalue = addBound(BC_idx, BC_status, BT_TRUE); + if (returnvalue == RET_ADDBOUND_FAILED_INFEASIBILITY) + return returnvalue; + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(RET_ADD_TO_ACTIVESET_FAILED); + } else { +#ifndef __SUPPRESSANYOUTPUT__ + if (BC_status == ST_LOWER) + snprintf(messageString, MAX_STRING_LENGTH, "lower constraint's bound no. %d.", (int)BC_idx); + else + snprintf(messageString, MAX_STRING_LENGTH, "upper constraint's bound no. %d.", (int)BC_idx); + getGlobalMessageHandler()->throwInfo( + RET_ADD_TO_ACTIVESET, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + returnvalue = addConstraint(BC_idx, BC_status, BT_TRUE); + if (returnvalue == RET_ADDCONSTRAINT_FAILED_INFEASIBILITY) + return returnvalue; + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(RET_ADD_TO_ACTIVESET_FAILED); + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * g e t R e l a t i v e H o m o t o p y L e n g t h + */ +real_t QProblem::getRelativeHomotopyLength(const real_t * const g_new, + const real_t * const lb_new, + const real_t * const ub_new, + const real_t * const lbA_new, + const real_t * const ubA_new) +{ + int_t i; + int_t nC = getNC(); + real_t len = QProblemB::getRelativeHomotopyLength(g_new, lb_new, ub_new); + real_t d, s; + + /*fprintf( stdFile, "len in homotopyLength = %.3e\n",len ); */ + + /* lower constraint bounds */ + if (lbA_new != 0) { + for (i = 0; i < nC; i++) { + s = getAbs(lbA_new[i]); + if (s < 1.0) + s = 1.0; + d = getAbs(lbA_new[i] - lbA[i]) / s; + if (d > len) + len = d; + } + } + /*fprintf( stdFile, "len in homotopyLength = %.3e\n",len ); */ + + /* upper constraint bounds */ + if (ubA_new != 0) { + for (i = 0; i < nC; i++) { + s = getAbs(ubA_new[i]); + if (s < 1.0) + s = 1.0; + d = getAbs(ubA_new[i] - ubA[i]) / s; + if (d > len) + len = d; + } + } + /*fprintf( stdFile, "len in homotopyLength = %.3e\n",len ); */ + + return len; +} + +/* + * p e r f o r m R a m p i n g + */ +returnValue QProblem::performRamping() +{ + int_t nV = getNV(), nC = getNC(), bstat, cstat, i, nRamp; + real_t tP, rampValP, tD, rampValD, sca; + + /* compute number of values in ramp */ + nRamp = nV + nC + nC + nV; + + /* ramp inactive variable bounds and active dual bound variables */ + for (i = 0; i < nV; i++) { + switch (bounds.getType(i)) { + case ST_EQUALITY: + lb[i] = x[i]; + ub[i] = x[i]; /* reestablish exact feasibility */ + continue; + + case ST_BOUNDED: + tP = static_cast((i + rampOffset) % nRamp) / static_cast(nRamp - 1); + rampValP = (1.0 - tP) * ramp0 + tP * ramp1; + tD = static_cast((nV + nC + nC + i + rampOffset) % nRamp) / static_cast(nRamp - 1); + rampValD = (1.0 - tD) * ramp0 + tD * ramp1; + bstat = bounds.getStatus(i); + if (bstat != ST_LOWER) { + sca = getMax(getAbs(x[i]), 1.0); + lb[i] = x[i] - sca * rampValP; + } + if (bstat != ST_UPPER) { + sca = getMax(getAbs(x[i]), 1.0); + ub[i] = x[i] + sca * rampValP; + } + if (bstat == ST_LOWER) { + lb[i] = x[i]; + y[i] = +rampValD; + } + if (bstat == ST_UPPER) { + ub[i] = x[i]; + y[i] = -rampValD; + } + if (bstat == ST_INACTIVE) + y[i] = 0.0; /* reestablish exact complementarity */ + break; + + case ST_UNBOUNDED: + case ST_DISABLED: + default: + continue; + } + } + + /* ramp inactive constraints and active dual constraint variables */ + for (i = 0; i < nC; i++) { + switch (constraints.getType(i)) { + case ST_EQUALITY: + lbA[i] = Ax[i]; + ubA[i] = Ax[i]; /* reestablish exact feasibility */ + continue; + + case ST_BOUNDED: + tP = static_cast((nV + i + rampOffset) % nRamp) / static_cast(nRamp - 1); + rampValP = (1.0 - tP) * ramp0 + tP * ramp1; + tD = static_cast((nV + nC + i + rampOffset) % nRamp) / static_cast(nRamp - 1); + rampValD = (1.0 - tD) * ramp0 + tD * ramp1; + cstat = constraints.getStatus(i); + if (cstat != ST_LOWER) { + sca = getMax(getAbs(Ax[i]), 1.0); + lbA[i] = Ax[i] - sca * rampValP; + } + if (cstat != ST_UPPER) { + sca = getMax(getAbs(Ax[i]), 1.0); + ubA[i] = Ax[i] + sca * rampValP; + } + if (cstat == ST_LOWER) { + lbA[i] = Ax[i]; + y[nV + i] = +rampValD; + } + if (cstat == ST_UPPER) { + ubA[i] = Ax[i]; + y[nV + i] = -rampValD; + } + if (cstat == ST_INACTIVE) + y[nV + i] = 0.0; /* reestablish exact complementarity */ + + Ax_l[i] = Ax[i] - lbA[i]; + Ax_u[i] = ubA[i] - Ax[i]; + break; + + case ST_UNBOUNDED: + case ST_DISABLED: + default: + continue; + } + } + + /* reestablish exact stationarity */ + setupAuxiliaryQPgradient(); + + /* advance ramp offset to avoid Ramping cycles */ + rampOffset++; + + return SUCCESSFUL_RETURN; +} + +/* + * u p d a t e F a r B o u n d s + */ +returnValue QProblem::updateFarBounds(real_t curFarBound, + int_t nRamp, + const real_t * const lb_new, + real_t * const lb_new_far, + const real_t * const ub_new, + real_t * const ub_new_far, + const real_t * const lbA_new, + real_t * const lbA_new_far, + const real_t * const ubA_new, + real_t * const ubA_new_far) const +{ + int_t i; + real_t rampVal, t; + int_t nV = getNV(); + int_t nC = getNC(); + + returnValue returnvalue = + QProblemB::updateFarBounds(curFarBound, nRamp, lb_new, lb_new_far, ub_new, ub_new_far); + if (returnvalue != SUCCESSFUL_RETURN) { + return returnvalue; + } + + if (options.enableRamping == BT_TRUE) { + for (i = 0; i < nC; ++i) { + t = static_cast((nV + i + rampOffset) % nRamp) / static_cast(nRamp - 1); + rampVal = curFarBound * (1.0 + (1.0 - t) * ramp0 + t * ramp1); + + if (lbA_new == 0) + lbA_new_far[i] = -rampVal; + else + lbA_new_far[i] = getMax(-rampVal, lbA_new[i]); + + if (ubA_new == 0) + ubA_new_far[i] = rampVal; + else + ubA_new_far[i] = getMin(rampVal, ubA_new[i]); + } + } else { + for (i = 0; i < nC; ++i) { + if (lbA_new == 0) + lbA_new_far[i] = -curFarBound; + else + lbA_new_far[i] = getMax(-curFarBound, lbA_new[i]); + + if (ubA_new == 0) + ubA_new_far[i] = curFarBound; + else + ubA_new_far[i] = getMin(curFarBound, ubA_new[i]); + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * p e r f o r m D r i f t C o r r e c t i o n + */ +returnValue QProblem::performDriftCorrection() +{ + int_t i; + int_t nV = getNV(); + int_t nC = getNC(); + + for (i = 0; i < nV; ++i) { + switch (bounds.getType(i)) { + case ST_BOUNDED: + switch (bounds.getStatus(i)) { + case ST_LOWER: + lb[i] = x[i]; + ub[i] = getMax(ub[i], x[i]); + y[i] = getMax(y[i], 0.0); + break; + case ST_UPPER: + lb[i] = getMin(lb[i], x[i]); + ub[i] = x[i]; + y[i] = getMin(y[i], 0.0); + break; + case ST_INACTIVE: + lb[i] = getMin(lb[i], x[i]); + ub[i] = getMax(ub[i], x[i]); + y[i] = 0.0; + break; + case ST_UNDEFINED: + case ST_INFEASIBLE_LOWER: + case ST_INFEASIBLE_UPPER: + break; + } + break; + case ST_EQUALITY: + lb[i] = x[i]; + ub[i] = x[i]; + break; + case ST_UNBOUNDED: + case ST_UNKNOWN: + case ST_DISABLED: + break; + } + } + + for (i = 0; i < nC; ++i) { + switch (constraints.getType(i)) { + case ST_BOUNDED: + switch (constraints.getStatus(i)) { + case ST_LOWER: + lbA[i] = Ax[i]; + Ax_l[i] = 0.0; + ubA[i] = getMax(ubA[i], Ax[i]); + Ax_u[i] = ubA[i] - Ax[i]; + y[i + nV] = getMax(y[i + nV], 0.0); + break; + case ST_UPPER: + lbA[i] = getMin(lbA[i], Ax[i]); + Ax_l[i] = Ax[i] - lbA[i]; + ubA[i] = Ax[i]; + Ax_u[i] = 0.0; + y[i + nV] = getMin(y[i + nV], 0.0); + break; + case ST_INACTIVE: + lbA[i] = getMin(lbA[i], Ax[i]); + Ax_l[i] = Ax[i] - lbA[i]; + ubA[i] = getMax(ubA[i], Ax[i]); + Ax_u[i] = ubA[i] - Ax[i]; + y[i + nV] = 0.0; + break; + case ST_UNDEFINED: + case ST_INFEASIBLE_LOWER: + case ST_INFEASIBLE_UPPER: + break; + } + break; + case ST_EQUALITY: + lbA[i] = Ax[i]; + Ax_l[i] = 0.0; + ubA[i] = Ax[i]; + Ax_u[i] = 0.0; + break; + case ST_UNBOUNDED: + case ST_UNKNOWN: + case ST_DISABLED: + break; + } + } + + return setupAuxiliaryQPgradient(); +} + +/* + * s e t u p A u x i l i a r y Q P + */ +returnValue QProblem::setupAuxiliaryQP( + const Bounds * const guessedBounds, const Constraints * const guessedConstraints) +{ + int_t i, j; + int_t nV = getNV(); + int_t nC = getNC(); + + /* consistency check */ + if ((guessedBounds == 0) || (guessedConstraints == 0)) + return THROWERROR(RET_INVALID_ARGUMENTS); + + /* nothing to do */ + if ((guessedBounds == &bounds) && (guessedConstraints == &constraints)) + return SUCCESSFUL_RETURN; + + status = QPS_PREPARINGAUXILIARYQP; + + /* I) SETUP WORKING SET ... */ + if (shallRefactorise(guessedBounds, guessedConstraints) == BT_TRUE) { + /* ... WITH REFACTORISATION: */ + /* 1) Reset bounds/constraints ... */ + bounds.init(nV); + constraints.init(nC); + + /* ... and set them up afresh. */ + if (setupSubjectToType() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + if (bounds.setupAllFree() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + if (constraints.setupAllInactive() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + /* 2) Setup TQ factorisation. */ + if (setupTQfactorisation() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + /* 3) Setup guessed working sets afresh. */ + if (setupAuxiliaryWorkingSet(guessedBounds, guessedConstraints, BT_TRUE) != SUCCESSFUL_RETURN) + THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + /* 4) Computes Cholesky decomposition of projected Hessian + * This now handles all special cases (no active bounds/constraints, no nullspace) */ + if (computeProjectedCholesky() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + } else { + /* ... WITHOUT REFACTORISATION: */ + if (setupAuxiliaryWorkingSet(guessedBounds, guessedConstraints, BT_FALSE) != SUCCESSFUL_RETURN) + THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + } + + /* II) SETUP AUXILIARY QP DATA: */ + /* 1) Ensure that dual variable is zero for free bounds and inactive constraints. */ + for (i = 0; i < nV; ++i) + if (bounds.getStatus(i) == ST_INACTIVE) + y[i] = 0.0; + + for (i = 0; i < nC; ++i) + if (constraints.getStatus(i) == ST_INACTIVE) + y[nV + i] = 0.0; + + /* 2) Setup gradient and (constraints') bound vectors. */ + if (setupAuxiliaryQPgradient() != SUCCESSFUL_RETURN) + THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + A->times(1, 1.0, x, nV, 0.0, Ax, nC); + for (j = 0; j < nC; ++j) { + Ax_l[j] = Ax[j]; + Ax_u[j] = Ax[j]; + } + + /* (also sets Ax_l and Ax_u) */ + if (setupAuxiliaryQPbounds(0, 0, BT_FALSE) != SUCCESSFUL_RETURN) + THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + return SUCCESSFUL_RETURN; +} + +/* + * s h a l l R e f a c t o r i s e + */ + +BooleanType QProblem::shallRefactorise( + const Bounds * const guessedBounds, const Constraints * const guessedConstraints) const +{ + int_t i; + int_t nV = getNV(); + int_t nC = getNC(); + + /* always refactorise if Hessian is not known to be positive definite */ + if ((hessianType == HST_SEMIDEF) || (hessianType == HST_INDEF)) + return BT_TRUE; + + /* 1) Determine number of bounds that have same status + * in guessed AND current bounds.*/ + int_t differenceNumberBounds = 0; + + for (i = 0; i < nV; ++i) + if (guessedBounds->getStatus(i) != bounds.getStatus(i)) + ++differenceNumberBounds; + + /* 2) Determine number of constraints that have same status + * in guessed AND current constraints.*/ + int_t differenceNumberConstraints = 0; + + for (i = 0; i < nC; ++i) + if (guessedConstraints->getStatus(i) != constraints.getStatus(i)) + ++differenceNumberConstraints; + + /* 3) Decide wheter to refactorise or not. */ + if (2 * (differenceNumberBounds + differenceNumberConstraints) > + guessedConstraints->getNAC() + guessedBounds->getNFX()) + return BT_TRUE; + else + return BT_FALSE; +} + +/* + * s e t u p Q P d a t a + */ +returnValue QProblem::setupQPdata(SymmetricMatrix * _H, + const real_t * const _g, + Matrix * _A, + const real_t * const _lb, + const real_t * const _ub, + const real_t * const _lbA, + const real_t * const _ubA) +{ + int_t nC = getNC(); + +#ifdef __WRITE_DATA_FILES__ + { + int_t i; + const double Infinity = 1e20; + int_t nV = getNV(); + GlobalOutputFileCounter++; + char buf[256]; + snprintf(buf, 256, "QP%d_setupQPdata.dat", GlobalOutputFileCounter); + MyPrintf("+++ Writing output file %s\n", buf); + + FILE * output_file = fopen(buf, "w"); + + fprintf(output_file, "nVar = %d\n", nV); + fprintf(output_file, "nCon = %d\n", nC); + + _H->writeToFile(output_file, "H_"); + for (i = 0; i < nV; i++) { + fprintf(output_file, "g[%d] = %23.16e\n", i, _g[i]); + } + _A->writeToFile(output_file, "A_"); + for (i = 0; i < nV; i++) { + fprintf(output_file, "lb[%d] = %23.16e\n", i, getMax(-Infinity, _lb[i])); + } + for (i = 0; i < nV; i++) { + fprintf(output_file, "ub[%d] = %23.16e\n", i, getMin(Infinity, _ub[i])); + } + + for (i = 0; i < nC; i++) { + fprintf(output_file, "lbA[%d] = %23.16e\n", i, getMax(-Infinity, _lbA[i])); + } + for (i = 0; i < nC; i++) { + fprintf(output_file, "ubA[%d] = %23.16e\n", i, getMin(Infinity, _ubA[i])); + } + fclose(output_file); + } +#endif + + /* 1) Load Hessian matrix as well as lower and upper bounds vectors. */ + if (QProblemB::setupQPdata(_H, _g, _lb, _ub) != SUCCESSFUL_RETURN) + return THROWERROR(RET_INVALID_ARGUMENTS); + + if ((nC > 0) && (_A == 0)) + return THROWERROR(RET_INVALID_ARGUMENTS); + + if (nC > 0) { + /* 2) Setup lower/upper constraints' bounds vector. */ + setLBA(_lbA); + setUBA(_ubA); + + /* 3) Only load constraint matrix after setting up vectors! */ + setA(_A); + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p Q P d a t a + */ +returnValue QProblem::setupQPdata(const real_t * const _H, + const real_t * const _g, + const real_t * const _A, + const real_t * const _lb, + const real_t * const _ub, + const real_t * const _lbA, + const real_t * const _ubA) +{ + int_t nC = getNC(); + + /* 1) Load Hessian matrix as well as lower and upper bounds vectors. */ + if (QProblemB::setupQPdata(_H, _g, _lb, _ub) != SUCCESSFUL_RETURN) + return THROWERROR(RET_INVALID_ARGUMENTS); + + if ((nC > 0) && (_A == 0)) + return THROWERROR(RET_INVALID_ARGUMENTS); + + if (nC > 0) { + /* 2) Setup lower/upper constraints' bounds vector. */ + setLBA(_lbA); + setUBA(_ubA); + + /* 3) Only load constraint matrix after setting up vectors! */ + setA(_A); + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p Q P d a t a F r o m F i l e + */ +returnValue QProblem::setupQPdataFromFile(const char * const H_file, + const char * const g_file, + const char * const A_file, + const char * const lb_file, + const char * const ub_file, + const char * const lbA_file, + const char * const ubA_file) +{ + int_t i; + int_t nV = getNV(); + int_t nC = getNC(); + + returnValue returnvalue; + + /* 1) Load Hessian matrix as well as lower and upper bounds vectors from files. */ + returnvalue = QProblemB::setupQPdataFromFile(H_file, g_file, lb_file, ub_file); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(returnvalue); + + if ((nC > 0) && (A_file == 0)) + return THROWERROR(RET_INVALID_ARGUMENTS); + + if (nC > 0) { + /* 2) Load lower constraints' bounds vector from file. */ + if (lbA_file != 0) { + returnvalue = readFromFile(lbA, nC, lbA_file); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(returnvalue); + } else { + /* if no lower constraints' bounds are specified, set them to -infinity */ + for (i = 0; i < nC; ++i) + lbA[i] = -INFTY; + } + + /* 3) Load upper constraints' bounds vector from file. */ + if (ubA_file != 0) { + returnvalue = readFromFile(ubA, nC, ubA_file); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(returnvalue); + } else { + /* if no upper constraints' bounds are specified, set them to infinity */ + for (i = 0; i < nC; ++i) + ubA[i] = INFTY; + } + + /* 4) Only load constraint matrix from file after setting up vectors! */ + real_t * _A = new real_t[nC * nV]; + returnvalue = readFromFile(_A, nC, nV, A_file); + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] _A; + return THROWERROR(returnvalue); + } + setA(_A); + A->doFreeMemory(); + } + + return SUCCESSFUL_RETURN; +} + +/* + * l o a d Q P v e c t o r s F r o m F i l e + */ +returnValue QProblem::loadQPvectorsFromFile(const char * const g_file, + const char * const lb_file, + const char * const ub_file, + const char * const lbA_file, + const char * const ubA_file, + real_t * const g_new, + real_t * const lb_new, + real_t * const ub_new, + real_t * const lbA_new, + real_t * const ubA_new) const +{ + int_t nC = getNC(); + + returnValue returnvalue; + + /* 1) Load gradient vector as well as lower and upper bounds vectors from files. */ + returnvalue = QProblemB::loadQPvectorsFromFile(g_file, lb_file, ub_file, g_new, lb_new, ub_new); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(returnvalue); + + if (nC > 0) { + /* 2) Load lower constraints' bounds vector from file. */ + if (lbA_file != 0) { + if (lbA_new != 0) { + returnvalue = readFromFile(lbA_new, nC, lbA_file); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(returnvalue); + } else { + /* If filename is given, storage must be provided! */ + return THROWERROR(RET_INVALID_ARGUMENTS); + } + } + + /* 3) Load upper constraints' bounds vector from file. */ + if (ubA_file != 0) { + if (ubA_new != 0) { + returnvalue = readFromFile(ubA_new, nC, ubA_file); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(returnvalue); + } else { + /* If filename is given, storage must be provided! */ + return THROWERROR(RET_INVALID_ARGUMENTS); + } + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * p r i n t I t e r a t i o n + */ +returnValue QProblem::printIteration(int_t iter, + int_t BC_idx, + SubjectToStatus BC_status, + BooleanType BC_isBound, + real_t homotopyLength, + BooleanType isFirstCall) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + /* consistency check */ + if (iter < 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + int_t i; + int_t nV = getNV(); + int_t nC = getNC(); + int_t nAC = getNAC(); + + real_t stat, bfeas, cfeas, bcmpl, ccmpl, Tmaxomin; + real_t * grad = 0; + real_t * AX = 0; + real_t Tmin, Tmax; + + char myPrintfString[MAX_STRING_LENGTH]; + char info[MAX_STRING_LENGTH]; + const char excStr[] = " ef"; + + switch (options.printLevel) { + case PL_DEBUG_ITER: + grad = new real_t[nV]; + AX = new real_t[nC]; + stat = bfeas = cfeas = bcmpl = ccmpl = Tmaxomin = 0.0; + + /* stationarity */ + for (i = 0; i < nV; i++) + grad[i] = g[i] - y[i]; + + switch (hessianType) { + case HST_ZERO: + for (i = 0; i < nV; ++i) + grad[i] += regVal * x[i]; + break; + + case HST_IDENTITY: + for (i = 0; i < nV; ++i) + grad[i] += 1.0 * x[i]; + break; + + default: + H->times(1, 1.0, x, nV, 1.0, grad, nV); + break; + } + + A->transTimes(1, -1.0, y + nV, nC, 1.0, grad, nV); + for (i = 0; i < nV; i++) + if (getAbs(grad[i]) > stat) + stat = getAbs(grad[i]); + + /* feasibility */ + for (i = 0; i < nV; i++) + if (lb[i] - x[i] > bfeas) + bfeas = lb[i] - x[i]; + for (i = 0; i < nV; i++) + if (x[i] - ub[i] > bfeas) + bfeas = x[i] - ub[i]; + A->times(1, 1.0, x, nV, 0.0, AX, nC); + for (i = 0; i < nC; i++) + if (lbA[i] - AX[i] > cfeas) + cfeas = lbA[i] - AX[i]; + for (i = 0; i < nC; i++) + if (AX[i] - ubA[i] > cfeas) + cfeas = AX[i] - ubA[i]; + + /* complementarity */ + for (i = 0; i < nV; i++) + if (y[i] > +EPS && getAbs((lb[i] - x[i]) * y[i]) > bcmpl) + bcmpl = getAbs((lb[i] - x[i]) * y[i]); + for (i = 0; i < nV; i++) + if (y[i] < -EPS && getAbs((ub[i] - x[i]) * y[i]) > bcmpl) + bcmpl = getAbs((ub[i] - x[i]) * y[i]); + for (i = 0; i < nC; i++) + if (y[nV + i] > +EPS && getAbs((lbA[i] - AX[i]) * y[nV + i]) > ccmpl) + ccmpl = getAbs((lbA[i] - AX[i]) * y[nV + i]); + for (i = 0; i < nC; i++) + if (y[nV + i] < -EPS && getAbs((ubA[i] - AX[i]) * y[nV + i]) > ccmpl) + ccmpl = getAbs((ubA[i] - AX[i]) * y[nV + i]); + + Tmin = 1.0e16; + Tmax = 0.0; + for (i = 0; i < nAC; i++) + if (getAbs(TT(i, sizeT - i - 1)) < Tmin) + Tmin = getAbs(TT(i, sizeT - i - 1)); + else if (getAbs(TT(i, sizeT - i - 1)) > Tmax) + Tmax = getAbs(TT(i, sizeT - i - 1)); + Tmaxomin = Tmax / Tmin; + + if ((iter % 10 == 0) && (isFirstCall == BT_TRUE)) { + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "\n%5s %4s %4s %4s %4s %9s %9s %9s %9s %9s %9s %9s %9s\n", + "iter", + "addB", + "remB", + "addC", + "remC", + "hom len", + "tau", + "stat", + "bfeas", + "cfeas", + "bcmpl", + "ccmpl", + "Tmin"); + myPrintf(myPrintfString); + } + + if (isFirstCall == BT_TRUE) + snprintf(myPrintfString, MAX_STRING_LENGTH, "%5d ", (int)iter); + else + snprintf(myPrintfString, MAX_STRING_LENGTH, "%5d*", (int)iter); + myPrintf(myPrintfString); + + if (tabularOutput.idxAddB >= 0) { + snprintf(myPrintfString, MAX_STRING_LENGTH, "%4d ", (int)(tabularOutput.idxAddB)); + myPrintf(myPrintfString); + } else { + myPrintf(" "); + } + + if (tabularOutput.idxRemB >= 0) { + snprintf(myPrintfString, MAX_STRING_LENGTH, "%4d ", (int)(tabularOutput.idxRemB)); + myPrintf(myPrintfString); + } else { + myPrintf(" "); + } + + if (tabularOutput.idxAddC >= 0) { + snprintf(myPrintfString, MAX_STRING_LENGTH, "%4d ", (int)(tabularOutput.idxAddC)); + myPrintf(myPrintfString); + } else { + myPrintf(" "); + } + + if (tabularOutput.idxRemC >= 0) { + snprintf(myPrintfString, MAX_STRING_LENGTH, "%4d ", (int)(tabularOutput.idxRemC)); + myPrintf(myPrintfString); + } else { + myPrintf(" "); + } + + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "%9.2e %9.2e %9.2e %9.2e %9.2e %9.2e %9.2e %9.2e\n", + homotopyLength, + tau, + stat, + bfeas, + cfeas, + bcmpl, + ccmpl, + Tmin); + myPrintf(myPrintfString); + + delete[] AX; + delete[] grad; + break; + + case PL_TABULAR: + if ((iter % 10 == 0) && (isFirstCall == BT_TRUE)) { + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "\n%5s %6s %6s %6s %6s %9s %9s\n", + "iter", + "addB", + "remB", + "addC", + "remC", + "hom len", + "tau"); + myPrintf(myPrintfString); + } + if (isFirstCall == BT_TRUE) + snprintf(myPrintfString, MAX_STRING_LENGTH, "%5d ", (int)iter); + else + snprintf(myPrintfString, MAX_STRING_LENGTH, "%5d*", (int)iter); + myPrintf(myPrintfString); + + if (tabularOutput.idxAddB >= 0) { + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "%5d%c ", + (int)(tabularOutput.idxAddB), + excStr[tabularOutput.excAddB]); + myPrintf(myPrintfString); + } else { + myPrintf(" "); + } + + if (tabularOutput.idxRemB >= 0) { + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "%5d%c ", + (int)(tabularOutput.idxRemB), + excStr[tabularOutput.excRemB]); + myPrintf(myPrintfString); + } else { + myPrintf(" "); + } + + if (tabularOutput.idxAddC >= 0) { + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "%5d%c ", + (int)(tabularOutput.idxAddC), + excStr[tabularOutput.excAddC]); + myPrintf(myPrintfString); + } else { + myPrintf(" "); + } + + if (tabularOutput.idxRemC >= 0) { + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "%5d%c ", + (int)(tabularOutput.idxRemC), + excStr[tabularOutput.excRemC]); + myPrintf(myPrintfString); + } else { + myPrintf(" "); + } + + snprintf(myPrintfString, MAX_STRING_LENGTH, "%9.2e %9.2e\n", homotopyLength, tau); + myPrintf(myPrintfString); + break; + + case PL_MEDIUM: + /* 1) Print header at first iteration. */ + if ((iter == 0) && (isFirstCall == BT_TRUE)) { + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "\n\n#################### qpOASES -- QP NO. %3.0d #####################\n\n", + (int)count); + myPrintf(myPrintfString); + + myPrintf(" Iter | StepLength | Info | nFX | nAC \n"); + myPrintf(" ----------+------------------+------------------+---------+--------- \n"); + } + + /* 2) Print iteration line. */ + if (BC_status == ST_UNDEFINED) { + if (hessianType == HST_ZERO) + snprintf(info, 3, "LP"); + else + snprintf(info, 3, "QP"); + + if (isFirstCall == BT_TRUE) + snprintf(myPrintfString, + MAX_STRING_LENGTH, + " %5.1d | %1.6e | %s SOLVED | %4.1d | %4.1d \n", + (int)iter, + tau, + info, + (int)getNFX(), + (int)getNAC()); + else + snprintf(myPrintfString, + MAX_STRING_LENGTH, + " %5.1d* | %1.6e | %s SOLVED | %4.1d | %4.1d \n", + (int)iter, + tau, + info, + (int)getNFX(), + (int)getNAC()); + myPrintf(myPrintfString); + } else { + if (BC_status == ST_INACTIVE) + snprintf(info, 5, "REM "); + else + snprintf(info, 5, "ADD "); + + if (BC_isBound == BT_TRUE) + snprintf(&(info[4]), 4, "BND"); + else + snprintf(&(info[4]), 4, "CON"); + + snprintf(myPrintfString, + MAX_STRING_LENGTH, + " %5.1d | %1.6e | %s %4.1d | %4.1d | %4.1d \n", + (int)iter, + tau, + info, + (int)BC_idx, + (int)getNFX(), + (int)getNAC()); + myPrintf(myPrintfString); + } + break; + + default: + /* nothing to display */ + break; + } + +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +/* + * d r o p I n f e a s i b l e s + */ +returnValue QProblem::dropInfeasibles( + int_t BC_number, SubjectToStatus BC_status, BooleanType BC_isBound, real_t * xiB, real_t * xiC) +{ + int_t i; + + int_t nAC = getNAC(); + int_t nFX = getNFX(); + int_t blockingPriority = (BC_isBound) ? options.dropBoundPriority : options.dropIneqConPriority; + int_t y_min_number = -1; + BooleanType y_min_isBound = BC_isBound; + int_t y_min_priority = blockingPriority; + + int_t * AC_idx; + constraints.getActive()->getNumberArray(&AC_idx); + + int_t * FX_idx; + bounds.getFixed()->getNumberArray(&FX_idx); + + if (options.dropEqConPriority <= y_min_priority) { + // look for an equality constraint we can drop according to priorities + for (i = 0; i < nAC; ++i) + if ((constraints.getType(i) == ST_EQUALITY) && (getAbs(xiC[i]) > options.epsDen)) { + y_min_number = AC_idx[i]; + y_min_isBound = BT_FALSE; + y_min_priority = options.dropEqConPriority; + break; + } + } + + if (options.dropIneqConPriority <= y_min_priority) { + // look for an inequality constraint we can drop according to priorities + for (i = 0; i < nAC; ++i) + if ((constraints.getType(i) == ST_BOUNDED) && (getAbs(xiC[i]) > options.epsDen)) { + y_min_number = AC_idx[i]; + y_min_isBound = BT_FALSE; + y_min_priority = options.dropIneqConPriority; + break; + } + } + + if (options.dropBoundPriority <= y_min_priority) { + // look for a simple bound we can drop according to priorities + for (i = 0; i < nFX; ++i) + if (getAbs(xiB[i]) > options.epsDen) { + y_min_number = FX_idx[i]; + y_min_isBound = BT_TRUE; + y_min_priority = options.dropBoundPriority; + break; + } + } + + if (y_min_number >= 0) { + // drop active equality or active bound we have found + if (y_min_isBound) { + SubjectToStatus status_ = bounds.getStatus(y_min_number); + removeBound(y_min_number, BT_TRUE, BT_FALSE, BT_FALSE); + bounds.setStatus(y_min_number, (status_ == ST_LOWER) ? ST_INFEASIBLE_LOWER : ST_INFEASIBLE_UPPER); + // TODO: fix duals y[] + /* fprintf (stdFile, "Dropping bounds %d for %s %d\n", y_min_number, BC_isBound?"bound":"constraint", + * BC_number); */ + } else { + SubjectToStatus status_ = constraints.getStatus(y_min_number); + removeConstraint(y_min_number, BT_TRUE, BT_FALSE, BT_FALSE); + constraints.setStatus( + y_min_number, (status_ == ST_LOWER) ? ST_INFEASIBLE_LOWER : ST_INFEASIBLE_UPPER); + // TODO: fix duals y[] + /* fprintf (stdFile, "Dropping constraint %d for %s %d\n", y_min_number, + * BC_isBound?"bound":"constraint", BC_number); */ + } + + // ... now return, add the blocking constraint, and continue solving QP with dropped bound/constraint + return SUCCESSFUL_RETURN; + + } else { + // nothing found, then drop the blocking (still inactive) constraint + if (BC_isBound) + bounds.setStatus(BC_number, (BC_status == ST_LOWER) ? ST_INFEASIBLE_LOWER : ST_INFEASIBLE_UPPER); + else + constraints.setStatus(BC_number, (BC_status == ST_LOWER) ? ST_INFEASIBLE_LOWER : ST_INFEASIBLE_UPPER); + + /* fprintf (stdFile, "Dropping %s %d itself\n", BC_isBound?"bound":"constraint", BC_number); */ + + // ... now return, and continue solving QP with dropped bound/constraint + return RET_ENSURELI_DROPPED; + } +} + +/* + * w r i t e Q p D a t a I n t o M a t F i l e + */ +returnValue QProblem::writeQpDataIntoMatFile(const char * const filename) const +{ +#ifndef __SUPPRESSANYOUTPUT__ + + FILE * matFile; + matFile = fopen(filename, "w+"); + + if (matFile == 0) + return RET_UNABLE_TO_OPEN_FILE; + + int_t nV = getNV(); + int_t nC = getNC(); + + real_t * Hfull = H->full(); + writeIntoMatFile(matFile, Hfull, nV, nV, "H"); + delete[] Hfull; + + writeIntoMatFile(matFile, g, nV, 1, "g"); + + real_t * Afull = A->full(); + writeIntoMatFile(matFile, Afull, nC, nV, "A"); + delete[] Afull; + + writeIntoMatFile(matFile, lb, nV, 1, "lb"); + writeIntoMatFile(matFile, ub, nV, 1, "ub"); + writeIntoMatFile(matFile, lbA, nC, 1, "lbA"); + writeIntoMatFile(matFile, ubA, nC, 1, "ubA"); + + fclose(matFile); + + return SUCCESSFUL_RETURN; + +#else /* __SUPPRESSANYOUTPUT__ */ + + return RET_NOT_YET_IMPLEMENTED; + +#endif /* __SUPPRESSANYOUTPUT__ */ +} + +/* + * w r i t e Q p W o r k s p a c e I n t o M a t F i l e + */ +returnValue QProblem::writeQpWorkspaceIntoMatFile(const char * const filename) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + FILE * matFile; + matFile = fopen(filename, "w+"); + + if (matFile == 0) + return RET_UNABLE_TO_OPEN_FILE; + + int_t nV = getNV(); + int_t nC = getNC(); + int_t nFR = getNFR(); + int_t nFX = getNFX(); + int_t nAC = getNAC(); + int_t nIAC = getNIAC(); + + writeIntoMatFile(matFile, T, sizeT, sizeT, "T"); + writeIntoMatFile(matFile, Q, nV, nV, "Q"); + + writeIntoMatFile(matFile, Ax, nC, 1, "Ax"); + writeIntoMatFile(matFile, Ax_l, nC, 1, "Ax_l"); + writeIntoMatFile(matFile, Ax_u, nC, 1, "Ax_u"); + + int_t *FR_idx, *FX_idx, *AC_idx, *IAC_idx; + bounds.getFree()->getNumberArray(&FR_idx); + bounds.getFixed()->getNumberArray(&FX_idx); + constraints.getActive()->getNumberArray(&AC_idx); + constraints.getInactive()->getNumberArray(&IAC_idx); + + writeIntoMatFile(matFile, FR_idx, nFR, 1, "FR_idx"); + writeIntoMatFile(matFile, FX_idx, nFX, 1, "FX_idx"); + writeIntoMatFile(matFile, AC_idx, nAC, 1, "AC_idx"); + writeIntoMatFile(matFile, IAC_idx, nIAC, 1, "IAC_idx"); + + fclose(matFile); + + return SUCCESSFUL_RETURN; + +#else /* __SUPPRESSANYOUTPUT__ */ + + return RET_NOT_YET_IMPLEMENTED; + +#endif /* __SUPPRESSANYOUTPUT__ */ +} + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/QProblemB.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/QProblemB.cpp new file mode 100644 index 0000000..7f00d26 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/QProblemB.cpp @@ -0,0 +1,3545 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/QProblemB.cpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of the QProblemB class which is able to use the newly + * developed online active set strategy for parametric quadratic programming. + */ + +#include +#include + +BEGIN_NAMESPACE_QPOASES + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +/* + * Q P r o b l e m B + */ +QProblemB::QProblemB() +{ + /* print copyright notice */ + if (options.printLevel != PL_NONE) + printCopyrightNotice(); + + /* reset global message handler */ + getGlobalMessageHandler()->reset(); + + freeHessian = BT_FALSE; + H = 0; + + g = 0; + lb = 0; + ub = 0; + + R = 0; + haveCholesky = BT_FALSE; + + x = 0; + y = 0; + + tau = 0.0; + + hessianType = HST_UNKNOWN; + regVal = 0.0; + + infeasible = BT_FALSE; + unbounded = BT_FALSE; + + status = QPS_NOTINITIALISED; + + count = 0; + + ramp0 = options.initialRamping; + ramp1 = options.finalRamping; + rampOffset = 0; + + delta_xFR_TMP = 0; + + setPrintLevel(options.printLevel); +} + +/* + * Q P r o b l e m B + */ +QProblemB::QProblemB(int_t _nV, HessianType _hessianType, BooleanType allocDenseMats) +{ + int_t i; + + /* print copyright notice */ + if (options.printLevel != PL_NONE) + printCopyrightNotice(); + + /* consistency check */ + if (_nV <= 0) { + _nV = 1; + THROWERROR(RET_INVALID_ARGUMENTS); + } + + /* reset global message handler */ + getGlobalMessageHandler()->reset(); + + freeHessian = BT_FALSE; + H = 0; + + g = new real_t[_nV]; + for (i = 0; i < _nV; ++i) + g[i] = 0.0; + + lb = new real_t[_nV]; + for (i = 0; i < _nV; ++i) + lb[i] = 0.0; + + ub = new real_t[_nV]; + for (i = 0; i < _nV; ++i) + ub[i] = 0.0; + + bounds.init(_nV); + + if (allocDenseMats == BT_TRUE) { + R = new real_t[_nV * _nV]; + for (i = 0; i < _nV * _nV; ++i) + R[i] = 0.0; + } else + R = 0; + haveCholesky = BT_FALSE; + + x = new real_t[_nV]; + for (i = 0; i < _nV; ++i) + x[i] = 0.0; + + y = new real_t[_nV]; + for (i = 0; i < _nV; ++i) + y[i] = 0.0; + + tau = 0.0; + + hessianType = _hessianType; + regVal = 0.0; + + infeasible = BT_FALSE; + unbounded = BT_FALSE; + + status = QPS_NOTINITIALISED; + + count = 0; + + ramp0 = options.initialRamping; + ramp1 = options.finalRamping; + rampOffset = 0; + + delta_xFR_TMP = new real_t[_nV]; + + setPrintLevel(options.printLevel); + + flipper.init((uint_t)_nV); +} + +/* + * Q P r o b l e m B + */ +QProblemB::QProblemB(const QProblemB & rhs) +{ + freeHessian = BT_FALSE; + H = 0; + + copy(rhs); +} + +/* + * ~ Q P r o b l e m B + */ +QProblemB::~QProblemB() +{ + clear(); + + /* reset global message handler */ + getGlobalMessageHandler()->reset(); +} + +/* + * o p e r a t o r = + */ +QProblemB & QProblemB::operator=(const QProblemB & rhs) +{ + if (this != &rhs) { + clear(); + copy(rhs); + } + + return *this; +} + +/* + * r e s e t + */ +returnValue QProblemB::reset() +{ + int_t i; + int_t nV = getNV(); + + if (nV == 0) + return THROWERROR(RET_QPOBJECT_NOT_SETUP); + + /* 1) Reset bounds. */ + bounds.init(nV); + + /* 2) Reset Cholesky decomposition. */ + if (R != 0) + for (i = 0; i < nV * nV; ++i) + R[i] = 0.0; + + haveCholesky = BT_FALSE; + + /* 3) Reset steplength and status flags. */ + tau = 0.0; + + hessianType = HST_UNKNOWN; + regVal = 0.0; + + infeasible = BT_FALSE; + unbounded = BT_FALSE; + + status = QPS_NOTINITIALISED; + + ramp0 = options.initialRamping; + ramp1 = options.finalRamping; + rampOffset = 0; + + /* 4) Reset flipper object */ + flipper.init((uint_t)nV); + + return SUCCESSFUL_RETURN; +} + +/* + * i n i t + */ +returnValue QProblemB::init(SymmetricMatrix * _H, + const real_t * const _g, + const real_t * const _lb, + const real_t * const _ub, + int_t & nWSR, + real_t * const cputime, + const real_t * const xOpt, + const real_t * const yOpt, + const Bounds * const guessedBounds, + const real_t * const _R) +{ + int_t i; + int_t nV = getNV(); + + if (nV == 0) + return THROWERROR(RET_QPOBJECT_NOT_SETUP); + + /* 1) Consistency checks. */ + if (isInitialised() == BT_TRUE) { + THROWWARNING(RET_QP_ALREADY_INITIALISED); + reset(); + } + + if (guessedBounds != 0) { + for (i = 0; i < nV; ++i) { + if (guessedBounds->getStatus(i) == ST_UNDEFINED) + return THROWERROR(RET_INVALID_ARGUMENTS); + } + } + + /* exclude this possibility in order to avoid inconsistencies */ + if ((xOpt == 0) && (yOpt != 0) && (guessedBounds != 0)) + return THROWERROR(RET_INVALID_ARGUMENTS); + + if ((_R != 0) && ((xOpt != 0) || (yOpt != 0) || (guessedBounds != 0))) + return THROWERROR(RET_NO_CHOLESKY_WITH_INITIAL_GUESS); + + /* 2) Setup QP data. */ + if (setupQPdata(_H, _g, _lb, _ub) != SUCCESSFUL_RETURN) + return THROWERROR(RET_INVALID_ARGUMENTS); + + /* 3) Call to main initialisation routine. */ + return solveInitialQP(xOpt, yOpt, guessedBounds, _R, nWSR, cputime); +} + +/* + * i n i t + */ +returnValue QProblemB::init(const real_t * const _H, + const real_t * const _g, + const real_t * const _lb, + const real_t * const _ub, + int_t & nWSR, + real_t * const cputime, + const real_t * const xOpt, + const real_t * const yOpt, + const Bounds * const guessedBounds, + const real_t * const _R) +{ + int_t i; + int_t nV = getNV(); + + if (nV == 0) + return THROWERROR(RET_QPOBJECT_NOT_SETUP); + + /* 1) Consistency checks. */ + if (isInitialised() == BT_TRUE) { + THROWWARNING(RET_QP_ALREADY_INITIALISED); + reset(); + } + + if (guessedBounds != 0) { + for (i = 0; i < nV; ++i) { + if (guessedBounds->getStatus(i) == ST_UNDEFINED) + return THROWERROR(RET_INVALID_ARGUMENTS); + } + } + + /* exclude this possibility in order to avoid inconsistencies */ + if ((xOpt == 0) && (yOpt != 0) && (guessedBounds != 0)) + return THROWERROR(RET_INVALID_ARGUMENTS); + + if ((_R != 0) && ((xOpt != 0) || (yOpt != 0) || (guessedBounds != 0))) + return THROWERROR(RET_NO_CHOLESKY_WITH_INITIAL_GUESS); + + /* 2) Setup QP data. */ + if (setupQPdata(_H, _g, _lb, _ub) != SUCCESSFUL_RETURN) + return THROWERROR(RET_INVALID_ARGUMENTS); + + /* 3) Call to main initialisation routine. */ + return solveInitialQP(xOpt, yOpt, guessedBounds, _R, nWSR, cputime); +} + +/* + * i n i t + */ +returnValue QProblemB::init(const char * const H_file, + const char * const g_file, + const char * const lb_file, + const char * const ub_file, + int_t & nWSR, + real_t * const cputime, + const real_t * const xOpt, + const real_t * const yOpt, + const Bounds * const guessedBounds, + const char * const R_file) +{ + int_t i; + int_t nV = getNV(); + + if (nV == 0) + return THROWERROR(RET_QPOBJECT_NOT_SETUP); + + /* 1) Consistency checks. */ + if (isInitialised() == BT_TRUE) { + THROWWARNING(RET_QP_ALREADY_INITIALISED); + reset(); + } + + if (guessedBounds != 0) { + for (i = 0; i < nV; ++i) { + if (guessedBounds->getStatus(i) == ST_UNDEFINED) + return THROWERROR(RET_INVALID_ARGUMENTS); + } + } + + /* exclude this possibility in order to avoid inconsistencies */ + if ((xOpt == 0) && (yOpt != 0) && (guessedBounds != 0)) + return THROWERROR(RET_INVALID_ARGUMENTS); + + if ((R_file != 0) && ((xOpt != 0) || (yOpt != 0) || (guessedBounds != 0))) + return THROWERROR(RET_NO_CHOLESKY_WITH_INITIAL_GUESS); + + /* 2) Setup QP data from files. */ + if (setupQPdataFromFile(H_file, g_file, lb_file, ub_file) != SUCCESSFUL_RETURN) + return THROWERROR(RET_UNABLE_TO_READ_FILE); + + if (R_file == 0) { + /* 3) Call to main initialisation routine. */ + return solveInitialQP(xOpt, yOpt, guessedBounds, 0, nWSR, cputime); + } else { + /* Also read Cholesky factor from file and store it directly into R [thus... */ + returnValue returnvalue = readFromFile(R, nV, nV, R_file); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWWARNING(returnvalue); + + /* 3) Call to main initialisation routine. ...passing R here!] */ + return solveInitialQP(xOpt, yOpt, guessedBounds, R, nWSR, cputime); + } +} + +/* + * h o t s t a r t + */ +returnValue QProblemB::hotstart(const real_t * const g_new, + const real_t * const lb_new, + const real_t * const ub_new, + int_t & nWSR, + real_t * const cputime, + const Bounds * const guessedBounds) +{ + int_t i, nActiveFar; + int_t nV = getNV(); + real_t starttime = 0.0; + real_t auxTime = 0.0; + + if (nV == 0) + return THROWERROR(RET_QPOBJECT_NOT_SETUP); + + /* Possibly update working set according to guess for working set of bounds. */ + if (guessedBounds != 0) { + if (cputime != 0) + starttime = getCPUtime(); + + if (setupAuxiliaryQP(guessedBounds) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + status = QPS_AUXILIARYQPSOLVED; + + /* Allow only remaining CPU time for usual hotstart. */ + if (cputime != 0) { + auxTime = getCPUtime() - starttime; + *cputime -= auxTime; + } + } + + returnValue returnvalue = SUCCESSFUL_RETURN; + + /* Simple check for consistency of bounds */ + if (areBoundsConsistent(lb_new, ub_new) != SUCCESSFUL_RETURN) + return setInfeasibilityFlag(returnvalue, BT_TRUE); + + ++count; + + int_t nWSR_max = nWSR; + int_t nWSR_performed = 0; + + real_t cputime_remaining = INFTY; + real_t cputime_needed = 0.0; + + real_t farbound = options.initialFarBounds; + + if (haveCholesky == BT_FALSE) { + returnvalue = setupInitialCholesky(); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(returnvalue); + } + + BooleanType isFirstCall = BT_TRUE; + + if (options.enableFarBounds == BT_FALSE) { + /* Automatically call standard solveQP if regularisation is not active. */ + returnvalue = solveRegularisedQP(g_new, lb_new, ub_new, nWSR, cputime, 0, isFirstCall); + } else { + real_t * ub_new_far = new real_t[nV]; + real_t * lb_new_far = new real_t[nV]; + + /* possibly extend initial far bounds to largest bound/constraint data */ + if (ub_new) + for (i = 0; i < nV; i++) + if ((ub_new[i] < INFTY) && (ub_new[i] > farbound)) + farbound = ub_new[i]; + if (lb_new) + for (i = 0; i < nV; i++) + if ((lb_new[i] > -INFTY) && (lb_new[i] < -farbound)) + farbound = -lb_new[i]; + + updateFarBounds(farbound, nV, lb_new, lb_new_far, ub_new, ub_new_far); + + for (;;) { + nWSR = nWSR_max; + if (cputime != 0) + cputime_remaining = *cputime - cputime_needed; + + /* Automatically call standard solveQP if regularisation is not active. */ + returnvalue = solveRegularisedQP( + g_new, lb_new_far, ub_new_far, nWSR, &cputime_remaining, nWSR_performed, isFirstCall); + + nWSR_performed = nWSR; + cputime_needed += cputime_remaining; + isFirstCall = BT_FALSE; + + /* Check for active far-bounds and move them away */ + nActiveFar = 0; + farbound *= options.growFarBounds; + + if (infeasible == BT_TRUE) { + if (farbound >= INFTY) { + returnvalue = RET_HOTSTART_STOPPED_INFEASIBILITY; + goto farewell; + } + + updateFarBounds(farbound, nV, lb_new, lb_new_far, ub_new, ub_new_far); + } else if (status == QPS_SOLVED) { + real_t tol = farbound / options.growFarBounds * options.boundTolerance; + nActiveFar = 0; + for (i = 0; i < nV; ++i) { + if (((lb_new == 0) || (lb_new_far[i] > lb_new[i])) && (getAbs(lb_new_far[i] - x[i]) < tol)) + ++nActiveFar; + if (((ub_new == 0) || (ub_new_far[i] < ub_new[i])) && (getAbs(ub_new_far[i] - x[i]) < tol)) + ++nActiveFar; + } + + if (nActiveFar == 0) + break; + + status = QPS_HOMOTOPYQPSOLVED; + + if (farbound >= INFTY) { + unbounded = BT_TRUE; + returnvalue = RET_HOTSTART_STOPPED_UNBOUNDEDNESS; + goto farewell; + } + + updateFarBounds(farbound, nV, lb_new, lb_new_far, ub_new, ub_new_far); + } else { + /* some other error when solving QP */ + break; + } + + /* advance ramp offset to avoid Ramping cycles */ + rampOffset++; + } + + farewell: + /* add time to setup auxiliary QP */ + if (cputime != 0) + *cputime = cputime_needed + auxTime; + delete[] lb_new_far; + delete[] ub_new_far; + } + + return (returnvalue != SUCCESSFUL_RETURN) ? THROWERROR(returnvalue) : returnvalue; +} + +/* + * h o t s t a r t + */ +returnValue QProblemB::hotstart(const char * const g_file, + const char * const lb_file, + const char * const ub_file, + int_t & nWSR, + real_t * const cputime, + const Bounds * const guessedBounds) +{ + int_t nV = getNV(); + + if (nV == 0) + return THROWERROR(RET_QPOBJECT_NOT_SETUP); + + /* consistency check */ + if (g_file == 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + /* 1) Allocate memory (if bounds exist). */ + real_t * g_new = new real_t[nV]; + real_t * lb_new = (lb_file != 0) ? new real_t[nV] : 0; + real_t * ub_new = (ub_file != 0) ? new real_t[nV] : 0; + + /* 2) Load new QP vectors from file. */ + returnValue returnvalue; + returnvalue = loadQPvectorsFromFile(g_file, lb_file, ub_file, g_new, lb_new, ub_new); + if (returnvalue != SUCCESSFUL_RETURN) { + if (ub_file != 0) + delete[] ub_new; + if (lb_file != 0) + delete[] lb_new; + delete[] g_new; + + return THROWERROR(RET_UNABLE_TO_READ_FILE); + } + + /* 3) Actually perform hotstart. */ + returnvalue = hotstart(g_new, lb_new, ub_new, nWSR, cputime, guessedBounds); + + /* 4) Free memory. */ + if (ub_file != 0) + delete[] ub_new; + if (lb_file != 0) + delete[] lb_new; + delete[] g_new; + + return returnvalue; +} + +/* + * g e t W o r k i n g S e t + */ +returnValue QProblemB::getWorkingSet(real_t * workingSet) +{ + return getWorkingSetBounds(workingSet); +} + +/* + * g e t W o r k i n g S e t B o u n d s + */ +returnValue QProblemB::getWorkingSetBounds(real_t * workingSetB) +{ + int_t i; + int_t nV = this->getNV(); + + if (workingSetB == 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + for (i = 0; i < nV; ++i) { + switch (bounds.getStatus(i)) { + case ST_LOWER: + workingSetB[i] = -1.0; + break; + case ST_UPPER: + workingSetB[i] = +1.0; + break; + default: + workingSetB[i] = 0.0; + break; + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * g e t W o r k i n g S e t C o n s t r a i n t s + */ +returnValue QProblemB::getWorkingSetConstraints(real_t * workingSetC) +{ + if (workingSetC == 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + else + return SUCCESSFUL_RETURN; +} + +/* + * g e t N Z + */ +int_t QProblemB::getNZ() const +{ + /* if no constraints are present: nZ=nFR */ + return getNFR(); +} + +/* + * g e t O b j V a l + */ +real_t QProblemB::getObjVal() const +{ + real_t objVal; + + /* calculated optimal objective function value + * only if current QP has been solved */ + if ((getStatus() == QPS_AUXILIARYQPSOLVED) || (getStatus() == QPS_HOMOTOPYQPSOLVED) || + (getStatus() == QPS_SOLVED)) { + objVal = getObjVal(x); + } else { + objVal = INFTY; + } + + return objVal; +} + +/* + * g e t O b j V a l + */ +real_t QProblemB::getObjVal(const real_t * const _x) const +{ + int_t i; + int_t nV = getNV(); + + if (nV == 0) + return 0.0; + + real_t objVal = 0.0; + + for (i = 0; i < nV; ++i) + objVal += _x[i] * g[i]; + + switch (hessianType) { + case HST_ZERO: + break; + + case HST_IDENTITY: + for (i = 0; i < nV; ++i) + objVal += 0.5 * _x[i] * _x[i]; + break; + + default: + real_t * Hx = new real_t[nV]; + H->times(1, 1.0, _x, nV, 0.0, Hx, nV); + for (i = 0; i < nV; ++i) + objVal += 0.5 * _x[i] * Hx[i]; + delete[] Hx; + break; + } + + /* When using regularisation, the objective function value + * needs to be modified as follows: + * objVal = objVal - 0.5*_x*(Hmod-H)*_x - _x'*(gMod-g) + * = objVal - 0.5*_x*eps*_x * - _x'*(-eps*_x) + * = objVal + 0.5*_x*eps*_x */ + if (usingRegularisation() == BT_TRUE) { + for (i = 0; i < nV; ++i) + objVal += 0.5 * _x[i] * regVal * _x[i]; + } + + return objVal; +} + +/* + * g e t P r i m a l S o l u t i o n + */ +returnValue QProblemB::getPrimalSolution(real_t * const xOpt) const +{ + int_t i; + + /* return optimal primal solution vector + * only if current QP has been solved */ + if ((getStatus() == QPS_AUXILIARYQPSOLVED) || (getStatus() == QPS_HOMOTOPYQPSOLVED) || + (getStatus() == QPS_SOLVED)) { + for (i = 0; i < getNV(); ++i) + xOpt[i] = x[i]; + + return SUCCESSFUL_RETURN; + } else { + return RET_QP_NOT_SOLVED; + } +} + +/* + * g e t D u a l S o l u t i o n + */ +returnValue QProblemB::getDualSolution(real_t * const yOpt) const +{ + int_t i; + + for (i = 0; i < getNV(); ++i) + yOpt[i] = y[i]; + + /* return optimal dual solution vector + * only if current QP has been solved */ + if ((getStatus() == QPS_AUXILIARYQPSOLVED) || (getStatus() == QPS_HOMOTOPYQPSOLVED) || + (getStatus() == QPS_SOLVED)) { + return SUCCESSFUL_RETURN; + } else { + return RET_QP_NOT_SOLVED; + } +} + +/* + * s e t P r i n t L e v e l + */ +returnValue QProblemB::setPrintLevel(PrintLevel _printLevel) +{ +#ifndef __SUPPRESSANYOUTPUT__ +#ifndef __MATLAB__ + if ((options.printLevel == PL_HIGH) && (options.printLevel != _printLevel)) + THROWINFO(RET_PRINTLEVEL_CHANGED); +#endif /* __MATLAB__ */ + options.printLevel = _printLevel; +#else + options.printLevel = PL_NONE; +#endif /* __SUPPRESSANYOUTPUT__ */ + + /* update message handler preferences */ + switch (options.printLevel) { + case PL_NONE: + getGlobalMessageHandler()->setErrorVisibilityStatus(VS_HIDDEN); + getGlobalMessageHandler()->setWarningVisibilityStatus(VS_HIDDEN); + getGlobalMessageHandler()->setInfoVisibilityStatus(VS_HIDDEN); + break; + + case PL_TABULAR: + case PL_LOW: + getGlobalMessageHandler()->setErrorVisibilityStatus(VS_VISIBLE); + getGlobalMessageHandler()->setWarningVisibilityStatus(VS_HIDDEN); + getGlobalMessageHandler()->setInfoVisibilityStatus(VS_HIDDEN); + break; + + case PL_DEBUG_ITER: + case PL_MEDIUM: + getGlobalMessageHandler()->setErrorVisibilityStatus(VS_VISIBLE); + getGlobalMessageHandler()->setWarningVisibilityStatus(VS_VISIBLE); + getGlobalMessageHandler()->setInfoVisibilityStatus(VS_HIDDEN); + break; + + default: /* PL_HIGH */ + getGlobalMessageHandler()->setErrorVisibilityStatus(VS_VISIBLE); + getGlobalMessageHandler()->setWarningVisibilityStatus(VS_VISIBLE); + getGlobalMessageHandler()->setInfoVisibilityStatus(VS_VISIBLE); + break; + } + + return SUCCESSFUL_RETURN; +} + +/* + * p r i n t P r o p e r t i e s + */ +returnValue QProblemB::printProperties() +{ +#ifndef __SUPPRESSANYOUTPUT__ + + /* Do not print properties if print level is set to none! */ + if (options.printLevel == PL_NONE) + return SUCCESSFUL_RETURN; + + char myPrintfString[MAX_STRING_LENGTH]; + + myPrintf("\n################# qpOASES -- QP PROPERTIES #################\n"); + myPrintf("\n"); + + /* 1) Variables properties. */ + snprintf(myPrintfString, MAX_STRING_LENGTH, "Number of Variables: %4.1d\n", (int)getNV()); + myPrintf(myPrintfString); + + if (bounds.hasNoLower() == BT_TRUE) + myPrintf("Variables are not bounded from below.\n"); + else + myPrintf("Variables are bounded from below.\n"); + + if (bounds.hasNoUpper() == BT_TRUE) + myPrintf("Variables are not bounded from above.\n"); + else + myPrintf("Variables are bounded from above.\n"); + + myPrintf("\n"); + + /* 2) Further properties. */ + switch (hessianType) { + case HST_ZERO: + myPrintf("Hessian is zero matrix (i.e. actually an LP is solved).\n"); + break; + + case HST_IDENTITY: + myPrintf("Hessian is identity matrix.\n"); + break; + + case HST_POSDEF: + myPrintf("Hessian matrix is (strictly) positive definite.\n"); + break; + + case HST_POSDEF_NULLSPACE: + myPrintf("Hessian matrix is positive definite on null space of active constraints.\n"); + break; + + case HST_SEMIDEF: + myPrintf("Hessian matrix is positive semi-definite.\n"); + break; + + case HST_INDEF: + myPrintf("Hessian matrix is indefinite.\n"); + break; + + default: + myPrintf("Hessian matrix has unknown type.\n"); + break; + } + + if (infeasible == BT_TRUE) + myPrintf("QP was found to be infeasible.\n"); + else + myPrintf("QP seems to be feasible.\n"); + + if (unbounded == BT_TRUE) + myPrintf("QP was found to be unbounded from below.\n"); + else + myPrintf("QP seems to be bounded from below.\n"); + + myPrintf("\n"); + + /* 3) QP object properties. */ + switch (status) { + case QPS_NOTINITIALISED: + myPrintf("Status of QP object: freshly instantiated or reset.\n"); + break; + + case QPS_PREPARINGAUXILIARYQP: + myPrintf("Status of QP object: an auxiliary QP is currently setup.\n"); + break; + + case QPS_AUXILIARYQPSOLVED: + myPrintf("Status of QP object: an auxilary QP was solved.\n"); + break; + + case QPS_PERFORMINGHOMOTOPY: + myPrintf("Status of QP object: a homotopy step is performed.\n"); + break; + + case QPS_HOMOTOPYQPSOLVED: + myPrintf("Status of QP object: an intermediate QP along the homotopy path was solved.\n"); + break; + + case QPS_SOLVED: + myPrintf("Status of QP object: solution of the actual QP was found.\n"); + break; + } + + switch (options.printLevel) { + case PL_DEBUG_ITER: + myPrintf("Print level of QP object is set to display a tabular output for debugging.\n"); + break; + + case PL_TABULAR: + myPrintf("Print level of QP object is set to display a tabular output.\n"); + break; + + case PL_LOW: + myPrintf("Print level of QP object is low, i.e. only error are printed.\n"); + break; + + case PL_MEDIUM: + myPrintf("Print level of QP object is medium, i.e. error and warnings are printed.\n"); + break; + + case PL_HIGH: + myPrintf("Print level of QP object is high, i.e. all available output is printed.\n"); + break; + + default: + break; + } + + myPrintf("\n"); + +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +returnValue QProblemB::printOptions() const +{ + return options.print(); +} + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + +/* + * c l e a r + */ +returnValue QProblemB::clear() +{ + if ((freeHessian == BT_TRUE) && (H != 0)) { + delete H; + H = 0; + } + + if (g != 0) { + delete[] g; + g = 0; + } + + if (lb != 0) { + delete[] lb; + lb = 0; + } + + if (ub != 0) { + delete[] ub; + ub = 0; + } + + if (R != 0) { + delete[] R; + R = 0; + } + + if (x != 0) { + delete[] x; + x = 0; + } + + if (y != 0) { + delete[] y; + y = 0; + } + + if (delta_xFR_TMP != 0) { + delete[] delta_xFR_TMP; + delta_xFR_TMP = 0; + } + + return SUCCESSFUL_RETURN; +} + +/* + * c o p y + */ +returnValue QProblemB::copy(const QProblemB & rhs) +{ + uint_t _nV = (uint_t)rhs.getNV(); + + bounds = rhs.bounds; + + freeHessian = rhs.freeHessian; + + if (freeHessian == BT_TRUE) + H = (SymmetricMatrix *)(rhs.H->duplicateSym()); + else + H = rhs.H; + + if (rhs.g != 0) { + g = new real_t[_nV]; + setG(rhs.g); + } else + g = 0; + + if (rhs.lb != 0) { + lb = new real_t[_nV]; + setLB(rhs.lb); + } else + lb = 0; + + if (rhs.ub != 0) { + ub = new real_t[_nV]; + setUB(rhs.ub); + } else + ub = 0; + + if (rhs.R != 0) { + R = new real_t[_nV * _nV]; + memcpy(R, rhs.R, _nV * _nV * sizeof(real_t)); + } else + R = 0; + + haveCholesky = rhs.haveCholesky; + + if (rhs.x != 0) { + x = new real_t[_nV]; + memcpy(x, rhs.x, _nV * sizeof(real_t)); + } else + x = 0; + + if (rhs.y != 0) { + y = new real_t[_nV]; + memcpy(y, rhs.y, _nV * sizeof(real_t)); + } else + y = 0; + + tau = rhs.tau; + + hessianType = rhs.hessianType; + regVal = rhs.regVal; + + infeasible = rhs.infeasible; + unbounded = rhs.unbounded; + + status = rhs.status; + + count = rhs.count; + + ramp0 = rhs.ramp0; + ramp1 = rhs.ramp1; + // AW: Following line seemed to be missing + rampOffset = rhs.rampOffset; + + delta_xFR_TMP = new real_t[_nV]; /* nFR */ + + options = rhs.options; + setPrintLevel(options.printLevel); + + flipper = rhs.flipper; + + return SUCCESSFUL_RETURN; +} + +/* + * d e t e r m i n e H e s s i a n T y p e + */ +returnValue QProblemB::determineHessianType() +{ + int_t i; + int_t nV = getNV(); + real_t curDiag; + + /* if Hessian type has been set by user, do NOT change it! */ + switch (hessianType) { + case HST_ZERO: + /* ensure regularisation as default options do not always solve LPs */ + if (options.enableRegularisation == BT_FALSE) { + options.enableRegularisation = BT_TRUE; + options.numRegularisationSteps = 1; + } + return SUCCESSFUL_RETURN; + + case HST_IDENTITY: + return SUCCESSFUL_RETURN; + + case HST_POSDEF: + case HST_POSDEF_NULLSPACE: + case HST_SEMIDEF: + case HST_INDEF: + /* if H == 0, continue to reset hessianType to HST_ZERO + * to avoid segmentation faults! */ + if (H != 0) + return SUCCESSFUL_RETURN; + + default: + /* HST_UNKNOWN, continue */ + break; + } + + /* if Hessian has not been allocated, assume it to be all zeros! */ + if (H == 0) { + hessianType = HST_ZERO; + THROWINFO(RET_ZERO_HESSIAN_ASSUMED); + + /* ensure regularisation as default options do not always solve LPs */ + if (options.enableRegularisation == BT_FALSE) { + options.enableRegularisation = BT_TRUE; + options.numRegularisationSteps = 1; + } + + return SUCCESSFUL_RETURN; + } + + /* 1) If Hessian has outer-diagonal elements, + * Hessian is assumed to be positive definite. */ + hessianType = HST_POSDEF; + if (H->isDiag() == BT_FALSE) + return SUCCESSFUL_RETURN; + + /* 2) Otherwise it is diagonal and test for identity or zero matrix is performed. */ + BooleanType isIdentity = BT_TRUE; + BooleanType isZero = BT_TRUE; + + for (i = 0; i < nV; ++i) { + curDiag = H->diag(i); + if (curDiag >= INFTY) + return RET_DIAGONAL_NOT_INITIALISED; + + if (curDiag < -ZERO) { + hessianType = HST_INDEF; + if (options.enableFlippingBounds == BT_FALSE) + return THROWERROR(RET_HESSIAN_INDEFINITE); + else + return SUCCESSFUL_RETURN; + } + + if (getAbs(curDiag - 1.0) > EPS) + isIdentity = BT_FALSE; + + if (getAbs(curDiag) > EPS) + isZero = BT_FALSE; + } + + if (isIdentity == BT_TRUE) + hessianType = HST_IDENTITY; + + if (isZero == BT_TRUE) { + hessianType = HST_ZERO; + + /* ensure regularisation as default options do not always solve LPs */ + if (options.enableRegularisation == BT_FALSE) { + options.enableRegularisation = BT_TRUE; + options.numRegularisationSteps = 1; + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p S u b j e c t T o T y p e + */ +returnValue QProblemB::setupSubjectToType() +{ + return setupSubjectToType(lb, ub); +} + +/* + * s e t u p S u b j e c t T o T y p e + */ +returnValue QProblemB::setupSubjectToType(const real_t * const lb_new, const real_t * const ub_new) +{ + int_t i; + int_t nV = getNV(); + + /* 1) Check if lower bounds are present. */ + bounds.setNoLower(BT_TRUE); + if (lb_new != 0) { + for (i = 0; i < nV; ++i) { + if (lb_new[i] > -INFTY) { + bounds.setNoLower(BT_FALSE); + break; + } + } + } + + /* 2) Check if upper bounds are present. */ + bounds.setNoUpper(BT_TRUE); + if (ub_new != 0) { + for (i = 0; i < nV; ++i) { + if (ub_new[i] < INFTY) { + bounds.setNoUpper(BT_FALSE); + break; + } + } + } + + /* 3) Determine implicitly fixed and unbounded variables. */ + if ((lb_new != 0) && (ub_new != 0)) { + for (i = 0; i < nV; ++i) { + if ((lb_new[i] < -INFTY + options.boundTolerance) && (ub_new[i] > INFTY - options.boundTolerance) && + (options.enableFarBounds == BT_FALSE)) { + bounds.setType(i, ST_UNBOUNDED); + } else { + if (options.enableEqualities && lb[i] > ub[i] - options.boundTolerance && + lb_new[i] > ub_new[i] - options.boundTolerance) + bounds.setType(i, ST_EQUALITY); + else + bounds.setType(i, ST_BOUNDED); + } + } + } else { + if ((lb_new == 0) && (ub_new == 0)) { + for (i = 0; i < nV; ++i) + bounds.setType(i, ST_UNBOUNDED); + } else { + for (i = 0; i < nV; ++i) + bounds.setType(i, ST_BOUNDED); + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * c o m p u t e C h o l e s k y + */ +returnValue QProblemB::computeCholesky() +{ + int_t i, j; + int_t nV = getNV(); + int_t nFR = getNFR(); + + /* 1) Initialises R with all zeros. */ + for (i = 0; i < nV * nV; ++i) + R[i] = 0.0; + + /* 2) Calculate Cholesky decomposition of H (projected to free variables). */ + switch (hessianType) { + case HST_ZERO: + + /* if Hessian is zero matrix and it has been regularised, + * its Cholesky factor is the identity matrix scaled by sqrt(eps). */ + if (usingRegularisation() == BT_TRUE) { + for (i = 0; i < nV; ++i) + RR(i, i) = getSqrt(regVal); + } else { + return THROWERROR(RET_CHOLESKY_OF_ZERO_HESSIAN); + } + break; + + case HST_IDENTITY: + + /* if Hessian is identity, so is its Cholesky factor. */ + for (i = 0; i < nV; ++i) + RR(i, i) = 1.0; + break; + + default: + + if (nFR > 0) { + int_t * FR_idx; + bounds.getFree()->getNumberArray(&FR_idx); + + /* get H */ + for (j = 0; j < nFR; ++j) + H->getCol(FR_idx[j], bounds.getFree(), 1.0, &(R[j * nV])); + + /* R'*R = H */ + la_int_t info = 0; + la_uint_t _nFR = (la_uint_t)nFR, _nV = (la_uint_t)nV; + + POTRF("U", &_nFR, R, &_nV, &info); + + /* <0 = invalid call, =0 ok, >0 not spd */ + if (info > 0) { + if (R[0] < 0.0) { + /* Cholesky decomposition has tunneled a negative + * diagonal element. */ + options.epsRegularisation = + getMin(-R[0] + options.epsRegularisation, getSqrt(getAbs(options.epsRegularisation))); + } + + hessianType = HST_SEMIDEF; + return RET_HESSIAN_NOT_SPD; + } + + /* zero first subdiagonal to make givens updates work */ + for (i = 0; i < nFR - 1; ++i) + RR(i + 1, i) = 0.0; + } + break; + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p I n i t i a l C h o l e s k y + */ +returnValue QProblemB::setupInitialCholesky() +{ + returnValue returnvalueCholesky; + + /* If regularisation shall be used, always regularise at beginning + * if initial working set is not empty. */ + if ((getNV() != getNFR() - getNFV()) && (options.enableRegularisation == BT_TRUE)) + if (regulariseHessian() != SUCCESSFUL_RETURN) + return RET_INIT_FAILED_REGULARISATION; + + returnvalueCholesky = computeCholesky(); + + /* If Hessian is not positive definite, regularise and try again. */ + if (returnvalueCholesky == RET_HESSIAN_NOT_SPD) { + if (regulariseHessian() != SUCCESSFUL_RETURN) + return RET_INIT_FAILED_REGULARISATION; + + returnvalueCholesky = computeCholesky(); + } + + if (returnvalueCholesky != SUCCESSFUL_RETURN) + return RET_INIT_FAILED_CHOLESKY; + + haveCholesky = BT_TRUE; + return SUCCESSFUL_RETURN; +} + +/* + * o b t a i n A u x i l i a r y W o r k i n g S e t + */ +returnValue QProblemB::obtainAuxiliaryWorkingSet(const real_t * const xOpt, + const real_t * const yOpt, + const Bounds * const guessedBounds, + Bounds * auxiliaryBounds) const +{ + int_t i = 0; + int_t nV = getNV(); + + /* 1) Ensure that desiredBounds is allocated (and different from guessedBounds). */ + if ((auxiliaryBounds == 0) || (auxiliaryBounds == guessedBounds)) + return THROWERROR(RET_INVALID_ARGUMENTS); + + /* 2) Setup working set for auxiliary initial QP. */ + if (guessedBounds != 0) { + /* If an initial working set is specific, use it! + * Moreover, add all implictly fixed variables if specified. */ + for (i = 0; i < nV; ++i) { +#ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ + if (bounds.getType(i) == ST_EQUALITY) { + if (auxiliaryBounds->setupBound(i, ST_LOWER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + } else +#endif + { + if (auxiliaryBounds->setupBound(i, guessedBounds->getStatus(i)) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + } + } + } else /* No initial working set specified. */ + { + if ((xOpt != 0) && (yOpt == 0)) { + /* Obtain initial working set by "clipping". */ + for (i = 0; i < nV; ++i) { + if (xOpt[i] <= lb[i] + options.boundTolerance) { + if (auxiliaryBounds->setupBound(i, ST_LOWER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + continue; + } + + if (xOpt[i] >= ub[i] - options.boundTolerance) { + if (auxiliaryBounds->setupBound(i, ST_UPPER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + continue; + } + +/* Moreover, add all implictly fixed variables if specified. */ +#ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ + if (bounds.getType(i) == ST_EQUALITY) { + if (auxiliaryBounds->setupBound(i, ST_LOWER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + } else +#endif + { + if (auxiliaryBounds->setupBound(i, ST_INACTIVE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + } + } + } + + if (yOpt != 0) { + /* Obtain initial working set in accordance to sign of dual solution vector. */ + for (i = 0; i < nV; ++i) { + if (yOpt[i] > EPS) { + if (auxiliaryBounds->setupBound(i, ST_LOWER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + continue; + } + + if (yOpt[i] < -EPS) { + if (auxiliaryBounds->setupBound(i, ST_UPPER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + continue; + } + +/* Moreover, add all implictly fixed variables if specified. */ +#ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ + if (bounds.getType(i) == ST_EQUALITY) { + if (auxiliaryBounds->setupBound(i, ST_LOWER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + } else +#endif + { + if (auxiliaryBounds->setupBound(i, ST_INACTIVE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + } + } + } + + /* If xOpt and yOpt are null pointer and no initial working is specified, + * start with empty working set (or implicitly fixed bounds only) + * for auxiliary QP. */ + if ((xOpt == 0) && (yOpt == 0)) { + for (i = 0; i < nV; ++i) { + switch (bounds.getType(i)) { + case ST_UNBOUNDED: + if (auxiliaryBounds->setupBound(i, ST_INACTIVE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + break; + +/* Only add all implictly fixed variables if specified. */ +#ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ + case ST_EQUALITY: + if (auxiliaryBounds->setupBound(i, ST_LOWER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + break; +#endif + + default: + if (auxiliaryBounds->setupBound(i, options.initialStatusBounds) != SUCCESSFUL_RETURN) + return THROWERROR(RET_OBTAINING_WORKINGSET_FAILED); + break; + } + } + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * b a c k s o l v e R + */ +returnValue QProblemB::backsolveR(const real_t * const b, BooleanType transposed, real_t * const a) const +{ + /* Call standard backsolve procedure (i.e. removingBound == BT_FALSE). */ + return backsolveR(b, transposed, BT_FALSE, a); +} + +/* + * b a c k s o l v e R + */ +returnValue QProblemB::backsolveR( + const real_t * const b, BooleanType transposed, BooleanType removingBound, real_t * const a) const +{ + int_t i, j; + int_t nV = getNV(); + int_t nR = getNZ(); + + real_t sum; + + /* if backsolve is called while removing a bound, reduce nZ by one. */ + if (removingBound == BT_TRUE) + --nR; + + /* nothing to do */ + if (nR <= 0) + return SUCCESSFUL_RETURN; + + /* Solve Ra = b, where R might be transposed. */ + if (transposed == BT_FALSE) { + /* solve Ra = b */ + for (i = (nR - 1); i >= 0; --i) { + sum = b[i]; + for (j = (i + 1); j < nR; ++j) + sum -= RR(i, j) * a[j]; + + if (getAbs(RR(i, i)) >= ZERO * getAbs(sum)) + a[i] = sum / RR(i, i); + else + return THROWERROR(RET_DIV_BY_ZERO); + } + } else { + /* solve R^T*a = b */ + for (i = 0; i < nR; ++i) { + sum = b[i]; + for (j = 0; j < i; ++j) + sum -= RR(j, i) * a[j]; + + if (getAbs(RR(i, i)) >= ZERO * getAbs(sum)) + a[i] = sum / RR(i, i); + else + return THROWERROR(RET_DIV_BY_ZERO); + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * d e t e r m i n e D a t a S h i f t + */ +returnValue QProblemB::determineDataShift(const real_t * const g_new, + const real_t * const lb_new, + const real_t * const ub_new, + real_t * const delta_g, + real_t * const delta_lb, + real_t * const delta_ub, + BooleanType & Delta_bB_isZero) +{ + int_t i, ii; + int_t nV = getNV(); + int_t nFX = getNFX(); + + int_t * FX_idx; + bounds.getFixed()->getNumberArray(&FX_idx); + + /* 1) Calculate shift directions. */ + for (i = 0; i < nV; ++i) + delta_g[i] = g_new[i] - g[i]; + + if (lb_new != 0) { + for (i = 0; i < nV; ++i) + delta_lb[i] = lb_new[i] - lb[i]; + } else { + /* if no lower bounds exist, assume the new lower bounds to be -infinity */ + for (i = 0; i < nV; ++i) + delta_lb[i] = -INFTY - lb[i]; + } + + if (ub_new != 0) { + for (i = 0; i < nV; ++i) + delta_ub[i] = ub_new[i] - ub[i]; + } else { + /* if no upper bounds exist, assume the new upper bounds to be infinity */ + for (i = 0; i < nV; ++i) + delta_ub[i] = INFTY - ub[i]; + } + + /* 2) Determine if active bounds are to be shifted. */ + Delta_bB_isZero = BT_TRUE; + + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + + if ((getAbs(delta_lb[ii]) > EPS) || (getAbs(delta_ub[ii]) > EPS)) { + Delta_bB_isZero = BT_FALSE; + break; + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p Q P d a t a + */ +returnValue QProblemB::setupQPdata( + SymmetricMatrix * _H, const real_t * const _g, const real_t * const _lb, const real_t * const _ub) +{ + /* 1) Setup Hessian matrix. */ + setH(_H); + + /* 2) Setup gradient vector. */ + if (_g == 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + else + setG(_g); + + /* 3) Setup lower/upper bounds vector. */ + setLB(_lb); + setUB(_ub); + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p Q P d a t a + */ +returnValue QProblemB::setupQPdata( + const real_t * const _H, const real_t * const _g, const real_t * const _lb, const real_t * const _ub) +{ + /* 1) Setup Hessian matrix. */ + setH(_H); + + /* 2) Setup gradient vector. */ + if (_g == 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + else + setG(_g); + + /* 3) Setup lower/upper bounds vector. */ + setLB(_lb); + setUB(_ub); + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p Q P d a t a F r o m F i l e + */ +returnValue QProblemB::setupQPdataFromFile(const char * const H_file, + const char * const g_file, + const char * const lb_file, + const char * const ub_file) +{ + int_t i; + int_t nV = getNV(); + + returnValue returnvalue; + + /* 1) Load Hessian matrix from file. */ + if (H_file != 0) { + real_t * _H = new real_t[nV * nV]; + returnvalue = readFromFile(_H, nV, nV, H_file); + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] _H; + return THROWERROR(returnvalue); + } + setH(_H); + H->doFreeMemory(); + } else { + real_t * _H = 0; + setH(_H); + } + + /* 2) Load gradient vector from file. */ + if (g_file == 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + returnvalue = readFromFile(g, nV, g_file); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(returnvalue); + + /* 3) Load lower bounds vector from file. */ + if (lb_file != 0) { + returnvalue = readFromFile(lb, nV, lb_file); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(returnvalue); + } else { + /* if no lower bounds are specified, set them to -infinity */ + for (i = 0; i < nV; ++i) + lb[i] = -INFTY; + } + + /* 4) Load upper bounds vector from file. */ + if (ub_file != 0) { + returnvalue = readFromFile(ub, nV, ub_file); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(returnvalue); + } else { + /* if no upper bounds are specified, set them to infinity */ + for (i = 0; i < nV; ++i) + ub[i] = INFTY; + } + + return SUCCESSFUL_RETURN; +} + +/* + * l o a d Q P v e c t o r s F r o m F i l e + */ +returnValue QProblemB::loadQPvectorsFromFile(const char * const g_file, + const char * const lb_file, + const char * const ub_file, + real_t * const g_new, + real_t * const lb_new, + real_t * const ub_new) const +{ + int_t nV = getNV(); + + returnValue returnvalue; + + /* 1) Load gradient vector from file. */ + if ((g_file != 0) && (g_new != 0)) { + returnvalue = readFromFile(g_new, nV, g_file); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(returnvalue); + } else { + /* At least gradient vector needs to be specified! */ + return THROWERROR(RET_INVALID_ARGUMENTS); + } + + /* 2) Load lower bounds vector from file. */ + if (lb_file != 0) { + if (lb_new != 0) { + returnvalue = readFromFile(lb_new, nV, lb_file); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(returnvalue); + } else { + /* If filename is given, storage must be provided! */ + return THROWERROR(RET_INVALID_ARGUMENTS); + } + } + + /* 3) Load upper bounds vector from file. */ + if (ub_file != 0) { + if (ub_new != 0) { + returnvalue = readFromFile(ub_new, nV, ub_file); + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(returnvalue); + } else { + /* If filename is given, storage must be provided! */ + return THROWERROR(RET_INVALID_ARGUMENTS); + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t I n f e a s i b i l i t y F l a g + */ +returnValue QProblemB::setInfeasibilityFlag(returnValue returnvalue, BooleanType doThrowError) +{ + infeasible = BT_TRUE; + + if ((doThrowError == BT_TRUE) || (options.enableFarBounds == BT_FALSE)) + THROWERROR(returnvalue); + + return returnvalue; +} + +/* + * a r e B o u n d s C o n s i s t e n t + */ +returnValue QProblemB::areBoundsConsistent(const real_t * const lb_new, const real_t * const ub_new) const +{ + if (lb_new && ub_new) { + for (int_t i = 0; i < getNV(); ++i) { + if (lb_new[i] > ub_new[i] + EPS) { + return RET_QP_INFEASIBLE; + } + } + } + return SUCCESSFUL_RETURN; +} + +/* + * i s C P U t i m e L i m i t E x c e e d e d + */ +BooleanType QProblemB::isCPUtimeLimitExceeded( + const real_t * const cputime, real_t starttime, int_t nWSR) const +{ + /* Always perform next QP iteration if no CPU time limit is given. */ + if (cputime == 0) + return BT_FALSE; + + /* Always perform first QP iteration. */ + if (nWSR <= 0) + return BT_FALSE; + + real_t elapsedTime = getCPUtime() - starttime; + real_t timePerIteration = elapsedTime / ((real_t)nWSR); + + /* Determine if next QP iteration exceed CPU time limit + * considering the (current) average CPU time per iteration. */ + if ((elapsedTime + timePerIteration * 1.25) <= (*cputime)) + return BT_FALSE; + else + return BT_TRUE; +} + +/* + * r e g u l a r i s e H e s s i a n + */ +returnValue QProblemB::regulariseHessian() +{ + /* Do nothing if Hessian regularisation is disbaled! */ + if (options.enableRegularisation == BT_FALSE) + return SUCCESSFUL_RETURN; + + /* Regularisation of identity Hessian not possible. */ + if (hessianType == HST_IDENTITY) + return THROWERROR(RET_CANNOT_REGULARISE_IDENTITY); + + /* Determine regularisation parameter. */ + if (usingRegularisation() == BT_TRUE) + return SUCCESSFUL_RETURN; /*THROWERROR( RET_HESSIAN_ALREADY_REGULARISED );*/ + else { + /* Regularisation of zero Hessian is done implicitly. */ + if (hessianType == HST_ZERO) { + regVal = getNorm(g, getNV()) * options.epsRegularisation; + } else { + regVal = H->getNorm() * options.epsRegularisation; + + if (H->addToDiag(regVal) == RET_NO_DIAGONAL_AVAILABLE) + return THROWERROR(RET_CANNOT_REGULARISE_SPARSE); + } + + THROWINFO(RET_USING_REGULARISATION); + } + + return SUCCESSFUL_RETURN; +} + +/* + * c r e a t e D i a g S p a r s e M a t + */ +SymSparseMat * QProblemB::createDiagSparseMat(int_t n, real_t diagVal) +{ + real_t * M_val = new real_t[n]; + sparse_int_t * M_jc = new sparse_int_t[n + 1]; + sparse_int_t * M_ir = new sparse_int_t[n + 1]; + + for (int_t ii = 0; ii < n; ++ii) { + M_val[ii] = diagVal; + M_jc[ii] = (sparse_int_t)ii; + M_ir[ii] = (sparse_int_t)ii; + } + M_jc[n] = (sparse_int_t)n; + M_ir[n] = (sparse_int_t)n; + + SymSparseMat * M = new SymSparseMat(n, n, M_ir, M_jc, M_val); + M->createDiagInfo(); + M->doFreeMemory(); + + return M; +} + +/* + * p e r f o r m R a t i o T e s t + */ +returnValue QProblemB::performRatioTest(int_t nIdx, + const int_t * const idxList, + const SubjectTo * const subjectTo, + const real_t * const num, + const real_t * const den, + real_t epsNum, + real_t epsDen, + real_t & t, + int_t & BC_idx) const +{ + int_t i, ii; + + BC_idx = -1; + + for (i = 0; i < nIdx; ++i) { + ii = idxList[i]; + + if (subjectTo->getType(ii) != ST_EQUALITY) { + if ((subjectTo->getStatus(ii) == ST_LOWER) || (subjectTo->getStatus(ii) == ST_INACTIVE)) { + if (isBlocking(num[i], den[i], epsNum, epsDen, t) == BT_TRUE) { + t = num[i] / den[i]; + BC_idx = ii; + } + } else if (subjectTo->getStatus(ii) == ST_UPPER) { + if (isBlocking(-num[i], -den[i], epsNum, epsDen, t) == BT_TRUE) { + t = num[i] / den[i]; + BC_idx = ii; + } + } + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * g e t R e l a t i v e H o m o t o p y L e n g t h + */ +real_t QProblemB::getRelativeHomotopyLength( + const real_t * const g_new, const real_t * const lb_new, const real_t * const ub_new) +{ + int_t i; + int_t nV = getNV(); + real_t d, s, len = 0.0; + + /* gradient */ + for (i = 0; i < nV; i++) { + s = getAbs(g_new[i]); + if (s < 1.0) + s = 1.0; + d = getAbs(g_new[i] - g[i]) / s; + if (d > len) + len = d; + } + /*fprintf( stderr, "homLen = %e\n", len );*/ + + /* lower bounds */ + if (lb_new != 0) { + for (i = 0; i < nV; i++) { + s = getAbs(lb_new[i]); + if (s < 1.0) + s = 1.0; + d = getAbs(lb_new[i] - lb[i]) / s; + if (d > len) + len = d; + } + } + /*fprintf( stderr, "homLen = %e\n", len );*/ + + /* upper bounds */ + if (ub_new != 0) { + for (i = 0; i < nV; i++) { + s = getAbs(ub_new[i]); + if (s < 1.0) + s = 1.0; + d = getAbs(ub_new[i] - ub[i]) / s; + if (d > len) + len = d; + } + } + /*fprintf( stderr, "homLen = %e\n", len );*/ + + return len; +} + +/* + * p e r f o r m R a m p i n g + */ +returnValue QProblemB::performRamping() +{ + int_t nV = getNV(), bstat, i; + real_t t, rampVal; + + /* ramp inactive bounds and active dual variables */ + for (i = 0; i < nV; i++) { + switch (bounds.getType(i)) { + case ST_EQUALITY: + lb[i] = x[i]; + ub[i] = x[i]; + continue; /* reestablish exact feasibility */ + case ST_UNBOUNDED: + continue; + case ST_DISABLED: + continue; + default: + break; + } + + t = static_cast((i + rampOffset) % nV) / static_cast(nV - 1); + rampVal = (1.0 - t) * ramp0 + t * ramp1; + bstat = bounds.getStatus(i); + if (bstat != ST_LOWER) { + lb[i] = x[i] - rampVal; + } + if (bstat != ST_UPPER) { + ub[i] = x[i] + rampVal; + } + if (bstat == ST_LOWER) { + lb[i] = x[i]; + y[i] = +rampVal; + } + if (bstat == ST_UPPER) { + ub[i] = x[i]; + y[i] = -rampVal; + } + if (bstat == ST_INACTIVE) + y[i] = 0.0; /* reestablish exact complementarity */ + } + + /* reestablish exact stationarity */ + setupAuxiliaryQPgradient(); + + /* advance ramp offset to avoid Ramping cycles */ + rampOffset++; + + return SUCCESSFUL_RETURN; +} + +/* + * u p d a t e F a r B o u n d s + */ +returnValue QProblemB::updateFarBounds(real_t curFarBound, + int_t nRamp, + const real_t * const lb_new, + real_t * const lb_new_far, + const real_t * const ub_new, + real_t * const ub_new_far) const +{ + int_t i; + real_t rampVal, t; + int_t nV = getNV(); + + if (options.enableRamping == BT_TRUE) { + for (i = 0; i < nV; ++i) { + t = static_cast((i + rampOffset) % nRamp) / static_cast(nRamp - 1); + rampVal = curFarBound * (1.0 + (1.0 - t) * ramp0 + t * ramp1); + + if (lb_new == 0) + lb_new_far[i] = -rampVal; + else + lb_new_far[i] = getMax(-rampVal, lb_new[i]); + + if (ub_new == 0) + ub_new_far[i] = rampVal; + else + ub_new_far[i] = getMin(rampVal, ub_new[i]); + } + } else { + for (i = 0; i < nV; ++i) { + if (lb_new == 0) + lb_new_far[i] = -curFarBound; + else + lb_new_far[i] = getMax(-curFarBound, lb_new[i]); + + if (ub_new == 0) + ub_new_far[i] = curFarBound; + else + ub_new_far[i] = getMin(curFarBound, ub_new[i]); + } + } + + return SUCCESSFUL_RETURN; +} + +/***************************************************************************** + * P R I V A T E * + *****************************************************************************/ + +/* + * s o l v e I n i t i a l Q P + */ +returnValue QProblemB::solveInitialQP(const real_t * const xOpt, + const real_t * const yOpt, + const Bounds * const guessedBounds, + const real_t * const _R, + int_t & nWSR, + real_t * const cputime) +{ + int_t i, j; + int_t nV = getNV(); + + /* start runtime measurement */ + real_t starttime = 0.0; + if (cputime != 0) + starttime = getCPUtime(); + + status = QPS_NOTINITIALISED; + + /* I) ANALYSE QP DATA: */ + /* 1) Check if Hessian happens to be the identity matrix. */ + if (determineHessianType() != SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED); + + /* 2) Setup type of bounds (i.e. unbounded, implicitly fixed etc.). */ + if (setupSubjectToType() != SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED); + + status = QPS_PREPARINGAUXILIARYQP; + + /* II) SETUP AUXILIARY QP WITH GIVEN OPTIMAL SOLUTION: */ + /* 1) Setup bounds data structure. */ + if (bounds.setupAllFree() != SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED); + + /* 2) Setup optimal primal/dual solution for auxiliary QP. */ + if (setupAuxiliaryQPsolution(xOpt, yOpt) != SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED); + + /* 3) Obtain linear independent working set for auxiliary QP. */ + Bounds auxiliaryBounds(nV); + if (obtainAuxiliaryWorkingSet(xOpt, yOpt, guessedBounds, &auxiliaryBounds) != SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED); + + /* 4) Setup working set of auxiliary QP and possibly cholesky decomposition. */ + /* a) Working set of auxiliary QP. */ + if (setupAuxiliaryWorkingSet(&auxiliaryBounds, BT_TRUE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED); + + /* b) Regularise Hessian if necessary. */ + if ((hessianType == HST_ZERO) || (hessianType == HST_SEMIDEF)) { + if (regulariseHessian() != SUCCESSFUL_RETURN) + return THROWERROR(RET_INIT_FAILED_REGULARISATION); + } + + /* c) Copy external Cholesky factor if provided */ + haveCholesky = BT_FALSE; + + if (_R != 0) { + if (options.initialStatusBounds != ST_INACTIVE) { + THROWWARNING(RET_NO_CHOLESKY_WITH_INITIAL_GUESS); + } else { + if (_R == R) { + /* Cholesky factor read from file and already loaded into R. */ + haveCholesky = BT_TRUE; + } else if ((xOpt == 0) && (yOpt == 0) && (guessedBounds == 0)) { + for (i = 0; i < nV; ++i) + for (j = i; j < nV; ++j) + RR(i, j) = _R[i * nV + j]; + haveCholesky = BT_TRUE; + } + } + } + + /* 5) Store original QP formulation... */ + real_t * g_original = new real_t[nV]; + real_t * lb_original = new real_t[nV]; + real_t * ub_original = new real_t[nV]; + + for (i = 0; i < nV; ++i) { + g_original[i] = g[i]; + lb_original[i] = lb[i]; + ub_original[i] = ub[i]; + } + + /* ... and setup QP data of an auxiliary QP having an optimal solution + * as specified by the user (or xOpt = yOpt = 0, by default). */ + if (setupAuxiliaryQPgradient() != SUCCESSFUL_RETURN) { + delete[] ub_original; + delete[] lb_original; + delete[] g_original; + return THROWERROR(RET_INIT_FAILED); + } + + if (setupAuxiliaryQPbounds(BT_TRUE) != SUCCESSFUL_RETURN) { + delete[] ub_original; + delete[] lb_original; + delete[] g_original; + return THROWERROR(RET_INIT_FAILED); + } + + status = QPS_AUXILIARYQPSOLVED; + + /* III) SOLVE ACTUAL INITIAL QP: */ + + /* Allow only remaining CPU time for usual hotstart. */ + if (cputime != 0) + *cputime -= getCPUtime() - starttime; + + /* Use hotstart method to find the solution of the original initial QP,... */ + returnValue returnvalue = hotstart(g_original, lb_original, ub_original, nWSR, cputime); + + /* ... deallocate memory,... */ + delete[] ub_original; + delete[] lb_original; + delete[] g_original; + + /* ... check for infeasibility and unboundedness... */ + if (isInfeasible() == BT_TRUE) + return THROWERROR(RET_INIT_FAILED_INFEASIBILITY); + + if (isUnbounded() == BT_TRUE) + return THROWERROR(RET_INIT_FAILED_UNBOUNDEDNESS); + + /* ... and internal errors. */ + if ((returnvalue != SUCCESSFUL_RETURN) && (returnvalue != RET_MAX_NWSR_REACHED)) + return THROWERROR(RET_INIT_FAILED_HOTSTART); + + /* stop runtime measurement */ + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + THROWINFO(RET_INIT_SUCCESSFUL); + + return returnvalue; +} + +/* + * s o l v e Q P + */ +returnValue QProblemB::solveQP(const real_t * const g_new, + const real_t * const lb_new, + const real_t * const ub_new, + int_t & nWSR, + real_t * const cputime, + int_t nWSRperformed, + BooleanType isFirstCall) +{ + int_t iter; + int_t nV = getNV(); + + /* consistency check */ + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_PREPARINGAUXILIARYQP) || + (getStatus() == QPS_PERFORMINGHOMOTOPY)) { + return THROWERROR(RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED); + } + + /* start runtime measurement */ + real_t starttime = 0.0; + if (cputime != 0) + starttime = getCPUtime(); + + /* I) PREPARATIONS */ + /* 1) Allocate delta vectors of gradient and bounds, + * index arrays and step direction arrays. */ + real_t * delta_xFR = new real_t[nV]; + real_t * delta_xFX = new real_t[nV]; + real_t * delta_yFX = new real_t[nV]; + + real_t * delta_g = new real_t[nV]; + real_t * delta_lb = new real_t[nV]; + real_t * delta_ub = new real_t[nV]; + + returnValue returnvalue; + BooleanType Delta_bB_isZero; + + int_t BC_idx; + SubjectToStatus BC_status; + + real_t homotopyLength; + +#ifndef __SUPPRESSANYOUTPUT__ + char messageString[MAX_STRING_LENGTH]; +#endif + + /* 2) Update type of bounds, e.g. a formerly implicitly fixed + * variable might have become a normal one etc. */ + if (setupSubjectToType(lb_new, ub_new) != SUCCESSFUL_RETURN) + return THROWERROR(RET_HOTSTART_FAILED); + + /* 3) Reset status flags. */ + infeasible = BT_FALSE; + unbounded = BT_FALSE; + + /* II) MAIN HOMOTOPY LOOP */ + for (iter = nWSRperformed; iter < nWSR; ++iter) { + tabularOutput.idxAddB = tabularOutput.idxRemB = tabularOutput.idxAddC = tabularOutput.idxRemC = -1; + tabularOutput.excAddB = tabularOutput.excRemB = tabularOutput.excAddC = tabularOutput.excRemC = 0; + + if (isCPUtimeLimitExceeded(cputime, starttime, iter - nWSRperformed) == BT_TRUE) { + /* Assign number of working set recalculations and stop runtime measurement. */ + nWSR = iter; + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + break; + } + + status = QPS_PERFORMINGHOMOTOPY; + +#ifndef __SUPPRESSANYOUTPUT__ + if (isFirstCall == BT_TRUE) + snprintf(messageString, MAX_STRING_LENGTH, "%d ...", (int)iter); + else + snprintf(messageString, MAX_STRING_LENGTH, "%d* ...", (int)iter); + getGlobalMessageHandler()->throwInfo( + RET_ITERATION_STARTED, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + /* 2) Initialise shift direction of the gradient and the bounds. */ + returnvalue = determineDataShift(g_new, lb_new, ub_new, delta_g, delta_lb, delta_ub, Delta_bB_isZero); + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] delta_yFX; + delete[] delta_xFX; + delete[] delta_xFR; + delete[] delta_ub; + delete[] delta_lb; + delete[] delta_g; + + /* Assign number of working set recalculations and stop runtime measurement. */ + nWSR = iter; + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + THROWERROR(RET_SHIFT_DETERMINATION_FAILED); + return returnvalue; + } + + /* 3) Determination of step direction of X and Y. */ + returnvalue = + determineStepDirection(delta_g, delta_lb, delta_ub, Delta_bB_isZero, delta_xFX, delta_xFR, delta_yFX); + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] delta_yFX; + delete[] delta_xFX; + delete[] delta_xFR; + delete[] delta_ub; + delete[] delta_lb; + delete[] delta_g; + + /* Assign number of working set recalculations and stop runtime measurement. */ + nWSR = iter; + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + THROWERROR(RET_STEPDIRECTION_DETERMINATION_FAILED); + return returnvalue; + } + + /* 4) Determination of step length TAU. + * This step along the homotopy path is also taken (without changing working set). */ + returnvalue = + performStep(delta_g, delta_lb, delta_ub, delta_xFX, delta_xFR, delta_yFX, BC_idx, BC_status); + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] delta_yFX; + delete[] delta_xFX; + delete[] delta_xFR; + delete[] delta_ub; + delete[] delta_lb; + delete[] delta_g; + + /* Assign number of working set recalculations and stop runtime measurement. */ + nWSR = iter; + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + THROWERROR(RET_STEPLENGTH_DETERMINATION_FAILED); + return returnvalue; + } + + /* 5) Termination criterion. */ + homotopyLength = getRelativeHomotopyLength(g_new, lb_new, ub_new); + if (homotopyLength <= options.terminationTolerance) { + status = QPS_SOLVED; + + THROWINFO(RET_OPTIMAL_SOLUTION_FOUND); + + if (printIteration(iter, BC_idx, BC_status, homotopyLength, isFirstCall) != SUCCESSFUL_RETURN) + THROWERROR(RET_PRINT_ITERATION_FAILED); /* do not pass this as return value! */ + + nWSR = iter; + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + delete[] delta_yFX; + delete[] delta_xFX; + delete[] delta_xFR; + delete[] delta_ub; + delete[] delta_lb; + delete[] delta_g; + + return SUCCESSFUL_RETURN; + } + + /* 6) Change active set. */ + returnvalue = changeActiveSet(BC_idx, BC_status); + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] delta_yFX; + delete[] delta_xFX; + delete[] delta_xFR; + delete[] delta_ub; + delete[] delta_lb; + delete[] delta_g; + + /* Assign number of working set recalculations and stop runtime measurement. */ + nWSR = iter; + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + /* checks for infeasibility... */ + if (infeasible == BT_TRUE) { + status = QPS_HOMOTOPYQPSOLVED; + return setInfeasibilityFlag(RET_HOTSTART_STOPPED_INFEASIBILITY); + } + + /* ...unboundedness... */ + if (unbounded == BT_TRUE) /* not necessary since objective function convex! */ + return THROWERROR(RET_HOTSTART_STOPPED_UNBOUNDEDNESS); + + /* ... and throw unspecific error otherwise */ + THROWERROR(RET_HOMOTOPY_STEP_FAILED); + return returnvalue; + } + + /* 6a) Possibly refactorise projected Hessian from scratch. */ + if ((options.enableCholeskyRefactorisation > 0) && + ((iter % options.enableCholeskyRefactorisation) == 0)) { + returnvalue = computeCholesky(); + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] delta_yFX; + delete[] delta_xFX; + delete[] delta_xFR; + delete[] delta_ub; + delete[] delta_lb; + delete[] delta_g; + return returnvalue; + } + } + + /* 7) Perform Ramping Strategy on zero homotopy step or drift correction (if desired). */ + if ((tau <= EPS) && (options.enableRamping == BT_TRUE)) + performRamping(); + else if ((options.enableDriftCorrection > 0) && ((iter + 1) % options.enableDriftCorrection == 0)) + performDriftCorrection(); /* always returns SUCCESSFUL_RETURN */ + + /* 8) Output information of successful QP iteration. */ + status = QPS_HOMOTOPYQPSOLVED; + + if (printIteration(iter, BC_idx, BC_status, homotopyLength, isFirstCall) != SUCCESSFUL_RETURN) + THROWERROR(RET_PRINT_ITERATION_FAILED); /* do not pass this as return value! */ + } + + delete[] delta_yFX; + delete[] delta_xFX; + delete[] delta_xFR; + delete[] delta_ub; + delete[] delta_lb; + delete[] delta_g; + + /* stop runtime measurement */ + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + /* if programm gets to here, output information that QP could not be solved + * within the given maximum numbers of working set changes */ + if (options.printLevel == PL_HIGH) { +#ifndef __SUPPRESSANYOUTPUT__ + snprintf(messageString, MAX_STRING_LENGTH, "(nWSR = %d)", (int)iter); + return getGlobalMessageHandler()->throwWarning( + RET_MAX_NWSR_REACHED, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#else + return RET_MAX_NWSR_REACHED; +#endif + } else { + return RET_MAX_NWSR_REACHED; + } +} + +/* + * s o l v e R e g u l a r i s e d Q P + */ +returnValue QProblemB::solveRegularisedQP(const real_t * const g_new, + const real_t * const lb_new, + const real_t * const ub_new, + int_t & nWSR, + real_t * const cputime, + int_t nWSRperformed, + BooleanType isFirstCall) +{ + int_t i, step; + int_t nV = getNV(); + + /* Perform normal QP solution if QP has not been regularised. */ + if (usingRegularisation() == BT_FALSE) + return solveQP(g_new, lb_new, ub_new, nWSR, cputime, nWSRperformed, isFirstCall); + + /* I) SOLVE USUAL REGULARISED QP */ + returnValue returnvalue; + + int_t nWSR_max = nWSR; + int_t nWSR_total = nWSRperformed; + + real_t cputime_total = 0.0; + real_t cputime_cur = 0.0; + + if (cputime == 0) { + returnvalue = solveQP(g_new, lb_new, ub_new, nWSR, 0, nWSRperformed, isFirstCall); + } else { + cputime_cur = *cputime; + returnvalue = solveQP(g_new, lb_new, ub_new, nWSR, &cputime_cur, nWSRperformed, isFirstCall); + } + nWSR_total = nWSR; + cputime_total += cputime_cur; + isFirstCall = BT_FALSE; + + /* Only continue if QP solution has been successful. */ + if (returnvalue != SUCCESSFUL_RETURN) { + if (cputime != 0) + *cputime = cputime_total; + + if (returnvalue == RET_MAX_NWSR_REACHED) + THROWWARNING(RET_NO_REGSTEP_NWSR); + + return returnvalue; + } + + /* II) PERFORM SUCCESSIVE REGULARISATION STEPS */ + real_t * gMod = new real_t[nV]; + + for (step = 0; step < options.numRegularisationSteps; ++step) { + /* 1) Modify gradient: gMod = g - eps*xOpt + * (assuming regularisation matrix to be regVal*Id). */ + for (i = 0; i < nV; ++i) + gMod[i] = g_new[i] - regVal * x[i]; + + /* 2) Solve regularised QP with modified gradient allowing + * only as many working set recalculations and CPU time + * as have been left from previous QP solutions. */ + if (cputime == 0) { + nWSR = nWSR_max; + returnvalue = solveQP(gMod, lb_new, ub_new, nWSR, 0, nWSR_total, isFirstCall); + } else { + nWSR = nWSR_max; + cputime_cur = *cputime - cputime_total; + returnvalue = solveQP(gMod, lb_new, ub_new, nWSR, &cputime_cur, nWSR_total, isFirstCall); + } + + nWSR_total = nWSR; + cputime_total += cputime_cur; + + /* Only continue if QP solution has been successful. */ + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] gMod; + + if (cputime != 0) + *cputime = cputime_total; + + if (returnvalue == RET_MAX_NWSR_REACHED) + THROWWARNING(RET_FEWER_REGSTEPS_NWSR); + + return returnvalue; + } + } + + for (i = 0; i < nV; ++i) + g[i] = g_new[i]; + + delete[] gMod; + + if (cputime != 0) + *cputime = cputime_total; + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A u x i l i a r y W o r k i n g S e t + */ +returnValue QProblemB::setupAuxiliaryWorkingSet( + const Bounds * const auxiliaryBounds, BooleanType setupAfresh) +{ + int_t i; + int_t nV = getNV(); + + /* consistency checks */ + if (auxiliaryBounds != 0) { + for (i = 0; i < nV; ++i) + if ((bounds.getStatus(i) == ST_UNDEFINED) || (auxiliaryBounds->getStatus(i) == ST_UNDEFINED)) + return THROWERROR(RET_UNKNOWN_BUG); + } else { + return THROWERROR(RET_INVALID_ARGUMENTS); + } + + /* I) SETUP CHOLESKY FLAG: + * Cholesky decomposition shall only be updated if working set + * shall be updated (i.e. NOT setup afresh!) */ + BooleanType updateCholesky; + if (setupAfresh == BT_TRUE) + updateCholesky = BT_FALSE; + else + updateCholesky = BT_TRUE; + + /* II) REMOVE FORMERLY ACTIVE BOUNDS (IF NECESSARY): */ + if (setupAfresh == BT_FALSE) { + /* Remove all active bounds that shall be inactive AND + * all active bounds that are active at the wrong bound. */ + for (i = 0; i < nV; ++i) { + if ((bounds.getStatus(i) == ST_LOWER) && (auxiliaryBounds->getStatus(i) != ST_LOWER)) + if (removeBound(i, updateCholesky) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + + if ((bounds.getStatus(i) == ST_UPPER) && (auxiliaryBounds->getStatus(i) != ST_UPPER)) + if (removeBound(i, updateCholesky) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + } + } + + /* III) ADD NEWLY ACTIVE BOUNDS: */ + /* Add all inactive bounds that shall be active AND + * all formerly active bounds that have been active at the wrong bound. */ + for (i = 0; i < nV; ++i) { + if ((bounds.getStatus(i) == ST_INACTIVE) && (auxiliaryBounds->getStatus(i) != ST_INACTIVE)) { + if (addBound(i, auxiliaryBounds->getStatus(i), updateCholesky) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A u x i l i a r y Q P s o l u t i o n + */ +returnValue QProblemB::setupAuxiliaryQPsolution(const real_t * const xOpt, const real_t * const yOpt) +{ + int_t i; + int_t nV = getNV(); + + /* Setup primal/dual solution vectors for auxiliary initial QP: + * if a null pointer is passed, a zero vector is assigned; + * old solution vector is kept if pointer to internal solution vector is passed. */ + if (xOpt != 0) { + if (xOpt != x) + for (i = 0; i < nV; ++i) + x[i] = xOpt[i]; + } else { + for (i = 0; i < nV; ++i) + x[i] = 0.0; + } + + if (yOpt != 0) { + if (yOpt != y) + for (i = 0; i < nV; ++i) + y[i] = yOpt[i]; + } else { + for (i = 0; i < nV; ++i) + y[i] = 0.0; + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A u x i l i a r y Q P g r a d i e n t + */ +returnValue QProblemB::setupAuxiliaryQPgradient() +{ + int_t i; + int_t nV = getNV(); + + /* Setup gradient vector: g = -H*x + y'*Id. */ + switch (hessianType) { + case HST_ZERO: + if (usingRegularisation() == BT_FALSE) + for (i = 0; i < nV; ++i) + g[i] = y[i]; + else + for (i = 0; i < nV; ++i) + g[i] = y[i] - regVal * x[i]; + break; + + case HST_IDENTITY: + for (i = 0; i < nV; ++i) + g[i] = y[i] - x[i]; + break; + + default: + /* y'*Id */ + for (i = 0; i < nV; ++i) + g[i] = y[i]; + + /* -H*x */ + H->times(1, -1.0, x, nV, 1.0, g, nV); + + break; + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A u x i l i a r y Q P b o u n d s + */ +returnValue QProblemB::setupAuxiliaryQPbounds(BooleanType useRelaxation) +{ + int_t i; + int_t nV = getNV(); + + /* Setup bound vectors. */ + for (i = 0; i < nV; ++i) { + switch (bounds.getStatus(i)) { + case ST_INACTIVE: + if (useRelaxation == BT_TRUE) { + if (bounds.getType(i) == ST_EQUALITY) { + lb[i] = x[i]; + ub[i] = x[i]; + } else { + lb[i] = x[i] - options.boundRelaxation; + ub[i] = x[i] + options.boundRelaxation; + } + } + break; + + case ST_LOWER: + lb[i] = x[i]; + if (bounds.getType(i) == ST_EQUALITY) { + ub[i] = x[i]; + } else { + if (useRelaxation == BT_TRUE) + ub[i] = x[i] + options.boundRelaxation; + } + break; + + case ST_UPPER: + ub[i] = x[i]; + if (bounds.getType(i) == ST_EQUALITY) { + lb[i] = x[i]; + } else { + if (useRelaxation == BT_TRUE) + lb[i] = x[i] - options.boundRelaxation; + } + break; + + case ST_INFEASIBLE_LOWER: + case ST_INFEASIBLE_UPPER: + break; + + default: + return THROWERROR(RET_UNKNOWN_BUG); + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A u x i l i a r y Q P + */ +returnValue QProblemB::setupAuxiliaryQP(const Bounds * const guessedBounds) +{ + int_t i; + int_t nV = getNV(); + + /* nothing to do */ + if (guessedBounds == &bounds) + return SUCCESSFUL_RETURN; + + status = QPS_PREPARINGAUXILIARYQP; + + /* I) SETUP WORKING SET ... */ + if (shallRefactorise(guessedBounds) == BT_TRUE) { + /* ... WITH REFACTORISATION: */ + /* 1) Reset bounds ... */ + bounds.init(nV); + + /* ... and set them up afresh. */ + if (setupSubjectToType() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + if (bounds.setupAllFree() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + /* 2) Setup guessed working set afresh. */ + if (setupAuxiliaryWorkingSet(guessedBounds, BT_TRUE) != SUCCESSFUL_RETURN) + THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + /* 3) Calculate Cholesky decomposition. */ + if (computeCholesky() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + } else { + /* ... WITHOUT REFACTORISATION: */ + if (setupAuxiliaryWorkingSet(guessedBounds, BT_FALSE) != SUCCESSFUL_RETURN) + THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + } + + /* II) SETUP AUXILIARY QP DATA: */ + /* 1) Ensure that dual variable is zero for free bounds. */ + for (i = 0; i < nV; ++i) + if (bounds.getStatus(i) == ST_INACTIVE) + y[i] = 0.0; + + /* 2) Setup gradient and bound vectors. */ + if (setupAuxiliaryQPgradient() != SUCCESSFUL_RETURN) + THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + if (setupAuxiliaryQPbounds(BT_FALSE) != SUCCESSFUL_RETURN) + THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + return SUCCESSFUL_RETURN; +} + +/* + * d e t e r m i n e S t e p D i r e c t i o n + */ +returnValue QProblemB::determineStepDirection(const real_t * const delta_g, + const real_t * const delta_lb, + const real_t * const delta_ub, + BooleanType Delta_bB_isZero, + real_t * const delta_xFX, + real_t * const delta_xFR, + real_t * const delta_yFX) +{ + int_t i, ii; + int_t r; + int_t nFR = getNFR(); + int_t nFX = getNFX(); + + int_t * FR_idx; + int_t * FX_idx; + + bounds.getFree()->getNumberArray(&FR_idx); + bounds.getFixed()->getNumberArray(&FX_idx); + + /* This routine computes + * delta_xFX := delta_b + * delta_xFR := R \ R' \ -( delta_g + HMX*delta_xFX ) + * delta_yFX := HMX'*delta_xFR + HFX*delta_xFX { + eps*delta_xFX } + */ + + /* I) DETERMINE delta_xFX := delta_{l|u}b */ + if (Delta_bB_isZero == BT_FALSE) { + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + + if (bounds.getStatus(ii) == ST_LOWER) + delta_xFX[i] = delta_lb[ii]; + else + delta_xFX[i] = delta_ub[ii]; + } + } else { + for (i = 0; i < nFX; ++i) + delta_xFX[i] = 0.0; + } + + /* delta_xFR_TMP holds the residual, initialized with right hand side + * delta_xFR holds the step that gets refined incrementally */ + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + delta_xFR_TMP[i] = -delta_g[ii]; + delta_xFR[i] = 0.0; + } + + /* Iterative refinement loop for delta_xFR */ + for (r = 0; r <= options.numRefinementSteps; ++r) { + /* II) DETERMINE delta_xFR */ + if (nFR > 0) { + /* Add - HMX*delta_xFX + * This is skipped if delta_b=0 or mixed part HM=0 (H=0 or H=Id) */ + if ((hessianType != HST_ZERO) && (hessianType != HST_IDENTITY) && (Delta_bB_isZero == BT_FALSE) && + (r == 0)) + H->times(bounds.getFree(), bounds.getFixed(), 1, -1.0, delta_xFX, nFX, 1.0, delta_xFR_TMP, nFR); + + /* Determine R' \ ( - HMX*delta_xFX - delta_gFR ) where R'R = HFR */ + if (backsolveR(delta_xFR_TMP, BT_TRUE, delta_xFR_TMP) != SUCCESSFUL_RETURN) + return THROWERROR(RET_STEPDIRECTION_FAILED_CHOLESKY); + + /* Determine HFR \ ( - HMX*delta_xFX - delta_gFR ) */ + if (backsolveR(delta_xFR_TMP, BT_FALSE, delta_xFR_TMP) != SUCCESSFUL_RETURN) + return THROWERROR(RET_STEPDIRECTION_FAILED_CHOLESKY); + } + + /* refine solution found for delta_xFR so far */ + for (i = 0; i < nFR; ++i) + delta_xFR[i] += delta_xFR_TMP[i]; + + if (options.numRefinementSteps > 0) { + real_t rnrm = 0.0; + /* compute new residual in delta_xFR_TMP: + * residual := - HFR*delta_xFR - HMX*delta_xFX - delta_gFR + * set to -delta_gFR */ + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + delta_xFR_TMP[i] = -delta_g[ii]; + } + /* add - HFR*delta_xFR */ + switch (hessianType) { + case HST_ZERO: + break; + + case HST_IDENTITY: + for (i = 0; i < nFR; ++i) { + delta_xFR_TMP[i] -= delta_xFR[i]; + + /* compute max norm */ + if (rnrm < getAbs(delta_xFR_TMP[i])) + rnrm = getAbs(delta_xFR_TMP[i]); + } + break; + + default: + H->times(bounds.getFree(), bounds.getFree(), 1, -1.0, delta_xFR, nFR, 1.0, delta_xFR_TMP, nFR); + H->times(bounds.getFree(), bounds.getFixed(), 1, -1.0, delta_xFX, nFX, 1.0, delta_xFR_TMP, nFR); + + /* compute max norm */ + for (i = 0; i < nFR; ++i) + if (rnrm < getAbs(delta_xFR_TMP[i])) + rnrm = getAbs(delta_xFR_TMP[i]); + + break; + } + + /* early termination of residual norm small enough */ + if (rnrm < options.epsIterRef) + break; + } + + } /* end of refinement loop for delta_xFR */ + + /* III) DETERMINE delta_yFX */ + if (nFX > 0) { + if ((hessianType == HST_ZERO) || (hessianType == HST_IDENTITY)) { + for (i = 0; i < nFX; ++i) { + /* set to delta_g */ + ii = FX_idx[i]; + delta_yFX[i] = delta_g[ii]; + + /* add HFX*delta_xFX = {0|I}*delta_xFX */ + if (hessianType == HST_ZERO) { + if (usingRegularisation() == BT_TRUE) + delta_yFX[i] += regVal * delta_xFX[i]; + } else + delta_yFX[i] += delta_xFX[i]; + } + } else { + for (i = 0; i < nFX; ++i) { + /* set to delta_g */ + ii = FX_idx[i]; + delta_yFX[i] = delta_g[ii]; + } + H->times(bounds.getFixed(), bounds.getFree(), 1, 1.0, delta_xFR, nFR, 1.0, delta_yFX, nFX); + if (Delta_bB_isZero == BT_FALSE) + H->times(bounds.getFixed(), bounds.getFixed(), 1, 1.0, delta_xFX, nFX, 1.0, delta_yFX, nFX); + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * p e r f o r m S t e p + */ +returnValue QProblemB::performStep(const real_t * const delta_g, + const real_t * const delta_lb, + const real_t * const delta_ub, + const real_t * const delta_xFX, + const real_t * const delta_xFR, + const real_t * const delta_yFX, + int_t & BC_idx, + SubjectToStatus & BC_status) +{ + int_t i, ii; + int_t nV = getNV(); + int_t nFR = getNFR(); + int_t nFX = getNFX(); + + int_t * FR_idx; + int_t * FX_idx; + + bounds.getFree()->getNumberArray(&FR_idx); + bounds.getFixed()->getNumberArray(&FX_idx); + + tau = 1.0; + BC_idx = -1; + BC_status = ST_UNDEFINED; + + int_t BC_idx_tmp = -1; + + real_t * num = new real_t[nV]; + real_t * den = new real_t[nV]; + + /* I) DETERMINE MAXIMUM DUAL STEPLENGTH, i.e. ensure that + * active dual bounds remain valid (ignoring implicitly fixed variables): */ + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + num[i] = y[ii]; + den[i] = -delta_yFX[i]; + } + + performRatioTest(nFX, FX_idx, &bounds, num, den, options.epsNum, options.epsDen, tau, BC_idx_tmp); + + if (BC_idx_tmp >= 0) { + BC_idx = BC_idx_tmp; + BC_status = ST_INACTIVE; + } + + /* II) DETERMINE MAXIMUM PRIMAL STEPLENGTH, i.e. ensure that + * inactive bounds remain valid (ignoring unbounded variables). */ + /* 1) Inactive lower bounds. */ + if (bounds.hasNoLower() == BT_FALSE) { + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + num[i] = getMax(x[ii] - lb[ii], 0.0); + den[i] = delta_lb[ii] - delta_xFR[i]; + } + + performRatioTest(nFR, FR_idx, &bounds, num, den, options.epsNum, options.epsDen, tau, BC_idx_tmp); + + if (BC_idx_tmp >= 0) { + BC_idx = BC_idx_tmp; + BC_status = ST_LOWER; + } + } + + /* 2) Inactive upper bounds. */ + if (bounds.hasNoUpper() == BT_FALSE) { + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + num[i] = getMax(ub[ii] - x[ii], 0.0); + den[i] = delta_xFR[i] - delta_ub[ii]; + } + + performRatioTest(nFR, FR_idx, &bounds, num, den, options.epsNum, options.epsDen, tau, BC_idx_tmp); + + if (BC_idx_tmp >= 0) { + BC_idx = BC_idx_tmp; + BC_status = ST_UPPER; + } + } + + delete[] den; + delete[] num; + +#ifndef __SUPPRESSANYOUTPUT__ + char messageString[MAX_STRING_LENGTH]; + + if (BC_status == ST_UNDEFINED) + snprintf(messageString, MAX_STRING_LENGTH, "Stepsize is %.15e!", tau); + else + snprintf(messageString, + MAX_STRING_LENGTH, + "Stepsize is %.15e! (idx = %d, status = %d)", + tau, + (int)BC_idx, + (int)BC_status); + + getGlobalMessageHandler()->throwInfo( + RET_STEPSIZE_NONPOSITIVE, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + /* III) PERFORM STEP ALONG HOMOTOPY PATH */ + if (tau > ZERO) { + /* 1) Perform step in primal und dual space. */ + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + x[ii] += tau * delta_xFR[i]; + } + + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + x[ii] += tau * delta_xFX[i]; + y[ii] += tau * delta_yFX[i]; + } + + /* 2) Shift QP data. */ + for (i = 0; i < nV; ++i) { + g[i] += tau * delta_g[i]; + lb[i] += tau * delta_lb[i]; + ub[i] += tau * delta_ub[i]; + } + } else { +/* print a warning if stepsize is zero */ +#ifndef __SUPPRESSANYOUTPUT__ + snprintf(messageString, MAX_STRING_LENGTH, "Stepsize is %.15e", tau); + getGlobalMessageHandler()->throwWarning( + RET_STEPSIZE, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + } + + return SUCCESSFUL_RETURN; +} + +/* + * c h a n g e A c t i v e S e t + */ +returnValue QProblemB::changeActiveSet(int_t BC_idx, SubjectToStatus BC_status) +{ +#ifndef __SUPPRESSANYOUTPUT__ + char messageString[MAX_STRING_LENGTH]; +#endif + + /* IV) UPDATE ACTIVE SET */ + switch (BC_status) { + /* Optimal solution found as no working set change detected. */ + case ST_UNDEFINED: + return RET_OPTIMAL_SOLUTION_FOUND; + + /* Remove one variable from active set. */ + case ST_INACTIVE: +#ifndef __SUPPRESSANYOUTPUT__ + snprintf(messageString, MAX_STRING_LENGTH, "bound no. %d.", (int)BC_idx); + getGlobalMessageHandler()->throwInfo( + RET_REMOVE_FROM_ACTIVESET, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + if (removeBound(BC_idx, BT_TRUE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_REMOVE_FROM_ACTIVESET_FAILED); + + y[BC_idx] = 0.0; + break; + + /* Add one variable to active set. */ + default: +#ifndef __SUPPRESSANYOUTPUT__ + if (BC_status == ST_LOWER) { + snprintf(messageString, MAX_STRING_LENGTH, "lower bound no. %d.", (int)BC_idx); + } else { + snprintf(messageString, MAX_STRING_LENGTH, "upper bound no. %d.", (int)BC_idx); + } + getGlobalMessageHandler()->throwInfo( + RET_ADD_TO_ACTIVESET, messageString, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + if (addBound(BC_idx, BC_status, BT_TRUE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ADD_TO_ACTIVESET_FAILED); + break; + } + + return SUCCESSFUL_RETURN; +} + +/* + * p e r f o r m D r i f t C o r r e c t i o n + */ +returnValue QProblemB::performDriftCorrection() +{ + int_t i; + int_t nV = getNV(); + + for (i = 0; i < nV; ++i) { + switch (bounds.getType(i)) { + case ST_BOUNDED: + switch (bounds.getStatus(i)) { + case ST_LOWER: + lb[i] = x[i]; + ub[i] = getMax(ub[i], x[i]); + y[i] = getMax(y[i], 0.0); + break; + case ST_UPPER: + lb[i] = getMin(lb[i], x[i]); + ub[i] = x[i]; + y[i] = getMin(y[i], 0.0); + break; + case ST_INACTIVE: + lb[i] = getMin(lb[i], x[i]); + ub[i] = getMax(ub[i], x[i]); + y[i] = 0.0; + break; + case ST_UNDEFINED: + case ST_INFEASIBLE_LOWER: + case ST_INFEASIBLE_UPPER: + break; + } + break; + case ST_EQUALITY: + lb[i] = x[i]; + ub[i] = x[i]; + break; + case ST_UNBOUNDED: + case ST_UNKNOWN: + case ST_DISABLED: + break; + } + } + + return setupAuxiliaryQPgradient(); +} + +/* + * s h a l l R e f a c t o r i s e + */ +BooleanType QProblemB::shallRefactorise(const Bounds * const guessedBounds) const +{ + int_t i; + int_t nV = getNV(); + + /* always refactorise if Hessian is not known to be positive definite */ + if ((hessianType == HST_SEMIDEF) || (hessianType == HST_INDEF)) + return BT_TRUE; + + /* 1) Determine number of bounds that have same status + * in guessed AND current bounds.*/ + int_t differenceNumber = 0; + + for (i = 0; i < nV; ++i) + if (guessedBounds->getStatus(i) != bounds.getStatus(i)) + ++differenceNumber; + + /* 2) Decide wheter to refactorise or not. */ + if (2 * differenceNumber > guessedBounds->getNFX()) + return BT_TRUE; + else + return BT_FALSE; +} + +/* + * a d d B o u n d + */ +returnValue QProblemB::addBound(int_t number, SubjectToStatus B_status, BooleanType updateCholesky) +{ + int_t i, j; + int_t nV = getNV(); + int_t nFR = getNFR(); + + /* consistency check */ + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_AUXILIARYQPSOLVED) || + (getStatus() == QPS_HOMOTOPYQPSOLVED) || (getStatus() == QPS_SOLVED)) { + return THROWERROR(RET_UNKNOWN_BUG); + } + + /* Perform cholesky updates only if QProblemB has been initialised! */ + if (getStatus() == QPS_PREPARINGAUXILIARYQP) { + /* UPDATE INDICES */ + if (bounds.moveFreeToFixed(number, B_status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ADDBOUND_FAILED); + + return SUCCESSFUL_RETURN; + } + + /* I) PERFORM CHOLESKY UPDATE: */ + if ((updateCholesky == BT_TRUE) && (hessianType != HST_ZERO) && (hessianType != HST_IDENTITY)) { + /* 1) Index of variable to be added within the list of free variables. */ + int_t number_idx = bounds.getFree()->getIndex(number); + + real_t c, s, nu; + + /* 2) Use row-wise Givens rotations to restore upper triangular form of R. */ + for (i = number_idx + 1; i < nFR; ++i) { + computeGivens(RR(i - 1, i), RR(i, i), RR(i - 1, i), RR(i, i), c, s); + nu = s / (1.0 + c); + + for (j = (1 + i); j < nFR; ++j) /* last column of R is thrown away */ + applyGivens(c, s, nu, RR(i - 1, j), RR(i, j), RR(i - 1, j), RR(i, j)); + } + + /* 3) Delete th column and ... */ + for (i = 0; i < nFR - 1; ++i) + for (j = number_idx + 1; j < nFR; ++j) + RR(i, j - 1) = RR(i, j); + /* ... last column of R. */ + for (i = 0; i < nFR; ++i) + RR(i, nFR - 1) = 0.0; + } + + /* II) UPDATE INDICES */ + tabularOutput.idxAddB = number; + if (bounds.moveFreeToFixed(number, B_status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ADDBOUND_FAILED); + + return SUCCESSFUL_RETURN; +} + +/* + * r e m o v e B o u n d + */ +returnValue QProblemB::removeBound(int_t number, BooleanType updateCholesky) +{ + int_t i; + int_t nV = getNV(); + int_t nFR = getNFR(); + + /* consistency check */ + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_AUXILIARYQPSOLVED) || + (getStatus() == QPS_HOMOTOPYQPSOLVED) || (getStatus() == QPS_SOLVED)) { + return THROWERROR(RET_UNKNOWN_BUG); + } + + /* save index sets and decompositions for flipping bounds strategy */ + if (options.enableFlippingBounds == BT_TRUE) + flipper.set(&bounds, R); + + /* I) UPDATE INDICES */ + tabularOutput.idxRemB = number; + if (bounds.moveFixedToFree(number) != SUCCESSFUL_RETURN) + return THROWERROR(RET_REMOVEBOUND_FAILED); + + /* Perform cholesky updates only if QProblemB has been initialised! */ + if (getStatus() == QPS_PREPARINGAUXILIARYQP) + return SUCCESSFUL_RETURN; + + /* II) PERFORM CHOLESKY UPDATE */ + if ((updateCholesky == BT_TRUE) && (hessianType != HST_ZERO) && (hessianType != HST_IDENTITY)) { + int_t * FR_idx; + bounds.getFree()->getNumberArray(&FR_idx); + + /* 1) Calculate new column of cholesky decomposition. */ + real_t * rhs = new real_t[nFR + 1]; + real_t * r = new real_t[nFR]; + + real_t r0; + switch (hessianType) { + case HST_ZERO: /* TODO: Code can/should? never get here!! */ + if (usingRegularisation() == BT_FALSE) + r0 = 0.0; + else + r0 = regVal; + for (i = 0; i < nFR; ++i) + rhs[i] = 0.0; + break; + + case HST_IDENTITY: + r0 = 1.0; + for (i = 0; i < nFR; ++i) + rhs[i] = 0.0; + break; + + default: + H->getRow(number, bounds.getFree(), 1.0, rhs); + r0 = H->diag(number); + break; + } + + if (backsolveR(rhs, BT_TRUE, BT_TRUE, r) != SUCCESSFUL_RETURN) { + delete[] rhs; + delete[] r; + return THROWERROR(RET_REMOVEBOUND_FAILED); + } + + for (i = 0; i < nFR; ++i) + r0 -= r[i] * r[i]; + + /* 2) Store new column into R. */ + for (i = 0; i < nFR; ++i) + RR(i, nFR) = r[i]; + + if (options.enableFlippingBounds == BT_TRUE) { + if (r0 > options.epsFlipping) + RR(nFR, nFR) = getSqrt(r0); + else { + hessianType = HST_SEMIDEF; + + flipper.get(&bounds, R); + bounds.flipFixed(number); + + switch (bounds.getStatus(number)) { + case ST_LOWER: + lb[number] = ub[number]; + break; + case ST_UPPER: + ub[number] = lb[number]; + break; + default: + delete[] rhs; + delete[] r; + return THROWERROR(RET_MOVING_BOUND_FAILED); + } + } + } else { + if (r0 > ZERO) + RR(nFR, nFR) = getSqrt(r0); + else { + delete[] rhs; + delete[] r; + + hessianType = HST_SEMIDEF; + return THROWERROR(RET_HESSIAN_NOT_SPD); + } + } + + delete[] rhs; + delete[] r; + } + + if ((hessianType == HST_ZERO) && (options.enableFlippingBounds == BT_TRUE)) { + flipper.get(&bounds, R); + bounds.flipFixed(number); + + switch (bounds.getStatus(number)) { + case ST_LOWER: + lb[number] = ub[number]; + break; + case ST_UPPER: + ub[number] = lb[number]; + break; + default: + return THROWERROR(RET_MOVING_BOUND_FAILED); + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * p r i n t I t e r a t i o n + */ +returnValue QProblemB::printIteration( + int_t iter, int_t BC_idx, SubjectToStatus BC_status, real_t homotopyLength, BooleanType isFirstCall) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + /* consistency check */ + if (iter < 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + int_t i; + int_t nV = getNV(); + real_t stat, bfeas, bcmpl; + real_t * grad = 0; + + char myPrintfString[MAX_STRING_LENGTH]; + char info[MAX_STRING_LENGTH]; + const char excStr[] = " ef"; + + switch (options.printLevel) { + case PL_DEBUG_ITER: + grad = new real_t[nV]; + stat = bfeas = bcmpl = 0.0; + + /* stationarity */ + for (i = 0; i < nV; i++) + grad[i] = g[i] - y[i]; + H->times(1, 1.0, x, nV, 1.0, grad, nV); + for (i = 0; i < nV; i++) + if (getAbs(grad[i]) > stat) + stat = getAbs(grad[i]); + + /* feasibility */ + for (i = 0; i < nV; i++) + if (lb[i] - x[i] > bfeas) + bfeas = lb[i] - x[i]; + for (i = 0; i < nV; i++) + if (x[i] - ub[i] > bfeas) + bfeas = x[i] - ub[i]; + + /* complementarity */ + for (i = 0; i < nV; i++) + if (y[i] > +EPS && getAbs((lb[i] - x[i]) * y[i]) > bcmpl) + bcmpl = getAbs((lb[i] - x[i]) * y[i]); + for (i = 0; i < nV; i++) + if (y[i] < -EPS && getAbs((ub[i] - x[i]) * y[i]) > bcmpl) + bcmpl = getAbs((ub[i] - x[i]) * y[i]); + + if ((iter % 10 == 0) && (isFirstCall == BT_TRUE)) { + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "\n%5s %4s %4s %9s %9s %9s %9s %9s\n", + "iter", + "addB", + "remB", + "hom len", + "tau", + "stat", + "bfeas", + "bcmpl"); + } + myPrintf(myPrintfString); + + snprintf(myPrintfString, MAX_STRING_LENGTH, "%5d ", (int)iter); + myPrintf(myPrintfString); + + if (tabularOutput.idxAddB >= 0) { + snprintf(myPrintfString, MAX_STRING_LENGTH, "%4d ", (int)(tabularOutput.idxAddB)); + myPrintf(myPrintfString); + } else { + myPrintf(" "); + } + + if (tabularOutput.idxRemB >= 0) { + snprintf(myPrintfString, MAX_STRING_LENGTH, "%4d ", (int)(tabularOutput.idxRemB)); + myPrintf(myPrintfString); + } else { + myPrintf(" "); + } + + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "%9.2e %9.2e %9.2e %9.2e %9.2e\n", + homotopyLength, + tau, + stat, + bfeas, + bcmpl); + myPrintf(myPrintfString); + + delete[] grad; + break; + + case PL_TABULAR: + if ((iter % 10 == 0) && (isFirstCall == BT_TRUE)) { + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "\n%5s %6s %6s %9s %9s\n", + "iter", + "addB", + "remB", + "hom len", + "tau"); + myPrintf(myPrintfString); + } + + snprintf(myPrintfString, MAX_STRING_LENGTH, "%5d ", (int)iter); + myPrintf(myPrintfString); + + if (tabularOutput.idxAddB >= 0) { + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "%5d%c ", + (int)(tabularOutput.idxAddB), + excStr[tabularOutput.excAddB]); + myPrintf(myPrintfString); + } else { + myPrintf(" "); + } + + if (tabularOutput.idxRemB >= 0) { + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "%5d%c ", + (int)(tabularOutput.idxRemB), + excStr[tabularOutput.excRemB]); + myPrintf(myPrintfString); + } else { + myPrintf(" "); + } + + snprintf(myPrintfString, MAX_STRING_LENGTH, "%9.2e %9.2e\n", homotopyLength, tau); + myPrintf(myPrintfString); + break; + + case PL_MEDIUM: + /* 1) Print header at first iteration. */ + if ((iter == 0) && (isFirstCall == BT_TRUE)) { + snprintf(myPrintfString, + MAX_STRING_LENGTH, + "\n\n################# qpOASES -- QP NO. %3.0d ##################\n\n", + (int)count); + myPrintf(myPrintfString); + + myPrintf(" Iter | StepLength | Info | nFX \n"); + myPrintf(" ----------+------------------+------------------+--------- \n"); + } + + /* 2) Print iteration line. */ + if (BC_status == ST_UNDEFINED) { + if (hessianType == HST_ZERO) + snprintf(info, 3, "LP"); + else + snprintf(info, 3, "QP"); + + if (isFirstCall == BT_TRUE) + snprintf(myPrintfString, + MAX_STRING_LENGTH, + " %5.1d | %1.6e | %s SOLVED | %4.1d \n", + (int)iter, + tau, + info, + (int)getNFX()); + else + snprintf(myPrintfString, + MAX_STRING_LENGTH, + " %5.1d* | %1.6e | %s SOLVED | %4.1d \n", + (int)iter, + tau, + info, + (int)getNFX()); + myPrintf(myPrintfString); + } else { + if (BC_status == ST_INACTIVE) + snprintf(info, 8, "REM BND"); + else + snprintf(info, 8, "ADD BND"); + + snprintf(myPrintfString, + MAX_STRING_LENGTH, + " %5.1d | %1.6e | %s %4.1d | %4.1d \n", + (int)iter, + tau, + info, + (int)BC_idx, + (int)getNFX()); + myPrintf(myPrintfString); + } + break; + + default: + /* nothing to display */ + break; + } + +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/SQProblem.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/SQProblem.cpp new file mode 100644 index 0000000..627cf53 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/SQProblem.cpp @@ -0,0 +1,533 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/SQProblem.cpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of the SQProblem class which is able to use the newly + * developed online active set strategy for parametric quadratic programming + * with varying matrices. + */ + +#include + +BEGIN_NAMESPACE_QPOASES + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +/* + * S Q P r o b l e m + */ +SQProblem::SQProblem() : QProblem() +{ +} + +/* + * S Q P r o b l e m + */ +SQProblem::SQProblem(int_t _nV, int_t _nC, HessianType _hessianType, BooleanType allocDenseMats) +: QProblem(_nV, _nC, _hessianType, allocDenseMats) +{ +} + +/* + * S Q P r o b l e m + */ +SQProblem::SQProblem(const SQProblem & rhs) : QProblem(rhs) +{ +} + +/* + * ~ S Q P r o b l e m + */ +SQProblem::~SQProblem() +{ +} + +/* + * o p e r a t o r = + */ +SQProblem & SQProblem::operator=(const SQProblem & rhs) +{ + if (this != &rhs) { + QProblem::operator=(rhs); + } + + return *this; +} + +/* + * h o t s t a r t + */ +returnValue SQProblem::hotstart(SymmetricMatrix * H_new, + const real_t * const g_new, + Matrix * A_new, + const real_t * const lb_new, + const real_t * const ub_new, + const real_t * const lbA_new, + const real_t * const ubA_new, + int_t & nWSR, + real_t * const cputime, + const Bounds * const guessedBounds, + const Constraints * const guessedConstraints) +{ + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_PREPARINGAUXILIARYQP) || + (getStatus() == QPS_PERFORMINGHOMOTOPY)) { + return THROWERROR(RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED); + } + + real_t starttime = 0.0; + real_t auxTime = 0.0; + + if (cputime != 0) { + starttime = getCPUtime(); + } + + /* I) UPDATE QP MATRICES AND VECTORS */ + if (setupNewAuxiliaryQP(H_new, A_new, lb_new, ub_new, lbA_new, ubA_new) != SUCCESSFUL_RETURN) { + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + } + + /* II) PERFORM USUAL HOMOTOPY */ + + /* Allow only remaining CPU time for usual hotstart. */ + if (cputime != 0) { + auxTime = getCPUtime() - starttime; + *cputime -= auxTime; + } + + returnValue returnvalue = QProblem::hotstart( + g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR, cputime, guessedBounds, guessedConstraints); + + if (cputime != 0) { + *cputime += auxTime; + } + + return returnvalue; +} + +/* + * h o t s t a r t + */ +returnValue SQProblem::hotstart(const real_t * const H_new, + const real_t * const g_new, + const real_t * const A_new, + const real_t * const lb_new, + const real_t * const ub_new, + const real_t * const lbA_new, + const real_t * const ubA_new, + int_t & nWSR, + real_t * const cputime, + const Bounds * const guessedBounds, + const Constraints * const guessedConstraints) +{ + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_PREPARINGAUXILIARYQP) || + (getStatus() == QPS_PERFORMINGHOMOTOPY)) { + return THROWERROR(RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED); + } + + /* start runtime measurement */ + real_t starttime = 0.0; + if (cputime != 0) { + starttime = getCPUtime(); + } + + /* I) UPDATE QP MATRICES AND VECTORS */ + if (setupNewAuxiliaryQP(H_new, A_new, lb_new, ub_new, lbA_new, ubA_new) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + /* II) PERFORM USUAL HOMOTOPY */ + + /* Allow only remaining CPU time for usual hotstart. */ + if (cputime != 0) { + *cputime -= getCPUtime() - starttime; + } + + returnValue returnvalue = QProblem::hotstart( + g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR, cputime, guessedBounds, guessedConstraints); + + /* stop runtime measurement */ + if (cputime != 0) + *cputime = getCPUtime() - starttime; + + return returnvalue; +} + +/* + * h o t s t a r t + */ +returnValue SQProblem::hotstart(const char * const H_file, + const char * const g_file, + const char * const A_file, + const char * const lb_file, + const char * const ub_file, + const char * const lbA_file, + const char * const ubA_file, + int_t & nWSR, + real_t * const cputime, + const Bounds * const guessedBounds, + const Constraints * const guessedConstraints) +{ + int_t nV = getNV(); + int_t nC = getNC(); + + returnValue returnvalue; + + /* consistency checks */ + if ((H_file == 0) || (g_file == 0)) + return THROWERROR(RET_INVALID_ARGUMENTS); + + if ((nC > 0) && (A_file == 0)) + return THROWERROR(RET_INVALID_ARGUMENTS); + + /* 1) Load new QP matrices from files. */ + real_t * H_new = new real_t[nV * nV]; + real_t * A_new = new real_t[nC * nV]; + + if (readFromFile(H_new, nV, nV, H_file) != SUCCESSFUL_RETURN) { + delete[] A_new; + delete[] H_new; + return THROWERROR(RET_UNABLE_TO_READ_FILE); + } + + if (readFromFile(A_new, nC, nV, A_file) != SUCCESSFUL_RETURN) { + delete[] A_new; + delete[] H_new; + return THROWERROR(RET_UNABLE_TO_READ_FILE); + } + + /* 2) Load new QP vectors from files. */ + real_t * g_new = new real_t[nV]; + real_t * lb_new = (lb_file != 0) ? new real_t[nV] : 0; + real_t * ub_new = (ub_file != 0) ? new real_t[nV] : 0; + real_t * lbA_new = (lbA_file != 0) ? new real_t[nC] : 0; + real_t * ubA_new = (ubA_file != 0) ? new real_t[nC] : 0; + + returnvalue = loadQPvectorsFromFile( + g_file, lb_file, ub_file, lbA_file, ubA_file, g_new, lb_new, ub_new, lbA_new, ubA_new); + if (returnvalue != SUCCESSFUL_RETURN) { + if (ubA_file != 0) + delete[] ubA_new; + if (lbA_file != 0) + delete[] lbA_new; + if (ub_file != 0) + delete[] ub_new; + if (lb_file != 0) + delete[] lb_new; + delete[] g_new; + delete[] A_new; + delete[] H_new; + + return THROWERROR(RET_UNABLE_TO_READ_FILE); + } + + /* 3) Actually perform hotstart. */ + returnvalue = hotstart(H_new, + g_new, + A_new, + lb_new, + ub_new, + lbA_new, + ubA_new, + nWSR, + cputime, + guessedBounds, + guessedConstraints); + + if (ubA_file != 0) + delete[] ubA_new; + if (lbA_file != 0) + delete[] lbA_new; + if (ub_file != 0) + delete[] ub_new; + if (lb_file != 0) + delete[] lb_new; + delete[] g_new; + delete[] A_new; + delete[] H_new; + + return returnvalue; +} + +/* + * h o t s t a r t + */ +returnValue SQProblem::hotstart(const real_t * const g_new, + const real_t * const lb_new, + const real_t * const ub_new, + const real_t * const lbA_new, + const real_t * const ubA_new, + int_t & nWSR, + real_t * const cputime, + const Bounds * const guessedBounds, + const Constraints * const guessedConstraints) +{ + /* Call to hotstart function for fixed QP matrices. */ + return QProblem::hotstart( + g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR, cputime, guessedBounds, guessedConstraints); +} + +/* + * h o t s t a r t + */ +returnValue SQProblem::hotstart(const char * const g_file, + const char * const lb_file, + const char * const ub_file, + const char * const lbA_file, + const char * const ubA_file, + int_t & nWSR, + real_t * const cputime, + const Bounds * const guessedBounds, + const Constraints * const guessedConstraints) +{ + /* Call to hotstart function for fixed QP matrices. */ + return QProblem::hotstart( + g_file, lb_file, ub_file, lbA_file, ubA_file, nWSR, cputime, guessedBounds, guessedConstraints); +} + +#ifdef __MATLAB__ +returnValue SQProblem::resetMatrixPointers() +{ + H = 0; + A = 0; + + return SUCCESSFUL_RETURN; +} +#endif + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + +/* + * s e t u p N e w A u x i l i a r y Q P + */ +returnValue SQProblem::setupNewAuxiliaryQP(SymmetricMatrix * H_new, + Matrix * A_new, + const real_t * lb_new, + const real_t * ub_new, + const real_t * lbA_new, + const real_t * ubA_new) +{ + int_t i; + int_t nV = getNV(); + int_t nC = getNC(); + returnValue returnvalue; + + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_PREPARINGAUXILIARYQP) || + (getStatus() == QPS_PERFORMINGHOMOTOPY)) { + return THROWERROR(RET_UPDATEMATRICES_FAILED_AS_QP_NOT_SOLVED); + } + + status = QPS_PREPARINGAUXILIARYQP; + + /* I) SETUP NEW QP MATRICES AND VECTORS: */ + /* 1) Shift constraints' bounds vectors by (A_new - A)'*x_opt to ensure + * that old optimal solution remains feasible for new QP data. */ + /* Firstly, shift by -A'*x_opt and ... */ + if (nC > 0) { + if (A_new == 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + for (i = 0; i < nC; ++i) { + lbA[i] = -Ax_l[i]; + ubA[i] = Ax_u[i]; + } + + /* Set constraint matrix as well as ... */ + setA(A_new); + + /* ... secondly, shift by +A_new'*x_opt. */ + for (i = 0; i < nC; ++i) { + lbA[i] += Ax[i]; + ubA[i] += Ax[i]; + } + + /* update constraint products. */ + for (i = 0; i < nC; ++i) { + Ax_u[i] = ubA[i] - Ax[i]; + Ax_l[i] = Ax[i] - lbA[i]; + } + } + + /* 2) Set new Hessian matrix, determine Hessian type and + * regularise new Hessian matrix if necessary. */ + /* a) Setup new Hessian matrix and determine its type. */ + if (H_new != 0) { + setH(H_new); + + hessianType = HST_UNKNOWN; + if (determineHessianType() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + /* b) Regularise new Hessian if necessary. */ + if ((hessianType == HST_ZERO) || (hessianType == HST_SEMIDEF) || (usingRegularisation() == BT_TRUE)) { + regVal = 0.0; /* reset previous regularisation */ + + if (regulariseHessian() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + } + } else { + /* if no Hessian is specified, keep previous trivial Hessian (HST_ZERO or HST_IDENTITY), + otherwise abort */ + if (H != 0) + return THROWERROR(RET_NO_HESSIAN_SPECIFIED); + } + + /* 3) Setup QP gradient. */ + if (setupAuxiliaryQPgradient() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + /* II) SETUP WORKING SETS AND MATRIX FACTORISATIONS: */ + /* 1) Make a copy of current bounds/constraints ... */ + Bounds oldBounds = bounds; + Constraints oldConstraints = constraints; + + /* we're trying to find an active set with positive definite null + * space Hessian twice: + * - first for the current active set including all equalities + * - second after moving all inactive variables to a bound + * (depending on Options). This creates an empty null space and + * is guaranteed to succeed. Thus this loop will exit after n_try=1. + */ + int_t n_try; + for (n_try = 0; n_try < 2; ++n_try) { + if (n_try > 0) { + // the current active set leaves an indefinite null space Hessian + // move all inactive variables to a bound, creating an empty null space + for (int_t ii = 0; ii < nV; ++ii) + if (oldBounds.getStatus(ii) == ST_INACTIVE) + oldBounds.setStatus(ii, options.initialStatusBounds); + } + + /* ... reset them ... */ + bounds.init(nV); + constraints.init(nC); + + /* ... and set them up afresh. */ + if (setupSubjectToType(lb_new, ub_new, lbA_new, ubA_new) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + if (bounds.setupAllFree() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + if (constraints.setupAllInactive() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + /* 2) Setup TQ factorisation. */ + if (setupTQfactorisation() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + // check for equalities that have become bounds ... + for (int_t ii = 0; ii < nC; ++ii) { + if (oldConstraints.getType(ii) == ST_EQUALITY && constraints.getType(ii) == ST_BOUNDED) { + if (oldConstraints.getStatus(ii) == ST_LOWER && y[nV + ii] < 0.0) + oldConstraints.setStatus(ii, ST_UPPER); + else if (oldConstraints.getStatus(ii) == ST_UPPER && y[nV + ii] > 0.0) + oldConstraints.setStatus(ii, ST_LOWER); + } + } + + // ... and do the same also for the bounds! + for (int_t ii = 0; ii < nV; ++ii) { + if (oldBounds.getType(ii) == ST_EQUALITY && bounds.getType(ii) == ST_BOUNDED) { + if (oldBounds.getStatus(ii) == ST_LOWER && y[ii] < 0.0) + oldBounds.setStatus(ii, ST_UPPER); + else if (oldBounds.getStatus(ii) == ST_UPPER && y[ii] > 0.0) + oldBounds.setStatus(ii, ST_LOWER); + } + } + + /* 3) Setup old working sets afresh (updating TQ factorisation). */ + if (setupAuxiliaryWorkingSet(&oldBounds, &oldConstraints, BT_TRUE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + /* Factorise projected Hessian + * this now handles all special cases (no active bounds/constraints, no nullspace) */ + returnvalue = computeProjectedCholesky(); + + /* leave the loop if decomposition was successful, i.e. we have + * found an active set with positive definite null space Hessian */ + if (returnvalue == SUCCESSFUL_RETURN) + break; + } + + /* adjust lb/ub if we changed the old active set in the second try + */ + if (n_try > 0) { + // as per setupAuxiliaryQPbounds assumptions ... oh the troubles + for (int_t ii = 0; ii < nC; ++ii) + Ax_l[ii] = Ax_u[ii] = Ax[ii]; + setupAuxiliaryQPbounds(&bounds, &constraints, BT_FALSE); + } + + status = QPS_AUXILIARYQPSOLVED; + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p N e w A u x i l i a r y Q P + */ +returnValue SQProblem::setupNewAuxiliaryQP(const real_t * const H_new, + const real_t * const A_new, + const real_t * lb_new, + const real_t * ub_new, + const real_t * lbA_new, + const real_t * ubA_new) +{ + int_t nV = getNV(); + int_t nC = getNC(); + + DenseMatrix * dA = 0; + SymDenseMat * sH = 0; + + if (A_new != 0) { + dA = new DenseMatrix(nC, nV, nV, (real_t *)A_new); + } else { + if (nC > 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + } + + if (H_new != 0) + sH = new SymDenseMat(nV, nV, nV, (real_t *)H_new); + + returnValue returnvalue = setupNewAuxiliaryQP(sH, dA, lb_new, ub_new, lbA_new, ubA_new); + + if (H_new != 0) + freeHessian = BT_TRUE; + freeConstraintMatrix = BT_TRUE; + + return returnvalue; +} + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/SQProblemSchur.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/SQProblemSchur.cpp new file mode 100644 index 0000000..54bcc1c --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/SQProblemSchur.cpp @@ -0,0 +1,3529 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2014 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/SQProblemSchur.cpp + * \author Andreas Waechter and Dennis Janka, based on QProblem.cpp by Hans Joachim Ferreau, Andreas + *Potschka, Christian Kirches \version 3.2 \date 2012-2017 + * + * Implementation of the SQProblemSchur class which is able to use the newly + * developed online active set strategy for parametric quadratic programming. + * This implementation uses a Schur complement approach to solve the linear + * systems. + */ + +#include +#include + +#ifndef __MATLAB__ +#include +#include +void MyPrintf(const char * pformat, ...) +{ + va_list ap; + va_start(ap, pformat); + + vfprintf(stdout, pformat, ap); + + va_end(ap); +} +#else +#include +#define MyPrintf mexPrintf +#endif + +BEGIN_NAMESPACE_QPOASES + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +/* + * Q P r o b l e m + */ +SQProblemSchur::SQProblemSchur() : SQProblem() +{ +#ifdef SOLVER_MA57 + sparseSolver = new Ma57SparseSolver(); +#elif defined SOLVER_MA27 + sparseSolver = new Ma27SparseSolver(); +#elif defined SOLVER_MUMPS + sparseSolver = new MumpsSparseSolver(); +#elif defined SOLVER_NONE + sparseSolver = new DummySparseSolver(); +#endif + + nSmax = 0; + nS = -1; + S = 0; + Q_ = 0; + R_ = 0; + detS = 0.0; + rcondS = 0.0; + schurUpdateIndex = 0; + schurUpdate = 0; + numFactorizations = 0; + + M_physicallength = 0; + M_vals = 0; + M_ir = 0; + M_jc = 0; +} + +/* + * Q P r o b l e m + */ +SQProblemSchur::SQProblemSchur(int_t _nV, int_t _nC, HessianType _hessianType, int_t maxSchurUpdates) +: SQProblem(_nV, _nC, _hessianType, BT_FALSE) +{ + /* The interface to the sparse linear solver. In the long run, + different linear solvers might be optionally chosen. */ +#ifdef SOLVER_MA57 + sparseSolver = new Ma57SparseSolver(); +#elif defined SOLVER_MA27 + sparseSolver = new Ma27SparseSolver(); +#elif defined SOLVER_MUMPS + sparseSolver = new MumpsSparseSolver(); +#elif defined SOLVER_NONE + sparseSolver = new DummySparseSolver(); +#endif + + nSmax = maxSchurUpdates; + nS = -1; + if (nSmax > 0) { + S = new real_t[nSmax * nSmax]; + schurUpdateIndex = new int_t[nSmax]; + schurUpdate = new SchurUpdateType[nSmax]; + Q_ = new real_t[nSmax * nSmax]; + R_ = new real_t[nSmax * nSmax]; + M_physicallength = 10 * nSmax; /* TODO: Decide good default. */ + M_vals = new real_t[M_physicallength]; + M_ir = new sparse_int_t[M_physicallength]; + M_jc = new sparse_int_t[nSmax + 1]; + detS = 1.0; + rcondS = 1.0; + } else { + S = 0; + Q_ = 0; + R_ = 0; + detS = 0.0; + rcondS = 0.0; + schurUpdateIndex = 0; + schurUpdate = 0; + M_physicallength = 0; + M_vals = 0; + M_ir = 0; + M_jc = 0; + } + numFactorizations = 0; +} + +/* + * Q P r o b l e m + */ +SQProblemSchur::SQProblemSchur(const SQProblemSchur & rhs) : SQProblem(rhs) +{ +#ifdef SOLVER_MA57 + sparseSolver = new Ma57SparseSolver(); +#elif defined SOLVER_MA27 + sparseSolver = new Ma27SparseSolver(); +#elif defined SOLVER_MUMPS + sparseSolver = new MumpsSparseSolver(); +#elif defined SOLVER_NONE + sparseSolver = new DummySparseSolver(); +#endif + copy(rhs); +} + +/* + * ~ Q P r o b l e m + */ +SQProblemSchur::~SQProblemSchur() +{ + delete sparseSolver; + + clear(); +} + +/* + * o p e r a t o r = + */ +SQProblemSchur & SQProblemSchur::operator=(const SQProblemSchur & rhs) +{ + if (this != &rhs) { + clear(); + SQProblem::operator=(rhs); + copy(rhs); + } + return *this; +} + +/* + * r e s e t + */ +returnValue SQProblemSchur::reset() +{ + /* AW: We probably want to avoid resetting factorization in QProblem */ + if (SQProblem::reset() != SUCCESSFUL_RETURN) + return THROWERROR(RET_RESET_FAILED); + + sparseSolver->reset(); + nS = -1; + + return SUCCESSFUL_RETURN; +} + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + +/* + * c l e a r + */ +returnValue SQProblemSchur::clear() +{ + nSmax = 0; + nS = -1; + detS = 0.0; + rcondS = 0.0; + numFactorizations = 0; + delete[] S; + S = 0; + delete[] Q_; + Q_ = 0; + delete[] R_; + R_ = 0; + delete[] schurUpdateIndex; + schurUpdateIndex = 0; + delete[] schurUpdate; + schurUpdate = 0; + M_physicallength = 0; + delete[] M_vals; + M_vals = 0; + delete[] M_ir; + M_ir = 0; + delete[] M_jc; + M_jc = 0; + + return SUCCESSFUL_RETURN; +} + +/* + * c o p y + */ +returnValue SQProblemSchur::copy(const SQProblemSchur & rhs) +{ + int_t i, j, length; + + *sparseSolver = *(rhs.sparseSolver); + + nS = rhs.nS; + nSmax = rhs.nSmax; + if (nSmax > 0) { + detS = rhs.detS; + rcondS = rhs.rcondS; + S = new real_t[nSmax * nSmax]; + Q_ = new real_t[nSmax * nSmax]; + R_ = new real_t[nSmax * nSmax]; + schurUpdateIndex = new int_t[nSmax]; + schurUpdate = new SchurUpdateType[nSmax]; + + if (nS > 0) { + for (i = 0; i < nS; i++) + for (j = 0; j < nS; j++) { + S[i * nSmax + j] = rhs.S[i * nSmax + j]; + Q_[i * nSmax + j] = rhs.Q_[i * nSmax + j]; + R_[i * nSmax + j] = rhs.R_[i * nSmax + j]; + } + + memcpy(schurUpdateIndex, rhs.schurUpdateIndex, ((unsigned int)nS) * sizeof(int_t)); + memcpy(schurUpdate, rhs.schurUpdate, ((unsigned int)nS) * sizeof(SchurUpdateType)); + } + + M_physicallength = rhs.M_physicallength; + if (M_physicallength > 0) { + M_vals = new real_t[M_physicallength]; + M_ir = new sparse_int_t[M_physicallength]; + M_jc = new sparse_int_t[nSmax + 1]; + + if (nS > 0) { + memcpy(M_jc, rhs.M_jc, ((unsigned int)(nS + 1)) * sizeof(sparse_int_t)); + length = M_jc[nS]; + memcpy(M_vals, rhs.M_vals, ((unsigned int)length) * sizeof(real_t)); + memcpy(M_ir, rhs.M_ir, ((unsigned int)length) * sizeof(sparse_int_t)); + } else if (nS == 0) + M_jc[0] = rhs.M_jc[0]; + } + } else { + S = 0; + Q_ = 0; + R_ = 0; + detS = 0.0; + rcondS = 0.0; + schurUpdateIndex = 0; + schurUpdate = 0; + M_physicallength = 0; + M_vals = 0; + M_ir = 0; + M_jc = 0; + } + numFactorizations = rhs.numFactorizations; + + boundsFreeStart = rhs.boundsFreeStart; + constraintsActiveStart = rhs.constraintsActiveStart; + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A u x i l i a r y Q P + */ +returnValue SQProblemSchur::setupAuxiliaryQP(SymmetricMatrix * H_new, + Matrix * A_new, + const real_t * lb_new, + const real_t * ub_new, + const real_t * lbA_new, + const real_t * ubA_new) +{ + int_t i; + int_t nV = getNV(); + int_t nC = getNC(); + returnValue returnvalue; + + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_PREPARINGAUXILIARYQP) || + (getStatus() == QPS_PERFORMINGHOMOTOPY)) { + return THROWERROR(RET_UPDATEMATRICES_FAILED_AS_QP_NOT_SOLVED); + } + + status = QPS_PREPARINGAUXILIARYQP; + + /* I) SETUP NEW QP MATRICES AND VECTORS: */ + /* 1) Shift constraints' bounds vectors by (A_new - A)'*x_opt to ensure + * that old optimal solution remains feasible for new QP data. */ + /* Firstly, shift by -A'*x_opt and ... */ + if (nC > 0) { + if (A_new == 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + for (i = 0; i < nC; ++i) { + lbA[i] = -Ax_l[i]; + ubA[i] = Ax_u[i]; + } + + /* Set constraint matrix as well as ... */ + setA(A_new); + + /* ... secondly, shift by +A_new'*x_opt. */ + for (i = 0; i < nC; ++i) { + lbA[i] += Ax[i]; + ubA[i] += Ax[i]; + } + + /* update constraint products. */ + for (i = 0; i < nC; ++i) { + Ax_u[i] = ubA[i] - Ax[i]; + Ax_l[i] = Ax[i] - lbA[i]; + } + } + + /* 2) Set new Hessian matrix,determine Hessian type and + * regularise new Hessian matrix if necessary. */ + /* a) Setup new Hessian matrix and determine its type. */ + if (H_new != 0) { + setH(H_new); + + hessianType = HST_UNKNOWN; + if (determineHessianType() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + /* b) Regularise new Hessian if necessary. */ + if ((hessianType == HST_ZERO) || (hessianType == HST_SEMIDEF) || (usingRegularisation() == BT_TRUE)) { + regVal = 0.0; /* reset previous regularisation */ + + if (regulariseHessian() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + } + } else { + if (H != 0) + return THROWERROR(RET_NO_HESSIAN_SPECIFIED); + } + + /* 3) Setup QP gradient. */ + if (setupAuxiliaryQPgradient() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + /* II) SETUP WORKING SET AND MATRIX FACTORISATION: */ + + /* 1) Check if current active set is linearly independent and has the correct inertia */ + returnvalue = resetSchurComplement(BT_FALSE); + int_t neig = sparseSolver->getNegativeEigenvalues(); + + if (returnvalue == SUCCESSFUL_RETURN && neig == getNAC()) { + /* a) This means the proposed working set is linearly independent and + * leaves no zero curvature exposed in the nullspace and can be used to start QP solve. */ + if (options.printLevel == PL_HIGH) + MyPrintf( + "In hotstart for new matrices, old working set is linearly independent and has correct inertia.\n"); + + status = QPS_AUXILIARYQPSOLVED; + return SUCCESSFUL_RETURN; + } else if (returnvalue == SUCCESSFUL_RETURN && neig > getNAC()) { + /* b) KKT matrix has too many negative eigenvalues. Try to correct the inertia by adding bounds (reduce + * nullspace dimension). */ + if (options.printLevel == PL_HIGH) + MyPrintf("WARNING: In hotstart for new matrices, reduced Hessian for initial working set has %i " + "negative eigenvalues, should be %i.\n", + neig, + getNAC()); + + /* If enabling inertia correction is disabled, exit here */ + if (options.enableInertiaCorrection) { + returnvalue = correctInertia(); + if (returnvalue == SUCCESSFUL_RETURN) { + status = QPS_AUXILIARYQPSOLVED; + return SUCCESSFUL_RETURN; + } + } else + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + } + + /* 2) If inertia correction has failed or factorization yielded some other error, + * try to rebuild the active set with all simple bounds set according to initialStatusBounds + * (Note: in exact arithmetic, this cannot happen) */ + if (options.printLevel == PL_HIGH) + MyPrintf("WARNING: hotstart for old active set failed. Trying to rebuild a working set.\n"); + + Bounds oldBounds = bounds; + Constraints oldConstraints = constraints; + + /* Move all inactive variables to a bound */ + for (i = 0; i < nV; i++) { +#ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ + if (bounds.getType(i) == ST_EQUALITY) { + if (oldBounds.setStatus(i, ST_LOWER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + } else +#endif + { + if (oldBounds.getStatus(i) == ST_INACTIVE) + if (oldBounds.setStatus(i, options.initialStatusBounds) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + } + } + +/* Set all equalities active */ +#ifdef __ALWAYS_INITIALISE_WITH_ALL_EQUALITIES__ + for (i = 0; i < nC; ++i) { + if (constraints.getType(i) == ST_EQUALITY) + if (oldConstraints.setStatus(i, ST_LOWER) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + } +#endif + + /* Set all inequalities inactive */ + for (i = 0; i < nC; ++i) { + if (constraints.getType(i) != ST_EQUALITY) + if (oldConstraints.setStatus(i, ST_INACTIVE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + } + + /* Reset bounds and constraints */ + bounds.init(nV); + constraints.init(nC); + + if (setupSubjectToType(lb_new, ub_new, lbA_new, ubA_new) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + if (bounds.setupAllFree() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + if (constraints.setupAllInactive() != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + /* Setup working sets afresh. */ + if (setupAuxiliaryWorkingSet(&oldBounds, &oldConstraints, BT_TRUE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_AUXILIARYQP_FAILED); + + /* adjust lb/ub */ + for (int_t ii = 0; ii < nC; ++ii) + Ax_l[ii] = Ax_u[ii] = Ax[ii]; + setupAuxiliaryQPbounds(&bounds, &constraints, BT_FALSE); + + status = QPS_AUXILIARYQPSOLVED; + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p A u x i l i a r y W o r k i n g S e t + */ +returnValue SQProblemSchur::setupAuxiliaryWorkingSet(const Bounds * const auxiliaryBounds, + const Constraints * const auxiliaryConstraints, + BooleanType setupAfresh) +{ + int_t i; + int_t nV = getNV(); + int_t nC = getNC(); + + /* consistency checks */ + if (auxiliaryBounds != 0) { + for (i = 0; i < nV; ++i) + if ((bounds.getStatus(i) == ST_UNDEFINED) || (auxiliaryBounds->getStatus(i) == ST_UNDEFINED)) + return THROWERROR(RET_UNKNOWN_BUG); + } else { + return THROWERROR(RET_INVALID_ARGUMENTS); + } + + if (auxiliaryConstraints != 0) { + for (i = 0; i < nC; ++i) + if ((constraints.getStatus(i) == ST_UNDEFINED) || + (auxiliaryConstraints->getStatus(i) == ST_UNDEFINED)) + return THROWERROR(RET_UNKNOWN_BUG); + } else { + return THROWERROR(RET_INVALID_ARGUMENTS); + } + + /* I.) REMOVE INEQUALITY BOUNDS/CONSTRAINTS */ + + /* I.1) Remove inequality bounds that are active now but shall be + * inactive or active at the other bound according to auxiliaryBounds */ + for (i = 0; i < nV; ++i) { + if ((bounds.getStatus(i) == ST_LOWER) && (auxiliaryBounds->getStatus(i) != ST_LOWER)) + if (bounds.moveFixedToFree(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + + if ((bounds.getStatus(i) == ST_UPPER) && (auxiliaryBounds->getStatus(i) != ST_UPPER)) + if (bounds.moveFixedToFree(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + } + + /* I.2.) Remove inequality constraints that are active now but shall be + * inactive or active at the other bound according to auxiliaryConstraints */ + for (i = 0; i < nC; ++i) { + if ((constraints.getStatus(i) == ST_LOWER) && (auxiliaryConstraints->getStatus(i) != ST_LOWER)) + if (constraints.moveActiveToInactive(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + + if ((constraints.getStatus(i) == ST_UPPER) && (auxiliaryConstraints->getStatus(i) != ST_UPPER)) + if (constraints.moveActiveToInactive(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + } + + /* II.) ADD BOUNDS/CONSTRAINTS */ + + /* II.1.) Add bounds according to auxiliaryBounds */ + for (i = 0; i < nV; ++i) { + if ((bounds.getStatus(i) == ST_INACTIVE) && (auxiliaryBounds->getStatus(i) != ST_INACTIVE)) + if (bounds.moveFreeToFixed(i, auxiliaryBounds->getStatus(i)) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + } + + /* II.2.) Add constraints according to auxiliaryConstraints */ + for (i = 0; i < nC; ++i) { + if ((constraints.getStatus(i) == ST_INACTIVE) && (auxiliaryConstraints->getStatus(i) != ST_INACTIVE)) + if (constraints.moveInactiveToActive(i, auxiliaryConstraints->getStatus(i)) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + } + + /* III) FACTORIZATION */ + + /* III.1.) Factorize (resolves linear dependency) */ + if (resetSchurComplement(BT_FALSE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); + + /* III.2.) Check if inertia is correct. If so, we now have a linearly independent working set with a pos + * def reduced Hessian */ + int_t neig = sparseSolver->getNegativeEigenvalues(); + if (neig == getNAC()) { + /* We now have a linearly independent working set with a pos def reduced Hessian. + * We need to correct the QP bounds and gradient after this. */ + return SUCCESSFUL_RETURN; + } + + /* IV.) INERTIA CORRECTION IF NECESSARY */ + + /* We now have a fresh factorization and can start the usual inertia correction routine */ + if (options.printLevel == PL_HIGH) + MyPrintf("WARNING: In setupAuxiliaryWorkingSet: Initial working set reduced Hessian has %i negative " + "eigenvalues, should be %i.\n", + neig, + getNAC()); + + if (options.enableInertiaCorrection == BT_TRUE) + return correctInertia(); + else + return THROWERROR(RET_SETUP_WORKINGSET_FAILED); +} + +/* + * c h o l e s k y D e c o m p o s i t i o n P r o j e c t e d + */ +returnValue SQProblemSchur::computeProjectedCholesky() +{ + return SUCCESSFUL_RETURN; +} + +/* + * c o m p u t e I n i t i a l C h o l e s k y + */ +returnValue SQProblemSchur::computeInitialCholesky() +{ + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p T Q f a c t o r i s a t i o n + */ +returnValue SQProblemSchur::setupTQfactorisation() +{ + return SUCCESSFUL_RETURN; +} + +/* + * a d d C o n s t r a i n t + */ +returnValue SQProblemSchur::addConstraint( + int_t number, SubjectToStatus C_status, BooleanType updateCholesky, BooleanType ensureLI) +{ + int_t idxDeleted = -1; + + /* consistency checks */ + if (constraints.getStatus(number) != ST_INACTIVE) + return THROWERROR(RET_CONSTRAINT_ALREADY_ACTIVE); + + if ((constraints.getNC() - getNAC()) == constraints.getNUC()) + return THROWERROR(RET_ALL_CONSTRAINTS_ACTIVE); + + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_AUXILIARYQPSOLVED) || + (getStatus() == QPS_HOMOTOPYQPSOLVED) || (getStatus() == QPS_SOLVED)) { + return THROWERROR(RET_UNKNOWN_BUG); + } + + /* I) ENSURE LINEAR INDEPENDENCE OF THE WORKING SET, + * i.e. remove a constraint or bound if linear dependence occurs. */ + if (ensureLI == BT_TRUE) { + returnValue ensureLIreturnvalue = addConstraint_ensureLI(number, C_status); + + switch (ensureLIreturnvalue) { + case SUCCESSFUL_RETURN: + break; + + case RET_LI_RESOLVED: + break; + + case RET_ENSURELI_FAILED_NOINDEX: + return RET_ADDCONSTRAINT_FAILED_INFEASIBILITY; + + case RET_ENSURELI_FAILED_CYCLING: + return RET_ADDCONSTRAINT_FAILED_INFEASIBILITY; + + case RET_ENSURELI_DROPPED: + return SUCCESSFUL_RETURN; + + default: + return THROWERROR(RET_ENSURELI_FAILED); + } + } + + /* IV) UPDATE INDICES */ + tabularOutput.idxAddC = number; + if (constraints.moveInactiveToActive(number, C_status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ADDCONSTRAINT_FAILED); + + /* Also update the Schur complement. */ + + /* First check if this constraint had been removed before. In that + case delete this constraint from the Schur complement. */ + bool found = false; + for (int_t i = 0; i < nS; i++) { + if (schurUpdate[i] == SUT_ConRemoved && number == schurUpdateIndex[i]) { + if (deleteFromSchurComplement(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ADDCONSTRAINT_FAILED); + found = true; + idxDeleted = i; + break; + } + } + if (!found) { + if (nS < 0 || nS == nSmax) { + /* The schur complement has become too large, reset. */ + /* Correct inertia if necessary. */ + returnValue retval = resetSchurComplement(BT_TRUE); + if (retval != SUCCESSFUL_RETURN) { + if (retval == RET_KKT_MATRIX_SINGULAR && options.printLevel == PL_HIGH) + MyPrintf("In addConstraint: KKT matrix singular when resetting Schur complement\n"); + else if (options.printLevel == PL_HIGH) + MyPrintf("In addConstraint, resetSchurComplement failed with retval = %d\n", retval); + return THROWERROR(RET_ADDCONSTRAINT_FAILED); + } + found = true; + } else { + /* If the constraint was not yet in Schur complement, add it now. */ + int_t nFRStart = boundsFreeStart.getLength(); + int_t * FR_idxStart; + boundsFreeStart.getNumberArray(&FR_idxStart); + + sparse_int_t * MNpos = new sparse_int_t[nFRStart + nS]; // This is an overestimate + real_t * MNvals = new real_t[nFRStart + nS]; + + int_t * irn = new int_t[nFRStart + nS]; + int_t * jcn = new int_t[nFRStart + nS]; + real_t * vals = new real_t[nFRStart + nS]; + int_t * icolsNumber = new int_t[nFRStart + nS]; + int_t * icolsSIdx = new int_t[nS]; + + for (int_t i = 0; i < nFRStart; i++) + icolsNumber[i] = FR_idxStart[i]; + + int_t icolsLength = nFRStart; + for (int_t i = 0; i < nS; i++) + if (schurUpdate[i] == SUT_VarFreed) { + icolsNumber[icolsLength] = schurUpdateIndex[i]; + icolsSIdx[icolsLength - nFRStart] = i; + icolsLength++; + } + + if (constraintProduct != 0) { + MyPrintf("In SQProblemSchur::addConstraint, constraintProduct not yet implemented.\n"); + return THROWERROR(RET_NOT_YET_IMPLEMENTED); + } + int_t numNonzerosA; + A->getSparseSubmatrix(1, &number, icolsLength, icolsNumber, 0, 0, numNonzerosA, irn, jcn, vals); + delete[] irn; + + int_t numNonzerosM = 0; + int_t numNonzerosN = 0; + for (int_t i = 0; i < numNonzerosA; i++) + if (jcn[i] < nFRStart) { + MNpos[numNonzerosM] = jcn[i]; + MNvals[numNonzerosM] = vals[i]; + numNonzerosM++; + } else { + MNpos[nFRStart + numNonzerosN] = icolsSIdx[jcn[i] - nFRStart]; + MNvals[nFRStart + numNonzerosN] = vals[i]; + numNonzerosN++; + } + + returnValue returnvalue = addToSchurComplement(number, + SUT_ConAdded, + numNonzerosM, + MNpos, + MNvals, + numNonzerosN, + MNpos + nFRStart, + MNvals + nFRStart, + 0.0); + + delete[] icolsSIdx; + delete[] icolsNumber; + delete[] vals; + delete[] jcn; + delete[] MNvals; + delete[] MNpos; + + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(RET_ADDCONSTRAINT_FAILED); + + found = true; + } + } + + if (!found) + return THROWERROR(RET_ADDCONSTRAINT_FAILED); + + updateSchurQR(idxDeleted); + + /* If reciprocal of condition number becomes to small, refactorize KKT matrix */ + if (rcondS < options.rcondSMin) { + returnValue retval = resetSchurComplement(BT_TRUE); + if (retval != SUCCESSFUL_RETURN) { + if (retval == RET_KKT_MATRIX_SINGULAR && options.printLevel == PL_HIGH) + MyPrintf("In addConstraint: KKT matrix singular when resetting Schur complement\n"); + else if (options.printLevel == PL_HIGH) + MyPrintf("In addConstraint, resetSchurComplement failed with retval = %d\n", retval); + return THROWERROR(RET_ADDCONSTRAINT_FAILED); + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * a d d C o n s t r a i n t _ c h e c k L I + */ +returnValue SQProblemSchur::addConstraint_checkLI(int_t number) +{ + /* Get space for the multipliers xi in linear independence test */ + int_t nAC = getNAC(); + int_t nFX = getNFX(); + real_t * xiC = new real_t[nAC]; + real_t * xiB = new real_t[nFX]; + + /* I) Check if new constraint is linearly independent from the active ones. */ + returnValue returnvalueCheckLI = addConstraint_checkLISchur(number, xiC, xiB); + + delete[] xiB; + delete[] xiC; + + return returnvalueCheckLI; +} + +/* + * a d d C o n s t r a i n t _ c h e c k L I S c h u r + */ +returnValue SQProblemSchur::addConstraint_checkLISchur(int_t number, real_t * xiC, real_t * xiB) +{ + returnValue returnvalue = RET_LINEARLY_DEPENDENT; + + int_t ii; + int_t nV = getNV(); + int_t nFR = getNFR(); + int_t nC = getNC(); + int_t nAC = getNAC(); + int_t nFX = getNFX(); + int_t * FR_idx; + + bounds.getFree()->getNumberArray(&FR_idx); + + /* For the Schur complement version we only use options.enableFullLITests = TRUE */ + { + /* + * expensive LI test. Backsolve with refinement using special right + * hand side. This gives an estimate for what should be considered + * "zero". We then check linear independence relative to this estimate. + */ + + int_t *FX_idx, *AC_idx, *IAC_idx; + + real_t * delta_g = new real_t[nV]; + real_t * delta_xFX = new real_t[nFX]; + real_t * delta_xFR = new real_t[nFR]; + real_t * delta_yAC = xiC; + real_t * delta_yFX = xiB; + + bounds.getFixed()->getNumberArray(&FX_idx); + constraints.getActive()->getNumberArray(&AC_idx); + constraints.getInactive()->getNumberArray(&IAC_idx); + + int_t dim = (nC > nV) ? nC : nV; + real_t * nul = new real_t[dim]; + for (ii = 0; ii < dim; ++ii) + nul[ii] = 0.0; + + A->getRow(number, 0, 1.0, delta_g); + + returnValue dsdreturnvalue = determineStepDirection( + delta_g, nul, nul, nul, nul, BT_FALSE, BT_FALSE, delta_xFX, delta_xFR, delta_yAC, delta_yFX); + if (dsdreturnvalue != SUCCESSFUL_RETURN) + returnvalue = dsdreturnvalue; + + delete[] nul; + + /* compute the weight in inf-norm */ + real_t weight = 0.0; + for (ii = 0; ii < nAC; ++ii) { + real_t a = getAbs(delta_yAC[ii]); + if (weight < a) + weight = a; + } + for (ii = 0; ii < nFX; ++ii) { + real_t a = getAbs(delta_yFX[ii]); + if (weight < a) + weight = a; + } + + /* look at the "zero" in a relative inf-norm */ + real_t zero = 0.0; + for (ii = 0; ii < nFX; ++ii) { + real_t a = getAbs(delta_xFX[ii]); + if (zero < a) + zero = a; + } + for (ii = 0; ii < nFR; ++ii) { + real_t a = getAbs(delta_xFR[ii]); + if (zero < a) + zero = a; + } + + /* relative test against zero in inf-norm */ + if (zero > options.epsLITests * weight) + returnvalue = RET_LINEARLY_INDEPENDENT; + + delete[] delta_xFR; + delete[] delta_xFX; + delete[] delta_g; + } + return THROWINFO(returnvalue); +} + +/* + * a d d C o n s t r a i n t _ e n s u r e L I + */ +returnValue SQProblemSchur::addConstraint_ensureLI(int_t number, SubjectToStatus C_status) +{ + /* Get space for the multipliers xi in linear independence test */ + int_t nAC = getNAC(); + int_t nFX = getNFX(); + real_t * xiC = new real_t[nAC]; + real_t * xiB = new real_t[nFX]; + + /* I) Check if new constraint is linearly independent from the active ones. */ + returnValue returnvalueCheckLI = addConstraint_checkLISchur(number, xiC, xiB); + + if (returnvalueCheckLI == RET_INDEXLIST_CORRUPTED) { + delete[] xiB; + delete[] xiC; + return THROWERROR(RET_ENSURELI_FAILED); + } + + if (returnvalueCheckLI == RET_LINEARLY_INDEPENDENT) { + delete[] xiB; + delete[] xiC; + return SUCCESSFUL_RETURN; + } + + /* II) NEW BOUND IS LINEARLY DEPENDENT: */ + /* 1) Coefficients of linear combination, have already been computed, but we need to correct the sign. */ + int_t i, ii; + + if (C_status != ST_LOWER) { + for (i = 0; i < nAC; ++i) + xiC[i] = -xiC[i]; + for (i = 0; i < nFX; ++i) + xiB[i] = -xiB[i]; + } + + int_t nV = getNV(); + + int_t * FX_idx; + bounds.getFixed()->getNumberArray(&FX_idx); + + int_t * AC_idx; + constraints.getActive()->getNumberArray(&AC_idx); + + real_t * num = new real_t[nV]; + + real_t y_min = options.maxDualJump; + int_t y_min_number = -1; + int_t y_min_number_bound = -1; + BooleanType y_min_isBound = BT_FALSE; + + returnValue returnvalue = SUCCESSFUL_RETURN; + + /* III) DETERMINE CONSTRAINT/BOUND TO BE REMOVED. */ + + /* 1) Constraints. */ + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + num[i] = y[nV + ii]; + } + + performRatioTest( + nAC, AC_idx, &constraints, num, xiC, options.epsNum, options.epsDen, y_min, y_min_number); + + /* 2) Bounds. */ + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + num[i] = y[ii]; + } + + performRatioTest( + nFX, FX_idx, &bounds, num, xiB, options.epsNum, options.epsDen, y_min, y_min_number_bound); + + if (y_min_number_bound >= 0) { + y_min_number = y_min_number_bound; + y_min_isBound = BT_TRUE; + } + +#ifndef __XPCTARGET__ + /* setup output preferences */ + char messageString[80]; +#endif + + /* IV) REMOVE CONSTRAINT/BOUND FOR RESOLVING LINEAR DEPENDENCE: */ + if (y_min_number >= 0) { + /* Update Lagrange multiplier... */ + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + y[nV + ii] -= y_min * xiC[i]; + } + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + y[ii] -= y_min * xiB[i]; + } + + /* ... also for newly active constraint... */ + if (C_status == ST_LOWER) + y[nV + number] = y_min; + else + y[nV + number] = -y_min; + + /* ... and for constraint to be removed. */ + if (y_min_isBound == BT_TRUE) { +#ifndef __XPCTARGET__ + snprintf(messageString, 80, "bound no. %d.", (int)y_min_number); + getGlobalMessageHandler()->throwInfo( + RET_REMOVE_FROM_ACTIVESET, messageString, __FUNCTION__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + if (removeBound(y_min_number, BT_TRUE, BT_FALSE, BT_FALSE) != SUCCESSFUL_RETURN) { + returnvalue = RET_REMOVE_FROM_ACTIVESET_FAILED; + goto farewell; + } + tabularOutput.excRemB = 1; + + y[y_min_number] = 0.0; + } else { +#ifndef __XPCTARGET__ + snprintf(messageString, 80, "constraint no. %d.", (int)y_min_number); + getGlobalMessageHandler()->throwInfo( + RET_REMOVE_FROM_ACTIVESET, messageString, __FUNCTION__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + if (removeConstraint(y_min_number, BT_TRUE, BT_FALSE, BT_FALSE) != SUCCESSFUL_RETURN) { + returnvalue = RET_REMOVE_FROM_ACTIVESET_FAILED; + goto farewell; + } + tabularOutput.excRemC = 1; + + y[nV + y_min_number] = 0.0; + } + } else { + if (options.enableDropInfeasibles == BT_TRUE) { + /* dropping of infeasible constraints according to drop priorities */ + returnvalue = dropInfeasibles(number, C_status, BT_FALSE, xiB, xiC); + } else { + /* no constraint/bound can be removed => QP is infeasible! */ + returnvalue = RET_ENSURELI_FAILED_NOINDEX; + setInfeasibilityFlag(returnvalue); + } + } + +farewell: + delete[] num; + delete[] xiB; + delete[] xiC; + + getGlobalMessageHandler()->throwInfo(RET_LI_RESOLVED, 0, __FUNCTION__, __FILE__, __LINE__, VS_VISIBLE); + + return (returnvalue != SUCCESSFUL_RETURN) ? THROWERROR(returnvalue) : returnvalue; +} + +/* + * a d d B o u n d + */ +returnValue SQProblemSchur::addBound( + int_t number, SubjectToStatus B_status, BooleanType updateCholesky, BooleanType ensureLI) +{ + int_t idxDeleted = -1; + + /* consistency checks */ + if (bounds.getStatus(number) != ST_INACTIVE) + return THROWERROR(RET_BOUND_ALREADY_ACTIVE); + + if (getNFR() == bounds.getNUV()) + return THROWERROR(RET_ALL_BOUNDS_ACTIVE); + + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_AUXILIARYQPSOLVED) || + (getStatus() == QPS_HOMOTOPYQPSOLVED) || (getStatus() == QPS_SOLVED)) { + return THROWERROR(RET_UNKNOWN_BUG); + } + + /* I) ENSURE LINEAR INDEPENDENCE OF THE WORKING SET, + * i.e. remove a constraint or bound if linear dependence occurs. */ + if (ensureLI == BT_TRUE) { + returnValue ensureLIreturnvalue = addBound_ensureLI(number, B_status); + + switch (ensureLIreturnvalue) { + case SUCCESSFUL_RETURN: + break; + + case RET_LI_RESOLVED: + break; + + case RET_ENSURELI_FAILED_NOINDEX: + return RET_ADDBOUND_FAILED_INFEASIBILITY; + + case RET_ENSURELI_FAILED_CYCLING: + return RET_ADDBOUND_FAILED_INFEASIBILITY; + + case RET_ENSURELI_DROPPED: + return SUCCESSFUL_RETURN; + + default: + return THROWERROR(RET_ENSURELI_FAILED); + } + } + + /* II) UPDATE INDICES */ + tabularOutput.idxAddB = number; + if (bounds.moveFreeToFixed(number, B_status) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ADDBOUND_FAILED); + + /* Also update the Schur complement. */ + + /* First check if this variable had been freed before. In that + case delete this variable from the Schur complement. */ + bool found = false; + for (int_t i = 0; i < nS; i++) { + if (schurUpdate[i] == SUT_VarFreed && number == schurUpdateIndex[i]) { + if (deleteFromSchurComplement(i) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ADDBOUND_FAILED); + found = true; + idxDeleted = i; + break; + } + } + if (!found) { + if (nS < 0 || nS == nSmax) { + /* The schur complement has become too large, reset. */ + /* Correct inertia if necessary. */ + returnValue retval = resetSchurComplement(BT_TRUE); + if (retval != SUCCESSFUL_RETURN) { + if (retval == RET_KKT_MATRIX_SINGULAR && options.printLevel == PL_HIGH) + MyPrintf("In addBound: KKT matrix singular when resetting Schur complement\n"); + else if (options.printLevel == PL_HIGH) + MyPrintf("In addBound, resetSchurComplement failed with retval = %d\n", retval); + return THROWERROR(RET_ADDBOUND_FAILED); + } + found = true; + } else { + /* If the variable was not yet in Schur complement, add it now. */ + int_t nFRStart = boundsFreeStart.getLength(); + int_t * FR_idxStart; + boundsFreeStart.getNumberArray(&FR_idxStart); + for (int_t i = 0; i < nFRStart; i++) + if (FR_idxStart[i] == number) { + real_t one = 1.0; + sparse_int_t pos = i; + if (addToSchurComplement(number, SUT_VarFixed, 1, &pos, &one, 0, 0, 0, 0.0) != SUCCESSFUL_RETURN) + return THROWERROR(RET_ADDBOUND_FAILED); + found = true; + break; + } + } + } + + if (!found) + return THROWERROR(RET_ADDBOUND_FAILED); + + updateSchurQR(idxDeleted); + + /* If reciprocal of condition number becomes to small, refactorize KKT matrix */ + if (rcondS < options.rcondSMin) { + returnValue retval = resetSchurComplement(BT_TRUE); + if (retval != SUCCESSFUL_RETURN) { + if (retval == RET_KKT_MATRIX_SINGULAR && options.printLevel == PL_HIGH) + MyPrintf("In addBound: KKT matrix singular when resetting Schur complement\n"); + else if (options.printLevel == PL_HIGH) + MyPrintf("In addBound, resetSchurComplement failed with retval = %d\n", retval); + return THROWERROR(RET_ADDCONSTRAINT_FAILED); + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * a d d B o u n d _ c h e c k L I + */ +returnValue SQProblemSchur::addBound_checkLI(int_t number) +{ + /* Get space for the multipliers xi in linear independence test */ + int_t nAC = getNAC(); + int_t nFX = getNFX(); + real_t * xiC = new real_t[nAC]; + real_t * xiB = new real_t[nFX]; + + /* I) Check if new constraint is linearly independent from the active ones. */ + returnValue returnvalueCheckLI = addBound_checkLISchur(number, xiC, xiB); + + delete[] xiB; + delete[] xiC; + + return returnvalueCheckLI; +} + +/* + * a d d B o u n d _ c h e c k L I S c h u r + */ +returnValue SQProblemSchur::addBound_checkLISchur(int_t number, real_t * xiC, real_t * xiB) +{ + returnValue returnvalue = RET_LINEARLY_DEPENDENT; + + int_t ii; + int_t nV = getNV(); + int_t nFR = getNFR(); + int_t nC = getNC(); + int_t nAC = getNAC(); + int_t nFX = getNFX(); + int_t * FR_idx; + + bounds.getFree()->getNumberArray(&FR_idx); + + /* For the Schur complement version we only use options.enableFullLITests = TRUE */ + { + /* + * expensive LI test. Backsolve with refinement using special right + * hand side. This gives an estimate for what should be considered + * "zero". We then check linear independence relative to this estimate. + */ + + real_t * delta_g = new real_t[nV]; + real_t * delta_xFX = new real_t[nFX]; + real_t * delta_xFR = new real_t[nFR]; + real_t * delta_yAC = xiC; + real_t * delta_yFX = xiB; + + for (ii = 0; ii < nV; ++ii) + delta_g[ii] = 0.0; + delta_g[number] = 1.0; + + int_t dim = (nC > nV) ? nC : nV; + real_t * nul = new real_t[dim]; + for (ii = 0; ii < dim; ++ii) + nul[ii] = 0.0; + + returnValue dsdReturnValue = determineStepDirection( + delta_g, nul, nul, nul, nul, BT_FALSE, BT_FALSE, delta_xFX, delta_xFR, delta_yAC, delta_yFX); + if (dsdReturnValue != SUCCESSFUL_RETURN) + returnvalue = dsdReturnValue; + + /* compute the weight in inf-norm */ + real_t weight = 0.0; + for (ii = 0; ii < nAC; ++ii) { + real_t a = getAbs(delta_yAC[ii]); + if (weight < a) + weight = a; + } + for (ii = 0; ii < nFX; ++ii) { + real_t a = getAbs(delta_yFX[ii]); + if (weight < a) + weight = a; + } + + /* look at the "zero" in a relative inf-norm */ + real_t zero = 0.0; + for (ii = 0; ii < nFX; ++ii) { + real_t a = getAbs(delta_xFX[ii]); + if (zero < a) + zero = a; + } + for (ii = 0; ii < nFR; ++ii) { + real_t a = getAbs(delta_xFR[ii]); + if (zero < a) + zero = a; + } + + /* relative test against zero in inf-norm */ + if (zero > options.epsLITests * weight) + returnvalue = RET_LINEARLY_INDEPENDENT; + + delete[] nul; + delete[] delta_xFR; + delete[] delta_xFX; + delete[] delta_g; + } + return THROWINFO(returnvalue); +} + +/* + * a d d B o u n d _ e n s u r e L I + */ +returnValue SQProblemSchur::addBound_ensureLI(int_t number, SubjectToStatus B_status) +{ + /* Get space for the multipliers xi in linear independence test */ + int_t nAC = getNAC(); + int_t nFX = getNFX(); + real_t * xiC = new real_t[nAC]; + real_t * xiB = new real_t[nFX]; + + /* I) Check if new constraint is linearly independent from the active ones. */ + returnValue returnvalueCheckLI = addBound_checkLISchur(number, xiC, xiB); + + if (returnvalueCheckLI == RET_INDEXLIST_CORRUPTED) { + delete[] xiB; + delete[] xiC; + return THROWERROR(RET_ENSURELI_FAILED); + } + + if (returnvalueCheckLI == RET_LINEARLY_INDEPENDENT) { + delete[] xiB; + delete[] xiC; + return SUCCESSFUL_RETURN; + } + + /* II) NEW BOUND IS LINEARLY DEPENDENT: */ + /* 1) Coefficients of linear combination, have already been computed, but we need to correct the sign. */ + int_t i, ii; + + if (B_status != ST_LOWER) { + for (i = 0; i < nAC; ++i) + xiC[i] = -xiC[i]; + for (i = 0; i < nFX; ++i) + xiB[i] = -xiB[i]; + } + + int_t nV = getNV(); + + int_t * FX_idx; + bounds.getFixed()->getNumberArray(&FX_idx); + + int_t * AC_idx; + constraints.getActive()->getNumberArray(&AC_idx); + + real_t * num = new real_t[nV]; + + real_t y_min = options.maxDualJump; + int_t y_min_number = -1; + int_t y_min_number_bound = -1; + BooleanType y_min_isBound = BT_FALSE; + + returnValue returnvalue = SUCCESSFUL_RETURN; + + /* III) DETERMINE CONSTRAINT/BOUND TO BE REMOVED. */ + + /* 1) Constraints. */ + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + num[i] = y[nV + ii]; + } + + performRatioTest( + nAC, AC_idx, &constraints, num, xiC, options.epsNum, options.epsDen, y_min, y_min_number); + + /* 2) Bounds. */ + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + num[i] = y[ii]; + } + + performRatioTest( + nFX, FX_idx, &bounds, num, xiB, options.epsNum, options.epsDen, y_min, y_min_number_bound); + + if (y_min_number_bound >= 0) { + y_min_number = y_min_number_bound; + y_min_isBound = BT_TRUE; + } + + /* IV) REMOVE CONSTRAINT/BOUND FOR RESOLVING LINEAR DEPENDENCE: */ + char messageString[80]; + + if (y_min_number >= 0) { + /* Update Lagrange multiplier... */ + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + y[nV + ii] -= y_min * xiC[i]; + } + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + y[ii] -= y_min * xiB[i]; + } + + /* ... also for newly active bound ... */ + if (B_status == ST_LOWER) + y[number] = y_min; + else + y[number] = -y_min; + + /* ... and for bound to be removed. */ + if (y_min_isBound == BT_TRUE) { +#ifndef __XPCTARGET__ + snprintf(messageString, 80, "bound no. %d.", (int)y_min_number); + getGlobalMessageHandler()->throwInfo( + RET_REMOVE_FROM_ACTIVESET, messageString, __FUNCTION__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + if (removeBound(y_min_number, BT_TRUE, BT_FALSE, BT_FALSE) != SUCCESSFUL_RETURN) { + returnvalue = RET_REMOVE_FROM_ACTIVESET_FAILED; + goto farewell; + } + tabularOutput.excRemB = 1; + + y[y_min_number] = 0.0; + } else { +#ifndef __XPCTARGET__ + snprintf(messageString, 80, "constraint no. %d.", (int)y_min_number); + getGlobalMessageHandler()->throwInfo( + RET_REMOVE_FROM_ACTIVESET, messageString, __FUNCTION__, __FILE__, __LINE__, VS_VISIBLE); +#endif + + if (removeConstraint(y_min_number, BT_TRUE, BT_FALSE, BT_FALSE) != SUCCESSFUL_RETURN) { + returnvalue = RET_REMOVE_FROM_ACTIVESET_FAILED; + goto farewell; + } + tabularOutput.excRemC = 1; + + y[nV + y_min_number] = 0.0; + } + } else { + if (options.enableDropInfeasibles == BT_TRUE) { + /* dropping of infeasible constraints according to drop priorities */ + returnvalue = dropInfeasibles(number, B_status, BT_TRUE, xiB, xiC); + } else { + /* no constraint/bound can be removed => QP is infeasible! */ + returnvalue = RET_ENSURELI_FAILED_NOINDEX; + setInfeasibilityFlag(returnvalue); + } + } + +farewell: + delete[] num; + delete[] xiB; + delete[] xiC; + + getGlobalMessageHandler()->throwInfo(RET_LI_RESOLVED, 0, __FUNCTION__, __FILE__, __LINE__, VS_VISIBLE); + + return (returnvalue != SUCCESSFUL_RETURN) ? THROWERROR(returnvalue) : returnvalue; +} + +/* + * r e m o v e C o n s t r a i n t + */ +returnValue SQProblemSchur::removeConstraint( + int_t number, BooleanType updateCholesky, BooleanType allowFlipping, BooleanType ensureNZC) +{ + returnValue returnvalue = SUCCESSFUL_RETURN; + + int_t sModType = 0; + int_t idxDeleted = -1; + SubjectToStatus oldStatus; + real_t oldDet, newDet; + + /* consistency check */ + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_AUXILIARYQPSOLVED) || + (getStatus() == QPS_HOMOTOPYQPSOLVED) || (getStatus() == QPS_SOLVED)) { + return THROWERROR(RET_UNKNOWN_BUG); + } + + /* some definitions */ + int_t nAC = getNAC(); + int_t number_idx = constraints.getActive()->getIndex(number); + + int_t addIdx; + BooleanType addBoundNotConstraint; + SubjectToStatus addStatus; + BooleanType exchangeHappened = BT_FALSE; + + /* consistency checks */ + if (constraints.getStatus(number) == ST_INACTIVE) + return THROWERROR(RET_CONSTRAINT_NOT_ACTIVE); + + if ((number_idx < 0) || (number_idx >= nAC)) + return THROWERROR(RET_CONSTRAINT_NOT_ACTIVE); + + /* N) PERFORM ZERO CURVATURE TEST. */ + if (ensureNZC == BT_TRUE) { + returnvalue = + ensureNonzeroCurvature(BT_FALSE, number, exchangeHappened, addBoundNotConstraint, addIdx, addStatus); + + if (returnvalue != SUCCESSFUL_RETURN) + return returnvalue; + } + + /* save old constraint status and determinant of old S for flipping strategy */ + oldStatus = constraints.getStatus(number); + oldDet = detS; + + /* I) UPDATE INDICES */ + tabularOutput.idxRemC = number; + if (constraints.moveActiveToInactive(number) != SUCCESSFUL_RETURN) + return THROWERROR(RET_REMOVECONSTRAINT_FAILED); + + /* Also update the Schur complement. */ + + /* First check if this constraint had been added before. In that + case delete this constraint from the Schur complement. */ + bool found = false; + for (int_t i = 0; i < nS; i++) { + if (schurUpdate[i] == SUT_ConAdded && number == schurUpdateIndex[i]) { + if (deleteFromSchurComplement(i, BT_TRUE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_REMOVECONSTRAINT_FAILED); + found = true; + idxDeleted = i; + sModType = 2; + break; + } + } + if (!found) { + if (nS < 0 || nS == nSmax) { + /* The schur complement has become too large, reset. */ + /* Don't check inertia here, may be corrected later! */ + returnValue retval = resetSchurComplement(BT_FALSE); + if (retval != SUCCESSFUL_RETURN) { + if (retval == RET_KKT_MATRIX_SINGULAR && options.printLevel == PL_HIGH) + MyPrintf("In removeConstraint: KKT matrix singular when resetting Schur complement\n"); + else if (options.printLevel == PL_HIGH) + MyPrintf("In removeConstraint, resetSchurComplement failed with retval = %d\n", retval); + return THROWERROR(RET_REMOVECONSTRAINT_FAILED); + } + found = true; + sModType = 3; + } else { + /* If the constraint was not yet in Schur complement, add it now. */ + int_t nFRStart = boundsFreeStart.getLength(); + int_t nACStart = constraintsActiveStart.getLength(); + int_t * AC_idxStart; + constraintsActiveStart.getNumberArray(&AC_idxStart); + + for (int_t i = 0; i < nACStart; i++) + if (AC_idxStart[i] == number) { + real_t one = 1.0; + sparse_int_t pos = nFRStart + i; + if (addToSchurComplement(number, SUT_ConRemoved, 1, &pos, &one, 0, 0, 0, 0.0) != + SUCCESSFUL_RETURN) + return THROWERROR(RET_REMOVECONSTRAINT_FAILED); + found = true; + break; + } + + sModType = 1; + } + } + + if (!found) + return THROWERROR(RET_REMOVECONSTRAINT_FAILED); + + /* Now we have a new Schur complement (might be smaller, larger, or empty). Update QR factorization. */ + + /* Flipping bounds strategy */ + if ((options.enableFlippingBounds == BT_TRUE) && (allowFlipping == BT_TRUE) && + (exchangeHappened == BT_FALSE)) { + if (sModType == 1) { /* Case 1: We added a row and column to S. */ + + /* Check if a direction of negative curvature showed up, i.e. determinants have THE SAME sign */ + newDet = calcDetSchur(idxDeleted); + + if (oldDet * newDet > 0) { + hessianType = HST_SEMIDEF; + + /* Restore old S */ + nS--; + + /* Flip bounds */ + tabularOutput.idxAddC = number; + tabularOutput.excAddC = 2; + switch (oldStatus) { + case ST_LOWER: + constraints.moveInactiveToActive(number, ST_UPPER); + ubA[number] = lbA[number]; + Ax_l[number] = -Ax_u[number]; + break; + case ST_UPPER: + constraints.moveInactiveToActive(number, ST_LOWER); + lbA[number] = ubA[number]; + Ax_u[number] = -Ax_l[number]; + break; + default: + return THROWERROR(RET_REMOVECONSTRAINT_FAILED); + } + } else { /* Determinants have the correct sign, compute QR of new (larger) S */ + updateSchurQR(idxDeleted); + } + } else if (sModType == 2) { /* Case 2: We deleted a row and column of S. */ + + /* Check if a direction of negative curvature showed up, i.e. determinants have DIFFERENT signs */ + newDet = calcDetSchur(idxDeleted); + + if (oldDet * newDet < 0.0) { + hessianType = HST_SEMIDEF; + + /* Restore old S */ + undoDeleteFromSchurComplement(idxDeleted); + + /* Flip bounds */ + tabularOutput.idxAddC = number; + tabularOutput.excAddC = 2; + switch (oldStatus) { + case ST_LOWER: + constraints.moveInactiveToActive(number, ST_UPPER); + ubA[number] = lbA[number]; + Ax_l[number] = -Ax_u[number]; + break; + case ST_UPPER: + constraints.moveInactiveToActive(number, ST_LOWER); + lbA[number] = ubA[number]; + Ax_u[number] = -Ax_l[number]; + break; + default: + return THROWERROR(RET_REMOVECONSTRAINT_FAILED); + } + } else { /* Determinants have the correct sign, compute QR of new (smaller) S */ + updateSchurQR(idxDeleted); + } + } else if (sModType == 3) { /* Case 3: S was reset. */ + + /* Check inertia of new factorization given by the sparse solver: must be ( nFR, nAC, 0 ) */ + int_t neig = sparseSolver->getNegativeEigenvalues(); + if (neig > getNAC()) // Wrong inertia! + { + /* Flip bounds and update Schur complement */ + tabularOutput.idxAddC = number; + tabularOutput.excAddC = 2; + switch (oldStatus) { + case ST_LOWER: + ubA[number] = lbA[number]; + Ax_l[number] = -Ax_u[number]; + addConstraint(number, ST_UPPER, BT_TRUE, BT_FALSE); + break; + case ST_UPPER: + lbA[number] = ubA[number]; + Ax_u[number] = -Ax_l[number]; + addConstraint(number, ST_LOWER, BT_TRUE, BT_FALSE); + break; + default: + return THROWERROR(RET_REMOVECONSTRAINT_FAILED); + } + } + + /* Check if flipping deleted the negative eigenvalue */ + if (correctInertia()) + return THROWERROR(RET_REMOVECONSTRAINT_FAILED); + } else { /* None of the three cases happened */ + return THROWERROR(RET_REMOVECONSTRAINT_FAILED); + } + } else { /* No flipping strategy, update QR factorization of S */ + updateSchurQR(idxDeleted); + } + + /* If reciprocal of condition number becomes to small, refactorize KKT matrix */ + if (rcondS < options.rcondSMin) { + returnValue retval = resetSchurComplement(BT_TRUE); + if (retval != SUCCESSFUL_RETURN) { + if (retval == RET_KKT_MATRIX_SINGULAR && options.printLevel == PL_HIGH) + MyPrintf("In removeConstraint: KKT matrix singular when resetting Schur complement\n"); + else if (options.printLevel == PL_HIGH) + MyPrintf("In removeConstraint, resetSchurComplement failed with retval = %d\n", retval); + return THROWERROR(RET_ADDCONSTRAINT_FAILED); + } + } + + if (exchangeHappened == BT_TRUE) { + /* add bound or constraint */ + + if (addBoundNotConstraint) { + addBound(addIdx, addStatus, BT_TRUE, BT_FALSE); + tabularOutput.excAddB = 1; + } else { + addConstraint(addIdx, addStatus, BT_TRUE, BT_FALSE); + tabularOutput.excAddC = 1; + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * r e m o v e B o u n d + */ +returnValue SQProblemSchur::removeBound( + int_t number, BooleanType updateCholesky, BooleanType allowFlipping, BooleanType ensureNZC) +{ + returnValue returnvalue = SUCCESSFUL_RETURN; + int_t addIdx; + BooleanType addBoundNotConstraint; + SubjectToStatus addStatus; + BooleanType exchangeHappened = BT_FALSE; + + int_t sModType = 0; + int_t idxDeleted = -1; + SubjectToStatus oldStatus; + real_t oldDet, newDet; + + /* consistency checks */ + if (bounds.getStatus(number) == ST_INACTIVE) + return THROWERROR(RET_BOUND_NOT_ACTIVE); + + if ((getStatus() == QPS_NOTINITIALISED) || (getStatus() == QPS_AUXILIARYQPSOLVED) || + (getStatus() == QPS_HOMOTOPYQPSOLVED) || (getStatus() == QPS_SOLVED)) { + return THROWERROR(RET_UNKNOWN_BUG); + } + + /* N) PERFORM ZERO CURVATURE TEST. */ + if (ensureNZC == BT_TRUE) { + returnvalue = + ensureNonzeroCurvature(BT_TRUE, number, exchangeHappened, addBoundNotConstraint, addIdx, addStatus); + + if (returnvalue != SUCCESSFUL_RETURN) + return returnvalue; + } + + /* save old bound status and determinant of old S for flipping strategy */ + oldStatus = bounds.getStatus(number); + oldDet = detS; + + /* I) UPDATE INDICES */ + tabularOutput.idxRemB = number; + if (bounds.moveFixedToFree(number) != SUCCESSFUL_RETURN) + return THROWERROR(RET_REMOVEBOUND_FAILED); + + /* Also update the Schur complement. */ + + /* First check if this variable had been fixed before. In that + case delete this variable from the Schur complement. */ + bool found = false; + for (int_t i = 0; i < nS; i++) { + if (schurUpdate[i] == SUT_VarFixed && number == schurUpdateIndex[i]) { + if (deleteFromSchurComplement(i, BT_TRUE) != SUCCESSFUL_RETURN) + return THROWERROR(RET_REMOVEBOUND_FAILED); + found = true; + idxDeleted = i; + sModType = 2; + break; + } + } + if (!found) { + if (nS < 0 || nS == nSmax) { + /* The schur complement has become too large, reset. */ + /* Don't correct inertia here, may be corrected by flipping bounds! */ + returnValue retval = resetSchurComplement(BT_FALSE); + if (retval != SUCCESSFUL_RETURN) { + if (retval == RET_KKT_MATRIX_SINGULAR && options.printLevel == PL_HIGH) + MyPrintf("In removeBound: KKT matrix singular when resetting Schur complement\n"); + else if (options.printLevel == PL_HIGH) + MyPrintf("In removeBound, resetSchurComplement failed with retval = %d\n", retval); + return THROWERROR(RET_REMOVEBOUND_FAILED); + } + found = true; + sModType = 3; + } else { + /* If the variable was not yet in Schur complement, add it now. */ + int_t nFRStart = boundsFreeStart.getLength(); + int_t nACStart = constraintsActiveStart.getLength(); + int_t * FR_idxStart; + boundsFreeStart.getNumberArray(&FR_idxStart); + int_t * AC_idxStart; + constraintsActiveStart.getNumberArray(&AC_idxStart); + + int_t numNonzerosM = 0; + sparse_int_t * Mpos = new sparse_int_t[nFRStart + nACStart + nS]; // This is an overestimate + real_t * Mvals = new real_t[nFRStart + nACStart + nS]; + int_t numNonzerosN = 0; + sparse_int_t * Npos = new sparse_int_t[nFRStart + nACStart + nS]; // This is an overestimate + real_t * Nvals = new real_t[nFRStart + nACStart + nS]; + real_t N_diag; + + int_t * irn = new int_t[nFRStart + nACStart + nS + 1]; + int_t * jcn = new int_t[nFRStart + nACStart + nS + 1]; + real_t * vals = new real_t[nFRStart + nACStart + nS + 1]; + int_t iLength; + int_t * iNumber = new int_t[nFRStart + nACStart + nS + 1]; + int_t numNonzeros; + int_t * iSIdx = new int_t[nS]; + + /* First the Hessian part. */ + real_t regularisation = options.epsRegularisation; + switch (hessianType) { + case HST_ZERO: + N_diag = regularisation; + break; + + case HST_IDENTITY: + N_diag = 1.0 + regularisation; + break; + + default: + N_diag = regularisation; + for (int_t i = 0; i < nFRStart; i++) + iNumber[i] = FR_idxStart[i]; + iLength = nFRStart; + for (int_t i = 0; i < nS; i++) + if (schurUpdate[i] == SUT_VarFreed) { + iNumber[iLength] = schurUpdateIndex[i]; + iSIdx[iLength - nFRStart] = i; + iLength++; + } + iNumber[iLength++] = number; + + H->getSparseSubmatrix(iLength, iNumber, 1, &number, 0, 0, numNonzeros, irn, jcn, vals); + + for (int_t i = 0; i < numNonzeros; i++) { + if (irn[i] < nFRStart) { + Mpos[numNonzerosM] = irn[i]; + Mvals[numNonzerosM] = vals[i]; + numNonzerosM++; + } else if (irn[i] != iLength - 1) { + Npos[numNonzerosN] = iSIdx[irn[i] - nFRStart]; + Nvals[numNonzerosN] = vals[i]; + numNonzerosN++; + } else + N_diag += vals[i]; + } + break; + } + + if (constraintProduct != 0) { + MyPrintf("In SQProblemSchur::removeBound, constraintProduct not yet implemented.\n"); + return THROWERROR(RET_NOT_YET_IMPLEMENTED); + } + + for (int_t i = 0; i < nACStart; i++) + iNumber[i] = AC_idxStart[i]; + iLength = nACStart; + for (int_t i = 0; i < nS; i++) + if (schurUpdate[i] == SUT_ConAdded) { + iNumber[iLength] = schurUpdateIndex[i]; + iSIdx[iLength - nACStart] = i; + iLength++; + } + + A->getSparseSubmatrix(iLength, iNumber, 1, &number, 0, 0, numNonzeros, irn, jcn, vals); + + for (int_t i = 0; i < numNonzeros; i++) { + if (irn[i] < nACStart) { + Mpos[numNonzerosM] = irn[i] + nFRStart; + Mvals[numNonzerosM] = vals[i]; + numNonzerosM++; + } else { + Npos[numNonzerosN] = iSIdx[irn[i] - nACStart]; + Nvals[numNonzerosN] = vals[i]; + numNonzerosN++; + } + } + + delete[] iSIdx; + delete[] iNumber; + delete[] vals; + delete[] jcn; + delete[] irn; + + returnvalue = addToSchurComplement( + number, SUT_VarFreed, numNonzerosM, Mpos, Mvals, numNonzerosN, Npos, Nvals, N_diag); + + delete[] Mvals; + delete[] Mpos; + delete[] Nvals; + delete[] Npos; + + if (returnvalue != SUCCESSFUL_RETURN) + return THROWERROR(RET_REMOVEBOUND_FAILED); + + found = true; + sModType = 1; + } + } + + if (!found) + return THROWERROR(RET_REMOVEBOUND_FAILED); + + /* Now we have a new Schur complement (might be smaller, larger, or empty). Update QR factorization. */ + + /* Flipping bounds strategy */ + if ((options.enableFlippingBounds == BT_TRUE) && (allowFlipping == BT_TRUE) && + (exchangeHappened == BT_FALSE)) { + if (sModType == 1) { /* Case 1: We added a row and column to S. */ + + /* Check if a direction of negative curvature showed up, i.e. determinants have THE SAME sign */ + newDet = calcDetSchur(idxDeleted); + + if (oldDet * newDet > 0.0) { + hessianType = HST_SEMIDEF; + + /* Restore old S */ + nS--; + + /* Flip bounds */ + tabularOutput.idxAddB = number; + tabularOutput.excAddB = 2; + switch (oldStatus) { + case ST_LOWER: + bounds.moveFreeToFixed(number, ST_UPPER); + ub[number] = lb[number]; + break; + case ST_UPPER: + bounds.moveFreeToFixed(number, ST_LOWER); + lb[number] = ub[number]; + break; + default: + return THROWERROR(RET_MOVING_BOUND_FAILED); + } + } else { /* Determinants have the correct sign, compute QR of new (larger) S */ + updateSchurQR(idxDeleted); + } + } else if (sModType == 2) { /* Case 2: We deleted a row and column of S. */ + + /* Check if a direction of negative curvature showed up, i.e. determinants have DIFFERENT signs */ + newDet = calcDetSchur(idxDeleted); + + if (oldDet * newDet < 0.0) { + hessianType = HST_SEMIDEF; + + /* Restore old S */ + undoDeleteFromSchurComplement(idxDeleted); + + /* Flip bounds */ + tabularOutput.idxAddB = number; + tabularOutput.excAddB = 2; + switch (oldStatus) { + case ST_LOWER: + bounds.moveFreeToFixed(number, ST_UPPER); + ub[number] = lb[number]; + break; + case ST_UPPER: + bounds.moveFreeToFixed(number, ST_LOWER); + lb[number] = ub[number]; + break; + default: + return THROWERROR(RET_MOVING_BOUND_FAILED); + } + } else { /* Determinants have the correct sign, compute QR of new (smaller) S */ + updateSchurQR(idxDeleted); + } + } else if (sModType == 3) { /* Case 3: S was reset. */ + + /* Check inertia of new factorization given by the sparse solver: must be ( nFR, nAC, 0 ) */ + int_t neig = sparseSolver->getNegativeEigenvalues(); + if (neig > getNAC()) // Wrong inertia, flip bounds! + { + /* Flip bounds and update Schur complement */ + tabularOutput.idxAddB = number; + tabularOutput.excAddB = 2; + switch (oldStatus) { + case ST_LOWER: + ub[number] = lb[number]; + addBound(number, ST_UPPER, BT_TRUE, BT_FALSE); + break; + case ST_UPPER: + lb[number] = ub[number]; + addBound(number, ST_LOWER, BT_TRUE, BT_FALSE); + break; + default: + return THROWERROR(RET_MOVING_BOUND_FAILED); + } + } + + /* Check if flipping deleted the negative eigenvalue */ + if (correctInertia()) + return THROWERROR(RET_REMOVEBOUND_FAILED); + } else { /* None of the three cases happened */ + return THROWERROR(RET_REMOVEBOUND_FAILED); + } + } else { /* No flipping strategy, update QR factorization of S */ + updateSchurQR(idxDeleted); + } + + /* If reciprocal of condition number becomes to small, refactorize KKT matrix */ + if (rcondS < options.rcondSMin) { + returnValue retval = resetSchurComplement(BT_TRUE); + if (retval != SUCCESSFUL_RETURN) { + if (retval == RET_KKT_MATRIX_SINGULAR && options.printLevel == PL_HIGH) + MyPrintf("In removeBound: KKT matrix singular when resetting Schur complement\n"); + else if (options.printLevel == PL_HIGH) + MyPrintf("In removeBound, resetSchurComplement failed with retval = %d\n", retval); + return THROWERROR(RET_ADDCONSTRAINT_FAILED); + } + } + + if (exchangeHappened == BT_TRUE) { + /* add bound or constraint */ + + if (addBoundNotConstraint) { + addBound(addIdx, addStatus, BT_TRUE, BT_FALSE); + tabularOutput.excAddB = 1; + } else { + addConstraint(addIdx, addStatus, BT_TRUE, BT_FALSE); + tabularOutput.excAddC = 1; + } + } + + return SUCCESSFUL_RETURN; +} + +/* + * s e t u p T Q f a c t o r i s a t i o n + */ +returnValue SQProblemSchur::backsolveT( + const real_t * const b, BooleanType transposed, real_t * const a) const +{ + return THROWERROR(RET_UNKNOWN_BUG); +} + +/* + * b a c k s o l v e R + */ +returnValue SQProblemSchur::backsolveR( + const real_t * const b, BooleanType transposed, real_t * const a) const +{ + return THROWERROR(RET_UNKNOWN_BUG); +} + +/* + * b a c k s o l v e R + */ +returnValue SQProblemSchur::backsolveR( + const real_t * const b, BooleanType transposed, BooleanType removingBound, real_t * const a) const +{ + return THROWERROR(RET_UNKNOWN_BUG); +} + +/* + * c a l c D e t S c h u r + */ +real_t SQProblemSchur::calcDetSchur(int_t idxDel) +{ + if (nS <= 0) + return 1.0; + + real_t newDet; + int_t i, j; + real_t c, s, nu; + + /* Case 1: S has been bordered by one row and column */ + if (idxDel < 0) { + /* Do a solve with the old S to check determinant of new (bordered) S */ + real_t * temp1 = new real_t[nS - 1]; + real_t * temp2 = new real_t[nS - 1]; + for (i = 0; i < nS - 1; i++) + temp1[i] = S[i + (nS - 1) * nSmax]; + backsolveSchurQR(nS - 1, temp1, 1, temp2); + + newDet = S[(nS - 1) + (nS - 1) * nSmax]; + for (i = 0; i < nS - 1; i++) + newDet -= temp1[i] * temp2[i]; + newDet *= detS; + delete[] temp1; + delete[] temp2; + } + /* Case 2: row and column idxDel have been deleted from S */ + else { + const int_t dim = nS + 1; + real_t * tempR = new real_t[dim * (dim - 1)]; + real_t * tempColQ = new real_t[dim]; + + /* Copy current R without column idxDel*/ + for (j = 0; j < idxDel; j++) + for (i = 0; i < dim; i++) + tempR[i + j * dim] = R_[i + j * nSmax]; + for (j = idxDel; j < dim - 1; j++) + for (i = 0; i < dim; i++) + tempR[i + j * dim] = R_[i + (j + 1) * nSmax]; + /* Copy row idxDel of Q */ + for (j = 0; j < dim; j++) + tempColQ[j] = Q_[idxDel + j * nSmax]; + + /* Bring tempR to triangular form with nS-idxDel Givens rotations */ + for (i = idxDel; i < nS; i++) { + computeGivens( + tempR[i + i * dim], tempR[(i + 1) + i * dim], tempR[i + i * dim], tempR[(i + 1) + i * dim], c, s); + nu = s / (1.0 + c); + /// \todo I think we do not need to transform all columns of R, i+3 or so should be sufficient + for (j = i + 1; j < nS; j++) + applyGivens(c, + s, + nu, + tempR[i + j * dim], + tempR[(i + 1) + j * dim], + tempR[i + j * dim], + tempR[(i + 1) + j * dim]); + + /* Simultaneously transform relevant column of Q**T */ + applyGivens(c, s, nu, tempColQ[i], tempColQ[i + 1], tempColQ[i], tempColQ[i + 1]); + } + + /* Delete row: nS Givens rotations to transform last column (and row!) of (old) Q**T to getAbs((nS+1)-th + * unity vector) */ + for (i = nS; i > 0; i--) { + computeGivens(tempColQ[nS], tempColQ[i - 1], tempColQ[nS], tempColQ[i - 1], c, s); + nu = s / (1.0 + c); + + /* Simultaneously transform diagonal elements of R (coldim is already one less than Q) */ + applyGivens(c, + s, + nu, + tempR[nS + (i - 1) * dim], + tempR[(i - 1) + (i - 1) * dim], + tempR[nS + (i - 1) * dim], + tempR[(i - 1) + (i - 1) * dim]); + } + + /* Note that we implicitly did a row permutation of Q. + * If we did an odd permutation AND deleted a positive unity vector or + * if we did an even permutation AND deleted a negative unity vector, then det(Q)=-1 + * ->Change signs of first column of Q and first row of R */ + if ((((nS - idxDel) % 2 == 1) && (tempColQ[nS] > 0.0)) || + (((nS - idxDel) % 2 == 0) && (tempColQ[nS] < 0.0))) { + tempR[0] = -tempR[0]; + } + + newDet = 1.0; + // for( i=0; i 0; i--) { + computeGivens( + Q_[nS + nS * nSmax], Q_[nS + (i - 1) * nSmax], Q_[nS + nS * nSmax], Q_[nS + (i - 1) * nSmax], c, s); + nu = s / (1.0 + c); + for (j = 0; j < nS; j++) + applyGivens(c, + s, + nu, + Q_[j + nS * nSmax], + Q_[j + (i - 1) * nSmax], + Q_[j + nS * nSmax], + Q_[j + (i - 1) * nSmax]); + + /* Simultaneously transform R (coldim is already one less than Q) */ + for (j = i - 1; j < nS; j++) + applyGivens(c, + s, + nu, + R_[nS + j * nSmax], + R_[(i - 1) + j * nSmax], + R_[nS + j * nSmax], + R_[(i - 1) + j * nSmax]); + } + + /* If we did an odd permutation AND deleted a positive unity vector or + * if we did an even permutation AND deleted a negative unity vector, then det(Q)=-1 + * ->Change signs of first column of Q and first row of R s.t. we always maintain det(Q)=1 */ + if ((((nS - idxDel) % 2 == 1) && (Q_[nS + nS * nSmax] > 0.0)) || + (((nS - idxDel) % 2 == 0) && (Q_[nS + nS * nSmax] < 0.0))) { + for (i = 0; i < nS + 1; i++) + Q_[i] = -Q_[i]; + for (i = 0; i < nS; i++) + R_[i * nSmax] = -R_[i * nSmax]; + } + } + + /* Compute determinant */ + detS = 1.0; + // for ( i=0; i 1) { + MyPrintf("backsolve not implemented for dimRhs = %d\n", dimRhs); + return RET_QR_FACTORISATION_FAILED; + } + + int_t i, j; + long INFO = 0; + unsigned long NRHS = 1; + unsigned long M = (unsigned long)dimS; + unsigned long LDA = (unsigned long)nSmax; + unsigned long LDC = (unsigned long)dimS; + + for (i = 0; i < dimS; i++) + sol[i] = 0.0; + + /* Compute sol = Q**T * rhs */ + for (i = 0; i < dimS; i++) + for (j = 0; j < dimS; j++) + sol[i] += Q_[j + i * nSmax] * rhs[j]; + + /* Solve Rx = sol */ + TRTRS("U", "N", "N", &M, &NRHS, R_, &LDA, sol, &LDC, &INFO); + if (INFO != 0) { + MyPrintf("TRTRS returns INFO = %d\n", INFO); + if (INFO == ((long)0xDEADBEEF)) + MyPrintf("If SQProblemSchur is to be used, system LAPACK must be used instead of the qpOASES LAPACK " + "replacement"); + return RET_QR_FACTORISATION_FAILED; + } + + return SUCCESSFUL_RETURN; +} + +returnValue SQProblemSchur::stepCalcRhs(int_t nFR, + int_t nFX, + int_t nAC, + int_t * FR_idx, + int_t * FX_idx, + int_t * AC_idx, + real_t & rhs_max, + const real_t * const delta_g, + const real_t * const delta_lbA, + const real_t * const delta_ubA, + const real_t * const delta_lb, + const real_t * const delta_ub, + BooleanType Delta_bC_isZero, + BooleanType Delta_bB_isZero, + real_t * const delta_xFX, + real_t * const delta_xFR, + real_t * const delta_yAC, + real_t * const delta_yFX) +{ + int_t i, ii; + returnValue retval; + + if (nS < 0) { + retval = resetSchurComplement(BT_FALSE); + if (retval != SUCCESSFUL_RETURN) { + MyPrintf("In SQProblemSchur::stepCalcRhs, resetSchurComplement returns %d\n", retval); + return THROWERROR(retval); + } + } + + /* tempA and tempB hold the residuals in gFR and bA (= lbA or ubA) + * delta_xFR, delta_yAC hold the steps that get refined */ + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + tempA[i] = delta_g[ii]; + delta_xFR[i] = 0.0; + } + for (i = 0; i < nAC; ++i) + delta_yAC[i] = 0.0; + if (Delta_bC_isZero == BT_FALSE) { + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + if (constraints.getStatus(ii) == ST_LOWER) + tempB[i] = delta_lbA[ii]; + else + tempB[i] = delta_ubA[ii]; + } + } else { + for (i = 0; i < nAC; ++i) + tempB[i] = 0.0; + } + if ((hessianType != HST_IDENTITY) && (hessianType != HST_ZERO)) { + /* tempA becomes RHS for reduced augmented system, gFR+H_FX*delta_xFR */ + H->times(bounds.getFree(), bounds.getFixed(), 1, 1.0, delta_xFX, nFX, 1.0, tempA, nFR); + } + /* tempB becomes RHS for reduced augmented system, bA-A_CX*delta_xFR */ + A->times(constraints.getActive(), bounds.getFixed(), 1, -1.0, delta_xFX, nFX, 1.0, tempB, nAC); + + /* If iterative refinement is requested, compute max-norm of RHS for termination test. */ + rhs_max = 0.0; + if (options.numRefinementSteps > 0) { + for (i = 0; i < nFR; i++) + rhs_max = getMax(rhs_max, getAbs(tempA[i])); + for (i = 0; i < nAC; i++) + rhs_max = getMax(rhs_max, getAbs(tempB[i])); + } + return SUCCESSFUL_RETURN; +} + +returnValue SQProblemSchur::stepCalcReorder(int_t nFR, + int_t nAC, + int_t * FR_idx, + int_t * AC_idx, + int_t nFRStart, + int_t nACStart, + int_t * FR_idxStart, + int_t * AC_idxStart, + int_t * FR_iSort, + int_t * FR_iSortStart, + int_t * AC_iSort, + int_t * AC_iSortStart, + real_t * rhs) +{ + int_t i, ii; + /* Reorder information for the new to the old free variables. */ + i = 0; + ii = 0; + while (ii < nFRStart) { + if (i == nFR) + rhs[FR_iSortStart[ii++]] = 0.0; + else { + int_t idx = FR_idx[FR_iSort[i]]; + int_t idxStart = FR_idxStart[FR_iSortStart[ii]]; + + if (idx == idxStart) + rhs[FR_iSortStart[ii++]] = -tempA[FR_iSort[i++]]; + else if (idx < idxStart) + i++; + else + rhs[FR_iSortStart[ii++]] = 0.0; + } + } + /* Reorder information for the new to the old active constraints. */ + i = 0; + ii = 0; + while (ii < nACStart) { + if (i == nAC) + rhs[nFRStart + AC_iSortStart[ii++]] = 0.0; + else { + int_t idx = AC_idx[AC_iSort[i]]; + int_t idxStart = AC_idxStart[AC_iSortStart[ii]]; + + if (idx == idxStart) + rhs[nFRStart + AC_iSortStart[ii++]] = tempB[AC_iSort[i++]]; + else if (idx < idxStart) + i++; + else + rhs[nFRStart + AC_iSortStart[ii++]] = 0.0; + } + } + return SUCCESSFUL_RETURN; +} + +returnValue SQProblemSchur::stepCalcBacksolveSchur(int_t nFR, + int_t nFX, + int_t nAC, + int_t * FR_idx, + int_t * FX_idx, + int_t * AC_idx, + int_t dim, + real_t * rhs, + real_t * sol) +{ + returnValue retval; + int_t i, ii; + + real_t * q = new real_t[nS]; + + /* Compute extra compoments of the RHS */ + for (ii = 0; ii < nS; ii++) { + int_t idx = schurUpdateIndex[ii]; + switch (schurUpdate[ii]) // TODO: All the loops below could be done faster by binary search or so + { + case SUT_VarFixed: + q[ii] = 0.0; + break; + + case SUT_VarFreed: + /* Find index of freed variable */ + for (i = 0; i < nFR; ++i) + if (FR_idx[i] == idx) { + q[ii] = -tempA[i]; + break; + } + break; + + case SUT_ConAdded: + /* Find index of added constraint */ + for (i = 0; i < nAC; ++i) + if (AC_idx[i] == idx) { + q[ii] = tempB[i]; + break; + } + break; + + case SUT_ConRemoved: + q[ii] = 0.0; + break; + + default: + return THROWERROR(RET_UNKNOWN_BUG); + } + } + + /* compute q = M^T K^{-1} r - q */ + computeMTransTimes(1.0, sol, -1.0, q); + + /* Solve linear system with Schur complement. */ + real_t * p = new real_t[nS]; + backsolveSchurQR(nS, q, 1, p); + + computeMTimes(-1.0, p, 1.0, rhs); + + retval = sparseSolver->solve(dim, rhs, sol); + + // for (int i = 0; i < dim; i++) + // printf("sol[%i] = %f\n", i, sol[i]); + + if (retval != SUCCESSFUL_RETURN) { + MyPrintf("sparseSolver->solve (second time) failed.\n"); + return THROWERROR(RET_MATRIX_FACTORISATION_FAILED); // TODO: Different return code + } + + /* Transfer extra compoments of the Schur complement solution to the correct place. */ + for (ii = 0; ii < nS; ii++) { + int_t idx = schurUpdateIndex[ii]; + switch (schurUpdate[ii]) // TODO: All the loops below could be done faster by binary search or so + { + case SUT_VarFixed: + break; + + case SUT_VarFreed: + /* Find index of freed variable */ + for (i = 0; i < nFR; ++i) + if (FR_idx[i] == idx) { + delta_xFR_TMP[i] = p[ii]; + break; + } + break; + + case SUT_ConAdded: + /* Find index of added constraint */ + for (i = 0; i < nAC; ++i) + if (AC_idx[i] == idx) { + delta_yAC_TMP[i] = -p[ii]; + break; + } + break; + + case SUT_ConRemoved: + break; + + default: + return THROWERROR(RET_UNKNOWN_BUG); + } + } + + delete[] p; + delete[] q; + return SUCCESSFUL_RETURN; +} + +returnValue SQProblemSchur::stepCalcReorder2(int_t nFR, + int_t nAC, + int_t * FR_idx, + int_t * AC_idx, + int_t nFRStart, + int_t nACStart, + int_t * FR_idxStart, + int_t * AC_idxStart, + int_t * FR_iSort, + int_t * FR_iSortStart, + int_t * AC_iSort, + int_t * AC_iSortStart, + real_t * sol, + real_t * const delta_xFR, + real_t * const delta_yAC) +{ + int_t i, ii; + i = 0; + ii = 0; + while (ii < nFRStart && i < nFR) { + int_t idx = FR_idx[FR_iSort[i]]; + int_t idxStart = FR_idxStart[FR_iSortStart[ii]]; + + if (idx == idxStart) + delta_xFR_TMP[FR_iSort[i++]] = sol[FR_iSortStart[ii++]]; + else if (idx < idxStart) + i++; + else + ii++; + } + /* Transfer Schur complement solution for the active constraint multipliers to the correct places */ + i = 0; + ii = 0; + while (ii < nACStart && i < nAC) { + int_t idx = AC_idx[AC_iSort[i]]; + int_t idxStart = AC_idxStart[AC_iSortStart[ii]]; + + if (idx == idxStart) + delta_yAC_TMP[AC_iSort[i++]] = -sol[nFRStart + AC_iSortStart[ii++]]; + else if (idx < idxStart) + i++; + else + ii++; + } + + /* refine the solution found so far */ + for (i = 0; i < nFR; ++i) + delta_xFR[i] += delta_xFR_TMP[i]; + for (i = 0; i < nAC; ++i) + delta_yAC[i] += delta_yAC_TMP[i]; + return SUCCESSFUL_RETURN; +} + +returnValue SQProblemSchur::stepCalcResid(int_t nFR, + int_t nFX, + int_t nAC, + int_t * FR_idx, + int_t * FX_idx, + int_t * AC_idx, + BooleanType Delta_bC_isZero, + real_t * const delta_xFX, + real_t * const delta_xFR, + real_t * const delta_yAC, + const real_t * const delta_g, + const real_t * const delta_lbA, + const real_t * const delta_ubA, + real_t & rnrm) +{ + int_t i, ii; + /* compute residuals in tempA and tempB, and max-norm */ + for (i = 0; i < nFR; ++i) { + ii = FR_idx[i]; + tempA[i] = delta_g[ii]; + } + + switch (hessianType) { + case HST_ZERO: + break; + + case HST_IDENTITY: + for (i = 0; i < nFR; ++i) + tempA[i] += delta_xFR[i]; + break; + + default: + H->times(bounds.getFree(), bounds.getFree(), 1, 1.0, delta_xFR, nFR, 1.0, tempA, nFR); + H->times(bounds.getFree(), bounds.getFixed(), 1, 1.0, delta_xFX, nFX, 1.0, tempA, nFR); + break; + } + + for (i = 0; i < nFR; ++i) + tempA[i] += options.epsRegularisation * delta_xFR[i]; + + A->transTimes(constraints.getActive(), bounds.getFree(), 1, -1.0, delta_yAC, nAC, 1.0, tempA, nFR); + rnrm = 0.0; + for (i = 0; i < nFR; ++i) + if (rnrm < getAbs(tempA[i])) + rnrm = getAbs(tempA[i]); + + if (!Delta_bC_isZero) { + for (i = 0; i < nAC; ++i) { + ii = AC_idx[i]; + if (constraints.getStatus(ii) == ST_LOWER) + tempB[i] = delta_lbA[ii]; + else + tempB[i] = delta_ubA[ii]; + } + } else { + for (i = 0; i < nAC; ++i) + tempB[i] = 0.0; + } + + A->times(constraints.getActive(), bounds.getFree(), 1, -1.0, delta_xFR, nFR, 1.0, tempB, nAC); + + A->times(constraints.getActive(), bounds.getFixed(), 1, -1.0, delta_xFX, nFX, 1.0, tempB, nAC); + for (i = 0; i < nAC; ++i) + if (rnrm < getAbs(tempB[i])) + rnrm = getAbs(tempB[i]); + + return SUCCESSFUL_RETURN; +} + +returnValue SQProblemSchur::stepCalcDeltayFx(int_t nFR, + int_t nFX, + int_t nAC, + int_t * FX_idx, + const real_t * const delta_g, + real_t * const delta_xFX, + real_t * const delta_xFR, + real_t * const delta_yAC, + real_t * const delta_yFX) +{ + int_t i; + for (i = 0; i < nFX; ++i) + delta_yFX[i] = delta_g[FX_idx[i]]; + + A->transTimes(constraints.getActive(), bounds.getFixed(), 1, -1.0, delta_yAC, nAC, 1.0, delta_yFX, nFX); + + if (hessianType == HST_ZERO) { + // TODO: if ( usingRegularisation( ) == BT_TRUE ) + for (i = 0; i < nFX; ++i) + delta_yFX[i] += options.epsRegularisation * delta_xFX[i]; + } else if (hessianType == HST_IDENTITY) { + for (i = 0; i < nFX; ++i) + delta_yFX[i] += delta_xFX[i]; + } else { + H->times(bounds.getFixed(), bounds.getFree(), 1, 1.0, delta_xFR, nFR, 1.0, delta_yFX, nFX); + H->times(bounds.getFixed(), bounds.getFixed(), 1, 1.0, delta_xFX, nFX, 1.0, delta_yFX, nFX); + } + return SUCCESSFUL_RETURN; +} + +returnValue SQProblemSchur::determineStepDirection(const real_t * const delta_g, + const real_t * const delta_lbA, + const real_t * const delta_ubA, + const real_t * const delta_lb, + const real_t * const delta_ub, + BooleanType Delta_bC_isZero, + BooleanType Delta_bB_isZero, + real_t * const delta_xFX, + real_t * const delta_xFR, + real_t * const delta_yAC, + real_t * const delta_yFX) +{ + returnValue retval = determineStepDirection2(delta_g, + delta_lbA, + delta_ubA, + delta_lb, + delta_ub, + Delta_bC_isZero, + Delta_bB_isZero, + delta_xFX, + delta_xFR, + delta_yAC, + delta_yFX); + + if (retval == RET_QR_FACTORISATION_FAILED) { + retval = resetSchurComplement(BT_FALSE); + if (retval != SUCCESSFUL_RETURN) { + MyPrintf("In SQProblem::determineStepDirection, resetSchurComplement returns %d\n", retval); + return THROWERROR(retval); + } + retval = determineStepDirection2(delta_g, + delta_lbA, + delta_ubA, + delta_lb, + delta_ub, + Delta_bC_isZero, + Delta_bB_isZero, + delta_xFX, + delta_xFR, + delta_yAC, + delta_yFX); + } + return retval; +} + +/* + * d e t e r m i n e S t e p D i r e c t i o n + */ +returnValue SQProblemSchur::determineStepDirection2(const real_t * const delta_g, + const real_t * const delta_lbA, + const real_t * const delta_ubA, + const real_t * const delta_lb, + const real_t * const delta_ub, + BooleanType Delta_bC_isZero, + BooleanType Delta_bB_isZero, + real_t * const delta_xFX, + real_t * const delta_xFR, + real_t * const delta_yAC, + real_t * const delta_yFX) +{ + /* The linear system to be solved here is this: + + / H_FF H_FX A_CF^T 0 \ / delta_xFR \ / -delta_g_F \ + | H_XF H_XX A_CX^T I | | delta_xFX | | -delta_g_X | + | A_CF A_CX 0 0 | | -delta_yAC | = | delta_bA | <-- active entries of delta_lbA and + delta_ubA with corresponding sign \ 0 I 0 0 / \ -delta_yFX / \ delta_bX / <-- fixed + entries of delta_lb and delta_ub with corresponding sign + + */ + + int_t i, ii, r; + + returnValue retval; + + // int_t nV = getNV( ); + int_t nFR = getNFR(); + int_t nFX = getNFX(); + int_t nAC = getNAC(); + + int_t * FR_idx; + int_t * FX_idx; + int_t * AC_idx; + + bounds.getFree()->getNumberArray(&FR_idx); + bounds.getFixed()->getNumberArray(&FX_idx); + constraints.getActive()->getNumberArray(&AC_idx); + + /* I) DETERMINE delta_xFX (this is exact, does not need refinement) */ + if (Delta_bB_isZero == BT_FALSE) { + for (i = 0; i < nFX; ++i) { + ii = FX_idx[i]; + + if (bounds.getStatus(ii) == ST_LOWER) + delta_xFX[i] = delta_lb[ii]; + else + delta_xFX[i] = delta_ub[ii]; + } + } else { + for (i = 0; i < nFX; ++i) + delta_xFX[i] = 0.0; + } + + if (nFR + nAC > 0) { + real_t rhs_max = 0.0; + retval = stepCalcRhs(nFR, + nFX, + nAC, + FR_idx, + FX_idx, + AC_idx, + rhs_max, + delta_g, + delta_lbA, + delta_ubA, + delta_lb, + delta_ub, + Delta_bC_isZero, + Delta_bB_isZero, + delta_xFX, + delta_xFR, + delta_yAC, + delta_yFX); + + if (retval != SUCCESSFUL_RETURN) + return retval; + int_t nFRStart = boundsFreeStart.getLength(); + int_t nACStart = constraintsActiveStart.getLength(); + + int_t * FR_iSort; + int_t * AC_iSort; + bounds.getFree()->getISortArray(&FR_iSort); + constraints.getActive()->getISortArray(&AC_iSort); + + int_t * FR_idxStart; + int_t * AC_idxStart; + boundsFreeStart.getNumberArray(&FR_idxStart); + constraintsActiveStart.getNumberArray(&AC_idxStart); + + int_t * FR_iSortStart; + int_t * AC_iSortStart; + boundsFreeStart.getISortArray(&FR_iSortStart); + constraintsActiveStart.getISortArray(&AC_iSortStart); + + int_t dim = nFRStart + nACStart; + real_t * rhs = new real_t[dim]; + real_t * sol = new real_t[dim]; + + /* Iterative refinement loop for delta_xFR, delta_yAC */ + for (r = 0; r <= options.numRefinementSteps; ++r) { + retval = stepCalcReorder(nFR, + nAC, + FR_idx, + AC_idx, + nFRStart, + nACStart, + FR_idxStart, + AC_idxStart, + FR_iSort, + FR_iSortStart, + AC_iSort, + AC_iSortStart, + rhs); + if (retval != SUCCESSFUL_RETURN) + return retval; + + retval = sparseSolver->solve(dim, rhs, sol); + + if (retval != SUCCESSFUL_RETURN) { + MyPrintf("sparseSolver->solve (first time) failed.\n"); + return THROWERROR(RET_MATRIX_FACTORISATION_FAILED); // TODO: Different return code + } + + if (nS > 0) { + retval = stepCalcBacksolveSchur(nFR, nFX, nAC, FR_idx, FX_idx, AC_idx, dim, rhs, sol); + if (retval != SUCCESSFUL_RETURN) + return retval; + } + + /* Transfer Schur complement solution for the free variables to the correct places */ + retval = stepCalcReorder2(nFR, + nAC, + FR_idx, + AC_idx, + nFRStart, + nACStart, + FR_idxStart, + AC_idxStart, + FR_iSort, + FR_iSortStart, + AC_iSort, + AC_iSortStart, + sol, + delta_xFR, + delta_yAC); + if (retval != SUCCESSFUL_RETURN) + return retval; + + if (r < options.numRefinementSteps) // TODO: use "<" to avoid computation in last round + { + real_t rnrm; + retval = stepCalcResid(nFR, + nFX, + nAC, + FR_idx, + FX_idx, + AC_idx, + Delta_bC_isZero, + delta_xFX, + delta_xFR, + delta_yAC, + delta_g, + delta_lbA, + delta_ubA, + rnrm); + if (retval != SUCCESSFUL_RETURN) + return retval; + + /* early termination of residual norm small enough */ + if (options.printLevel == PL_HIGH) + MyPrintf("In iterative refinement (iter %d) rnrm = %e and epsIterRef*rhs_max = %e.\n", + r, + rnrm, + options.epsIterRef * rhs_max); + + if (rnrm <= options.epsIterRef * rhs_max) + break; + } + } + + delete[] sol; + delete[] rhs; + } + + /* IV) DETERMINE delta_yFX */ + if (nFX > 0) { + retval = stepCalcDeltayFx(nFR, nFX, nAC, FX_idx, delta_g, delta_xFX, delta_xFR, delta_yAC, delta_yFX); + if (retval != SUCCESSFUL_RETURN) + return retval; + } + + return SUCCESSFUL_RETURN; +} + +returnValue SQProblemSchur::resetSchurComplement(BooleanType allowInertiaCorrection) +{ + int_t j; + int_t nFR = getNFR(); + int_t nAC = getNAC(); + + if (options.printLevel == PL_HIGH) + MyPrintf("Resetting Schur complement.\n"); + + nS = 0; + detS = 1.0; + rcondS = 1.0; + boundsFreeStart = *bounds.getFree(); + constraintsActiveStart = *constraints.getActive(); + + if (nSmax > 0) + M_jc[0] = 0; + + int_t dim = nFR + nAC; + // Count the number of nonzeros + int_t numNonzeros; + switch (hessianType) { + case HST_ZERO: + numNonzeros = 0; + break; + + case HST_IDENTITY: + numNonzeros = nFR; + break; + + default: + H->getSparseSubmatrix(bounds.getFree(), bounds.getFree(), 1, 1, numNonzeros, 0, 0, 0, BT_TRUE); + break; + } + // TODO: For now, we regularize every time + if (options.epsRegularisation > 0.0) + numNonzeros += nFR; + + int_t numNonzerosA; + + if (constraintProduct != 0) { + MyPrintf("In SQProblemSchur::determineStepDirection, constraintProduct not yet implemented.\n"); + return THROWERROR(RET_NOT_YET_IMPLEMENTED); + } + A->getSparseSubmatrix( + constraints.getActive(), bounds.getFree(), nFR + 1, 1, numNonzerosA, 0, 0, 0, BT_FALSE); + numNonzeros += numNonzerosA; + + // Get the values + real_t * avals = new real_t[numNonzeros]; + int_t * irn = new int_t[numNonzeros]; + int_t * jcn = new int_t[numNonzeros]; + numNonzeros = 0; + switch (hessianType) { + case HST_ZERO: + break; + + case HST_IDENTITY: + numNonzeros += nFR; + for (j = 0; j < nFR; j++) { + irn[j] = j + 1; + jcn[j] = j + 1; + avals[j] = 1.0; + } + break; + + default: + H->getSparseSubmatrix(bounds.getFree(), bounds.getFree(), 1, 1, numNonzeros, irn, jcn, avals, BT_TRUE); + break; + } + + // For now, we regularize every time + if (options.epsRegularisation > 0.0) { + for (j = 0; j < nFR; j++) { + irn[numNonzeros] = j + 1; + jcn[numNonzeros] = j + 1; + avals[numNonzeros++] = options.epsRegularisation; + } + } + + A->getSparseSubmatrix(constraints.getActive(), + bounds.getFree(), + nFR + 1, + 1, + numNonzerosA, + irn + numNonzeros, + jcn + numNonzeros, + avals + numNonzeros, + BT_FALSE); + numNonzeros += numNonzerosA; + + // Call the linear solver + sparseSolver->reset(); + returnValue retval = sparseSolver->setMatrixData(dim, numNonzeros, irn, jcn, avals); + delete[] jcn; + delete[] irn; + delete[] avals; + + if (retval != SUCCESSFUL_RETURN) + return THROWERROR(RET_NO_SPARSE_SOLVER); + + // Factorize the matrix for later backsolves + retval = sparseSolver->factorize(); + numFactorizations++; + + // If matrix is singular, add bounds/remove constraints according to zero pivots + if (retval == RET_KKT_MATRIX_SINGULAR) { + if (repairSingularWorkingSet() == SUCCESSFUL_RETURN) + return resetSchurComplement(allowInertiaCorrection); + else + return RET_KKT_MATRIX_SINGULAR; + } + + // If matrix has wrong inertia, add bounds until inertia is correct + if (retval == SUCCESSFUL_RETURN && allowInertiaCorrection) { + int_t neig = sparseSolver->getNegativeEigenvalues(); + if (neig > getNAC()) { + if (options.printLevel == PL_HIGH) + MyPrintf( + "WARNING: After new factorization, reduced Hessian has %i negative eigenvalues, should be %i.\n", + neig, + getNAC()); + + retval = correctInertia(); + } + } + + if (retval != SUCCESSFUL_RETURN) + return THROWERROR(RET_MATRIX_FACTORISATION_FAILED); + + nS = 0; + + return SUCCESSFUL_RETURN; +} + +returnValue SQProblemSchur::computeMTimes( + real_t alpha, const real_t * const x_, real_t beta, real_t * const y_) +{ + if (isEqual(alpha, -1.0) == BT_FALSE || isEqual(beta, 1.0) == BT_FALSE) + return THROWERROR(RET_NOT_YET_IMPLEMENTED); + + int_t i, j; + + for (j = 0; j < nS; j++) { + const real_t xval = x_[j]; + for (i = M_jc[j]; i < M_jc[j + 1]; i++) + y_[M_ir[i]] -= M_vals[i] * xval; + } + + return SUCCESSFUL_RETURN; +} + +returnValue SQProblemSchur::computeMTransTimes( + real_t alpha, const real_t * const x_, real_t beta, real_t * const y_) +{ + if (isEqual(alpha, 1.0) == BT_FALSE || (isZero(beta) == BT_FALSE && isEqual(beta, -1.0) == BT_FALSE)) + return THROWERROR(RET_NOT_YET_IMPLEMENTED); + + int_t i, j; + + if (isZero(beta) == BT_TRUE) { + for (j = 0; j < nS; j++) { + y_[j] = 0.0; + for (i = M_jc[j]; i < M_jc[j + 1]; i++) + y_[j] += M_vals[i] * x_[M_ir[i]]; + } + } else { + for (j = 0; j < nS; j++) { + y_[j] = -y_[j]; + for (i = M_jc[j]; i < M_jc[j + 1]; i++) + y_[j] += M_vals[i] * x_[M_ir[i]]; + } + } + + return SUCCESSFUL_RETURN; +} + +returnValue SQProblemSchur::addToSchurComplement(int_t number, + SchurUpdateType update, + int_t numNonzerosM, + const sparse_int_t * Mpos, + const real_t * const Mvals, + int_t numNonzerosN, + const sparse_int_t * Npos, + const real_t * const Nvals, + real_t N_diag) +{ + int_t i; + + int_t nFRStart = boundsFreeStart.getLength(); + int_t nACStart = constraintsActiveStart.getLength(); + + real_t * new_Scol = new real_t[nS]; + + int_t dim = nFRStart + nACStart; + real_t * rhs = new real_t[dim]; + real_t * sol = new real_t[dim]; + + for (i = 0; i < dim; i++) + rhs[i] = 0.0; + + for (i = 0; i < numNonzerosM; i++) + rhs[Mpos[i]] = Mvals[i]; + + returnValue retval = sparseSolver->solve(dim, rhs, sol); + if (retval != SUCCESSFUL_RETURN) { + MyPrintf("sparseSolver->solve in SQProblemSchur::addToSchurComplement failed.\n"); + return THROWERROR(RET_MATRIX_FACTORISATION_FAILED); // TODO: Different return code + } + + computeMTransTimes(1.0, sol, 0.0, new_Scol); + + /* Take care of off-diagonal elements in N. */ + for (i = 0; i < numNonzerosN; i++) + new_Scol[Npos[i]] -= Nvals[i]; + + real_t sdiag = -N_diag; + for (i = 0; i < numNonzerosM; i++) + sdiag += Mvals[i] * sol[Mpos[i]]; + + /* Now augment S */ + for (i = 0; i < nS; i++) + S[nS * nSmax + i] = new_Scol[i]; + for (i = 0; i < nS; i++) + S[i * nSmax + nS] = new_Scol[i]; + S[nS * nSmax + nS] = sdiag; + + schurUpdateIndex[nS] = number; + schurUpdate[nS] = update; + + /* Augment M matrix. */ + if (M_physicallength < M_jc[nS] + numNonzerosM) { + /* If necessary, allocate more memory for M. */ + int_t M_physicallength_new = getMax(2 * M_physicallength, M_physicallength + 2 * numNonzerosM); + real_t * M_vals_new = new real_t[M_physicallength_new]; + sparse_int_t * M_ir_new = new sparse_int_t[M_physicallength_new]; + memcpy(M_vals_new, M_vals, ((unsigned int)(M_jc[nS])) * sizeof(real_t)); + memcpy(M_ir_new, M_ir, ((unsigned int)(M_jc[nS])) * sizeof(sparse_int_t)); + M_physicallength = M_physicallength_new; + delete[] M_vals; + delete[] M_ir; + M_vals = M_vals_new; + M_ir = M_ir_new; + } + + for (i = 0; i < numNonzerosM; i++) { + M_vals[M_jc[nS] + i] = Mvals[i]; + M_ir[M_jc[nS] + i] = Mpos[i]; + } + M_jc[nS + 1] = M_jc[nS] + numNonzerosM; + + nS++; + + delete[] sol; + delete[] rhs; + delete[] new_Scol; + + if (options.printLevel == PL_HIGH) + MyPrintf("added index %d with update type %d to Schur complement. nS = %d\n", number, update, nS); + + return SUCCESSFUL_RETURN; +} + +returnValue SQProblemSchur::deleteFromSchurComplement(int_t idx, BooleanType allowUndo) +{ + if (options.printLevel == PL_HIGH) + MyPrintf("deleting entry %d with idx = %d and type %d from Schur complement.", + idx, + schurUpdateIndex[idx], + schurUpdate[idx]); + + if (idx != nS - 1) { + real_t * temp_vals = NULL; + int_t * temp_ir = NULL; + int_t schurUpdateIndexTemp = -1; + SchurUpdateType schurUpdateTemp = SUT_UNDEFINED; + + /* temporarily save the column of S to be deleted */ + if (allowUndo == BT_TRUE) { + temp_vals = new real_t[nS]; + for (int_t i = 0; i < nS; i++) + temp_vals[i] = S[idx * nSmax + i]; + + schurUpdateIndexTemp = schurUpdateIndex[idx]; + schurUpdateTemp = schurUpdate[idx]; + } + + /* Shift rows and columns >idx of S by one to the upper left */ + for (int_t i = 0; i < idx; i++) + for (int_t j = idx + 1; j < nS; j++) + S[i * nSmax + j - 1] = S[i * nSmax + j]; + for (int_t i = idx + 1; i < nS; i++) { + for (int_t j = 0; j < idx; j++) + S[(i - 1) * nSmax + j] = S[i * nSmax + j]; + for (int_t j = idx + 1; j < nS; j++) + S[(i - 1) * nSmax + j - 1] = S[i * nSmax + j]; + } + for (int_t i = idx + 1; i < nS; i++) { + schurUpdateIndex[i - 1] = schurUpdateIndex[i]; + schurUpdate[i - 1] = schurUpdate[i]; + } + + /* Store deleted row/column in the last row/column of S, can retrieve it from there later */ + if (allowUndo == BT_TRUE) { + for (int_t i = 0; i < nS; i++) { + S[(nS - 1) * nSmax + i] = temp_vals[i]; + S[i * nSmax + (nS - 1)] = temp_vals[i]; + } + schurUpdateIndex[nS - 1] = schurUpdateIndexTemp; + schurUpdate[nS - 1] = schurUpdateTemp; + delete[] temp_vals; + } + + /* temporarily save the (sparse) column of M to be deleted */ + int_t numEntries = M_jc[idx + 1] - M_jc[idx]; + if (allowUndo == BT_TRUE) { + temp_ir = new int_t[numEntries]; + temp_vals = new real_t[numEntries]; + + for (int_t i = M_jc[idx]; i < M_jc[idx + 1]; i++) { + temp_ir[i - M_jc[idx]] = M_ir[i]; + temp_vals[i - M_jc[idx]] = M_vals[i]; + } + } + + /* Shift all columns >idx one to the left */ + for (int_t i = M_jc[idx + 1]; i < M_jc[nS]; i++) { + M_ir[i - numEntries] = M_ir[i]; + M_vals[i - numEntries] = M_vals[i]; + } + for (int_t i = idx; i < nS; i++) + M_jc[i] = M_jc[i + 1] - numEntries; + + /* Store deleted column of M in the last column, can retrieve it from there later */ + if (allowUndo == BT_TRUE) { + for (int_t i = M_jc[nS - 1]; i < M_jc[nS]; i++) { + M_ir[i] = temp_ir[i - M_jc[nS - 1]]; + M_vals[i] = temp_vals[i - M_jc[nS - 1]]; + } + + delete[] temp_ir; + delete[] temp_vals; + } + } + + nS--; + + if (options.printLevel == PL_HIGH) + MyPrintf(" nS = %d\n", nS); + + return SUCCESSFUL_RETURN; +} + +returnValue SQProblemSchur::undoDeleteFromSchurComplement(int_t idx) +{ + if (options.printLevel == PL_HIGH) + MyPrintf("undo deletion of entry %d with idx = %d and type %d from Schur complement. nS = %i\n", + idx, + schurUpdateIndex[nS - 1], + schurUpdate[nS - 1], + nS + 1); + + if (idx != nS) { + real_t * temp_vals; + int_t * temp_ir; + int_t schurUpdateIndexTemp = -1; + SchurUpdateType schurUpdateTemp = SUT_UNDEFINED; + + /* temporarily save the last column of S */ + temp_vals = new real_t[nS + 1]; + for (int_t i = 0; i < nS + 1; i++) + temp_vals[i] = S[i + nS * nSmax]; + + schurUpdateIndexTemp = schurUpdateIndex[nS]; + schurUpdateTemp = schurUpdate[nS]; + + /* Shift rows and columns =>idx of S by one to the lower right */ + for (int_t i = idx - 1; i > -1; i--) + for (int_t j = nS - 1; j > idx - 1; j--) + S[(j + 1) + i * nSmax] = S[j + i * nSmax]; + for (int_t i = nS - 1; i > idx - 1; i--) { + for (int_t j = idx - 1; j > -1; j--) + S[j + (i + 1) * nSmax] = S[j + i * nSmax]; + for (int_t j = nS - 1; j > idx - 1; j--) + S[(j + 1) + (i + 1) * nSmax] = S[j + i * nSmax]; + } + for (int_t i = nS - 1; i > idx - 1; i--) { + schurUpdateIndex[i + 1] = schurUpdateIndex[i]; + schurUpdate[i + 1] = schurUpdate[i]; + } + + /* Insert stored row/column of S at position idx */ + for (int_t i = 0; i < nS + 1; i++) { + S[idx * nSmax + i] = temp_vals[i]; + S[i * nSmax + idx] = temp_vals[i]; + } + schurUpdateIndex[idx] = schurUpdateIndexTemp; + schurUpdate[idx] = schurUpdateTemp; + delete[] temp_vals; + + /* temporarily save the last (sparse) column of M */ + int_t numEntries = M_jc[nS + 1] - M_jc[nS]; + temp_ir = new int_t[numEntries]; + temp_vals = new real_t[numEntries]; + for (int_t i = M_jc[nS]; i < M_jc[nS + 1]; i++) { + temp_ir[i - M_jc[nS]] = M_ir[i]; + temp_vals[i - M_jc[nS]] = M_vals[i]; + } + + /* Shift all columns =>idx one to the right */ + for (int_t i = M_jc[nS] - 1; i > M_jc[idx] - 1; i--) { + M_ir[i + numEntries] = M_ir[i]; + M_vals[i + numEntries] = M_vals[i]; + } + for (int_t i = nS; i > idx - 1; i--) + M_jc[i + 1] = M_jc[i] + numEntries; + + /* Insert stored column of M at position idx */ + for (int_t i = M_jc[idx]; i < M_jc[idx + 1]; i++) { + M_ir[i] = temp_ir[i - M_jc[idx]]; + M_vals[i] = temp_vals[i - M_jc[idx]]; + } + + delete[] temp_ir; + delete[] temp_vals; + } + + nS++; + + if (options.printLevel == PL_HIGH) + MyPrintf(" nS = %d\n", nS); + + return SUCCESSFUL_RETURN; +} + +returnValue SQProblemSchur::correctInertia() +{ + SubjectToStatus B_status; + real_t oldDetS; + int_t nFR = getNFR(); + int_t k, number, neig, nAdded; + int_t * freeBoundIdx = new int_t[nFR]; + int_t * numberarray; + + /* method may only be called after refactorization or if one bound/constraint + * has been added, i.e. when a bound has flipped after refactorization */ + if (nS != 0 && nS != 1) + return THROWERROR(RET_INERTIA_CORRECTION_FAILED); + neig = sparseSolver->getNegativeEigenvalues(); + + /* if a bound flipped, check if it did in fact remove a negative eigenvalue */ + if (nS == 1 && detS < 0) + neig--; + + /* if this method is triggered after flipping bounds, inertia is now probably correct */ + if (neig == getNAC()) + return SUCCESSFUL_RETURN; + + /* get bound numbers in the order in which they are in the non-basis */ + bounds.getFree()->getNumberArray(&numberarray); + for (k = 0; k < nFR; k++) + freeBoundIdx[k] = numberarray[k]; + + k = 0; + nAdded = getNFR(); + while (neig > getNAC() && k < nFR) { + oldDetS = detS; + + /* If it's linearly independent, fix the next free variable at the nearest bound */ + number = freeBoundIdx[k]; + if (addBound_checkLI(number) == RET_LINEARLY_INDEPENDENT) { + /* This is just heuristics: we need the bound which gives correct multiplier sign */ + if (x[number] - lb[number] < ub[number] - x[number]) + B_status = ST_LOWER; + else + B_status = ST_UPPER; + + /* Update Schur complement */ + if (addBound(number, B_status, BT_TRUE, BT_FALSE) != SUCCESSFUL_RETURN) { + if (options.printLevel == PL_HIGH) + MyPrintf("In correctInertia: Adding bound[%i] = %i failed!\n", k, number); + return THROWERROR(RET_INERTIA_CORRECTION_FAILED); + } + + /* Adjust bounds */ + if (B_status == ST_LOWER) + lb[number] = x[number]; + else + ub[number] = x[number]; + } else { + if (options.printLevel == PL_HIGH) + MyPrintf("bound[%i] = %i is linearly dependent. Do not add.\n", k, number); + k++; + continue; + } + + /* Case 1: Schur complement has been reset, check inertia of new factorization */ + if (nS == 0) + neig = sparseSolver->getNegativeEigenvalues(); + /* Case 2: Schur complement has grown, check if determinant changed sign */ + else if (oldDetS * detS < 0) + neig--; + /* NB: Case 3: (Schur complement has shrunk) cannot happen here: + * This method is called after a factorization reset or after ONE bound has been added */ + + k++; + } + nAdded -= getNFR(); + + delete[] freeBoundIdx; + + /* if there are still too many negative eigenvalues, exit */ + if (neig > getNAC()) { + if (options.printLevel == PL_HIGH) + MyPrintf("Added %i bounds but KKT matrix still has %i negative eigenvalues, should be %i.\n", + nAdded, + neig, + getNAC()); + return THROWERROR(RET_INERTIA_CORRECTION_FAILED); + } else { + if (options.printLevel == PL_HIGH) + MyPrintf("After adding %i bounds, reduced Hessian has correct inertia.\n", nAdded, neig); + return SUCCESSFUL_RETURN; + } +} + +returnValue SQProblemSchur::repairSingularWorkingSet() +{ + int_t k, number; + SubjectToStatus B_status; + int_t rank = sparseSolver->getRank(); + int_t nFR = getNFR(); + int_t defect = nFR + getNAC() - rank; + + /* Rank detection not supported by linear solver */ + if (rank < 0) + return RET_KKT_MATRIX_SINGULAR; + + /* Consistency check */ + if (defect <= 0) + return RET_UNKNOWN_BUG; + + /* Determine zero pivots */ + int_t * zeroPivots = new int_t[defect]; + sparseSolver->getZeroPivots(zeroPivots); + + /* Determination of zero pivots not supported by linear solver */ + if (zeroPivots == 0) + return RET_KKT_MATRIX_SINGULAR; + + /* We assume implicitly that pivots are sorted in ascending order */ + /// \todo make sure that this is so. + /* Remove the one with the highest index first so not to mess up index lists */ + int_t bndsAdded = 0; + for (k = defect - 1; k > -1; k--) { + /* Zero curvature in the Hessian: add a bound */ + if (zeroPivots[k] < nFR) { + number = bounds.getFree()->getNumber(zeroPivots[k]); + + if (options.printLevel == PL_HIGH) + MyPrintf("WARNING: KKT matrix singular! Add bound %i before refactorization.\n", number); + + /* This is just heuristics: we need the bound which gives correct multiplier sign */ + if (x[number] - lb[number] < ub[number] - x[number]) + B_status = ST_LOWER; + else + B_status = ST_UPPER; + + /* Here we do not need to update the Schur complement because KKT matrix is factorized afterwards */ + if (bounds.moveFreeToFixed(number, B_status) != SUCCESSFUL_RETURN) + return RET_ADDBOUND_FAILED; + + /* Adjust bounds */ + if (B_status == ST_LOWER) + lb[number] = x[number]; + else + ub[number] = x[number]; + + bndsAdded++; + } + /* Linearly dependent row in the Jacobian: remove a constraint */ + else { + number = constraints.getActive()->getNumber(zeroPivots[k] - nFR); + if (options.printLevel == PL_HIGH) + MyPrintf("WARNING: KKT matrix singular! Removing constraint %i before refactorization.\n", number); + + if (constraints.moveActiveToInactive(number) != SUCCESSFUL_RETURN) + return RET_REMOVECONSTRAINT_FAILED; + + // AW: If this is an equality constraint, it is now inactive and + // will not be considered in the step computation which leads to + // violation of that constraint in the future. Here, I try to + // fix this by simply making this constraint no longer an + // equality. + // TODO: This is probably also necessary for bound constraints + if (constraints.getType(number) == ST_EQUALITY) { + if (options.printLevel == PL_HIGH) + MyPrintf("WARNING: Making this constraint no longer an equality.\n"); + constraints.setType(number, ST_BOUNDED); + } + + /* Adjust dual variable */ + y[number] = 0.0; + } + } + + if (options.printLevel == PL_HIGH) + MyPrintf( + "WARNING: KKT matrix singular! Removed %i constraints and added %i bounds before refactorization.\n", + defect - bndsAdded, + bndsAdded); + + delete[] zeroPivots; + + return SUCCESSFUL_RETURN; +} + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/SolutionAnalysis.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/SolutionAnalysis.cpp new file mode 100644 index 0000000..53263a4 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/SolutionAnalysis.cpp @@ -0,0 +1,644 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/SolutionAnalysis.cpp + * \author Hans Joachim Ferreau (thanks to Boris Houska) + * \version 3.2 + * \date 2008-2017 + * + * Implementation of the SolutionAnalysis class designed to perform + * additional analysis after solving a QP with qpOASES. + * + */ + +#include +#include + +BEGIN_NAMESPACE_QPOASES + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +/* + * S o l u t i o n A n a l y s i s + */ +SolutionAnalysis::SolutionAnalysis() +{ +} + +/* + * S o l u t i o n A n a l y s i s + */ +SolutionAnalysis::SolutionAnalysis(const SolutionAnalysis & rhs) +{ +} + +/* + * ~ S o l u t i o n A n a l y s i s + */ +SolutionAnalysis::~SolutionAnalysis() +{ +} + +/* + * o p e r a t o r = + */ +SolutionAnalysis & SolutionAnalysis::operator=(const SolutionAnalysis & rhs) +{ + if (this != &rhs) {} + + return *this; +} + +/* + * g e t K k t V i o l a t i o n + */ +real_t SolutionAnalysis::getKktViolation( + QProblemB * const qp, real_t * const maxStat, real_t * const maxFeas, real_t * const maxCmpl) const +{ + int_t i; + int_t nV = qp->getNV(); + + if (qp == 0) + return INFTY; + + /* setup Hessian matrix array (or pass NULL pointer) */ + real_t * H_ptr = 0; + BooleanType hasIdentityHessian = BT_FALSE; + + switch (qp->getHessianType()) { + case HST_ZERO: + break; + + case HST_IDENTITY: + hasIdentityHessian = BT_TRUE; + break; + + default: + H_ptr = qp->H->full(); + if (qp->usingRegularisation() == BT_TRUE) + for (i = 0; i < nV; ++i) + H_ptr[i * nV + i] -= qp->regVal; + } + + real_t * workingSetB = new real_t[nV]; + qp->getWorkingSetBounds(workingSetB); + + /* determine maximum KKT violation */ + real_t maxKktViolation = 0.0, stat = 0.0, feas = 0.0, cmpl = 0.0; + + returnValue returnvalue = REFER_NAMESPACE_QPOASES getKktViolation( + nV, H_ptr, qp->g, qp->lb, qp->ub, qp->x, qp->y, stat, feas, cmpl, workingSetB, hasIdentityHessian); + if (workingSetB != 0) + delete[] workingSetB; + + if (H_ptr != 0) + delete[] H_ptr; + + if (returnvalue != SUCCESSFUL_RETURN) + THROWERROR(returnvalue); + + /* assign return values */ + if (maxStat != 0) + *maxStat = stat; + + if (maxFeas != 0) + *maxFeas = feas; + + if (maxCmpl != 0) + *maxCmpl = cmpl; + + maxKktViolation = getMax(maxKktViolation, stat); + maxKktViolation = getMax(maxKktViolation, feas); + maxKktViolation = getMax(maxKktViolation, cmpl); + + return maxKktViolation; +} + +/* + * g e t K k t V i o l a t i o n + */ +real_t SolutionAnalysis::getKktViolation( + QProblem * const qp, real_t * const maxStat, real_t * const maxFeas, real_t * const maxCmpl) const +{ + int_t i; + int_t nV = qp->getNV(); + int_t nC = qp->getNC(); + + if (qp == 0) + return INFTY; + + /* setup Hessian matrix array (or pass NULL pointer) */ + real_t * H_ptr = 0; + BooleanType hasIdentityHessian = BT_FALSE; + + switch (qp->getHessianType()) { + case HST_ZERO: + break; + + case HST_IDENTITY: + hasIdentityHessian = BT_TRUE; + break; + + default: + H_ptr = qp->H->full(); + if (qp->usingRegularisation() == BT_TRUE) + for (i = 0; i < nV; ++i) + H_ptr[i * nV + i] -= qp->regVal; + } + + /* setup constraint matrix array */ + real_t * A_ptr = qp->A->full(); + + real_t * workingSetB = new real_t[nV]; + qp->getWorkingSetBounds(workingSetB); + + real_t * workingSetC = new real_t[nC]; + qp->getWorkingSetConstraints(workingSetC); + + /* determine maximum KKT violation */ + real_t maxKktViolation = 0.0, stat = 0.0, feas = 0.0, cmpl = 0.0; + + returnValue returnvalue = REFER_NAMESPACE_QPOASES getKktViolation(nV, + nC, + H_ptr, + qp->g, + A_ptr, + qp->lb, + qp->ub, + qp->lbA, + qp->ubA, + qp->x, + qp->y, + stat, + feas, + cmpl, + workingSetB, + workingSetC, + hasIdentityHessian); + + if (workingSetC != 0) + delete[] workingSetC; + + if (workingSetB != 0) + delete[] workingSetB; + + if (A_ptr != 0) + delete[] A_ptr; + + if (H_ptr != 0) + delete[] H_ptr; + + if (returnvalue != SUCCESSFUL_RETURN) + THROWERROR(returnvalue); + + /* assign return values */ + if (maxStat != 0) + *maxStat = stat; + + if (maxFeas != 0) + *maxFeas = feas; + + if (maxCmpl != 0) + *maxCmpl = cmpl; + + maxKktViolation = getMax(maxKktViolation, stat); + maxKktViolation = getMax(maxKktViolation, feas); + maxKktViolation = getMax(maxKktViolation, cmpl); + + return maxKktViolation; +} + +/* + * g e t K k t V i o l a t i o n + */ +real_t SolutionAnalysis::getKktViolation( + SQProblem * const qp, real_t * const maxStat, real_t * const maxFeas, real_t * const maxCmpl) const +{ + return getKktViolation((QProblem *)qp, maxStat, maxFeas, maxCmpl); +} + +/* + * g e t V a r i a n c e C o v a r i a n c e + */ +returnValue SolutionAnalysis::getVarianceCovariance( + QProblemB * const qp, const real_t * const g_b_bA_VAR, real_t * const Primal_Dual_VAR) const +{ + return THROWERROR(RET_NOT_YET_IMPLEMENTED); +} + +/* + * g e t V a r i a n c e C o v a r i a n c e + */ +returnValue SolutionAnalysis::getVarianceCovariance( + QProblem * qp, const real_t * const g_b_bA_VAR, real_t * const Primal_Dual_VAR) const +{ + /* DEFINITION OF THE DIMENSIONS nV AND nC: + * --------------------------------------- */ + int_t nV = qp->getNV(); /* dimension of x / the bounds */ + int_t nC = qp->getNC(); /* dimension of the constraints */ + int_t dim = 2 * nV + nC; /* dimension of input and output */ + /* variance-covariance matrix */ + int_t run1, run2, run3; /* simple run variables (for loops). */ + + /* ALLOCATION OF MEMORY: + * --------------------- */ + real_t * delta_g_cov = new real_t[nV]; /* a covariance-vector of g */ + real_t * delta_lb_cov = new real_t[nV]; /* a covariance-vector of lb */ + real_t * delta_ub_cov = new real_t[nV]; /* a covariance-vector of ub */ + real_t * delta_lbA_cov = new real_t[nC]; /* a covariance-vector of lbA */ + real_t * delta_ubA_cov = new real_t[nC]; /* a covariance-vector of ubA */ + + returnValue returnvalue; /* the return value */ + BooleanType Delta_bC_isZero = BT_FALSE; /* (just use FALSE here) */ + BooleanType Delta_bB_isZero = BT_FALSE; /* (just use FALSE here) */ + + /* ASK FOR THE NUMBER OF FREE AND FIXED VARIABLES: + * (ASSUMES THAT ACTIVE SET IS CONSTANT FOR THE + * VARIANCE-COVARIANCE EVALUATION) + * ----------------------------------------------- */ + int_t nFR, nFX, nAC; + + nFR = qp->getNFR(); + nFX = qp->getNFX(); + nAC = qp->getNAC(); + + /* ASK FOR THE CORRESPONDING INDEX ARRAYS: + * --------------------------------------- */ + int_t *FR_idx, *FX_idx, *AC_idx; + + if (qp->bounds.getFree()->getNumberArray(&FR_idx) != SUCCESSFUL_RETURN) + return THROWERROR(RET_HOTSTART_FAILED); + + if (qp->bounds.getFixed()->getNumberArray(&FX_idx) != SUCCESSFUL_RETURN) + return THROWERROR(RET_HOTSTART_FAILED); + + if (qp->constraints.getActive()->getNumberArray(&AC_idx) != SUCCESSFUL_RETURN) + return THROWERROR(RET_HOTSTART_FAILED); + + /* INTRODUCE VARIABLES TO MEASURE THE REACTION OF THE QP-SOLUTION TO + * THE VARIANCE-COVARIANCE DISTURBANCE: + * ----------------------------------------------------------------- */ + real_t * delta_xFR = new real_t[nFR]; + real_t * delta_xFX = new real_t[nFX]; + real_t * delta_yAC = new real_t[nAC]; + real_t * delta_yFX = new real_t[nFX]; + + real_t * K = new real_t[dim * dim]; /* matrix to store */ + /* an intermediate */ + /* result. */ + + /* SOME INITIALIZATIONS: + * --------------------- */ + for (run1 = 0; run1 < dim * dim; run1++) { + K[run1] = 0.0; + Primal_Dual_VAR[run1] = 0.0; + } + + /* ================================================================= */ + + /* FIRST MATRIX MULTIPLICATION (OBTAINS THE INTERMEDIATE RESULT + * K := [ ("ACTIVE" KKT-MATRIX OF THE QP)^(-1) * g_b_bA_VAR ]^T ) + * THE EVALUATION OF THE INVERSE OF THE KKT-MATRIX OF THE QP + * WITH RESPECT TO THE CURRENT ACTIVE SET + * USES THE EXISTING CHOLESKY AND TQ-DECOMPOSITIONS. FOR DETAILS + * cf. THE (protected) FUNCTION determineStepDirection. */ + + for (run3 = 0; run3 < dim; run3++) { + for (run1 = 0; run1 < nV; run1++) { + delta_g_cov[run1] = g_b_bA_VAR[run3 * dim + run1]; + delta_lb_cov[run1] = g_b_bA_VAR[run3 * dim + nV + run1]; /* LINE-WISE LOADING OF THE INPUT */ + delta_ub_cov[run1] = g_b_bA_VAR[run3 * dim + nV + run1]; /* VARIANCE-COVARIANCE */ + } + for (run1 = 0; run1 < nC; run1++) { + delta_lbA_cov[run1] = g_b_bA_VAR[run3 * dim + 2 * nV + run1]; + delta_ubA_cov[run1] = g_b_bA_VAR[run3 * dim + 2 * nV + run1]; + } + + /* EVALUATION OF THE STEP: + * ------------------------------------------------------------------------------ */ + + returnvalue = qp->determineStepDirection(delta_g_cov, + delta_lbA_cov, + delta_ubA_cov, + delta_lb_cov, + delta_ub_cov, + Delta_bC_isZero, + Delta_bB_isZero, + delta_xFX, + delta_xFR, + delta_yAC, + delta_yFX); + + /* ------------------------------------------------------------------------------ */ + + /* STOP THE ALGORITHM IN THE CASE OF NO SUCCESFUL RETURN: + * ------------------------------------------------------ */ + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] delta_g_cov; + delete[] delta_lb_cov; + delete[] delta_ub_cov; + delete[] delta_lbA_cov; + delete[] delta_ubA_cov; + delete[] delta_xFR; + delete[] delta_xFX; + delete[] delta_yAC; + delete[] delta_yFX; + delete[] K; + + THROWERROR(RET_STEPDIRECTION_DETERMINATION_FAILED); + return returnvalue; + } + + for (run1 = 0; run1 < nFR; run1++) { + run2 = FR_idx[run1]; + K[run3 * dim + run2] = delta_xFR[run1]; + } /* LINE WISE */ + for (run1 = 0; run1 < nFX; run1++) { /* STORAGE OF THE QP-REACTION */ + run2 = FX_idx[run1]; /* (uses the index list) */ + K[run3 * dim + run2] = delta_xFX[run1]; + K[run3 * dim + nV + run2] = delta_yFX[run1]; + } + for (run1 = 0; run1 < nAC; run1++) { + run2 = AC_idx[run1]; + K[run3 * dim + 2 * nV + run2] = delta_yAC[run1]; + } + } + + /* ================================================================= */ + + /* SECOND MATRIX MULTIPLICATION (OBTAINS THE FINAL RESULT + * Primal_Dual_VAR := ("ACTIVE" KKT-MATRIX OF THE QP)^(-1) * K ) + * THE APPLICATION OF THE KKT-INVERSE IS AGAIN REALIZED + * BY USING THE PROTECTED FUNCTION + * determineStepDirection */ + + for (run3 = 0; run3 < dim; run3++) { + for (run1 = 0; run1 < nV; run1++) { + delta_g_cov[run1] = K[run3 + run1 * dim]; + delta_lb_cov[run1] = K[run3 + (nV + run1) * dim]; /* ROW WISE LOADING OF THE */ + delta_ub_cov[run1] = K[run3 + (nV + run1) * dim]; /* INTERMEDIATE RESULT K */ + } + for (run1 = 0; run1 < nC; run1++) { + delta_lbA_cov[run1] = K[run3 + (2 * nV + run1) * dim]; + delta_ubA_cov[run1] = K[run3 + (2 * nV + run1) * dim]; + } + + /* EVALUATION OF THE STEP: + * ------------------------------------------------------------------------------ */ + + returnvalue = qp->determineStepDirection(delta_g_cov, + delta_lbA_cov, + delta_ubA_cov, + delta_lb_cov, + delta_ub_cov, + Delta_bC_isZero, + Delta_bB_isZero, + delta_xFX, + delta_xFR, + delta_yAC, + delta_yFX); + + /* ------------------------------------------------------------------------------ */ + + /* STOP THE ALGORITHM IN THE CASE OF NO SUCCESFUL RETURN: + * ------------------------------------------------------ */ + if (returnvalue != SUCCESSFUL_RETURN) { + delete[] delta_g_cov; + delete[] delta_lb_cov; + delete[] delta_ub_cov; + delete[] delta_lbA_cov; + delete[] delta_ubA_cov; + delete[] delta_xFR; + delete[] delta_xFX; + delete[] delta_yAC; + delete[] delta_yFX; + delete[] K; + + THROWERROR(RET_STEPDIRECTION_DETERMINATION_FAILED); + return returnvalue; + } + + for (run1 = 0; run1 < nFR; run1++) { + run2 = FR_idx[run1]; + Primal_Dual_VAR[run3 + run2 * dim] = delta_xFR[run1]; + } + for (run1 = 0; run1 < nFX; run1++) { /* ROW-WISE STORAGE */ + run2 = FX_idx[run1]; /* OF THE RESULT. */ + Primal_Dual_VAR[run3 + run2 * dim] = delta_xFX[run1]; + Primal_Dual_VAR[run3 + (nV + run2) * dim] = delta_yFX[run1]; + } + for (run1 = 0; run1 < nAC; run1++) { + run2 = AC_idx[run1]; + Primal_Dual_VAR[run3 + (2 * nV + run2) * dim] = delta_yAC[run1]; + } + } + + /* DEALOCATE MEMORY: + * ----------------- */ + + delete[] delta_g_cov; + delete[] delta_lb_cov; + delete[] delta_ub_cov; + delete[] delta_lbA_cov; + delete[] delta_ubA_cov; + delete[] delta_xFR; + delete[] delta_xFX; + delete[] delta_yAC; + delete[] delta_yFX; + delete[] K; + + return SUCCESSFUL_RETURN; +} + +/* + * g e t V a r i a n c e C o v a r i a n c e + */ +returnValue SolutionAnalysis::getVarianceCovariance( + SQProblem * const qp, const real_t * const g_b_bA_VAR, real_t * const Primal_Dual_VAR) const +{ + /* Call QProblem variant. */ + return getVarianceCovariance((QProblem *)qp, g_b_bA_VAR, Primal_Dual_VAR); +} + +/* + * c h e c k C u r v a t u r e O n S e t S + */ +returnValue SolutionAnalysis::checkCurvatureOnStronglyActiveConstraints(SQProblem * qp) +{ + printf("checkCurvatureOnStronglyActiveConstraints( SQProblem* qp ) not yet implemented for standard " + "qpOASES!\n"); + return RET_INERTIA_CORRECTION_FAILED; +} + +/* + * c h e c k C u r v a t u r e O n S t r o n g l y A c t i v e C o n s t r a i n t s + */ +returnValue SolutionAnalysis::checkCurvatureOnStronglyActiveConstraints(SQProblemSchur * qp) +{ + real_t eps = 1.0e-16; + returnValue ret; + Bounds saveBounds; + QProblemStatus saveStatus; + int_t k, neig, nAC, nFX, *FX_idx; + + nFX = qp->getNFX(); + nAC = qp->getNAC(); + + // If no bounds are active reduced Hessian is positive definite (otherwise qpOASES wouldnt have finished) + if (nFX == 0) + return SUCCESSFUL_RETURN; + + // Get active bounds (deep copy) + qp->getBounds(saveBounds); + saveBounds.getFixed()->getNumberArray(&FX_idx); + + // We have to change the status to modify the active set + saveStatus = qp->getStatus(); + qp->status = QPS_PERFORMINGHOMOTOPY; + + // If a variable is active now but has not been in the previous major iteration remove it + for (k = 0; k < nFX; k++) + if (getAbs(qp->x[FX_idx[k]]) > eps) + if (qp->bounds.moveFixedToFree(FX_idx[k]) != SUCCESSFUL_RETURN) + return THROWERROR(RET_REMOVEBOUND_FAILED); + + // Do a new factorization and check the inertia + ret = qp->resetSchurComplement(BT_FALSE); + neig = qp->sparseSolver->getNegativeEigenvalues(); + if (ret == SUCCESSFUL_RETURN && neig != nAC) + ret = RET_INERTIA_CORRECTION_FAILED; + + // Add all bounds that have been removed + for (k = 0; k < nFX; k++) + if (qp->bounds.getStatus(FX_idx[k]) == ST_INACTIVE) + qp->bounds.moveFreeToFixed(FX_idx[k], saveBounds.getStatus(FX_idx[k])); + + qp->status = saveStatus; + return ret; +} + +// int_t SolutionAnalysis::checkCurvatureOnStronglyActiveConstraints( SQProblemSchur* qp ) +//{ +// real_t eps = 1.0e-16; +// real_t oldDet, newDet; +// int_t oldNS; +// returnValue ret; +// Bounds saveBounds; +// QProblemStatus saveStatus; +// int_t nFX, *FX_idx; +// int_t k, fail, neig, rmCnt, nAC; + +//// Get active bounds (deep copy) +// nFX = qp->getNFX( ); +// nAC = qp->getNAC( ); +// qp->getBounds( saveBounds ); +// saveBounds.getFixed( )->getNumberArray( &FX_idx ); + +//// If no bounds are active reduced Hessian is positive definite (otherwise qpOASES wouldnt have finished) +// if( nFX == 0 ) +// return 0; + +//// We have to modify the status to call removeBound() +// saveStatus = qp->getStatus(); +// qp->status = QPS_PERFORMINGHOMOTOPY; + +//// If a variable is active but was not active in the previous major iteration +//// remove it to see if a negative eigenvalue appears +// rmCnt = 0; +// fail = 0; +// for( k=0; kx[FX_idx[k]]) > eps ) +//{ +// oldDet = qp->detS; +// oldNS = qp->nS; + +// ret = qp->removeBound( FX_idx[k], BT_TRUE, BT_FALSE, BT_FALSE ); +// if( ret != SUCCESSFUL_RETURN ) +//{ +// fail = 1; +// break; +// } + +// newDet = qp->detS; +// rmCnt++; + +//// Case 1: S has grown by 1 row and column +// if( qp->nS == oldNS + 1 ) +//{ +//// If the determinant does not change sign, then S has gained a positive eigenvalue. +//// That means there is a negative eigenvalue in the (extended) reduced Hessian! +// if ( ( oldDet <= 0.0 && newDet <= 0.0 ) || ( oldDet >= 0.0 && newDet >= 0.0 ) ) +//{ +// fail = 1; +// break; +//} +//} +//// Case 2: S has shrunk by 1 row and column +// else if( qp->nS == oldNS - 1 ) +//{ +//// If the determinant changes sign, then S has lost a negative eigenvalue. +//// That means there is a negative eigenvalue in the (extended) reduced Hessian! +// if ( ( oldDet <= 0.0 && newDet > 0.0 ) || ( oldDet >= 0.0 && newDet < 0.0 ) ) +//{ +// fail = 1; +// break; +//} +//} +//// Case 3: S was reset +// else if( qp->nS == 0 ) +//{ +//// Check inertia of KKT matrix +// neig = qp->sparseSolver->getNegativeEigenvalues( ); +// if( neig > nAC ) +//{ +// fail = 1; +// break; +//} +//} +// else +// printf("ERROR!\n"); +// } + +//// If test is successful, add all bounds that have been removed +//// If not, don't bother with that because we will discard this QP object anyway +// if( fail == 0 ) +// for( k=0; kaddBound( FX_idx[k], saveBounds.getStatus( FX_idx[k] ), BT_TRUE, BT_FALSE ); +// if( ret != SUCCESSFUL_RETURN && ret != RET_BOUND_ALREADY_ACTIVE ) +// printf( "addBound() in checkCurvatureOnStronglyActiveConstraints(): %s\n", +// getGlobalMessageHandler()->getErrorCodeMessage( ret ) ); +// } + +// qp->status = saveStatus; +// return fail; +//} + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/SparseSolver.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/SparseSolver.cpp new file mode 100644 index 0000000..bd92bdc --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/SparseSolver.cpp @@ -0,0 +1,1578 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/SparseSolver.cpp + * \author Andreas Waechter, Dennis Janka + * \version 3.2 + * \date 2012-2017 + * + * Interfaces to sparse linear solvers that are used in a Schur-complement + * implementation in qpOASES. + */ + +#include + +#ifndef __MATLAB__ +#include +void MyPrintf(const char * pformat, ...); +#else +#include +#define MyPrintf mexPrintf +#endif + +#if SOLVER_MUMPS + +#define USE_COMM_WORLD -987654 + +#include "mumps_compat.h" + +#ifdef USE_MPI_H +#include "mpi.h" +#else +#include "mumps_mpi.h" +#endif /* USE_MPI_H */ + +#include "dmumps_c.h" +#define MUMPS_STRUC_C DMUMPS_STRUC_C +#define mumps_c dmumps_c + +#endif /* SOLVER_MUMPS */ + +BEGIN_NAMESPACE_QPOASES + +/***************************************************************************** + * P U B L I C * + ****************************************************************************/ + +/* + * S p a r s e S o l v e r + */ +SparseSolver::SparseSolver() +{ +} + +/* + * S p a r s e S o l v e r + */ +SparseSolver::SparseSolver(const SparseSolver & rhs) +{ + copy(rhs); +} + +/* + * ~ S p a r s e S o l v e r + */ +SparseSolver::~SparseSolver() +{ + clear(); +} + +/* + * o p e r a t o r = + */ +SparseSolver & SparseSolver::operator=(const SparseSolver & rhs) +{ + if (this != &rhs) { + clear(); + copy(rhs); + } + + return *this; +} + +/* + * r e s e t + */ +returnValue SparseSolver::reset() +{ + return SUCCESSFUL_RETURN; +} + +/* + * g e t N e g a t i v e E i g e n v a l u e s + */ +int_t SparseSolver::getNegativeEigenvalues() +{ + return -1; +} + +/* + * g e t R a n k + */ +int_t SparseSolver::getRank() +{ + return -1; +} + +/* + * g e t Z e r o P i v o t s + */ +returnValue SparseSolver::getZeroPivots(int_t *& zeroPivots) +{ + if (zeroPivots) + delete[] zeroPivots; + zeroPivots = 0; + return SUCCESSFUL_RETURN; +} + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + +/* + * c l e a r + */ +returnValue SparseSolver::clear() +{ + return SUCCESSFUL_RETURN; +} + +/* + * c o p y + */ +returnValue SparseSolver::copy(const SparseSolver & rhs) +{ + return SUCCESSFUL_RETURN; +} + +#ifdef SOLVER_MA27 + +/***************************************************************************** + ***************************************************************************** + ***************************************************************************** + * M A 2 7 S P A R E S E S O L V E R * + ***************************************************************************** + ***************************************************************************** + *****************************************************************************/ + +#define MA27ID ma27id_ +#define MA27AD ma27ad_ +#define MA27BD ma27bd_ +#define MA27CD ma27cd_ + +extern "C" +{ + void MA27ID(fint_t * ICNTL, double * CNTL); + void MA27AD(fint_t * N, + fint_t * NZ, + const fint_t * IRN, + const fint_t * ICN, + fint_t * IW, + fint_t * LIW, + fint_t * IKEEP, + fint_t * IW1, + fint_t * NSTEPS, + fint_t * IFLAG, + fint_t * ICNTL, + double * CNTL, + fint_t * INFO, + double * OPS); + void MA27BD(fint_t * N, + fint_t * NZ, + const fint_t * IRN, + const fint_t * ICN, + double * A, + fint_t * LA, + fint_t * IW, + fint_t * LIW, + fint_t * IKEEP, + fint_t * NSTEPS, + fint_t * MAXFRT, + fint_t * IW1, + fint_t * ICNTL, + double * CNTL, + fint_t * INFO); + void MA27CD(fint_t * N, + double * A, + fint_t * LA, + fint_t * IW, + fint_t * LIW, + double * W, + fint_t * MAXFRT, + double * RHS, + fint_t * IW1, + fint_t * NSTEPS, + fint_t * ICNTL, + double * CNTL); +} + +/***************************************************************************** + * P U B L I C * + ****************************************************************************/ + +/* + * M a 2 7 S p a r s e S o l v e r + */ +Ma27SparseSolver::Ma27SparseSolver() : SparseSolver() +{ + a_ma27 = 0; + irn_ma27 = 0; + jcn_ma27 = 0; + iw_ma27 = 0; + ikeep_ma27 = 0; + clear(); + + /* Set default options for MA27 */ + MA27ID(icntl_ma27, cntl_ma27); + icntl_ma27[0] = 0; /* Suppress error messages */ + icntl_ma27[1] = 0; /* Suppress diagnostic messages */ + cntl_ma27[0] = 1e-8; /* Set pivot tolerance */ +} + +/* + * M a 2 7 S p a r s e S o l v e r + */ +Ma27SparseSolver::Ma27SparseSolver(const Ma27SparseSolver & rhs) +{ + copy(rhs); +} + +/* + * ~ M a 2 7 S p a r s e S o l v e r + */ +Ma27SparseSolver::~Ma27SparseSolver() +{ + clear(); +} + +/* + * o p e r a t o r = + */ +Ma27SparseSolver & Ma27SparseSolver::operator=(const SparseSolver & rhs) +{ + const Ma27SparseSolver * ma27_rhs = dynamic_cast(&rhs); + if (!ma27_rhs) { + fprintf(getGlobalMessageHandler()->getOutputFile(), + "Error in Ma27SparseSolver& Ma27SparseSolver::operator=( const SparseSolver& rhs )\n"); + throw; /* TODO: More elegant exit? */ + } + if (this != ma27_rhs) { + clear(); + SparseSolver::operator=(rhs); + copy(*ma27_rhs); + } + + return *this; +} + +/* + * s e t M a t r i x D a t a + */ +returnValue Ma27SparseSolver::setMatrixData(int_t dim_, + int_t numNonzeros_, + const int_t * const irn, + const int_t * const jcn, + const real_t * const avals) +{ + reset(); + dim = dim_; + numNonzeros = numNonzeros_; + + if (numNonzeros_ > 0) { + a_ma27 = new double[numNonzeros_]; + irn_ma27 = new fint_t[numNonzeros_]; + jcn_ma27 = new fint_t[numNonzeros_]; + + numNonzeros = 0; + for (int_t i = 0; i < numNonzeros_; ++i) + if (avals[i] != 0) { + a_ma27[numNonzeros] = avals[i]; + irn_ma27[numNonzeros] = irn[i]; + jcn_ma27[numNonzeros] = jcn[i]; + numNonzeros++; + } + } else { + numNonzeros = 0; + a_ma27 = 0; + irn_ma27 = 0; + jcn_ma27 = 0; + } + + return SUCCESSFUL_RETURN; +} + +/* + * f a c t o r i z e + */ +returnValue Ma27SparseSolver::factorize() +{ + if (dim == 0) { + have_factorization = true; + neig = 0; + rank = 0; + return SUCCESSFUL_RETURN; + } + + /****************************************** + * Call MA27AD for symbolic factorization * + ******************************************/ + + /* Overstimation factor for LIW (20% recommended in MA27 documentation) */ + const double LiwFact = 2.0; /* This is 200% overestimation */ + liw_ma27 = (fint_t)(LiwFact * (double(2 * numNonzeros + 3 * dim + 1))); + iw_ma27 = new fint_t[liw_ma27]; + + ikeep_ma27 = new fint_t[3 * dim]; + + fint_t iflag_ma27 = 0; + double ops_ma27; + fint_t info_ma27[20]; + fint_t * iw1_ma27 = new fint_t[2 * dim]; + MA27AD(&dim, + &numNonzeros, + irn_ma27, + jcn_ma27, + iw_ma27, + &liw_ma27, + ikeep_ma27, + iw1_ma27, + &nsteps_ma27, + &iflag_ma27, + icntl_ma27, + cntl_ma27, + info_ma27, + &ops_ma27); + + /* Receive some information from MA27AD */ + fint_t iflag = info_ma27[0]; /* Information flag */ + fint_t ierror = info_ma27[1]; /* Error flag */ + fint_t nrlnec = info_ma27[4]; /* recommended value for la */ + fint_t nirnec = info_ma27[5]; /* recommended value for liw */ + if (iflag != 0) { + MyPrintf("MA27AD returns iflag = %d with ierror = %d\n", iflag, ierror); + delete[] iw1_ma27; + clear(); + return THROWERROR(RET_MATRIX_FACTORISATION_FAILED); + } + + /* Allocate memory for actual factorization */ + delete[] iw_ma27; + double liw_init_factor = 5.0; /* This could be an option. */ + liw_ma27 = (fint_t)(liw_init_factor * (double)(nirnec)); + iw_ma27 = new fint_t[liw_ma27]; + + double la_init_factor = 20.0; /* This could be an option. */ + la_ma27 = getMax(numNonzeros, (fint_t)(la_init_factor * (double)(nrlnec))); + double * a_new = new double[la_ma27]; + for (int_t i = 0; i < numNonzeros; ++i) + a_new[i] = a_ma27[i]; + delete[] a_ma27; + a_ma27 = a_new; + + /******************************************* + * Call MA27BD for numerical factorization * + *******************************************/ + + MA27BD(&dim, + &numNonzeros, + irn_ma27, + jcn_ma27, + a_ma27, + &la_ma27, + iw_ma27, + &liw_ma27, + ikeep_ma27, + &nsteps_ma27, + &maxfrt_ma27, + iw1_ma27, + icntl_ma27, + cntl_ma27, + info_ma27); + + delete[] iw1_ma27; + /* Receive some information from MA27BD */ + iflag = info_ma27[0]; /* Information flag */ + ierror = info_ma27[1]; /* Error flag */ + neig = info_ma27[14]; /* Number of negative eigenvalues */ + if (iflag == 3) { + rank = info_ma27[1]; + return RET_KKT_MATRIX_SINGULAR; + } else if (iflag == -5) { /* DJ: I think this is more severe. Can this actually happen? */ + rank = -1; + return RET_KKT_MATRIX_SINGULAR; + } else if (iflag != 0) { + MyPrintf("MA27BD returns iflag = %d with ierror = %d\n", iflag, ierror); + clear(); + return THROWERROR(RET_MATRIX_FACTORISATION_FAILED); + } else + rank = dim; + + have_factorization = true; + return SUCCESSFUL_RETURN; +} + +/* + * s o l v e + */ +returnValue Ma27SparseSolver::solve(int_t dim_, const real_t * const rhs, real_t * const sol) +{ + /* consistency check */ + if (dim_ != dim) + return THROWERROR(RET_INVALID_ARGUMENTS); + + if (!have_factorization) { + MyPrintf("Factorization not called before solve in Ma27SparseSolver::solve.\n"); + return THROWERROR(RET_INVALID_ARGUMENTS); + } + + if (dim == 0) + return SUCCESSFUL_RETURN; + + /* Call MA27CD to solve the system */ + double * w_ma27 = new double[maxfrt_ma27]; + fint_t * iw1_ma27 = new fint_t[nsteps_ma27]; + + /* MA27CD overwrites rhs */ + for (int_t i = 0; i < dim; ++i) + sol[i] = rhs[i]; + MA27CD(&dim, + a_ma27, + &la_ma27, + iw_ma27, + &liw_ma27, + w_ma27, + &maxfrt_ma27, + sol, + iw1_ma27, + &nsteps_ma27, + icntl_ma27, + cntl_ma27); + + delete[] iw1_ma27; + delete[] w_ma27; + + return SUCCESSFUL_RETURN; +} + +/* + * r e s e t + */ +returnValue Ma27SparseSolver::reset() +{ + /* AW: We probably want to avoid resetting factorization in QProblem */ + if (SparseSolver::reset() != SUCCESSFUL_RETURN) + return THROWERROR(RET_RESET_FAILED); + + clear(); + return SUCCESSFUL_RETURN; +} + +/* + * g e t N e g a t i v e E i g e n v a l u e s + */ +int_t Ma27SparseSolver::getNegativeEigenvalues() +{ + if (!have_factorization) + return -1; + else + return neig; +} + +/* + * g e t R a n k + */ +int_t Ma27SparseSolver::getRank() +{ + return rank; +} + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + +/* + * c l e a r + */ +returnValue Ma27SparseSolver::clear() +{ + delete[] a_ma27; + delete[] irn_ma27; + delete[] jcn_ma27; + delete[] iw_ma27; + delete[] ikeep_ma27; + + dim = -1; + numNonzeros = -1; + neig = -1; + rank = -1; + la_ma27 = -1; + a_ma27 = 0; + irn_ma27 = 0; + jcn_ma27 = 0; + + liw_ma27 = -1; + iw_ma27 = 0; + ikeep_ma27 = 0; + nsteps_ma27 = -1; + maxfrt_ma27 = -1; + + have_factorization = false; + return SUCCESSFUL_RETURN; +} + +/* + * c o p y + */ +returnValue Ma27SparseSolver::copy(const Ma27SparseSolver & rhs) +{ + dim = rhs.dim; + numNonzeros = rhs.numNonzeros; + la_ma27 = rhs.la_ma27; + if (rhs.a_ma27 != 0) { + if (rhs.have_factorization) { + a_ma27 = new double[la_ma27]; + memcpy(a_ma27, rhs.a_ma27, la_ma27 * sizeof(double)); + } else { + a_ma27 = new double[numNonzeros]; + memcpy(a_ma27, rhs.a_ma27, numNonzeros * sizeof(double)); + } + } else + a_ma27 = 0; + + if (rhs.irn_ma27 != 0) { + irn_ma27 = new fint_t[numNonzeros]; + memcpy(irn_ma27, rhs.irn_ma27, numNonzeros * sizeof(fint_t)); + } else + irn_ma27 = 0; + + if (rhs.jcn_ma27 != 0) { + jcn_ma27 = new fint_t[numNonzeros]; + memcpy(jcn_ma27, rhs.jcn_ma27, numNonzeros * sizeof(fint_t)); + } else + jcn_ma27 = 0; + + for (int_t i = 0; i < 30; ++i) + icntl_ma27[i] = rhs.icntl_ma27[i]; + + for (int_t i = 0; i < 5; ++i) + cntl_ma27[i] = rhs.cntl_ma27[i]; + + liw_ma27 = rhs.liw_ma27; + + if (rhs.iw_ma27 != 0) { + iw_ma27 = new fint_t[liw_ma27]; + memcpy(iw_ma27, rhs.iw_ma27, liw_ma27 * sizeof(fint_t)); + } else + iw_ma27 = 0; + + if (rhs.ikeep_ma27 != 0) { + ikeep_ma27 = new fint_t[3 * dim]; + memcpy(ikeep_ma27, rhs.ikeep_ma27, 3 * dim * sizeof(fint_t)); + } else + ikeep_ma27 = 0; + + nsteps_ma27 = rhs.nsteps_ma27; + maxfrt_ma27 = rhs.maxfrt_ma27; + + have_factorization = rhs.have_factorization; + neig = rhs.neig; + rank = rhs.rank; + + return SUCCESSFUL_RETURN; +} + +#endif /* SOLVER_MA27 */ + +#ifdef SOLVER_MA57 + +/***************************************************************************** + ***************************************************************************** + ***************************************************************************** + * M A 5 7 S P A R E S E S O L V E R * + ***************************************************************************** + ***************************************************************************** + *****************************************************************************/ + +#define MA57ID ma57id_ +#define MA57AD ma57ad_ +#define MA57BD ma57bd_ +#define MA57CD ma57cd_ + +extern "C" +{ + /* + * MA57ID -- Initialize solver. + */ + extern void MA57ID(double * cntl, fint_t * icntl); + + /* + * MA57AD -- Symbolic Factorization. + */ + extern void MA57AD(fint_t * n, /* Order of matrix. */ + fint_t * ne, /* Number of entries. */ + const fint_t * irn, /* Matrix nonzero row structure */ + const fint_t * jcn, /* Matrix nonzero column structure */ + fint_t * lkeep, /* Workspace for the pivot order of lenght 3*n */ + fint_t * keep, /* Workspace for the pivot order of lenght 3*n */ + /* Automatically iflag = 0; ikeep pivot order iflag = 1 */ + fint_t * iwork, /* Integer work space. */ + fint_t * icntl, /* Integer Control parameter of length 30*/ + fint_t * info, /* Statistical Information; Integer array of length 20 */ + double * rinfo); /* Double Control parameter of length 5 */ + + /* + * MA57BD -- Numerical Factorization. + */ + extern void MA57BD(fint_t * n, /* Order of matrix. */ + fint_t * ne, /* Number of entries. */ + double * a, /* Numerical values. */ + double * fact, /* Entries of factors. */ + fint_t * lfact, /* Length of array `fact'. */ + fint_t * ifact, /* Indexing info for factors. */ + fint_t * lifact, /* Length of array `ifact'. */ + fint_t * lkeep, /* Length of array `keep'. */ + fint_t * keep, /* Integer array. */ + fint_t * iwork, /* Workspace of length `n'. */ + fint_t * icntl, /* Integer Control parameter of length 20. */ + double * cntl, /* Double Control parameter of length 5. */ + fint_t * info, /* Statistical Information; Integer array of length 40. */ + double * rinfo); /* Statistical Information; Real array of length 20. */ + + /* + * MA57CD -- Solution. + */ + extern void MA57CD(fint_t * job, /* Solution job. Solve for... */ + /* JOB <= 1: A */ + /* JOB == 2: PLP^t */ + /* JOB == 3: PDP^t */ + /* JOB >= 4: PL^t P^t */ + fint_t * n, /* Order of matrix. */ + double * fact, /* Entries of factors. */ + fint_t * lfact, /* Length of array `fact'. */ + fint_t * ifact, /* Indexing info for factors. */ + fint_t * lifact, /* Length of array `ifact'. */ + fint_t * nrhs, /* Number of right hand sides. */ + double * rhs, /* Numerical Values. */ + fint_t * lrhs, /* Leading dimensions of `rhs'. */ + double * work, /* Real workspace. */ + fint_t * lwork, /* Length of `work', >= N*NRHS. */ + fint_t * iwork, /* Integer array of length `n'. */ + fint_t * icntl, /* Integer Control parameter array of length 20. */ + fint_t * info); /* Statistical Information; Integer array of length 40. */ +} + +/***************************************************************************** + * P U B L I C * + ****************************************************************************/ + +/* + * M a 5 7 S p a r s e S o l v e r + */ +Ma57SparseSolver::Ma57SparseSolver() : SparseSolver() +{ + a_ma57 = 0; + irn_ma57 = 0; + jcn_ma57 = 0; + fact_ma57 = 0; + ifact_ma57 = 0; + pivots = 0; + clear(); + + /* Set default options for MA57 */ + MA57ID(cntl_ma57, icntl_ma57); + + icntl_ma57[0] = -1; /* Suppress error messages */ + icntl_ma57[1] = -1; /* Suppress warning messages */ + icntl_ma57[2] = -1; /* Suppress monitoring messages */ + /*icntl_ma57[4] = 4; // Print everything (for debugging) */ + icntl_ma57[15] = 1; /* Place small pivots at the end of the factorization (default: 0) */ + + /* \todo good default values? + cntl_ma57[1] = 5.0e-16; // Pivots smaller than this are treated as zero and are placed at the end of the + factorization (default: 1e-20) + cntl_ma57[0] = 0.5; // Set pivot tolerance: Higher values = more stable but slower/less sparse + (default: 0.01, max 0.5) */ +} + +/* + * M a 5 7 S p a r s e S o l v e r + */ +Ma57SparseSolver::Ma57SparseSolver(const Ma57SparseSolver & rhs) +{ + copy(rhs); +} + +/* + * ~ M a 5 7 S p a r s e S o l v e r + */ +Ma57SparseSolver::~Ma57SparseSolver() +{ + clear(); +} + +/* + * o p e r a t o r = + */ +Ma57SparseSolver & Ma57SparseSolver::operator=(const SparseSolver & rhs) +{ + const Ma57SparseSolver * ma57_rhs = dynamic_cast(&rhs); + if (!ma57_rhs) { + fprintf(getGlobalMessageHandler()->getOutputFile(), + "Error in Ma57SparseSolver& Ma57SparseSolver::operator=( const SparseSolver& rhs )\n"); + throw; /* TODO: More elegant exit? */ + } + if (this != ma57_rhs) { + clear(); + SparseSolver::operator=(rhs); + copy(*ma57_rhs); + } + + return *this; +} + +/* + * s e t M a t r i x D a t a + */ +returnValue Ma57SparseSolver::setMatrixData(int_t dim_, + int_t numNonzeros_, + const int_t * const irn, + const int_t * const jcn, + const real_t * const avals) +{ + reset(); + dim = dim_; + numNonzeros = numNonzeros_; + + if (numNonzeros_ > 0) { + a_ma57 = new double[numNonzeros_]; + irn_ma57 = new fint_t[numNonzeros_]; + jcn_ma57 = new fint_t[numNonzeros_]; + + numNonzeros = 0; + for (int_t i = 0; i < numNonzeros_; ++i) + if (isZero(avals[i]) == BT_FALSE) { + a_ma57[numNonzeros] = avals[i]; + irn_ma57[numNonzeros] = irn[i]; + jcn_ma57[numNonzeros] = jcn[i]; + numNonzeros++; + } + } else { + numNonzeros = 0; + a_ma57 = 0; + irn_ma57 = 0; + jcn_ma57 = 0; + } + + return SUCCESSFUL_RETURN; +} + +/* + * f a c t o r i z e + */ +returnValue Ma57SparseSolver::factorize() +{ + if (dim == 0) { + have_factorization = true; + neig = 0; + rank = 0; + return SUCCESSFUL_RETURN; + } + + /****************************************** + * Call MA57AD for symbolic factorization * + ******************************************/ + + fint_t max_nnz = numNonzeros > dim ? numNonzeros : dim; + fint_t lkeep_ma57 = 5 * dim + numNonzeros + max_nnz + 42; + fint_t * keep_ma57 = new fint_t[lkeep_ma57]; + fint_t * iwork_ma57 = new fint_t[5 * dim]; + + /* Set initial pivot sequence. */ + for (fint_t i = 0; i < lkeep_ma57; i++) + keep_ma57[i] = i + 1; + + fint_t info_ma57[40]; + double rinfo_ma57[20]; + + MA57AD(&dim, + &numNonzeros, + irn_ma57, + jcn_ma57, + &lkeep_ma57, + keep_ma57, + iwork_ma57, + icntl_ma57, + info_ma57, + rinfo_ma57); + + /* Receive some information from MA57AD */ + fint_t iflag = info_ma57[0]; /* Information flag */ + fint_t ierror = info_ma57[1]; /* Error flag */ + if (iflag != 0) { + MyPrintf("MA57AD returns iflag = %d with ierror = %d\n", iflag, ierror); + delete[] keep_ma57; + delete[] iwork_ma57; + clear(); + return THROWERROR(RET_MATRIX_FACTORISATION_FAILED); + } + + /* Allocate memory for actual factorization */ + double lfact_factor = 10.0; /* This could be an option */ + + lfact_ma57 = (fint_t)(lfact_factor * (double)(info_ma57[8])); + fact_ma57 = new double[lfact_ma57]; + + lifact_ma57 = (fint_t)(lfact_factor * (double)(info_ma57[9])); + ifact_ma57 = new fint_t[lifact_ma57]; + + /******************************************* + * Call MA57BD for numerical factorization * + *******************************************/ + + MA57BD(&dim, + &numNonzeros, + a_ma57, + fact_ma57, + &lfact_ma57, + ifact_ma57, + &lifact_ma57, + &lkeep_ma57, + keep_ma57, + iwork_ma57, + icntl_ma57, + cntl_ma57, + info_ma57, + rinfo_ma57); + + delete[] iwork_ma57; + delete[] keep_ma57; + + /* Receive some information from MA57BD */ + iflag = info_ma57[0]; /* Information flag */ + ierror = info_ma57[1]; /* Error flag */ + neig = info_ma57[23]; /* Number of negative eigenvalues */ + rank = info_ma57[24]; /* Rank of matrix */ + + /* Read pivot sequence (see MA57UD source code) */ + pivots = new fint_t[dim]; + fint_t nrows, ncols; + fint_t nblk = ifact_ma57[2]; + int_t iwpos = 3; /* = 4-1 */ + int_t k, kk, count = 0; + for (k = 0; k < nblk; k++) { + ncols = ifact_ma57[iwpos]; + nrows = ifact_ma57[iwpos + 1]; + + for (kk = 0; kk < nrows; kk++) + pivots[count++] = ifact_ma57[iwpos + 2 + kk] - 1; /* convert Fortran to C indices! */ + + iwpos = iwpos + ncols + 2; + } + + if (iflag == 4) { + /*MyPrintf("dim = %i, rank = %i. Pivots: ", dim, rank); + for( k=rank; k(calloc(1, sizeof(MUMPS_STRUC_C))); + mumps_->job = -1; // initialize mumps + mumps_->par = 1; // working host for sequential version + mumps_->sym = 2; // general symmetric matrix + mumps_->comm_fortran = USE_COMM_WORLD; + + // #ifndef IPOPT_MUMPS_NOMUTEX + // const std::lock_guard lock(mumps_call_mutex); + // #endif + + mumps_c(mumps_); + mumps_->icntl[1] = 0; + mumps_->icntl[2] = 0; // QUIETLY! + mumps_->icntl[3] = 0; + + // these values are just copied from Ipopt: better values might exist + mem_percent_ = 1000; + mumps_permuting_scaling_ = 7; + mumps_pivot_order_ = 7; + mumps_scaling_ = 77; + mumps_dep_tol_ = 0.0; + + pivtol_ = 0.000001; + // pivtol_ = 1.0; + // pivtol_ = 0.1; + // pivtol_ = 0.0; + pivtolmax_ = 0.1; // actually unused atm + + // Reset all private data + initialized_ = false; + pivtol_changed_ = false; + refactorize_ = false; + have_symbolic_factorization_ = false; + mumps_ptr_ = (void *)mumps_; +} + +/* + * M u m p s S p a r s e S o l v e r + */ +MumpsSparseSolver::MumpsSparseSolver(const MumpsSparseSolver & rhs) +{ + copy(rhs); +} + +/* + * ~ M u m p s S p a r s e S o l v e r + */ +MumpsSparseSolver::~MumpsSparseSolver() +{ + // #ifndef IPOPT_MUMPS_NOMUTEX + // const std::lock_guard lock(mumps_call_mutex); + // #endif + + MUMPS_STRUC_C * mumps_ = static_cast(mumps_ptr_); + mumps_->job = -2; // terminate mumps + mumps_c(mumps_); + delete[] mumps_->a; + free(mumps_); +} + +/* + * o p e r a t o r = + */ +MumpsSparseSolver & MumpsSparseSolver::operator=(const SparseSolver & rhs) +{ + const MumpsSparseSolver * mumps_rhs = dynamic_cast(&rhs); + if (!mumps_rhs) { + fprintf(getGlobalMessageHandler()->getOutputFile(), + "Error in MumpsSparseSolver& MumpsSparseSolver::operator=( const SparseSolver& rhs )\n"); + throw; /* TODO: More elegant exit? */ + } + if (this != mumps_rhs) { + clear(); + SparseSolver::operator=(rhs); + copy(*mumps_rhs); + } + + return *this; +} + +/* + * s e t M a t r i x D a t a + */ +returnValue MumpsSparseSolver::setMatrixData(int_t dim_, + int_t numNonzeros_, + const int_t * const irn, + const int_t * const jcn, + const real_t * const avals) +{ + reset(); + dim = dim_; + numNonzeros = numNonzeros_; + + if (numNonzeros_ > 0) { + a_mumps = new double[numNonzeros_]; + irn_mumps = new fint_t[numNonzeros_]; + jcn_mumps = new fint_t[numNonzeros_]; + + numNonzeros = 0; + for (int_t i = 0; i < numNonzeros_; ++i) + if (isZero(avals[i]) == BT_FALSE) { + a_mumps[numNonzeros] = avals[i]; + irn_mumps[numNonzeros] = irn[i]; + jcn_mumps[numNonzeros] = jcn[i]; + numNonzeros++; + } + } else { + numNonzeros = 0; + a_mumps = 0; + irn_mumps = 0; + jcn_mumps = 0; + } + + return SUCCESSFUL_RETURN; +} + +/* + * f a c t o r i z e + */ +returnValue MumpsSparseSolver::factorize() +{ + if (dim == 0) { + have_factorization = true; + negevals_ = 0; + return SUCCESSFUL_RETURN; + } + + /// IPOPT-MUMPS + MUMPS_STRUC_C * mumps_data = static_cast(mumps_ptr_); + + MUMPS_STRUC_C * mumps_ = static_cast(mumps_ptr_); + mumps_data->n = dim; + mumps_data->nz = numNonzeros; + delete[] mumps_data->a; + mumps_data->a = NULL; + + mumps_data->a = new double[numNonzeros]; + mumps_data->irn = const_cast(irn_mumps); + mumps_data->jcn = const_cast(jcn_mumps); + + // make sure we do the symbolic factorization before a real + // factorization + have_symbolic_factorization_ = false; + + // #ifndef IPOPT_MUMPS_NOMUTEX + // const std::lock_guard lock(mumps_call_mutex); + // #endif + + mumps_data->job = 1; // symbolic ordering pass + + // mumps_data->icntl[1] = 6; + // mumps_data->icntl[2] = 6;//QUIETLY! + // mumps_data->icntl[3] = 4; + + mumps_data->icntl[5] = mumps_permuting_scaling_; + mumps_data->icntl[6] = mumps_pivot_order_; + mumps_data->icntl[7] = mumps_scaling_; + mumps_data->icntl[9] = 0; // no iterative refinement iterations + + mumps_data->icntl[12] = + 1; // avoid lapack bug, ensures proper inertia; mentioned to be very expensive in mumps manual + mumps_data->icntl[13] = mem_percent_; //% memory to allocate over expected + mumps_data->cntl[0] = pivtol_; // Set pivot tolerance + + // dump_matrix(mumps_data); + + // MyPrintf("Calling MUMPS-1 for symbolic factorization.\n"); + mumps_c(mumps_data); + // MyPrintf("Done with MUMPS-1 for symbolic factorization.\n"); + int error = mumps_data->info[0]; + const int & mumps_permuting_scaling_used = mumps_data->infog[22]; + const int & mumps_pivot_order_used = mumps_data->infog[6]; + + // return appropriate value + if (error == -6) // system is singular + { + MyPrintf("MUMPS returned INFO(1) = %i matrix is singular.\n", error); + return RET_MATRIX_FACTORISATION_FAILED; + } + if (error < 0) { + printf("nnz = %i\n", numNonzeros); + MyPrintf("Error=%i returned from MUMPS in Factorization.\n", error); + MyPrintf("MUMPS returned INFO(2) = %i.\n", mumps_data->info[1]); + return RET_MATRIX_FACTORISATION_FAILED; + } + + //// IPOPT-MUMPS (ACTUAL FACTORIZATION) + // MUMPS_STRUC_C* mumps_data = static_cast(mumps_ptr_); + + mumps_data->job = 2; // numerical factorization + + // dump_matrix(mumps_data); + // MyPrintf("Calling MUMPS-2 for numerical factorization.\n"); + mumps_c(mumps_data); + // MyPrintf("Done with MUMPS-2 for numerical factorization.\n"); + error = mumps_data->info[0]; + + // Check for errors + if (error == -8 || error == -9) // not enough memory + { + const int trycount_max = 20; + for (int trycount = 0; trycount < trycount_max; trycount++) { + MyPrintf("MUMPS returned INFO(1) = %i and requires more memory, reallocating. Attempt %d\n", + error, + trycount + 1); + MUMPS_INT old_mem_percent = mumps_data->icntl[13]; + ComputeMemIncrease(mumps_data->icntl[13], + 2.0 * (double)old_mem_percent, + MUMPS_INT(0), + "percent extra working space for MUMPS"); + MyPrintf("Increasing icntl[13] from % to % .\n", old_mem_percent, mumps_data->icntl[13]); + + // dump_matrix(mumps_data); + MyPrintf("Calling MUMPS-2 (repeated) for numerical factorization.\n"); + mumps_c(mumps_data); + MyPrintf("Done with MUMPS-2 (repeated) for numerical factorization.\n"); + error = mumps_data->info[0]; + if (error != -8 && error != -9) { + break; + } + } + if (error == -8 || error == -9) { + MyPrintf("MUMPS was not able to obtain enough memory.\n"); + return RET_MATRIX_FACTORISATION_FAILED; + } + } + + // MyPrintf("Number of doubles for MUMPS to hold factorization (INFO(9)) = %i\n", mumps_data->info[8]); + // MyPrintf("Number of integers for MUMPS to hold factorization (INFO(10)) = %i\n", mumps_data->info[9]); + + if (error == -10) // system is singular + { + MyPrintf("MUMPS returned INFO(1) = %i matrix is singular.\n", error); + return RET_MATRIX_FACTORISATION_FAILED; + } + + negevals_ = mumps_data->infog[11]; + + if (error == -13) { + MyPrintf("MUMPS returned INFO(1) =%i - out of memory when trying to allocate % %s.\nIn some cases it " + "helps to decrease the value of the option \"mumps_mem_percent\".\n", + error, + mumps_data->info[1] < 0 ? -mumps_data->info[1] : mumps_data->info[1], + mumps_data->info[1] < 0 ? "MB" : "bytes"); + return RET_MATRIX_FACTORISATION_FAILED; + } + if (error < 0) // some other error + { + MyPrintf("MUMPS returned INFO(1) =%i MUMPS failure.\n", error); + return RET_MATRIX_FACTORISATION_FAILED; + } + + have_factorization = true; + + return SUCCESSFUL_RETURN; +} + +/* + * s o l v e + */ +returnValue MumpsSparseSolver::solve(int_t dim_, const real_t * const rhs, real_t * const sol) +{ + // printf("in solve (MUMPS)\n"); + /* consistency check */ + if (dim_ != dim) + return THROWERROR(RET_INVALID_ARGUMENTS); + + if (!have_factorization) { + MyPrintf("Factorization not called before solve in MumpsSparseSolver::solve.\n"); + return THROWERROR(RET_INVALID_ARGUMENTS); + } + + if (dim == 0) { + return SUCCESSFUL_RETURN; + } + + // MUMPS overwrites the rhs, copy rhs to sol and pass that to the solver + for (int_t i = 0; i < dim; ++i) + sol[i] = rhs[i]; + + /// IPOPT-MUMPS + MUMPS_STRUC_C * mumps_data = static_cast(mumps_ptr_); + + mumps_data->rhs = sol; + mumps_data->job = 3; // solve + // MyPrintf("Calling MUMPS-3 for solve.\n"); + mumps_c(mumps_data); + // MyPrintf("Done with MUMPS-3 for solve.\n"); + int error = mumps_data->info[0]; + if (error < 0) { + MyPrintf("Error=%i returned from MUMPS in Solve.\n", error); + return THROWERROR(RET_MATRIX_FACTORISATION_FAILED); + } + + return SUCCESSFUL_RETURN; +} + +/* + * r e s e t + */ +returnValue MumpsSparseSolver::reset() +{ + /* AW: We probably want to avoid resetting factorization in QProblem */ + if (SparseSolver::reset() != SUCCESSFUL_RETURN) + return THROWERROR(RET_RESET_FAILED); + + clear(); + return SUCCESSFUL_RETURN; +} + +/* + * g e t N e g a t i v e E i g e n v a l u e s */ +int_t MumpsSparseSolver::getNegativeEigenvalues() +{ + if (!have_factorization) + return -1; + else + return negevals_; +} + +// TODO(andrea: not implemented yet, default behavior) + +/* + * g e t R a n k + */ +int_t MumpsSparseSolver::getRank() +{ + return -1; +} +/* + * g e t Z e r o P i v o t s + */ +returnValue MumpsSparseSolver::getZeroPivots(int_t *& zeroPivots) +{ + if (zeroPivots) + delete[] zeroPivots; + zeroPivots = 0; + return SUCCESSFUL_RETURN; +} + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + +/* + * c l e a r + */ +returnValue MumpsSparseSolver::clear() +{ + delete[] a_mumps; + delete[] irn_mumps; + delete[] jcn_mumps; + + dim = -1; + numNonzeros = -1; + negevals_ = -1; + mumps_pivot_order_ = 0; + + a_mumps = 0; + irn_mumps = 0; + jcn_mumps = 0; + + have_factorization = false; + return SUCCESSFUL_RETURN; +} + +/* + * c o p y + */ +returnValue MumpsSparseSolver::copy(const MumpsSparseSolver & rhs) +{ + dim = rhs.dim; + numNonzeros = rhs.numNonzeros; + negevals_ = rhs.negevals_; + have_factorization = rhs.have_factorization; + + if (rhs.a_mumps != 0) { + a_mumps = new double[numNonzeros]; + memcpy(a_mumps, rhs.a_mumps, numNonzeros * sizeof(double)); + } else + a_mumps = 0; + + if (rhs.irn_mumps != 0) { + irn_mumps = new fint_t[numNonzeros]; + memcpy(irn_mumps, rhs.irn_mumps, numNonzeros * sizeof(fint_t)); + } else + irn_mumps = 0; + + if (rhs.jcn_mumps != 0) { + jcn_mumps = new fint_t[numNonzeros]; + memcpy(jcn_mumps, rhs.jcn_mumps, numNonzeros * sizeof(fint_t)); + } else + jcn_mumps = 0; + + return SUCCESSFUL_RETURN; +} + +#endif /* SOLVER_MUMPS */ + +#ifdef SOLVER_NONE + +returnValue DummySparseSolver::setMatrixData(int_t dim, /**< Dimension of the linear system. */ + int_t numNonzeros, /**< Number of nonzeros in the matrix. */ + const int_t * const airn, /**< Row indices for each matrix entry. */ + const int_t * const acjn, /**< Column indices for each matrix entry. */ + const real_t * const avals /**< Values for each matrix entry. */ +) +{ + return THROWERROR(RET_NO_SPARSE_SOLVER); +} + +returnValue DummySparseSolver::factorize() +{ + return THROWERROR(RET_NO_SPARSE_SOLVER); +} + +returnValue DummySparseSolver::solve(int_t dim, /**< Dimension of the linear system. */ + const real_t * const rhs, /**< Values for the right hand side. */ + real_t * const sol /**< Solution of the linear system. */ +) +{ + return THROWERROR(RET_NO_SPARSE_SOLVER); +} + +#endif /* SOLVER_NONE */ + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/SubjectTo.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/SubjectTo.cpp new file mode 100644 index 0000000..13c615c --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/SubjectTo.cpp @@ -0,0 +1,243 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/SubjectTo.cpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2007-2017 + * + * Implementation of the SubjectTo class designed to manage working sets of + * constraints and bounds within a QProblem. + */ + +#include + +BEGIN_NAMESPACE_QPOASES + +/***************************************************************************** + * P U B L I C * + *****************************************************************************/ + +/* + * S u b j e c t T o + */ +SubjectTo::SubjectTo() +{ + type = 0; + status = 0; + + init(); +} + +/* + * S u b j e c t T o + */ +SubjectTo::SubjectTo(int_t _n) +{ + type = 0; + status = 0; + + init(_n); +} + +/* + * S u b j e c t T o + */ +SubjectTo::SubjectTo(const SubjectTo & rhs) +{ + copy(rhs); +} + +/* + * ~ S u b j e c t T o + */ +SubjectTo::~SubjectTo() +{ + clear(); +} + +/* + * o p e r a t o r = + */ +SubjectTo & SubjectTo::operator=(const SubjectTo & rhs) +{ + if (this != &rhs) { + clear(); + copy(rhs); + } + + return *this; +} + +/* + * i n i t + */ +returnValue SubjectTo::init(int_t _n) +{ + int_t i; + + if (_n < 0) + return THROWERROR(RET_INVALID_ARGUMENTS); + + clear(); + + n = _n; + noLower = BT_TRUE; + noUpper = BT_TRUE; + + if (n > 0) { + type = new SubjectToType[n]; + status = new SubjectToStatus[n]; + + for (i = 0; i < n; ++i) { + type[i] = ST_UNKNOWN; + status[i] = ST_UNDEFINED; + } + } + + return SUCCESSFUL_RETURN; +} + +/***************************************************************************** + * P R O T E C T E D * + *****************************************************************************/ + +/* + * c l e a r + */ +returnValue SubjectTo::clear() +{ + if (type != 0) { + delete[] type; + type = 0; + } + + if (status != 0) { + delete[] status; + status = 0; + } + + return SUCCESSFUL_RETURN; +} + +/* + * c o p y + */ +returnValue SubjectTo::copy(const SubjectTo & rhs) +{ + int_t i; + + n = rhs.n; + noLower = rhs.noLower; + noUpper = rhs.noUpper; + + if (rhs.n != 0) { + type = new SubjectToType[n]; + status = new SubjectToStatus[n]; + + for (i = 0; i < n; ++i) { + type[i] = rhs.type[i]; + status[i] = rhs.status[i]; + } + } else { + type = 0; + status = 0; + } + + return SUCCESSFUL_RETURN; +} + +/* + * a d d I n d e x + */ +returnValue SubjectTo::addIndex(Indexlist * const indexlist, int_t newnumber, SubjectToStatus newstatus) +{ + if (status != 0) { + /* consistency check */ + if (status[newnumber] == newstatus) + return THROWERROR(RET_INDEX_ALREADY_OF_DESIRED_STATUS); + + status[newnumber] = newstatus; + } else + return THROWERROR(RET_ADDINDEX_FAILED); + + if (indexlist != 0) { + if (indexlist->addNumber(newnumber) == RET_INDEXLIST_EXCEEDS_MAX_LENGTH) + return THROWERROR(RET_ADDINDEX_FAILED); + } else + return THROWERROR(RET_INVALID_ARGUMENTS); + + return SUCCESSFUL_RETURN; +} + +/* + * r e m o v e I n d e x + */ +returnValue SubjectTo::removeIndex(Indexlist * const indexlist, int_t removenumber) +{ + if (status != 0) + status[removenumber] = ST_UNDEFINED; + else + return THROWERROR(RET_REMOVEINDEX_FAILED); + + if (indexlist != 0) { + if (indexlist->removeNumber(removenumber) != SUCCESSFUL_RETURN) + return THROWERROR(RET_REMOVEINDEX_FAILED); + } else + return THROWERROR(RET_INVALID_ARGUMENTS); + + return SUCCESSFUL_RETURN; +} + +/* + * s w a p I n d e x + */ +returnValue SubjectTo::swapIndex(Indexlist * const indexlist, int_t number1, int_t number2) +{ + /* consistency checks */ + if (status != 0) { + if (status[number1] != status[number2]) + return THROWERROR(RET_SWAPINDEX_FAILED); + } else + return THROWERROR(RET_SWAPINDEX_FAILED); + + if (number1 == number2) { + THROWWARNING(RET_NOTHING_TO_DO); + return SUCCESSFUL_RETURN; + } + + if (indexlist != 0) { + if (indexlist->swapNumbers(number1, number2) != SUCCESSFUL_RETURN) + return THROWERROR(RET_SWAPINDEX_FAILED); + } else + return THROWERROR(RET_INVALID_ARGUMENTS); + + return SUCCESSFUL_RETURN; +} + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Utils.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Utils.cpp new file mode 100644 index 0000000..20819b4 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/src/Utils.cpp @@ -0,0 +1,989 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file src/Utils.cpp + * \author Hans Joachim Ferreau, Andreas Potschka, Christian Kirches (thanks to Eckhard Arnold) + * \version 3.2 + * \date 2007-2017 + * + * Implementation of some utility functions for working with qpOASES. + */ + +#include + +#if defined(__WIN32__) || defined(WIN32) +#include +#elif defined(LINUX) || defined(__LINUX__) +#include +#include +#endif + +#ifdef __MATLAB__ +#include "mex.h" +#endif + +#ifdef __SCILAB__ +#include +#endif + +#include + +#ifdef __NO_SNPRINTF__ +#if (!defined(_MSC_VER)) || defined(__DSPACE__) || defined(__XPCTARGET__) +/* If snprintf is not available, provide an empty implementation. */ +int snprintf(char * s, size_t n, const char * format, ...) +{ + if (n > 0) + s[0] = '\0'; + + return 0; +} +#endif +#endif /* __NO_SNPRINTF__ */ + +BEGIN_NAMESPACE_QPOASES + +/* + * p r i n t + */ +returnValue print(const real_t * const v, int_t n, const char * name) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + int_t i; + char myPrintfString[MAX_STRING_LENGTH]; + + /* Print vector name. */ + if (name != 0) { + snprintf(myPrintfString, MAX_STRING_LENGTH, "%s = \n", name); + myPrintf(myPrintfString); + } + + /* Print vector data. */ + for (i = 0; i < n; ++i) { + snprintf(myPrintfString, MAX_STRING_LENGTH, " %.16e\t", v[i]); + myPrintf(myPrintfString); + } + myPrintf("\n"); + +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +/* + * p r i n t + */ +returnValue print(const real_t * const v, int_t n, const int_t * const V_idx, const char * name) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + int_t i; + char myPrintfString[MAX_STRING_LENGTH]; + + /* Print vector name. */ + if (name != 0) { + snprintf(myPrintfString, MAX_STRING_LENGTH, "%s = \n", name); + myPrintf(myPrintfString); + } + + /* Print a permuted vector data. */ + for (i = 0; i < n; ++i) { + snprintf(myPrintfString, MAX_STRING_LENGTH, " %.16e\t", v[V_idx[i]]); + myPrintf(myPrintfString); + } + myPrintf("\n"); + +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +/* + * p r i n t + */ +returnValue print(const real_t * const M, int_t nrow, int_t ncol, const char * name) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + int_t i; + char myPrintfString[MAX_STRING_LENGTH]; + + /* Print matrix name. */ + if (name != 0) { + snprintf(myPrintfString, MAX_STRING_LENGTH, "%s = \n", name); + myPrintf(myPrintfString); + } + + /* Print a matrix data as a collection of row vectors. */ + for (i = 0; i < nrow; ++i) + print(&(M[i * ncol]), ncol); + myPrintf("\n"); + +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +/* + * p r i n t + */ +returnValue print(const real_t * const M, + int_t nrow, + int_t ncol, + const int_t * const ROW_idx, + const int_t * const COL_idx, + const char * name) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + int_t i; + char myPrintfString[MAX_STRING_LENGTH]; + + /* Print matrix name. */ + if (name != 0) { + snprintf(myPrintfString, MAX_STRING_LENGTH, "%s = \n", name); + myPrintf(myPrintfString); + } + + /* Print a permuted matrix data as a collection of permuted row vectors. */ + for (i = 0; i < nrow; ++i) + print(&(M[ROW_idx[i] * ncol]), ncol, COL_idx); + myPrintf("\n"); + +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +/* + * p r i n t + */ +returnValue print(const int_t * const index, int_t n, const char * name) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + int_t i; + char myPrintfString[MAX_STRING_LENGTH]; + + /* Print indexlist name. */ + if (name != 0) { + snprintf(myPrintfString, MAX_STRING_LENGTH, "%s = \n", name); + myPrintf(myPrintfString); + } + + /* Print a indexlist data. */ + for (i = 0; i < n; ++i) { + snprintf(myPrintfString, MAX_STRING_LENGTH, " %d\t", (int)(index[i])); + myPrintf(myPrintfString); + } + myPrintf("\n"); + +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +/* + * m y P r i n t f + */ +returnValue myPrintf(const char * s) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + if (s == 0) + return RET_INVALID_ARGUMENTS; + +#ifdef __MATLAB__ + mexPrintf(s); +#else +#ifdef __SCILAB__ + sciprint(s); +#else + FILE * outputfile = getGlobalMessageHandler()->getOutputFile(); + if (outputfile == 0) + return THROWERROR(RET_NO_GLOBAL_MESSAGE_OUTPUTFILE); + fprintf(outputfile, "%s", s); +#endif /* __SCILAB__ */ +#endif /* __MATLAB__ */ + +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +/* + * p r i n t C o p y r i g h t N o t i c e + */ +returnValue printCopyrightNotice() +{ +#ifndef __SUPPRESSANYOUTPUT__ +#ifndef __XPCTARGET__ +#ifndef __DSPACE__ +#ifndef __NO_COPYRIGHT__ + myPrintf( + "\nqpOASES -- An Implementation of the Online Active Set Strategy.\nCopyright (C) 2007-2017 by Hans " + "Joachim Ferreau, Andreas Potschka,\nChristian Kirches et al. All rights reserved.\n\nqpOASES is " + "distributed under the terms of the \nGNU Lesser General Public License 2.1 in the hope that it will " + "be \nuseful, but WITHOUT ANY WARRANTY; without even the implied warranty \nof MERCHANTABILITY or " + "FITNESS FOR A PARTICULAR PURPOSE. \nSee the GNU Lesser General Public License for more details.\n\n"); +#endif /* __NO_COPYRIGHT__ */ +#endif /* __DSPACE__ */ +#endif /* __XPCTARGET__ */ +#endif /* __SUPPRESSANYOUTPUT__ */ + return SUCCESSFUL_RETURN; +} + +/* + * r e a d F r o m F i l e + */ +returnValue readFromFile(real_t * data, int_t nrow, int_t ncol, const char * datafilename) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + int_t i, j; + real_t float_data; + FILE * datafile; + + /* 1) Open file. */ + if ((datafile = fopen(datafilename, "r")) == 0) { + char errstr[MAX_STRING_LENGTH]; + snprintf(errstr, MAX_STRING_LENGTH, "(%s)", datafilename); + return getGlobalMessageHandler()->throwError( + RET_UNABLE_TO_OPEN_FILE, errstr, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); + } + + /* 2) Read data from file. */ + for (i = 0; i < nrow; ++i) { + for (j = 0; j < ncol; ++j) { +#ifdef __USE_SINGLE_PRECISION__ + if (fscanf(datafile, "%f ", &float_data) == 0) +#else + if (fscanf(datafile, "%lf ", &float_data) == 0) +#endif /* __USE_SINGLE_PRECISION__ */ + { + fclose(datafile); + char errstr[MAX_STRING_LENGTH]; + snprintf(errstr, MAX_STRING_LENGTH, "(%s)", datafilename); + return getGlobalMessageHandler()->throwError( + RET_UNABLE_TO_READ_FILE, errstr, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); + } + data[i * ncol + j] = ((real_t)float_data); + } + } + + /* 3) Close file. */ + fclose(datafile); + + return SUCCESSFUL_RETURN; + +#else /* __SUPPRESSANYOUTPUT__ */ + + return RET_NOT_YET_IMPLEMENTED; + +#endif /* __SUPPRESSANYOUTPUT__ */ +} + +/* + * r e a d F r o m F i l e + */ +returnValue readFromFile(real_t * data, int_t n, const char * datafilename) +{ + return readFromFile(data, n, 1, datafilename); +} + +/* + * r e a d F r o m F i l e + */ +returnValue readFromFile(int_t * data, int_t n, const char * datafilename) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + int_t i; + FILE * datafile; + + /* 1) Open file. */ + if ((datafile = fopen(datafilename, "r")) == 0) { + char errstr[MAX_STRING_LENGTH]; + snprintf(errstr, MAX_STRING_LENGTH, "(%s)", datafilename); + return getGlobalMessageHandler()->throwError( + RET_UNABLE_TO_OPEN_FILE, errstr, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); + } + + /* 2) Read data from file. */ + for (i = 0; i < n; ++i) { +#ifdef __USE_LONG_INTEGERS__ + if (fscanf(datafile, "%ld\n", &(data[i])) == 0) +#else + if (fscanf(datafile, "%d\n", &(data[i])) == 0) +#endif + { + fclose(datafile); + char errstr[MAX_STRING_LENGTH]; + snprintf(errstr, MAX_STRING_LENGTH, "(%s)", datafilename); + return getGlobalMessageHandler()->throwError( + RET_UNABLE_TO_READ_FILE, errstr, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); + } + } + + /* 3) Close file. */ + fclose(datafile); + + return SUCCESSFUL_RETURN; + +#else /* __SUPPRESSANYOUTPUT__ */ + + return RET_NOT_YET_IMPLEMENTED; + +#endif /* __SUPPRESSANYOUTPUT__ */ +} + +/* + * w r i t e I n t o F i l e + */ +returnValue writeIntoFile( + const real_t * const data, int_t nrow, int_t ncol, const char * datafilename, BooleanType append) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + int_t i, j; + FILE * datafile; + + /* 1) Open file. */ + if (append == BT_TRUE) { + /* append data */ + if ((datafile = fopen(datafilename, "a")) == 0) { + char errstr[MAX_STRING_LENGTH]; + snprintf(errstr, MAX_STRING_LENGTH, "(%s)", datafilename); + return getGlobalMessageHandler()->throwError( + RET_UNABLE_TO_OPEN_FILE, errstr, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); + } + } else { + /* do not append data */ + if ((datafile = fopen(datafilename, "w")) == 0) { + char errstr[MAX_STRING_LENGTH]; + snprintf(errstr, MAX_STRING_LENGTH, "(%s)", datafilename); + return getGlobalMessageHandler()->throwError( + RET_UNABLE_TO_OPEN_FILE, errstr, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); + } + } + + /* 2) Write data into file. */ + for (i = 0; i < nrow; ++i) { + for (j = 0; j < ncol; ++j) + fprintf(datafile, "%.16e ", data[i * ncol + j]); + + fprintf(datafile, "\n"); + } + + /* 3) Close file. */ + fclose(datafile); + + return SUCCESSFUL_RETURN; + +#else /* __SUPPRESSANYOUTPUT__ */ + + return RET_NOT_YET_IMPLEMENTED; + +#endif /* __SUPPRESSANYOUTPUT__ */ +} + +/* + * w r i t e I n t o F i l e + */ +returnValue writeIntoFile(const real_t * const data, int_t n, const char * datafilename, BooleanType append) +{ + return writeIntoFile(data, 1, n, datafilename, append); +} + +/* + * w r i t e I n t o F i l e + */ +returnValue writeIntoFile( + const int_t * const integer, int_t n, const char * datafilename, BooleanType append) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + int_t i; + + FILE * datafile; + + /* 1) Open file. */ + if (append == BT_TRUE) { + /* append data */ + if ((datafile = fopen(datafilename, "a")) == 0) { + char errstr[MAX_STRING_LENGTH]; + snprintf(errstr, MAX_STRING_LENGTH, "(%s)", datafilename); + return getGlobalMessageHandler()->throwError( + RET_UNABLE_TO_OPEN_FILE, errstr, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); + } + } else { + /* do not append data */ + if ((datafile = fopen(datafilename, "w")) == 0) { + char errstr[MAX_STRING_LENGTH]; + snprintf(errstr, MAX_STRING_LENGTH, "(%s)", datafilename); + return getGlobalMessageHandler()->throwError( + RET_UNABLE_TO_OPEN_FILE, errstr, __FUNC__, __FILE__, __LINE__, VS_VISIBLE); + } + } + + /* 2) Write data into file. */ + for (i = 0; i < n; ++i) + fprintf(datafile, "%d\n", (int)(integer[i])); + + /* 3) Close file. */ + fclose(datafile); + + return SUCCESSFUL_RETURN; + +#else /* __SUPPRESSANYOUTPUT__ */ + + return RET_NOT_YET_IMPLEMENTED; + +#endif /* __SUPPRESSANYOUTPUT__ */ +} + +/* + * w r i t e I n t o M a t F i l e + */ +returnValue writeIntoMatFile( + FILE * const matFile, const real_t * const data, int_t nRows, int_t nCols, const char * name) +{ + /* Note, this code snippet has been inspired from the document + * "Matlab(R) MAT-file Format, R2013b" by MathWorks */ + +#ifndef __SUPPRESSANYOUTPUT__ + + if ((matFile == 0) || (data == 0) || (nRows < 0) || (nCols < 0) || (name == 0)) + return RET_INVALID_ARGUMENTS; + + MatMatrixHeader var; + + // setup variable header + var.numericFormat = + 0000; /* IEEE Little Endian - reserved - double precision (64 bits) - numeric full matrix */ + var.nRows = nRows; /* number of rows */ + var.nCols = nCols; /* number of columns */ + var.imaginaryPart = 0; /* no imaginary part */ + var.nCharName = (long)(strlen(name)) + 1; /* matrix name length */ + + /* write variable header to mat file */ + if (fwrite(&var, sizeof(MatMatrixHeader), 1, matFile) < 1) + return RET_UNABLE_TO_WRITE_FILE; + + if (fwrite(name, sizeof(char), (unsigned long)(var.nCharName), matFile) < 1) + return RET_UNABLE_TO_WRITE_FILE; + + int_t ii, jj; + double curData; + + for (ii = 0; ii < nCols; ++ii) + for (jj = 0; jj < nRows; ++jj) { + curData = (real_t)data[jj * nCols + ii]; + if (fwrite(&curData, sizeof(double), 1, matFile) < 1) + return RET_UNABLE_TO_WRITE_FILE; + } + + return SUCCESSFUL_RETURN; + +#else /* __SUPPRESSANYOUTPUT__ */ + + return RET_NOT_YET_IMPLEMENTED; + +#endif /* __SUPPRESSANYOUTPUT__ */ +} + +/* + * w r i t e I n t o M a t F i l e + */ +returnValue writeIntoMatFile( + FILE * const matFile, const int_t * const data, int_t nRows, int_t nCols, const char * name) +{ + real_t * realData = new real_t[nRows * nCols]; + + int_t ii, jj; + + for (ii = 0; ii < nRows; ++ii) + for (jj = 0; jj < nCols; ++jj) + realData[ii * nCols + jj] = (real_t)data[ii * nCols + jj]; + + returnValue returnvalue = writeIntoMatFile(matFile, realData, nRows, nCols, name); + delete[] realData; + + return returnvalue; +} + +/* + * g e t C P U t i m e + */ +real_t getCPUtime() +{ + real_t current_time = -1.0; + +#if defined(__WIN32__) || defined(WIN32) + LARGE_INTEGER counter, frequency; + QueryPerformanceFrequency(&frequency); + QueryPerformanceCounter(&counter); + current_time = ((real_t)counter.QuadPart) / ((real_t)frequency.QuadPart); +#elif defined(LINUX) || defined(__LINUX__) + struct timeval theclock; + gettimeofday(&theclock, 0); + current_time = 1.0 * (real_t)theclock.tv_sec + 1.0e-6 * (real_t)theclock.tv_usec; +#endif + + return current_time; +} + +/* + * g e t N o r m + */ +real_t getNorm(const real_t * const v, int_t n, int_t type) +{ + int_t i; + + real_t norm = 0.0; + + switch (type) { + case 2: + for (i = 0; i < n; ++i) + norm += v[i] * v[i]; + return getSqrt(norm); + + case 1: + for (i = 0; i < n; ++i) + norm += getAbs(v[i]); + return norm; + + default: + THROWERROR(RET_INVALID_ARGUMENTS); + return -INFTY; + } +} + +/* + * g e t K k t V i o l a t i o n + */ +returnValue getKktViolation(int_t nV, + int_t nC, + const real_t * const H, + const real_t * const g, + const real_t * const A, + const real_t * const lb, + const real_t * const ub, + const real_t * const lbA, + const real_t * const ubA, + const real_t * const x, + const real_t * const y, + real_t & stat, + real_t & feas, + real_t & cmpl, + const real_t * const workingSetB, + const real_t * const workingSetC, + BooleanType hasIdentityHessian) +{ + /* Tolerance for dual variables considered zero. */ + const real_t dualActiveTolerance = 1.0e3 * EPS; + + int_t i, j; + real_t sum, prod; + + /* Initialize residuals */ + stat = feas = cmpl = 0.0; + + /* check stationarity */ + for (i = 0; i < nV; i++) { + /* g term and variable bounds dual term */ + if (g != 0) + sum = g[i] - y[i]; + else + sum = 0.0 - y[i]; + + /* H*x term */ + if (H != 0) + for (j = 0; j < nV; j++) + sum += H[i * nV + j] * x[j]; + else { + if (hasIdentityHessian == BT_TRUE) + sum += x[i]; + } + + /* A'*y term */ + if (A != 0) + for (j = 0; j < nC; j++) + sum -= A[j * nV + i] * y[nV + j]; + + /* update stat */ + if (getAbs(sum) > stat) + stat = getAbs(sum); + } + + /* check primal feasibility and complementarity of bounds */ + /* feasibility */ + for (i = 0; i < nV; i++) { + if (lb != 0) + if (lb[i] - x[i] > feas) + feas = lb[i] - x[i]; + + if (ub != 0) + if (x[i] - ub[i] > feas) + feas = x[i] - ub[i]; + } + + /* complementarity */ + if (workingSetB == 0) { + for (i = 0; i < nV; i++) { + prod = 0.0; + + /* lower bound */ + if (lb != 0) + if (y[i] > dualActiveTolerance) + prod = (x[i] - lb[i]) * y[i]; + + /* upper bound */ + if (ub != 0) + if (y[i] < -dualActiveTolerance) + prod = (x[i] - ub[i]) * y[i]; + + if (getAbs(prod) > cmpl) + cmpl = getAbs(prod); + } + } else { + for (i = 0; i < nV; i++) { + prod = 0.0; + + /* lower bound */ + if (lb != 0) { + if (isEqual(workingSetB[i], -1.0) == BT_TRUE) + prod = (x[i] - lb[i]) * y[i]; + } + + /* upper bound */ + if (ub != 0) { + if (isEqual(workingSetB[i], 1.0) == BT_TRUE) + prod = (x[i] - ub[i]) * y[i]; + } + + if (getAbs(prod) > cmpl) + cmpl = getAbs(prod); + } + } + + /* check primal feasibility and complementarity of constraints */ + for (i = 0; i < nC; i++) { + /* compute sum = (A*x)_i */ + sum = 0.0; + if (A != 0) + for (j = 0; j < nV; j++) + sum += A[i * nV + j] * x[j]; + + /* feasibility */ + if (lbA != 0) + if (lbA[i] - sum > feas) + feas = lbA[i] - sum; + + if (ubA != 0) + if (sum - ubA[i] > feas) + feas = sum - ubA[i]; + + /* complementarity */ + prod = 0.0; + + /* lower bound */ + if (lbA != 0) { + if (workingSetC == 0) { + if (y[nV + i] > dualActiveTolerance) + prod = (sum - lbA[i]) * y[nV + i]; + } else { + if (isEqual(workingSetC[i], -1.0) == BT_TRUE) + prod = (sum - lbA[i]) * y[nV + i]; + } + } + + /* upper bound */ + if (ubA != 0) { + if (workingSetC == 0) { + if (y[nV + i] < -dualActiveTolerance) + prod = (sum - ubA[i]) * y[nV + i]; + } else { + if (isEqual(workingSetC[i], 1.0) == BT_TRUE) + prod = (sum - ubA[i]) * y[nV + i]; + } + } + + if (getAbs(prod) > cmpl) + cmpl = getAbs(prod); + } + + return SUCCESSFUL_RETURN; +} + +/* + * g e t K k t V i o l a t i o n + */ +returnValue getKktViolation(int_t nV, + const real_t * const H, + const real_t * const g, + const real_t * const lb, + const real_t * const ub, + const real_t * const x, + const real_t * const y, + real_t & stat, + real_t & feas, + real_t & cmpl, + const real_t * const workingSetB, + BooleanType hasIdentityHessian) +{ + return getKktViolation( + nV, 0, H, g, 0, lb, ub, 0, 0, x, y, stat, feas, cmpl, workingSetB, 0, hasIdentityHessian); +} + +/* + * c o n v e r t B o o l e a n T y p e T o S t r i n g + */ +returnValue convertBooleanTypeToString(BooleanType value, char * const string) +{ +#ifndef __SUPPRESSANYOUTPUT__ + if (value == BT_FALSE) + snprintf(string, 20, "BT_FALSE"); + else + snprintf(string, 20, "BT_TRUE"); +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +/* + * c o n v e r t S u b j e c t T o S t a t u s T o S t r i n g + */ +returnValue convertSubjectToStatusToString(SubjectToStatus value, char * const string) +{ +#ifndef __SUPPRESSANYOUTPUT__ + switch (value) { + case ST_INACTIVE: + snprintf(string, 20, "ST_INACTIVE"); + break; + + case ST_LOWER: + snprintf(string, 20, "ST_LOWER"); + break; + + case ST_UPPER: + snprintf(string, 20, "ST_UPPER"); + break; + + case ST_UNDEFINED: + snprintf(string, 20, "ST_UNDEFINED"); + break; + + case ST_INFEASIBLE_LOWER: + snprintf(string, 20, "ST_INFEASIBLE_LOWER"); + break; + + case ST_INFEASIBLE_UPPER: + snprintf(string, 20, "ST_INFEASIBLE_UPPER"); + break; + + default: + snprintf(string, 20, ""); + break; + } +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +/* + * c o n v e r t P r i n t L e v e l T o S t r i n g + */ +returnValue convertPrintLevelToString(PrintLevel value, char * const string) +{ +#ifndef __SUPPRESSANYOUTPUT__ + switch (value) { + case PL_NONE: + snprintf(string, 20, "PL_NONE"); + break; + + case PL_LOW: + snprintf(string, 20, "PL_LOW"); + break; + + case PL_MEDIUM: + snprintf(string, 20, "PL_MEDIUM"); + break; + + case PL_HIGH: + snprintf(string, 20, "PL_HIGH"); + break; + + case PL_TABULAR: + snprintf(string, 20, "PL_TABULAR"); + break; + + case PL_DEBUG_ITER: + snprintf(string, 20, "PL_DEBUG_ITER"); + break; + + default: + snprintf(string, 20, ""); + break; + } +#endif /* __SUPPRESSANYOUTPUT__ */ + + return SUCCESSFUL_RETURN; +} + +/* + * g e t S i m p l e S t a t u s + */ +int_t getSimpleStatus(returnValue returnvalue, BooleanType doPrintStatus) +{ + int_t simpleStatus = -1; + + /* determine simple status from returnvalue */ + switch (returnvalue) { + case SUCCESSFUL_RETURN: + simpleStatus = 0; + break; + + case RET_MAX_NWSR_REACHED: + simpleStatus = 1; + break; + + case RET_INIT_FAILED_INFEASIBILITY: + case RET_HOTSTART_STOPPED_INFEASIBILITY: + simpleStatus = -2; + break; + + case RET_INIT_FAILED_UNBOUNDEDNESS: + case RET_HOTSTART_STOPPED_UNBOUNDEDNESS: + simpleStatus = -3; + break; + + default: + simpleStatus = -1; + break; + } + + if (doPrintStatus == BT_TRUE) { + VisibilityStatus vsInfo = getGlobalMessageHandler()->getInfoVisibilityStatus(); + getGlobalMessageHandler()->setInfoVisibilityStatus(VS_VISIBLE); + getGlobalMessageHandler()->setErrorCount(-1); + + int_t retValNumber = (int_t)RET_SIMPLE_STATUS_P0 - simpleStatus; + THROWINFO((returnValue)retValNumber); + + getGlobalMessageHandler()->setInfoVisibilityStatus(vsInfo); + } + + return simpleStatus; +} + +/* + * n o r m a l i s e C o n s t r a i n t s + */ +returnValue normaliseConstraints(int_t nV, int_t nC, real_t * A, real_t * lbA, real_t * ubA, int_t type) +{ + int_t ii, jj; + real_t curNorm; + + if ((nV <= 0) || (nC <= 0) || (A == 0)) + return THROWERROR(RET_INVALID_ARGUMENTS); + + for (ii = 0; ii < nC; ++ii) { + /* get row norm */ + curNorm = getNorm(&(A[ii * nV]), nV, type); + + if (curNorm > EPS) { + /* normalise if norm is positive */ + for (jj = 0; jj < nV; ++jj) + A[ii * nV + jj] /= curNorm; + + if (lbA != 0) + lbA[ii] /= curNorm; + if (ubA != 0) + ubA[ii] /= curNorm; + } else { + /* if row norm is (close to) zero, kind of erase constraint */ + if (type == 1) { + for (jj = 0; jj < nV; ++jj) + A[ii * nV + jj] = 1.0 / ((real_t)nV); + } else { + /* assume type == 2 */ + for (jj = 0; jj < nV; ++jj) + A[ii * nV + jj] = 1.0 / getSqrt((real_t)nV); + } + + if (lbA != 0) + lbA[ii] = -INFTY; + if (ubA != 0) + ubA[ii] = INFTY; + } + } + + return SUCCESSFUL_RETURN; +} + +#ifdef __DEBUG__ +/* + * g d b _ p r i n t m at + */ +extern "C" void gdb_printmat(const char * fname, real_t * M, int_t n, int_t m, int_t ldim) +{ +#ifndef __SUPPRESSANYOUTPUT__ + + int_t i, j; + FILE * fid; + + fid = fopen(fname, "wt"); + if (!fid) { + perror("Error opening file: "); + return; + } + + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) + fprintf(fid, " %23.16e", M[j * ldim + i]); + fprintf(fid, "\n"); + } + fclose(fid); + +#endif /* __SUPPRESSANYOUTPUT__ */ +} +#endif /* __DEBUG__ */ + +#if defined(__DSPACE__) || defined(__XPCTARGET__) || defined(__C_WRAPPER__) +/* + * _ _ c x a _ p u r e _ v i r t u a l + */ +void __cxa_pure_virtual(void) +{ + /* put your customized implementation here! */ +} +#endif /* __DSPACE__ || __XPCTARGET__ || __C_WRAPPER__ */ + +END_NAMESPACE_QPOASES + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/c/Makefile b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/c/Makefile new file mode 100755 index 0000000..f4d1a8e --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/c/Makefile @@ -0,0 +1,78 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: testing/c/Makefile +## Author: Hans Joachim Ferreau +## Version: 3.2 +## Date: 2014-2017 +## + + + +include ../../make.mk + +## +## flags +## + +IFLAGS = -I. \ + -I${IDIR} \ + -I${TOP}/interfaces/c + +QPOASES_TEST_EXES = \ + ${BINDIR}/test_c_example1${EXE} \ + ${BINDIR}/test_c_example1a${EXE} \ + ${BINDIR}/test_c_example1b${EXE} + + +## +## targets +## + +all: ${QPOASES_TEST_EXES} + +${BINDIR}/%${EXE}: %.${OBJEXT} ${LINK_DEPENDS_WRAPPER} + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${CPPFLAGS} $< ${QPOASES_LINK_WRAPPER} ${LINK_LIBRARIES_WRAPPER} + + +clean: + @${ECHO} "Cleaning up (testing/cpp)" + @${RM} -f *.${OBJEXT} ${QPOASES_TEST_EXES} + +clobber: clean + + +${LINK_DEPENDS_WRAPPER}: + @cd ../..; ${MAKE} -s c_wrapper + +%.${OBJEXT}: %.c + @${ECHO} "Creating" $@ + @${CC} ${DEF_TARGET} -c ${IFLAGS} ${CPPFLAGS} $< + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/c/test_c_example1.c b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/c/test_c_example1.c new file mode 100755 index 0000000..b5933cb --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/c/test_c_example1.c @@ -0,0 +1,104 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file testing/c/test_c_example1.c + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2014-2017 + * + * Very simple example for testing qpOASES (using QProblem class through C interface). + */ + +#include + +#include + + +/** Example for qpOASES main function using the QProblem class. */ +int main( ) +{ + /* Setup data of first QP. */ + real_t H[2*2] = { 1.0, 0.0, 0.0, 0.5 }; + real_t A[1*2] = { 1.0, 1.0 }; + real_t g[2] = { 1.5, 1.0 }; + real_t lb[2] = { 0.5, -2.0 }; + real_t ub[2] = { 5.0, 2.0 }; + real_t lbA[1] = { -1.0 }; + real_t ubA[1] = { 2.0 }; + + /* Setup data of second QP. */ + real_t g_new[2] = { 1.0, 1.5 }; + real_t lb_new[2] = { 0.0, -1.0 }; + real_t ub_new[2] = { 5.0, -0.5 }; + real_t lbA_new[1] = { -2.0 }; + real_t ubA_new[1] = { 1.0 }; + + int_t nWSR; + qpOASES_Options options; + + real_t xOpt[2]; + real_t yOpt[2+1]; + real_t obj; + int_t status; + + qpOASES_Options_init( &options,0 ); + options.printLevel = PL_MEDIUM; + + + QProblem_setup( 2,1,HST_UNKNOWN ); + + /* Solve first QP. */ + nWSR = 10; + QProblem_init( H,g,A,lb,ub,lbA,ubA, + &nWSR,0,&options, + xOpt,yOpt,&obj,&status + ); + + /* Print solution of first QP. */ + printf( "\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", + xOpt[0],xOpt[1],yOpt[0],yOpt[1],yOpt[2], obj ); + + + /* Solve second QP. */ + nWSR = 10; + QProblem_hotstart( g_new,lb_new,ub_new,lbA_new,ubA_new, + &nWSR,0, + xOpt,yOpt,&obj,&status + ); + + /* Print solution of first QP. */ + printf( "\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", + xOpt[0],xOpt[1],yOpt[0],yOpt[1],yOpt[2], obj ); + + + QProblem_cleanup(); + + return 0; +} + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/c/test_c_example1a.c b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/c/test_c_example1a.c new file mode 100755 index 0000000..690c661 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/c/test_c_example1a.c @@ -0,0 +1,105 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file testing/c/test_c_example1a.c + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2014-2017 + * + * Very simple example for testing qpOASES (using SQProblem class through C interface). + */ + +#include + +#include + + +/** Example for qpOASES main function using the QProblem class. */ +int main( ) +{ + /* Setup data of first QP. */ + real_t H[2*2] = { 1.0, 0.0, 0.0, 0.5 }; + real_t A[1*2] = { 1.0, 1.0 }; + real_t g[2] = { 1.5, 1.0 }; + real_t lb[2] = { 0.5, -2.0 }; + real_t ub[2] = { 5.0, 2.0 }; + real_t lbA[1] = { -1.0 }; + real_t ubA[1] = { 2.0 }; + + /* Setup data of second QP. */ + real_t H_new[2*2] = { 1.0, 0.5, 0.5, 0.5 }; + real_t A_new[1*2] = { 1.0, 5.0 }; + real_t g_new[2] = { 1.0, 1.5 }; + real_t lb_new[2] = { 0.0, -1.0 }; + real_t ub_new[2] = { 5.0, -0.5 }; + real_t lbA_new[1] = { -2.0 }; + real_t ubA_new[1] = { 1.0 }; + + int_t nWSR; + + real_t xOpt[2]; + real_t yOpt[2+1]; + real_t obj; + int_t status; + + qpOASES_Options options; + qpOASES_Options_init( &options,0 ); + + + SQProblem_setup( 2,1,HST_UNKNOWN ); + + /* Solve first QP. */ + nWSR = 10; + SQProblem_init( H,g,A,lb,ub,lbA,ubA, + &nWSR,0,&options, + xOpt,yOpt,&obj,&status + ); + + /* Print solution of first QP. */ + printf( "\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", + xOpt[0],xOpt[1],yOpt[0],yOpt[1],yOpt[2], obj ); + + + /* Solve second QP. */ + nWSR = 10; + SQProblem_hotstart( H_new,g_new,A_new,lb_new,ub_new,lbA_new,ubA_new, + &nWSR,0, + xOpt,yOpt,&obj,&status + ); + + /* Print solution of first QP. */ + printf( "\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", + xOpt[0],xOpt[1],yOpt[0],yOpt[1],yOpt[2], obj ); + + + SQProblem_cleanup(); + + return 0; +} + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/c/test_c_example1b.c b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/c/test_c_example1b.c new file mode 100755 index 0000000..84a4ffd --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/c/test_c_example1b.c @@ -0,0 +1,102 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +/** + * \file testing/c/test_example1b.c + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2014-2017 + * + * Very simple example for testing qpOASES (using QProblemB class through C interface). + */ + +#include + +#include + + +/** Example for qpOASES main function using the QProblem class. */ +int main( ) +{ + /* Setup data of first QP. */ + real_t H[2*2] = { 1.0, 0.0, 0.0, 0.5 }; + real_t g[2] = { 1.5, 1.0 }; + real_t lb[2] = { 0.5, -2.0 }; + real_t ub[2] = { 5.0, 2.0 }; + + /* Setup data of second QP. */ + real_t g_new[2] = { 1.0, 1.5 }; + real_t lb_new[2] = { 0.0, -1.0 }; + real_t ub_new[2] = { 5.0, -0.5 }; + + int_t nWSR; + qpOASES_Options options; + + real_t xOpt[2]; + real_t yOpt[2]; + real_t obj; + int_t status; + + qpOASES_Options_init( &options,0 ); + /*options.enableFlippingBounds = 0; */ + options.initialStatusBounds = ST_INACTIVE; + options.numRefinementSteps = 1; + options.enableCholeskyRefactorisation = 1; + + + QProblemB_setup( 2,HST_UNKNOWN ); + + /* Solve first QP. */ + nWSR = 10; + QProblemB_init( H,g,lb,ub, + &nWSR,0,&options, + xOpt,yOpt,&obj,&status + ); + + /* Print solution of first QP. */ + printf( "\nxOpt = [ %e, %e ]; yOpt = [ %e, %e ]; objVal = %e\n\n", + xOpt[0],xOpt[1],yOpt[0],yOpt[1], obj ); + + + /* Solve second QP. */ + nWSR = 10; + QProblemB_hotstart( g_new,lb_new,ub_new, + &nWSR,0, + xOpt,yOpt,&obj,&status + ); + + /* Print solution of first QP. */ + printf( "\nxOpt = [ %e, %e ]; yOpt = [ %e, %e ]; objVal = %e\n\n", + xOpt[0],xOpt[1],yOpt[0],yOpt[1], obj ); + + + QProblemB_cleanup(); + + return 0; +} + + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/checkForMemoryLeaks b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/checkForMemoryLeaks new file mode 100755 index 0000000..346a333 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/checkForMemoryLeaks @@ -0,0 +1,109 @@ +#!/usr/bin/env bash + +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: testing/checkForMemoryLeaks +## Author: Hans Joachim Ferreau +## Version: 3.2 +## Date: 2014-2017 + +# defining colors for output +red='\e[0;31m' +green='\e[0;32m' +NC='\e[0m' # No Color + +# runs valgrind on a number of examples to detect possible memory leaks + +function callValgrind { + echo -n "Checking for memory leaks in $2 $3... " + + valgrind --tool=memcheck --leak-check=yes --error-exitcode=42 -q $2 $3 > dummy.txt; + retVal=$?; + rm -rf dummy.txt; + + if [ $retVal == 42 ]; then + echo -e "${red}failed!${NC}" + counter=$[counter+1]; + else + if [ $retVal == 99 ]; then + echo "problem data missing!" + else + echo -e "${green}passed!${NC}" + fi + fi +} + + +cd ..; +make examples testing; +cd testing; + +counter=0; + +# run examples in /examples +callValgrind $counter ../bin/example1; +callValgrind $counter ../bin/example1a; +callValgrind $counter ../bin/example1b; +callValgrind $counter ../bin/example2; +callValgrind $counter ../bin/example3; +callValgrind $counter ../bin/example3b; +callValgrind $counter ../bin/example4; +callValgrind $counter ../bin/example5; +callValgrind $counter ../bin/exampleLP; +callValgrind $counter ../bin/qrecipe; +callValgrind $counter ../bin/qrecipeSchur; + +# run examples in /testing ... +callValgrind $counter ../bin/test_matrices; +callValgrind $counter ../bin/test_matrices2; +callValgrind $counter ../bin/test_indexlist; +callValgrind $counter ../bin/test_example6; +callValgrind $counter ../bin/test_example7; +callValgrind $counter ../bin/test_infeasible1; +callValgrind $counter ../bin/test_sebastien1; +callValgrind $counter ../bin/test_vanBarelsUnboundedQP; +callValgrind $counter ../bin/test_janick1; +callValgrind $counter ../bin/test_janick2; +callValgrind $counter ../bin/test_constraintProduct1; +callValgrind $counter ../bin/test_constraintProduct2; +callValgrind $counter ../bin/test_guessedWS1; +callValgrind $counter ../bin/test_externalChol1; +callValgrind $counter ../bin/test_runAllOqpExamples; + + +# ... including testbench with different settings +callValgrind $counter ../bin/test_bench Odd; # default dense +callValgrind $counter ../bin/test_bench Ods; # default sparse +callValgrind $counter ../bin/test_bench Omd; # MPC dense +callValgrind $counter ../bin/test_bench Ors; # reliable dense + + +if [ $counter == 0 ]; then + echo -e "${green}All available tests passed successfully!${NC}" +else + echo -e "${red}$counter test(s) failed!${NC}" + exit 1 +fi diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/Makefile b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/Makefile new file mode 100755 index 0000000..8d0bba8 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/Makefile @@ -0,0 +1,138 @@ +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: testing/cpp/Makefile +## Author: Hans Joachim Ferreau +## Version: 3.2 +## Date: 2007-2017 +## + + +include ../../make.mk + +## +## flags +## + +IFLAGS = -I. \ + -I${IDIR} + +QPOASES_TEST_EXES = \ + ${BINDIR}/test_bench${EXE} \ + ${BINDIR}/test_matrices${EXE} \ + ${BINDIR}/test_matrices2${EXE} \ + ${BINDIR}/test_matrices3${EXE} \ + ${BINDIR}/test_indexlist${EXE} \ + ${BINDIR}/test_example1${EXE} \ + ${BINDIR}/test_example1a${EXE} \ + ${BINDIR}/test_example1b${EXE} \ + ${BINDIR}/test_example2${EXE} \ + ${BINDIR}/test_example4${EXE} \ + ${BINDIR}/test_example5${EXE} \ + ${BINDIR}/test_example6${EXE} \ + ${BINDIR}/test_example7${EXE} \ + ${BINDIR}/test_exampleLP${EXE} \ + ${BINDIR}/test_qrecipe${EXE} \ + ${BINDIR}/test_qrecipeSchur${EXE} \ + ${BINDIR}/test_smallSchur${EXE} \ + ${BINDIR}/test_infeasible1${EXE} \ + ${BINDIR}/test_hs268${EXE} \ + ${BINDIR}/test_gradientShift${EXE} \ + ${BINDIR}/test_runAllOqpExamples${EXE} \ + ${BINDIR}/test_sebastien1${EXE} \ + ${BINDIR}/test_vanBarelsUnboundedQP${EXE} \ + ${BINDIR}/test_janick1${EXE} \ + ${BINDIR}/test_janick2${EXE} \ + ${BINDIR}/test_constraintProduct1${EXE} \ + ${BINDIR}/test_constraintProduct2${EXE} \ + ${BINDIR}/test_guessedWS1${EXE} \ + ${BINDIR}/test_externalChol1${EXE} \ + ${BINDIR}/test_identitySqproblem${EXE} + + +## +## targets +## + +all: ${QPOASES_TEST_EXES} + +runTests: ${QPOASES_TEST_EXES} + @cd .. && ./runUnitTests && ./checkForMemoryLeaks && cd cpp + +${BINDIR}/%${EXE}: %.${OBJEXT} ${LINK_DEPENDS} + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${CPPFLAGS} $< ${QPOASES_LINK} ${LINK_LIBRARIES} + +${BINDIR}/test_matrices2${EXE}: test_matrices2.${OBJEXT} test_qrecipe_data.hpp ${LINK_DEPENDS} + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${CPPFLAGS} $< ${QPOASES_LINK} ${LINK_LIBRARIES} + +${BINDIR}/test_matrices3${EXE}: test_matrices3.${OBJEXT} test_qrecipe_data.hpp ${LINK_DEPENDS} + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${CPPFLAGS} $< ${QPOASES_LINK} ${LINK_LIBRARIES} + +${BINDIR}/test_qrecipe${EXE}: test_qrecipe.${OBJEXT} test_qrecipe_data.hpp ${LINK_DEPENDS} + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${CPPFLAGS} $< ${QPOASES_LINK} ${LINK_LIBRARIES} + +${BINDIR}/test_qrecipeSchur${EXE}: test_qrecipeSchur.${OBJEXT} test_qrecipe_data.hpp ${LINK_DEPENDS} + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${CPPFLAGS} $< ${QPOASES_LINK} ${LINK_LIBRARIES} + + +clean: + @${ECHO} "Cleaning up (testing/cpp)" + @${RM} -f *.${OBJEXT} ${QPOASES_TEST_EXES} + +clobber: clean + + +${LINK_DEPENDS}: + @cd ../..; ${MAKE} -s src + +test_matrices2.${OBJEXT}: test_matrices2.cpp test_qrecipe_data.hpp + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${IFLAGS} ${CPPFLAGS} -c $< + +test_matrices3.${OBJEXT}: test_matrices3.cpp test_qrecipe_data.hpp + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${IFLAGS} ${CPPFLAGS} -c $< + +test_qrecipe.${OBJEXT}: test_qrecipe.cpp test_qrecipe_data.hpp + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${IFLAGS} ${CPPFLAGS} -c $< + +test_qrecipeSchur.${OBJEXT}: test_qrecipeSchur.cpp test_qrecipe_data.hpp + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${IFLAGS} ${CPPFLAGS} -c $< + +%.${OBJEXT}: %.cpp + @${ECHO} "Creating" $@ + @${CPP} ${DEF_TARGET} ${IFLAGS} ${CPPFLAGS} -c $< + + +## +## end of file +## diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/data/fetch_cpp_data b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/data/fetch_cpp_data new file mode 100755 index 0000000..cc52452 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/data/fetch_cpp_data @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: testing/cpp/data/fetch_cpp_data +## Author: Hans Joachim Ferreau +## Version: 3.2 +## Date: 2014 + + +svn export https://projects.coin-or.org/svn/qpOASES/misc/testingdata/cpp . --force diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_bench.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_bench.cpp new file mode 100644 index 0000000..cf7217c --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_bench.cpp @@ -0,0 +1,275 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_bench.cpp + * \author Andreas Potschka, Christian Kirches, Hans Joachim Ferreau + * \version 3.2 + * \date 2010-2017 + * + * Unit test running all benchmark examples stored in problems directory. + */ + +#include +#include +#include +#include +#include + +/** Run benchmark examples. */ +int main(int argc, char * argv[]) +{ + USING_NAMESPACE_QPOASES +#ifdef __USE_SINGLE_PRECISION__ + const real_t TOL = 5e-2; +#else + const real_t TOL = 1e-5; +#endif + + /* 1) Define benchmark arguments. */ + BooleanType isSparse = BT_FALSE; + // BooleanType isSparse = BT_TRUE; + Options options; + options.setToDefault(); + // options.setToMPC(); + // options.setToReliable(); + options.printLevel = PL_LOW; + // options.printLevel = PL_MEDIUM; + // options.printLevel = PL_TABULAR; + // options.enableFarBounds = BT_FALSE; + + // options.initialStatusBounds = ST_LOWER; + // options.numRegularisationSteps = 1; + // options.epsRegularisation = 1.0e3 * EPS; + + // options.enableFlippingBounds = BT_FALSE; + // options.enableFlippingBounds = BT_FALSE; + // options.enableRamping = BT_TRUE; + // options.enableFarBounds = BT_FALSE; + // options.enableNZCTests = BT_FALSE; + // options.epsNZCTests = 1.0e4 * EPS; + // options.epsFlipping = 1.0e5 * EPS; + // options.enableFullLITests = BT_TRUE; + // options.enableDriftCorrection = 1; + // options.enableEqualities = BT_TRUE; + // options.enableEqualities = BT_FALSE; + // options.epsNum = -1.0e3 * EPS; + // options.epsDen = 1.0e3 * EPS; + + int_t nWSR; + real_t maxCPUtime; /* seconds */ + real_t maxStationarity = 0.0, maxFeasibility = 0.0, maxComplementarity = 0.0; + real_t avgStationarity = 0.0, avgFeasibility = 0.0, avgComplementarity = 0.0; + + int_t scannedDir = 0; + int_t nfail = 0, npass = 0; + int_t nproblems, i; + struct dirent ** namelist; + char resstr[MAX_STRING_LENGTH], oqpProblem[MAX_STRING_LENGTH]; + char * problem; + returnValue returnvalue; + + int_t expectedNumSolvedProblems = 44; + real_t expectedAvgStationarity = TOL; + real_t expectedAvgFeasibility = TOL; + real_t expectedAvgComplementarity = TOL; + + if (argv[argc - 1][0] == 'O') { + if (strlen(argv[argc - 1]) != 3) { + fprintf(stdout, "ERROR (testbench): Invalid options passed!\n"); + return TEST_DATA_NOT_FOUND; + } + + fprintf(stdout, "Analysing passed options: "); + switch (argv[argc - 1][1]) { + case 'd': + fprintf(stdout, "default options, "); + options.setToDefault(); + if (argv[argc - 1][2] == 's') { + expectedNumSolvedProblems = 44; + expectedAvgStationarity = 1e-9; + expectedAvgFeasibility = 1e-9; + expectedAvgComplementarity = 5e-7; + } else { + expectedNumSolvedProblems = 44; + expectedAvgStationarity = 5e-10; + expectedAvgFeasibility = 5e-10; + expectedAvgComplementarity = 5e-8; + } + break; + + case 'r': + fprintf(stdout, "reliable options, "); + options.setToReliable(); + if (argv[argc - 1][2] == 's') { + expectedNumSolvedProblems = 44; + expectedAvgStationarity = 2e-9; + expectedAvgFeasibility = 2e-11; + expectedAvgComplementarity = 3e-9; + } else { + expectedNumSolvedProblems = 44; + expectedAvgStationarity = 2e-9; + expectedAvgFeasibility = 2e-9; + expectedAvgComplementarity = 3e-7; + } + break; + + case 'm': + fprintf(stdout, "MPC options, "); + options.setToMPC(); + if (argv[argc - 1][2] == 's') { + expectedNumSolvedProblems = 42; + expectedAvgStationarity = 2e-8; + expectedAvgFeasibility = 1e-8; + expectedAvgComplementarity = 2e-7; + } else { + expectedNumSolvedProblems = 42; + expectedAvgStationarity = 3e-8; + expectedAvgFeasibility = 1e-8; + expectedAvgComplementarity = 5e-8; + } + break; + + default: + fprintf(stdout, "ERROR (testbench): Invalid options passed!\n"); + return TEST_DATA_NOT_FOUND; + } + + switch (argv[argc - 1][2]) { + case 's': + fprintf(stdout, "sparse QP data\n"); + isSparse = BT_TRUE; + break; + + case 'd': + fprintf(stdout, "dense QP data\n"); + isSparse = BT_FALSE; + break; + + default: + fprintf(stdout, "ERROR (testbench): Invalid options passed!\n"); + return TEST_DATA_NOT_FOUND; + } + options.printLevel = PL_NONE; + // options.enableFlippingBounds = BT_FALSE; + + nproblems = argc - 2; + } else { + nproblems = argc - 1; + } + + if (nproblems == 0) { + /* 2a) Scan problem directory */ + nproblems = scandir("../testing/cpp/data/problems", &namelist, NULL, alphasort); + if (nproblems <= 0) { + myPrintf("No test problems found!\n"); + return TEST_DATA_NOT_FOUND; + } + scannedDir = 1; + } else { + /* 2b) Use problem list given by arguments */ + scannedDir = 0; + } + + /* 3) Run benchmark. */ + printf("%10s %9s %9s %9s %6s %-12s\n", "problem", "stat", "feas", "compl", "nWSR", "result"); + for (i = 0; i < nproblems; i++) { + if (scannedDir) { + /* skip special directories and zip file cuter.*bz2 */ + if (namelist[i]->d_name[0] == '.' || namelist[i]->d_name[0] == 'c') { + free(namelist[i]); + continue; + } + problem = namelist[i]->d_name; + } else { + problem = argv[i + 1]; + } + + fprintf(stdFile, "%-10s ", problem); + fflush(stdFile); + + snprintf(oqpProblem, MAX_STRING_LENGTH, "../testing/cpp/data/problems/%s/", problem); + maxCPUtime = 300.0; + nWSR = 2500; + + returnvalue = runOqpBenchmark( + oqpProblem, isSparse, options, nWSR, maxCPUtime, maxStationarity, maxFeasibility, maxComplementarity); + if (returnvalue == SUCCESSFUL_RETURN && maxStationarity < TOL && maxFeasibility < TOL && + maxComplementarity < TOL) { + npass++; + + avgStationarity += maxStationarity; + avgFeasibility += maxFeasibility; + avgComplementarity += maxComplementarity; + + strncpy(resstr, "pass", MAX_STRING_LENGTH); + } else { + if (returnvalue == RET_BENCHMARK_ABORTED) + return TEST_DATA_NOT_FOUND; + + nfail++; + snprintf(resstr, MAX_STRING_LENGTH, "fail (%d)", (int)returnvalue); + } + fprintf(stdFile, + "%9.2e %9.2e %9.2e %6d %-12s\n", + maxStationarity, + maxFeasibility, + maxComplementarity, + (int)nWSR, + resstr); + + if (scannedDir) + free(namelist[i]); + } + if (scannedDir) + free(namelist); + + avgStationarity /= (real_t)npass; + avgFeasibility /= (real_t)npass; + avgComplementarity /= (real_t)npass; + + /* 4) Print results. */ + printf("\n\n"); + printf("Testbench results:\n"); + printf("======================\n\n"); + printf("Pass: %3d\n", (int)npass); + printf("Fail: %3d\n", (int)nfail); + printf("Ratio: %5.1f%%\n", 100.0 * (real_t)npass / (real_t)(npass + nfail)); + printf("\n"); + + QPOASES_TEST_FOR_TRUE(npass >= expectedNumSolvedProblems); + + printf("avg. stat: %e\n", avgStationarity); + printf("avg. feas: %e\n", avgFeasibility); + printf("avg. cmpl: %e\n", avgComplementarity); + + QPOASES_TEST_FOR_TOL(avgStationarity, expectedAvgStationarity); + QPOASES_TEST_FOR_TOL(avgFeasibility, expectedAvgFeasibility); + QPOASES_TEST_FOR_TOL(avgComplementarity, expectedAvgComplementarity); + + return 0; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_constraintProduct1.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_constraintProduct1.cpp new file mode 100644 index 0000000..0f15568 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_constraintProduct1.cpp @@ -0,0 +1,175 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_constraintProduct1.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2014-2017 + * + * Another example for testing qpOASES using the possibility to specify + * user-defined constraint product function. + */ + +#include +#include + +USING_NAMESPACE_QPOASES + +/** + * \brief Example illustrating the use of the \a ConstraintProduct class. + * + * Example illustrating the use of the \a ConstraintProduct class. + * + * \author Hans Joachim Ferreau + * \version 3.1 + * \date 2007-2017 + */ +class MpcConstraintProduct : public ConstraintProduct +{ +public: + /** Default constructor. */ + MpcConstraintProduct(){}; + + /** Constructor. */ + MpcConstraintProduct(int_t _nV, int_t _nC, int_t _diagOffset, real_t * _A) + { + nV = _nV; + nC = _nC; + diagOffset = _diagOffset; + A = _A; + }; + + /** Copy constructor (flat copy). */ + MpcConstraintProduct(const MpcConstraintProduct & rhs) + { + nV = rhs.nV; + nC = rhs.nC; + diagOffset = rhs.diagOffset; + A = rhs.A; + }; + + /** Destructor. */ + virtual ~MpcConstraintProduct(){}; + + /** Assignment operator (flat copy). */ + MpcConstraintProduct & operator=(const MpcConstraintProduct & rhs) + { + if (this != &rhs) { + nV = rhs.nV; + nC = rhs.nC; + diagOffset = rhs.diagOffset; + A = rhs.A; + } else + return *this; + }; + + virtual int_t operator()(int_t constrIndex, const real_t * const x, real_t * const constrValue) const + { + int_t i; + int_t maxI = (int_t)(((real_t)constrIndex) * ((real_t)nV) / ((real_t)nC)) + diagOffset; + maxI = getMin(maxI, nV); + + constrValue[0] = 0.0; + + for (i = 0; i < maxI; ++i) + constrValue[0] += A[constrIndex * nV + i] * x[i]; + + return 0; + }; + +protected: + int_t nV; /**< Number of variables. */ + int_t nC; /**< Number of constraints. */ + int_t diagOffset; /**< ... */ + real_t * A; /**< Pointer to full constraint matrix (typically not needed!). */ +}; + +/** Example for qpOASES main function using the possibility to specify + * user-defined constraint product function. */ +int main() +{ + USING_NAMESPACE_QPOASES + + int_t nQP, nV, nC, nEC; + real_t *H, *g, *A, *lb, *ub, *lbA, *ubA; + real_t cputime; + + real_t xOpt[1000]; + real_t yOpt[1000]; + real_t xOptCP[1000 + 1000]; + real_t yOptCP[1000 + 1000]; + + const char * path = "./cpp/data/oqp/chain80w/"; + int_t k = 10; // th problem + + if (readOqpDimensions(path, nQP, nV, nC, nEC) != SUCCESSFUL_RETURN) + return TEST_DATA_NOT_FOUND; + + readOqpData(path, nQP, nV, nC, nEC, &H, &g, &A, &lb, &ub, &lbA, &ubA, 0, 0, 0); + + Options myOptions; + // myOptions.setToMPC(); + myOptions.printLevel = PL_LOW; + + int_t nWSR = 500; + cputime = 20.0; + QProblem qp(nV, nC); + qp.setOptions(myOptions); + qp.init(H, &(g[k * nV]), A, &(lb[k * nV]), &(ub[k * nV]), &(lbA[k * nC]), &(ubA[k * nC]), nWSR, &cputime); + qp.getPrimalSolution(xOpt); + qp.getDualSolution(yOpt); + printf("cputime without constraintProduct: %.3ems\n", cputime * 1000.0); + + nWSR = 500; + cputime = 20.0; + MpcConstraintProduct myCP(nV, nC, 2, A); + QProblem qpCP(nV, nC); + qpCP.setOptions(myOptions); + qpCP.setConstraintProduct(&myCP); + qpCP.init( + H, &(g[k * nV]), A, &(lb[k * nV]), &(ub[k * nV]), &(lbA[k * nC]), &(ubA[k * nC]), nWSR, &cputime); + qpCP.getPrimalSolution(xOptCP); + qpCP.getDualSolution(yOptCP); + printf("cputime with constraintProduct: %.3ems\n", cputime * 1000.0); + + delete[] ubA; + delete[] lbA; + delete[] ub; + delete[] lb; + delete[] A; + delete[] g; + delete[] H; + + for (int ii = 0; ii < nV; ++ii) + QPOASES_TEST_FOR_NEAR(xOptCP[ii], xOpt[ii]); + + for (int ii = 0; ii < nV + nC; ++ii) + QPOASES_TEST_FOR_NEAR(yOptCP[ii], yOpt[ii]); + + return 0; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_constraintProduct2.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_constraintProduct2.cpp new file mode 100644 index 0000000..352b55f --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_constraintProduct2.cpp @@ -0,0 +1,173 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_constraintProduct2.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2014-2017 + * + * Another example for testing qpOASES using the possibility to specify + * user-defined constraint product function. + */ + +#include +#include + +USING_NAMESPACE_QPOASES + +/** + * \brief Example illustrating the use of the \a ConstraintProduct class. + * + * Example illustrating the use of the \a ConstraintProduct class. + * + * \author Hans Joachim Ferreau + * \version 3.1 + * \date 2007-2017 + */ +class MpcConstraintProduct : public ConstraintProduct +{ +public: + /** Default constructor. */ + MpcConstraintProduct(){}; + + /** Constructor. */ + MpcConstraintProduct(int_t _nV, int_t _nC, int_t _diagOffset, real_t * _A) + { + nV = _nV; + nC = _nC; + diagOffset = _diagOffset; + A = _A; + }; + + /** Copy constructor (flat copy). */ + MpcConstraintProduct(const MpcConstraintProduct & rhs) + { + nV = rhs.nV; + nC = rhs.nC; + diagOffset = rhs.diagOffset; + A = rhs.A; + }; + + /** Destructor. */ + virtual ~MpcConstraintProduct(){}; + + /** Assignment operator (flat copy). */ + MpcConstraintProduct & operator=(const MpcConstraintProduct & rhs) + { + if (this != &rhs) { + nV = rhs.nV; + nC = rhs.nC; + diagOffset = rhs.diagOffset; + A = rhs.A; + } else + return *this; + }; + + virtual int_t operator()(int_t constrIndex, const real_t * const x, real_t * const constrValue) const + { + int_t i; + int_t maxI = (int_t)(((real_t)constrIndex) * ((real_t)nV) / ((real_t)nC)) + diagOffset; + maxI = getMin(maxI, nV); + + constrValue[0] = 0.0; + + for (i = 0; i < maxI; ++i) + constrValue[0] += A[constrIndex * nV + i] * x[i]; + + return 0; + }; + +protected: + int_t nV; /**< Number of variables. */ + int_t nC; /**< Number of constraints. */ + int_t diagOffset; /**< ... */ + real_t * A; /**< Pointer to full constraint matrix (typically not needed!). */ +}; + +/** Example for qpOASES main function using the possibility to specify + * user-defined constraint product function. */ +int main() +{ + int_t nQP, nV, nC, nEC; + real_t *H, *g, *A, *lb, *ub, *lbA, *ubA; + real_t cputime; + + real_t xOpt[1000]; + real_t yOpt[1000]; + real_t xOptCP[1000 + 1000]; + real_t yOptCP[1000 + 1000]; + + const char * path = "./cpp/data/oqp/diesel/"; + int_t k = 200; // th problem + + if (readOqpDimensions(path, nQP, nV, nC, nEC) != SUCCESSFUL_RETURN) + return TEST_DATA_NOT_FOUND; + + readOqpData(path, nQP, nV, nC, nEC, &H, &g, &A, &lb, &ub, &lbA, &ubA, 0, 0, 0); + + Options myOptions; + myOptions.setToMPC(); + myOptions.printLevel = PL_LOW; + + int_t nWSR = 500; + cputime = 10.0; + QProblem qp(nV, nC); + qp.setOptions(myOptions); + qp.init(H, &(g[k * nV]), A, &(lb[k * nV]), &(ub[k * nV]), &(lbA[k * nC]), &(ubA[k * nC]), nWSR, &cputime); + qp.getPrimalSolution(xOpt); + qp.getDualSolution(yOpt); + printf("cputime without constraintProduct: %.3ems\n", cputime * 1000.0); + + nWSR = 500; + cputime = 10.0; + MpcConstraintProduct myCP(nV, nC, 1, A); + QProblem qpCP(nV, nC); + qpCP.setOptions(myOptions); + qpCP.setConstraintProduct(&myCP); + qpCP.init( + H, &(g[k * nV]), A, &(lb[k * nV]), &(ub[k * nV]), &(lbA[k * nC]), &(ubA[k * nC]), nWSR, &cputime); + qpCP.getPrimalSolution(xOptCP); + qpCP.getDualSolution(yOptCP); + printf("cputime without constraintProduct: %.3ems\n", cputime * 1000.0); + + delete[] ubA; + delete[] lbA; + delete[] ub; + delete[] lb; + delete[] A; + delete[] g; + delete[] H; + + for (int_t ii = 0; ii < nV; ++ii) + QPOASES_TEST_FOR_NEAR(xOptCP[ii], xOpt[ii]); + + for (int_t ii = 0; ii < nV + nC; ++ii) + QPOASES_TEST_FOR_NEAR(yOptCP[ii], yOpt[ii]); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example1.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example1.cpp new file mode 100644 index 0000000..2743d5f --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example1.cpp @@ -0,0 +1,119 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_example1.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + * + * Very simple example for testing qpOASES (using QProblem class). + */ + +#include +#include + +/** Example for qpOASES main function using the QProblem class. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* Setup data of first QP. */ + real_t H[2 * 2] = {1.0, 0.0, 0.0, 0.5}; + real_t A[1 * 2] = {1.0, 1.0}; + real_t g[2] = {1.5, 1.0}; + real_t lb[2] = {0.5, -2.0}; + real_t ub[2] = {5.0, 2.0}; + real_t lbA[1] = {-1.0}; + real_t ubA[1] = {2.0}; + + /* Setup data of second QP. */ + real_t g_new[2] = {1.0, 1.5}; + real_t lb_new[2] = {0.0, -1.0}; + real_t ub_new[2] = {5.0, -0.5}; + real_t lbA_new[1] = {-2.0}; + real_t ubA_new[1] = {1.0}; + + /* Setting up QProblem object. */ + QProblem example(2, 1); + + Options options; + example.setOptions(options); + + /* Solve first QP. */ + int_t nWSR = 10; + example.init(H, g, A, lb, ub, lbA, ubA, nWSR); + + /* Get and print solution of second QP. */ + real_t xOpt[2]; + real_t yOpt[2 + 1]; + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + printf("\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", + xOpt[0], + xOpt[1], + yOpt[0], + yOpt[1], + yOpt[2], + example.getObjVal()); + + /* Compute KKT tolerances */ + real_t stat, feas, cmpl; + SolutionAnalysis analyzer; + + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-15); + QPOASES_TEST_FOR_TOL(feas, 1e-15); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + /* Solve second QP. */ + nWSR = 10; + example.hotstart(g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR); + + /* Get and print solution of second QP. */ + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + printf("\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", + xOpt[0], + xOpt[1], + yOpt[0], + yOpt[1], + yOpt[2], + example.getObjVal()); + + /* Compute KKT tolerances */ + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-15); + QPOASES_TEST_FOR_TOL(feas, 1e-15); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example1a.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example1a.cpp new file mode 100644 index 0000000..674377c --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example1a.cpp @@ -0,0 +1,104 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_example1a.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + * + * Very simple example for testing qpOASES using the SQProblem class. + */ + +#include +#include + +/** Example for qpOASES main function using the SQProblem class. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* Setup data of first QP. */ + real_t H[2 * 2] = {1.0, 0.0, 0.0, 0.5}; + real_t A[1 * 2] = {1.0, 1.0}; + real_t g[2] = {1.5, 1.0}; + real_t lb[2] = {0.5, -2.0}; + real_t ub[2] = {5.0, 2.0}; + real_t lbA[1] = {-1.0}; + real_t ubA[1] = {2.0}; + + /* Setup data of second QP. */ + real_t H_new[2 * 2] = {1.0, 0.5, 0.5, 0.5}; + real_t A_new[1 * 2] = {1.0, 5.0}; + real_t g_new[2] = {1.0, 1.5}; + real_t lb_new[2] = {0.0, -1.0}; + real_t ub_new[2] = {5.0, -0.5}; + real_t lbA_new[1] = {-2.0}; + real_t ubA_new[1] = {1.0}; + + /* Setting up SQProblem object. */ + SQProblem example(2, 1); + + /* Solve first QP. */ + int_t nWSR = 10; + example.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + + real_t xOpt[2]; + real_t yOpt[2 + 1]; + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + + /* Compute KKT tolerances */ + real_t stat, feas, cmpl; + SolutionAnalysis analyzer; + + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-15); + QPOASES_TEST_FOR_TOL(feas, 1e-15); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + /* Solve second QP. */ + nWSR = 10; + example.hotstart(H_new, g_new, A_new, lb_new, ub_new, lbA_new, ubA_new, nWSR, 0); + + /* Get and print solution of second QP. */ + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + printf("\nxOpt = [ %e, %e ]; objVal = %e\n\n", xOpt[0], xOpt[1], example.getObjVal()); + + /* Compute KKT tolerances */ + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 2e-15); + QPOASES_TEST_FOR_TOL(feas, 1e-15); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example1b.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example1b.cpp new file mode 100644 index 0000000..f7ebc0a --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example1b.cpp @@ -0,0 +1,106 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_example1b.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + * + * Very simple example for testing qpOASES using the QProblemB class. + */ + +#include +#include + +/** Example for qpOASES main function using the QProblemB class. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* Setup data of first QP. */ + real_t H[2 * 2] = {1.0, 0.0, 0.0, 0.5}; + real_t g[2] = {1.5, 1.0}; + real_t lb[2] = {0.5, -2.0}; + real_t ub[2] = {5.0, 2.0}; + + /* Setup data of second QP. */ + real_t g_new[2] = {1.0, 1.5}; + real_t lb_new[2] = {0.0, -1.0}; + real_t ub_new[2] = {5.0, -0.5}; + + /* Setting up QProblemB object. */ + QProblemB example(2); + + Options options; + // options.enableFlippingBounds = BT_FALSE; + options.initialStatusBounds = ST_INACTIVE; + options.numRefinementSteps = 1; + options.enableCholeskyRefactorisation = 1; + example.setOptions(options); + + /* Solve first QP. */ + int_t nWSR = 10; + example.init(H, g, lb, ub, nWSR, 0); + // printf( "\nnWSR = %d\n\n", nWSR ); + + real_t xOpt[2]; + real_t yOpt[2]; + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + + /* Compute KKT tolerances */ + real_t stat, feas, cmpl; + SolutionAnalysis analyzer; + + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-15); + QPOASES_TEST_FOR_TOL(feas, 1e-15); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + /* Solve second QP. */ + nWSR = 10; + example.hotstart(g_new, lb_new, ub_new, nWSR, 0); + // printf( "\nnWSR = %d\n\n", nWSR ); + + /* Get and print solution of second QP. */ + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + printf("\nxOpt = [ %e, %e ]; objVal = %e\n\n", xOpt[0], xOpt[1], example.getObjVal()); + + /* Compute KKT tolerances */ + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-15); + QPOASES_TEST_FOR_TOL(feas, 1e-15); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example2.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example2.cpp new file mode 100644 index 0000000..b94a8aa --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example2.cpp @@ -0,0 +1,122 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_example2.cpp + * \author Hans Joachim Ferreau (thanks to Boris Houska) + * \version 3.2 + * \date 2008-2017 + * + * Very simple example for testing qpOASES in combination + * with the SolutionAnalysis class. + */ + +#include +#include + +/** Example for qpOASES main function using the SolutionAnalysis class. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* Setup data of first QP. */ + real_t H[2 * 2] = {1.0, 0.0, 0.0, 0.5}; + real_t A[1 * 2] = {1.0, 1.0}; + real_t g[2] = {1.5, 1.0}; + real_t lb[2] = {0.5, -2.0}; + real_t ub[2] = {5.0, 2.0}; + real_t lbA[1] = {-1.0}; + real_t ubA[1] = {2.0}; + + /* Setup data of second QP. */ + real_t H_new[2 * 2] = {1.0, 0.5, 0.5, 0.5}; + real_t A_new[1 * 2] = {1.0, 5.0}; + real_t g_new[2] = {1.0, 1.5}; + real_t lb_new[2] = {0.0, -1.0}; + real_t ub_new[2] = {5.0, -0.5}; + real_t lbA_new[1] = {-2.0}; + real_t ubA_new[1] = {1.0}; + + /* Setting up SQProblem object and solution analyser. */ + SQProblem example(2, 1); + SolutionAnalysis analyser; + + /* Solve first QP ... */ + int_t nWSR = 10; + example.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + + /* ... and analyse it. */ + real_t maxKktViolation = analyser.getKktViolation(&example); + printf("maxKktViolation: %e\n", maxKktViolation); + + QPOASES_TEST_FOR_TOL(maxKktViolation, 1e-15); + + /* Solve second QP ... */ + nWSR = 10; + example.hotstart(H_new, g_new, A_new, lb_new, ub_new, lbA_new, ubA_new, nWSR, 0); + + /* ... and analyse it. */ + maxKktViolation = analyser.getKktViolation(&example); + printf("maxKktViolation: %e\n", maxKktViolation); + + QPOASES_TEST_FOR_TOL(maxKktViolation, 2e-15); + + // ------------ VARIANCE-COVARIANCE EVALUATION -------------------- + + real_t * Var = new real_t[5 * 5]; + real_t * Primal_Dual_Var = new real_t[5 * 5]; + + int_t run1, run2; + for (run1 = 0; run1 < 5 * 5; run1++) + Var[run1] = 0.0; + + Var[0] = 1.0; + Var[6] = 1.0; + + // ( 1 0 0 0 0 ) + // ( 0 1 0 0 0 ) + // Var = ( 0 0 0 0 0 ) + // ( 0 0 0 0 0 ) + // ( 0 0 0 0 0 ) + + analyser.getVarianceCovariance(&example, Var, Primal_Dual_Var); + + printf("\nPrimal_Dual_VAR = \n"); + for (run1 = 0; run1 < 5; run1++) { + for (run2 = 0; run2 < 5; run2++) { + printf(" %10f", Primal_Dual_Var[run1 * 5 + run2]); + } + printf("\n"); + } + + delete[] Primal_Dual_Var; + delete[] Var; + + QPOASES_TEST_FOR_NEAR(Primal_Dual_Var[3 * 5 + 3], 26.0); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example4.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example4.cpp new file mode 100644 index 0000000..fef8f47 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example4.cpp @@ -0,0 +1,197 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_example4.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2009-2017 + * + * Very simple example for testing qpOASES (using the possibility to specify + * user-defined constraint product function). + */ + +#include + +#include "../../examples/example4CP.cpp" +#include +#include + +/** Example for qpOASES main function using the possibility to specify + * user-defined constraint product function. */ +int main() +{ + USING_NAMESPACE_QPOASES + + int_t i, j; + + /* Setup data of first QP... */ + real_t H[7 * 7]; + real_t A[50 * 7]; + real_t g[7]; + real_t lbA[50]; + + /* ( 1.0 0.5 | ) + * ( 0.5 2.0 | ) + * ( --------+------------------- ) + * H = ( | 1e-6 ) + * ( | 1e-6 ) + * ( | ... ) + * ( | 1e-6 ) */ + for (i = 0; i < 7 * 7; ++i) + H[i] = 0.0; + for (i = 2; i < 7; ++i) + H[i * 7 + i] = 1.0e-6; + H[0] = 1.0; + H[1] = 0.5; + H[7] = 0.5; + H[8] = 2.0; + + /* ( x.x x.x | 1.0 ) + * ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) + * ( x.x x.x | 1.0 ) + * A = ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) + * ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) + * ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) */ + for (i = 0; i < 50 * 7; ++i) + A[i] = 0.0; + for (i = 0; i < 50; ++i) { + for (j = 0; j < 2; ++j) + A[i * 7 + j] = (real_t)rand() / (real_t)RAND_MAX; + + A[i * 7 + (i / 10) + 2] = 1.0; + } + + /* ( -1.0 ) + * ( -0.5 ) + * ( ---- ) + * g = ( ) + * ( ) + * ( ) + * ( ) */ + for (i = 0; i < 7; ++i) + g[i] = 0.0; + g[0] = -1.0; + g[1] = -0.5; + + for (i = 0; i < 50; ++i) + lbA[i] = 1.0; + + /* ... and setting up user-defined constraint product function. */ + MyConstraintProduct myCP(7, 50, A); + + /* Setting up QProblem object and set construct product function. */ + QProblem exampleCP(7, 50); + exampleCP.setPrintLevel(PL_NONE); + + exampleCP.setConstraintProduct(&myCP); + + /* Solve first QP. */ + real_t cputime = 1.0; + int_t nWSR = 100; + exampleCP.init(H, g, A, 0, 0, lbA, 0, nWSR, &cputime); + + /* Solve second QP using a modified gradient. */ + g[0] = -2.0; + g[1] = 0.5; + + cputime = 1.0; + nWSR = 100; + exampleCP.hotstart(g, 0, 0, lbA, 0, nWSR, &cputime); + + /* Get and print solution of second QP. */ + real_t xOptCP[7]; + real_t yOptCP[7 + 50]; + exampleCP.getPrimalSolution(xOptCP); + exampleCP.getDualSolution(yOptCP); + printf( + "\nxOpt = [ %e, %e, %e ... ]; objVal = %e\n", xOptCP[0], xOptCP[1], xOptCP[2], exampleCP.getObjVal()); + printf("CPU time: %.3f microseconds\n\n", cputime * 1.0e6); + + /* Compute KKT tolerances */ + real_t stat, feas, cmpl; + SolutionAnalysis analyzerCP; + + analyzerCP.getKktViolation(&exampleCP, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-15); + QPOASES_TEST_FOR_TOL(feas, 1e-15); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + /* Do the same without specifying constraint product. */ + QProblem example(7, 50); + example.setPrintLevel(PL_NONE); + + /* Solve first QP. */ + g[0] = -1.0; + g[1] = -0.5; + + cputime = 1.0; + nWSR = 100; + example.init(H, g, A, 0, 0, lbA, 0, nWSR, &cputime); + + /* Solve second QP using a modified gradient. */ + g[0] = -2.0; + g[1] = 0.5; + + cputime = 1.0; + nWSR = 100; + example.hotstart(g, 0, 0, lbA, 0, nWSR, &cputime); + + /* Get and print solution of second QP. */ + real_t xOpt[7]; + real_t yOpt[7 + 50]; + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + printf("\nxOpt = [ %e, %e, %e ... ]; objVal = %e\n", xOpt[0], xOpt[1], xOpt[2], example.getObjVal()); + printf("CPU time: %.3f microseconds\n\n", cputime * 1.0e6); + + /* Compute KKT tolerances */ + SolutionAnalysis analyzer; + + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-15); + QPOASES_TEST_FOR_TOL(feas, 1e-15); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + for (int_t ii = 0; ii < 7; ++ii) + QPOASES_TEST_FOR_NEAR(xOptCP[ii], xOpt[ii]); + + for (int_t ii = 0; ii < 7 + 50; ++ii) + QPOASES_TEST_FOR_NEAR(yOptCP[ii], yOpt[ii]); + + QPOASES_TEST_FOR_NEAR(exampleCP.getObjVal(), example.getObjVal()); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example5.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example5.cpp new file mode 100644 index 0000000..a7e42e7 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example5.cpp @@ -0,0 +1,193 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_example5.cpp + * \author Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2011-2017 + * + * Very simple example for testing qpOASES (using the possibility to + * compute the local linear feedback law) + */ + +#include + +#include "../../examples/example4CP.cpp" +#include +#include + +/** Example for qpOASES main function using the possibility to specify + * user-defined constraint product function. */ +int main() +{ + USING_NAMESPACE_QPOASES + + int_t i, j, jj; + real_t d = 0.0; + + /* Setup data of first QP... */ + real_t H[7 * 7]; + real_t A[50 * 7]; + real_t g[7]; + real_t lbA[50]; + + /* ( 1.0 0.5 | ) + * ( 0.5 2.0 | ) + * ( --------+------------------- ) + * H = ( | 1e-6 ) + * ( | 1e-6 ) + * ( | ... ) + * ( | 1e-6 ) */ + for (i = 0; i < 7 * 7; ++i) + H[i] = 0.0; + for (i = 2; i < 7; ++i) + H[i * 7 + i] = 1.0e-6; + H[0] = 1.0; + H[1] = 0.5; + H[7] = 0.5; + H[8] = 2.0; + + /* ( x.x x.x | 1.0 ) + * ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) + * ( x.x x.x | 1.0 ) + * A = ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) + * ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) + * ( x.x x.x | ... ) + * ( x.x x.x | 1.0 ) */ + for (i = 0; i < 50 * 7; ++i) + A[i] = 0.0; + for (i = 0; i < 50; ++i) { + for (j = 0; j < 2; ++j) + A[i * 7 + j] = (real_t)rand() / (real_t)RAND_MAX; + + A[i * 7 + (i / 10) + 2] = 1.0; + } + + /* ( -1.0 ) + * ( -0.5 ) + * ( ---- ) + * g = ( ) + * ( ) + * ( ) + * ( ) */ + for (i = 0; i < 7; ++i) + g[i] = 0.0; + g[0] = -1.0; + g[1] = -0.5; + + for (i = 0; i < 50; ++i) + lbA[i] = 1.0; + + /* ... and setting up user-defined constraint product function. */ + MyConstraintProduct myCP(7, 50, A); + + /* Setting up QProblem object and set construct product function. */ + QProblem example(7, 50); + example.setConstraintProduct(&myCP); + + /* Solve first QP. */ + real_t cputime = 1.0; + int_t nWSR = 100; + example.init(H, g, A, 0, 0, lbA, 0, nWSR, &cputime); + + /* Get and print solution of QP. */ + real_t xOpt[7], yOpt[7 + 50]; + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + + /* Compute local linear feedback law */ + const int_t n_rhs = 7 + 7 + 50; + real_t g_in[7 * n_rhs]; + real_t b_in[7 * n_rhs]; + real_t bA_in[50 * n_rhs]; + real_t x_out[7 * n_rhs]; + real_t y_out[(7 + 50) * n_rhs]; + + int_t ii; + memset(g_in, 0, sizeof(g_in)); + memset(b_in, 0, sizeof(b_in)); + memset(bA_in, 0, sizeof(bA_in)); + + for (ii = 0; ii < 7; ++ii) + g_in[ii * 7 + ii] = 1.0; + for (ii = 0; ii < 7; ++ii) + b_in[(ii + 7) * 7 + ii] = 1.0; + for (ii = 0; ii < 50; ++ii) + bA_in[(ii + 14) * 50 + ii] = 1.0; + + example.solveCurrentEQP(n_rhs, g_in, b_in, b_in, bA_in, bA_in, x_out, y_out); + + /* Verify validity of local feedback law by perturbation and hot starts */ + real_t perturb = 1.0e-6; + real_t nrm = 0.0; + for (ii = 0; ii < n_rhs; ++ii) { + for (jj = 0; jj < 7; ++jj) + g_in[ii * 7 + jj] = g[jj] + g_in[ii * 7 + jj] * perturb; + for (jj = 0; jj < 50; ++jj) + bA_in[ii * 50 + jj] = lbA[jj] + bA_in[ii * 50 + jj] * perturb; + + nWSR = 100; + example.hotstart(&g_in[ii * 7], 0, 0, &bA_in[ii * 50], 0, nWSR, 0); + + real_t xPer[7], yPer[7 + 50]; + example.getPrimalSolution(xPer); + example.getDualSolution(yPer); + + for (jj = 0; jj < 7; ++jj) { + d = getAbs(x_out[ii * 7 + jj] * perturb - (xPer[jj] - xOpt[jj])); + if (nrm < d) + nrm = d; + } + for (jj = 0; jj < 7 + 50; ++jj) { + d = getAbs(y_out[ii * (7 + 50) + jj] * perturb - (yPer[jj] - yOpt[jj])); + if (nrm < d) + nrm = d; + } + } + printf("Maximum perturbation over all directions: %e\n", nrm); + + QPOASES_TEST_FOR_TOL(nrm, 1e-15); + + /* // print feedback matrix + for (ii = 0; ii < n_rhs; ++ii) + { + printf ("x: "); + for (jj = 0; jj < 7; ++jj ) + printf ("%8.2e ", x_out[ii*7+jj]); + printf (" y: "); + for (jj = 0; jj < 7+50; ++jj ) + printf ("%8.2e ", y_out[ii*(7+50)+jj]); + printf("\n"); + } +*/ + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example6.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example6.cpp new file mode 100644 index 0000000..2202489 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example6.cpp @@ -0,0 +1,131 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_example6.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + * + * Example that caused troubles in an earlier release. + */ + +#include +#include + +/** Example for qpOASES main function using the QProblem class. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* Setup data of first QP. */ + real_t H[5 * 5] = {1.224642131370767e+01, + 2.908638763113702e+00, + 0.0, + 0.0, + 0.0, + 2.908638763113702e+00, + 2.497106275003180e+00, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 5.158460640334052e-02, + 4.723556059962540e-02, + 0.0, + 0.0, + 0.0, + 4.723556059962540e-02, + 4.325317843302175e-02}; + real_t A[2 * 5] = {-1.404358970692652e+00, + -2.556613491156063e+00, + 3.202524559238066e+00, + -1.0, + 0.0, + 6.587910295430314e-01, + -5.349454475937998e-01, + 4.391976356955536e-01, + 0.0, + -1.0}; + real_t g[5] = {2.474135331302147e+01, + 5.857286430296258e+00, + 2.359382646348721e-01, + 1.721047069188781e-01, + 1.575947337774199e-01}; + real_t lb[5] = {-10.0, -10.0, -10.0, -10.0, -10.0}; + real_t ub[5] = {10.0, 10.0, 10.0, 10.0, 10.0}; + real_t lbA[2] = {1.643135416077167e+00, 1.056813028189597e+00}; + real_t ubA[2] = {1.643135416077167e+00, 1.056813028189597e+00}; + + /* Setting up QProblem object. */ + QProblem example(5, 2); + + Options options; + // options.enableFlippingBounds = BT_FALSE; + // options.enableEqualities = BT_TRUE; + // options.initialStatusBounds = ST_INACTIVE; + example.setOptions(options); + example.setPrintLevel(PL_NONE); + + /* Solve first QP. */ + returnValue retVal; + int_t simpleStatus = -1; + + int_t nWSR = 10; + retVal = example.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + simpleStatus = getSimpleStatus(retVal, BT_TRUE); + + QPOASES_TEST_FOR_TRUE(simpleStatus == 0); + + /* Get and print solution of second QP. */ + real_t xOpt[5]; + real_t yOpt[5 + 2]; + + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + printf("\nxOpt = [ %e, %e, ... ]; objVal = %e\n\n", xOpt[0], xOpt[1], example.getObjVal()); + + /* Compute KKT tolerances */ + real_t stat, feas, cmpl; + SolutionAnalysis analyzer; + + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-14); + QPOASES_TEST_FOR_TOL(feas, 1e-14); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example7.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example7.cpp new file mode 100644 index 0000000..268479e --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_example7.cpp @@ -0,0 +1,131 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_example7.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + * + * Example that caused troubles in an earlier release. + */ + +#include +#include + +int main() +{ + USING_NAMESPACE_QPOASES + + real_t H[5 * 5] = {0.8514828085899353, + -0.15739890933036804, + -0.081726007163524628, + -0.530426025390625, + 0.16773293912410736, + -0.15739890933036804, + 1.1552412509918213, + 0.57780224084854126, + -0.0072606131434440613, + 0.010559185408055782, + -0.081726007163524628, + 0.57780224084854126, + 0.28925251960754395, + 5.324830453901086e-006, + -3.0256599075073609e-006, + -0.530426025390625, + -0.0072606131434440613, + 5.324830453901086e-006, + 0.35609596967697144, + -0.15124998986721039, + 0.16773293912410736, + 0.010559185408055782, + -3.0256599075073609e-006, + -0.15124998986721039, + 0.15129712224006653}; + real_t g[5] = {0.30908384919166565, + 0.99325823783874512, + 0.49822014570236206, + -0.26309865713119507, + 0.024296050891280174}; + real_t A[5 * 5] = {1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1}; + real_t lb[5] = {-0.052359879016876221, + -0.052359879016876221, + -0.052359879016876221, + -0.052359879016876221, + -0.052359938621520996}; + real_t ub[5] = {0.052359879016876221, 0.052359879016876221, 0.052359879016876221, 0, 0}; + real_t lbA[5] = {-0.052359879016876221, + -0.052359879016876221, + -0.052359879016876221, + -0.052359879016876221, + -0.052359938621520996}; + real_t ubA[5] = {0.052359879016876221, 0.052359879016876221, 0.052359879016876221, 0, 0}; + + /* Setting up QProblem object. */ + QProblem example(5, 5); + + /* Solve first QP. */ + int_t nWSR = 100; + returnValue retVal = example.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + printf("nWSR = %d, retVal = %d (%s)\n", + (int)nWSR, + retVal, + getGlobalMessageHandler()->getErrorCodeMessage(retVal)); + + real_t sol[5] = {0}; + real_t yOpt[5 + 5] = {0}; + example.getPrimalSolution(sol); + example.getDualSolution(yOpt); + + printf("l1 = %f, l2 = %f, l3 = %f, l4 = %f, l5 = %f\n", + (float)lb[0], + (float)lb[1], + (float)lb[2], + (float)lb[3], + (float)lb[4]); + printf("x1 = %f, x2 = %f, x3 = %f, x4 = %f, x5 = %f\n", + (float)sol[0], + (float)sol[1], + (float)sol[2], + (float)sol[3], + (float)sol[4]); + printf("u1 = %f, u2 = %f, u3 = %f, u4 = %f, u5 = %f\n", + (float)ub[0], + (float)ub[1], + (float)ub[2], + (float)ub[3], + (float)ub[4]); + + /* Compute KKT tolerances */ + real_t stat, feas, cmpl; + SolutionAnalysis analyzer; + + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-15); + QPOASES_TEST_FOR_TOL(feas, 1e-15); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + return TEST_PASSED; +} diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_exampleLP.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_exampleLP.cpp new file mode 100644 index 0000000..998ea46 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_exampleLP.cpp @@ -0,0 +1,107 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_exampleLP.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2008-2017 + * + * Very simple example for solving a LP sequence using qpOASES. + */ + +#include +#include + +/** Example for qpOASES main function solving LPs. */ +int main() +{ + USING_NAMESPACE_QPOASES + + real_t tol = 1e-14; + + /* Setup data of first LP. */ + real_t A[1 * 2] = {1.0, 1.0}; + real_t g[2] = {1.5, 1.0}; + real_t lb[2] = {0.5, -2.0}; + real_t ub[2] = {5.0, 2.0}; + real_t lbA[1] = {-1.0}; + real_t ubA[1] = {2.0}; + + /* Setup data of second LP. */ + real_t g_new[2] = {1.0, 1.5}; + real_t lb_new[2] = {0.0, -1.0}; + real_t ub_new[2] = {5.0, -0.5}; + real_t lbA_new[1] = {-2.0}; + real_t ubA_new[1] = {1.0}; + + /* Setting up QProblem object with zero Hessian matrix. */ + QProblem example(2, 1, HST_ZERO); + + Options options; + /*options.setToMPC();*/ + example.setOptions(options); + + /* Solve first LP. */ + int_t nWSR = 10; + example.init(0, g, A, lb, ub, lbA, ubA, nWSR, 0); + + real_t xOpt[2]; + real_t yOpt[2 + 1]; + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + + /* Compute KKT tolerances */ + real_t stat, feas, cmpl; + SolutionAnalysis analyzer; + printf("%d\n", example.getHessianType()); + + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, tol); + QPOASES_TEST_FOR_TOL(feas, tol); + QPOASES_TEST_FOR_TOL(cmpl, tol); + + /* Solve second LP. */ + nWSR = 10; + example.hotstart(g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR, 0); + + /* Get and print solution of second LP. */ + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + printf("\nxOpt = [ %e, %e ]; objVal = %e\n\n", xOpt[0], xOpt[1], example.getObjVal()); + + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, tol); + QPOASES_TEST_FOR_TOL(feas, tol); + QPOASES_TEST_FOR_TOL(cmpl, tol); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_externalChol1.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_externalChol1.cpp new file mode 100644 index 0000000..23d82f2 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_externalChol1.cpp @@ -0,0 +1,105 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_externalChol1.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2015-2017 + * + * Very simple example for testing qpOASES using the QProblem class + * and providing a pre-computed Cholesky factor of the Hessian matrix. + */ + +#include + +/** Example for qpOASES main function using the QProblem class. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* Setup data of first QP. */ + real_t H[2 * 2] = {1.0, 0.0, 0.0, 0.5}; + real_t A[1 * 2] = {1.0, 1.0}; + real_t g[2] = {1.5, 1.0}; + real_t lb[2] = {0.5, -2.0}; + real_t ub[2] = {5.0, 2.0}; + real_t lbA[1] = {-1.0}; + real_t ubA[1] = {2.0}; + + /* Setup data of second QP. */ + real_t g_new[2] = {1.0, 1.5}; + real_t lb_new[2] = {0.0, -1.0}; + real_t ub_new[2] = {5.0, -0.5}; + real_t lbA_new[1] = {-2.0}; + real_t ubA_new[1] = {1.0}; + + real_t R[2 * 2] = {sqrt(1.0), 0.0, 0.0, sqrt(0.5)}; + + /* Setting up QProblem object. */ + QProblem example(2, 1); + + Options options; + example.setOptions(options); + + /* Solve first QP. */ + int_t nWSR = 10; + example.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0, 0, 0, 0, 0, R); + + /* Get and print solution of first QP. */ + real_t xOpt[2]; + real_t yOpt[2 + 1]; + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + printf("\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", + xOpt[0], + xOpt[1], + yOpt[0], + yOpt[1], + yOpt[2], + example.getObjVal()); + + /* Solve second QP. */ + nWSR = 10; + example.hotstart(g_new, lb_new, ub_new, lbA_new, ubA_new, nWSR); + + /* Get and print solution of second QP. */ + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + printf("\nxOpt = [ %e, %e ]; yOpt = [ %e, %e, %e ]; objVal = %e\n\n", + xOpt[0], + xOpt[1], + yOpt[0], + yOpt[1], + yOpt[2], + example.getObjVal()); + + example.printOptions(); + /*example.printProperties();*/ + + return 0; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_gradientShift.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_gradientShift.cpp new file mode 100644 index 0000000..22777ec --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_gradientShift.cpp @@ -0,0 +1,116 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2009 by Hans Joachim Ferreau et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_gradientShift.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + * + * Simple test case which caused troubles in version 2.0. + */ + +#include +#include +#include +#include + +/** Running simple test case which caused troubles in version 2.0. */ +int main() +{ + USING_NAMESPACE_QPOASES + + real_t H[2 * 2] = {0.055944055944055944, 0, 0, 0}; + real_t A[1 * 2] = {0.70514808036997589, -1}; + // real_t g[2] = { -15.830543073928741, 0}; + real_t g[2] = {0, 0}; + real_t lb[2] = {137.00242299940646, 154.0}; + real_t ub[2] = {282.19008595111382, 198.98579740786641}; + real_t lbA[1] = {0.0}; + real_t ubA[1] = {0.0}; + + real_t gStart = -16.4; + + /* Setting up QProblem object. */ + QProblem example(2, 1); + Options options; + options.setToMPC(); + options.printLevel = REFER_NAMESPACE_QPOASES PL_NONE; + example.setOptions(options); + + returnValue ret; + int_t nWSR = 10; + real_t Xopt[2] = {0.0, 0.0}; + // fprintf(stdFile, "g[0]\t,\tReturn code\n"); + int_t errorCount = 0; + int_t i = 0; + real_t granularity = 0.00001; + g[0] = gStart; + for (i = 0; i < 70000; i++) { + g[0] += granularity; + /* Solve first QP. */ + nWSR = 10; + ret = example.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + if (ret != SUCCESSFUL_RETURN) { + // fprintf(stdFile, "%f\t,\t%d\n",g[0],ret); + errorCount++; + } + // fprintf(stdFile, "%f\t,\t%d\n",g[0],ret); + } + example.printProperties(); + fprintf(stdFile, "#Number of optimizer runs: %d\n", (int)i); + fprintf(stdFile, "#g[0] test interval: %f < g[0] < %f\n", gStart, g[0]); + fprintf(stdFile, "#Granularity: %f\n", granularity); + real_t errorPercent = real_t(errorCount) / real_t(i) * 100.0; + fprintf(stdFile, "#Number of errors (error): %d (%f)\n", (int)errorCount, errorPercent); + + example.getPrimalSolution(Xopt); + fprintf(stdFile, "#Optimization primary result : LD=%f BD=%f\n", Xopt[0], Xopt[1]); + + real_t Yopt[3] = {0.0, 0.0, 0.0}; + example.getDualSolution(Yopt); + fprintf(stdFile, "#Optimization dual result : %f %f %f8\n", Yopt[0], Yopt[1], Yopt[2]); + + int_t Nc = 0; + Nc = example.getNC(); + fprintf(stdFile, "#Number of constraints : %d\n", (int)Nc); + + int_t Nec = 0; + Nec = example.getNEC(); + fprintf(stdFile, "#Number of equality constraints : %d\n", (int)Nec); + + int_t Nac = 0; + Nac = example.getNAC(); + fprintf(stdFile, "#Number of active constraints : %d\n", (int)Nac); + + int_t Niac = 0; + Niac = example.getNIAC(); + fprintf(stdFile, "#Number of inactive constraints : %d\n", (int)Niac); + + QPOASES_TEST_FOR_TRUE(errorCount == 0) + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_guessedWS1.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_guessedWS1.cpp new file mode 100644 index 0000000..55c0eee --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_guessedWS1.cpp @@ -0,0 +1,139 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_guessedWS1.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2014-2017 + * + * Very simple example for testing qpOASES (using QProblem class). + */ + +#include +#include + +/** Example for qpOASES main function using the QProblem class. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* Setup data of first QP. */ + real_t H[4 * 4] = {1.0, 0.0, 0.0, 0.5, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.5, 0.0, 0.0, 1.0}; + real_t A[3 * 4] = {1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0}; + real_t g[4] = {1.5, 1.0, -1.0, -1.0}; + real_t lb[4] = {0.5, -2.0, 0.0, 0.0}; + real_t ub[4] = {1.0, 2.0, 1.0, 0.5}; + real_t lbA[3] = {-1.0, -1.0, -1.0}; + real_t ubA[3] = {0.0, 0.25, 1.0}; + + /* Setting up QProblem object. */ + QProblem example(4, 3); + + Options options; + example.setOptions(options); + + /* Solve first QP. */ + int_t nWSR = 10; + example.init(H, g, A, lb, ub, lbA, ubA, nWSR); + + /* Get and print solution of second QP. */ + real_t xOpt[4]; + real_t yOpt[4 + 3]; + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + print(xOpt, 4, "xOpt"); + print(yOpt, 4 + 3, "yOpt"); + printf("objVal = %e\n\n", example.getObjVal()); + + /* Compute KKT tolerances */ + real_t stat, feas, cmpl; + SolutionAnalysis analyzer; + + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-15); + QPOASES_TEST_FOR_TOL(feas, 1e-15); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + /* Solve first QP again (with optimal guess for working set). */ + Bounds prevBounds; + Constraints prevConstraints; + + example.getBounds(prevBounds); + example.getConstraints(prevConstraints); + + nWSR = 10; + example.hotstart(g, lb, ub, lbA, ubA, nWSR, 0, &prevBounds, &prevConstraints); + + /* Get and print solution of second QP. */ + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + print(xOpt, 4, "xOpt"); + print(yOpt, 4 + 3, "yOpt"); + printf("objVal = %e\n\n", example.getObjVal()); + + /* Compute KKT tolerances */ + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-15); + QPOASES_TEST_FOR_TOL(feas, 1e-15); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + /* Solve first QP again (with inaccurate guess for working set). */ + prevBounds.print(); + prevBounds.rotate(1); + // prevBounds.moveFixedToFree(0); + prevBounds.print(); + + prevConstraints.print(); + // prevConstraints.moveInactiveToActive(0,ST_LOWER); + prevConstraints.moveActiveToInactive(1); + prevConstraints.print(); + + nWSR = 10; + example.hotstart(g, lb, ub, lbA, ubA, nWSR, 0, &prevBounds, &prevConstraints); + + /* Get and print solution of second QP. */ + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + print(xOpt, 4, "xOpt"); + print(yOpt, 4 + 3, "yOpt"); + printf("objVal = %e\n\n", example.getObjVal()); + + /* Compute KKT tolerances */ + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-15); + QPOASES_TEST_FOR_TOL(feas, 1e-15); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_hs268.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_hs268.cpp new file mode 100644 index 0000000..840bf8a --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_hs268.cpp @@ -0,0 +1,97 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_hs268.cpp + * \author Andreas Potschka, Christian Kirches, Hans Joachim Ferreau + * \version 3.2 + * \date 2010-2017 + * + * Unit test running all benchmark examples stored in problems directory. + */ + +#include +#include +#include +#include +#include + +/** Run benchmark examples. */ +int main(int argc, char * argv[]) +{ + USING_NAMESPACE_QPOASES + + /* 1) Define benchmark arguments. */ + BooleanType isSparse = BT_FALSE; + // BooleanType isSparse = BT_TRUE; + Options options; + options.setToDefault(); + // options.setToMPC(); + // options.setToReliable(); + // options.printLevel = PL_LOW; + // options.printLevel = PL_MEDIUM; + options.printLevel = PL_TABULAR; + + int_t nWSR; + int_t npass = 0; + real_t maxCPUtime; /* seconds */ + real_t maxStationarity = 0.0, maxFeasibility = 0.0, maxComplementarity = 0.0; + + char oqpProblem[MAX_STRING_LENGTH]; + char problem[] = "HS268"; + returnValue returnvalue; + + /* 3) Run benchmark. */ + fprintf(stdFile, "%-10s ", problem); + fflush(stdFile); + + snprintf(oqpProblem, MAX_STRING_LENGTH, "../testing/cpp/data/problems/%s/", problem); + maxCPUtime = 100.0; + nWSR = 100; + + returnvalue = runOqpBenchmark( + oqpProblem, isSparse, options, nWSR, maxCPUtime, maxStationarity, maxFeasibility, maxComplementarity); + + if (returnvalue == RET_UNABLE_TO_READ_BENCHMARK) + return TEST_DATA_NOT_FOUND; + + if (returnvalue == SUCCESSFUL_RETURN) + npass += 1; + + QPOASES_TEST_FOR_TRUE(npass >= 1); + + printf("\n"); + printf("stat: %e\n", maxStationarity); + printf("feas: %e\n", maxFeasibility); + printf("cmpl: %e\n", maxComplementarity); + + QPOASES_TEST_FOR_TOL(maxStationarity, 1e-11); + QPOASES_TEST_FOR_TOL(maxFeasibility, 1e-14); + QPOASES_TEST_FOR_TOL(maxComplementarity, 1e-14); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_identitySqproblem.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_identitySqproblem.cpp new file mode 100644 index 0000000..64d0b43 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_identitySqproblem.cpp @@ -0,0 +1,182 @@ +#include + +int main(int argc, char ** argv) +{ + USING_NAMESPACE_QPOASES + + // Quadratic prog param + real_t H[7 * 7]; // here H = Id + real_t A[6 * 7] = {-0.270792, + -0.140175, + -0.249325, + -0.412277, + -0.250952, + -0.298071, + 1.49078e-19, + 0.534738, + 0.00704892, + 0.483388, + -0.193107, + 0.302895, + -0.2471, + -2.1684e-17, + 0, + -0.451464, + 0.117068, + -0.348254, + 0.00703103, + 0.00620952, + -7.96211e-20, + 0, + 0.0502231, + 0.393264, + -0.584145, + 0.758854, + -0.637889, + -0.023751, + 0, + 0.998738, + -0.0197759, + 0.766682, + 0.632337, + 0.769921, + 0.00352803, + 1, + 4.89658e-12, + 0.919213, + 0.266407, + -0.155855, + 0.017872, + -0.999712}; // the jacobian + real_t g[7]; // set to 0 + real_t lb[7]; // joints lower velocity limits + real_t ub[7]; // joints upper velocity limits + // Position control - no orientation + real_t lbA[6] = {0.00442514, -0.122699, -0.0725897, 0, 0, 0}; // stylus velocity : ubA = lbA + real_t ubA[6] = {0.00442514, -0.122699, -0.0725897, 0, 0, 0}; + ; // stylus velocity : ubA = lbA + int_t nWSR = 1000; // specifies the maximum number of working set recalculation + real_t cpu_time = 1.0; // maximum allowed CPU time(s) for the whole initialisation + real_t xOpt[7]; + + H[0] = 1.0; + for (int i = 1; i < 7 * 7; ++i) { + if (i % 8 == 0) + H[i] = 1.0; + else + H[i] = 0.0; + } + for (int i = 0; i < 7; i++) { + g[i] = 0.0; // g = 0 + } + + // joints velocities limits + lb[0] = -1.5; // s0 joints lower limits + lb[1] = -1.5; // s1 joints lower limits + lb[2] = -1.5; // e0 joints lower limits + lb[3] = -1.5; // e1 joints lower limits + lb[4] = -4.0; // w0 joints lower limits + lb[5] = -4.0; // w1 joints lower limits + lb[6] = -4.0; // w2 joints lower limits + for (int i = 0; i < 7; i++) { + ub[i] = -lb[i]; // joints lower limits + } + cpu_time = 1.0; // maximum amount of cpu time + nWSR = 100; + + /*//linear and angular velocities + the first three elements represent the linear velocity (px, py, pz) while + the next three are the angular velocity (yaw, pitch, roll)*/ + for (int i = 0; i < 6; i++) { + lbA[i] = 0.0; + ubA[i] = lbA[i]; + } + + printf("Initialisation of the QP problem"); + SQProblem joints_velocities(7, + 6); // create qp problem of 7 variables and 6 constraints with the hessian matrix set with the identity + joints_velocities.init(H, g, A, lb, ub, lbA, ubA, nWSR, &cpu_time); + if (joints_velocities.isSolved()) + printf("qp problem solved"); + if (joints_velocities.isInfeasible()) + printf("qp problem not feasible"); + joints_velocities.getPrimalSolution(xOpt); + printf("\nxOpt = [ %e, %e, %e, %e, %e, %e, %e ]; objVal = %e\n\n", + xOpt[0], + xOpt[1], + xOpt[2], + xOpt[3], + xOpt[4], + xOpt[5], + xOpt[6], + joints_velocities.getObjVal()); + + A[0] = -0.284328; + A[1] = -0.118524; + A[2] = -0.190925; + A[3] = -0.350569; + A[4] = -0.318565; + A[5] = -0.229695; + A[6] = 3.93023e-19; + A[7] = 0.559749; + A[8] = 0.0299793; + A[9] = 0.431302; + A[10] = -0.0760635; + A[11] = 0.234798; + A[12] = -0.311727; + A[13] = -9.11272e-17; + A[14] = 0; + A[15] = -0.403937; + A[16] = 0.293076; + A[17] = -0.267321; + A[18] = 0.00656818; + A[19] = 0.00311694; + A[20] = -3.12555e-19; + A[21] = 0; + A[22] = 0.245215; + A[23] = 0.688118; + A[24] = -0.611048; + A[25] = 0.592551; + A[26] = -0.804865; + A[27] = -0.0181344; + A[28] = 0; + A[29] = 0.969469; + A[30] = -0.174051; + A[31] = 0.38453; + A[32] = 0.801775; + A[33] = 0.593226; + A[34] = 0.003365; + A[35] = 1; + A[36] = 4.89658e-12; + A[37] = 0.704415; + A[38] = 0.691923; + A[39] = 0.0777117; + A[40] = 0.0165947; + A[41] = -0.99983; + + lbA[0] = -2.4834; + lbA[1] = -1.4414; + lbA[2] = -1.85119; + lbA[3] = 0; + lbA[4] = 0; + lbA[5] = 0; + + for (int i = 0; i < 6; i++) { + ubA[i] = lbA[i]; + } + + nWSR = 100; + cpu_time = 1.0; + joints_velocities.init(H, g, A, lb, ub, lbA, ubA, nWSR, &cpu_time); + joints_velocities.getPrimalSolution(xOpt); + printf("\nxOpt = [ %e, %e, %e, %e, %e, %e, %e ]; objVal = %e\n\n", + xOpt[0], + xOpt[1], + xOpt[2], + xOpt[3], + xOpt[4], + xOpt[5], + xOpt[6], + joints_velocities.getObjVal()); + return 0; +} diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_indexlist.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_indexlist.cpp new file mode 100644 index 0000000..023cb9d --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_indexlist.cpp @@ -0,0 +1,91 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_indexlist.cpp + * \author Andreas Potschka, Hans Joachim Ferreau + * \version 3.2 + * \date 2010-2017 + * + * Unit test for Indexlist class. + */ + +#include +#include + +/** Test Indexlist sorting */ +int main() +{ + USING_NAMESPACE_QPOASES + + Indexlist il(10); + int_t i, *numbers; + + il.addNumber(1); + il.addNumber(3); + il.addNumber(5); + il.addNumber(2); + il.addNumber(4); + il.addNumber(0); + il.addNumber(7); + il.addNumber(6); + il.addNumber(8); + il.addNumber(9); + + il.getNumberArray(&numbers); + fprintf(stdFile, "Unsorted numbers: "); + for (i = 0; i < 10; i++) + fprintf(stdFile, " %2d", (int)(numbers[i])); + fprintf(stdFile, "\n"); + + fprintf(stdFile, "Unsorted index of number 0: %3d\n", (int)(il.getIndex(0))); + + QPOASES_TEST_FOR_TRUE(il.getIndex(0) == 5) + + il.removeNumber(5); + fprintf(stdFile, "Unsorted index of (removed) number 5: %3d\n", (int)(il.getIndex(5))); + + QPOASES_TEST_FOR_TRUE(il.getIndex(5) == -1) + + il.getNumberArray(&numbers); + fprintf(stdFile, "Unsorted numbers: "); + for (i = 0; i < 9; i++) + fprintf(stdFile, " %2d", (int)(numbers[i])); + fprintf(stdFile, "\n"); + + il.swapNumbers(2, 7); + + il.getNumberArray(&numbers); + fprintf(stdFile, "Unsorted numbers: "); + for (i = 0; i < 9; i++) + fprintf(stdFile, " %2d", (int)(numbers[i])); + fprintf(stdFile, "\n"); + + QPOASES_TEST_FOR_TRUE(numbers[2] == 7) + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_infeasible1.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_infeasible1.cpp new file mode 100644 index 0000000..3b54416 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_infeasible1.cpp @@ -0,0 +1,132 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_infeasible1.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2015-2017 + * + * Example to test occurence of infeasible QP. + */ + +#include +#include + +/** Example for qpOASES main function using the QProblem class. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* Setup data of first QP. */ + real_t H[5 * 5] = {1.224642131370767e+01, + 2.908638763113702e+00, + 0.0, + 0.0, + 0.0, + 2.908638763113702e+00, + 2.497106275003180e+00, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 5.158460640334052e-02, + 4.723556059962540e-02, + 0.0, + 0.0, + 0.0, + 4.723556059962540e-02, + 4.325317843302175e-02}; + real_t A[2 * 5] = {-1.404358970692652e+00, + -2.556613491156063e+00, + 3.202524559238066e+00, + -1.0, + 0.0, + 6.587910295430314e-01, + -5.349454475937998e-01, + 4.391976356955536e-01, + 0.0, + -1.0}; + real_t g[5] = {2.474135331302147e+01, + 5.857286430296258e+00, + 2.359382646348721e-01, + 1.721047069188781e-01, + 1.575947337774199e-01}; + real_t lb[5] = {5.0, 5.0, 8.0, 9.0, 5.0}; + real_t ub[5] = {10.0, 10.0, 10.0, 10.0, 10.0}; + real_t lbA[2] = {1.643135416077167e+00, 1.056813028189597e+00}; + real_t ubA[2] = {1.643135416077167e+00, 1.056813028189597e+00}; + + /* Setting up QProblem object. */ + QProblem example(5, 2); + + Options options; + // options.enableFlippingBounds = BT_FALSE; + // options.enableEqualities = BT_TRUE; + // options.initialStatusBounds = ST_INACTIVE; + example.setOptions(options); + example.setPrintLevel(PL_NONE); + + /* Solve first QP. */ + returnValue retVal; + int_t simpleStatus = -1; + + int_t nWSR = 10; + retVal = example.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + simpleStatus = getSimpleStatus(retVal, BT_TRUE); + + /* Get and print solution of second QP. */ + real_t xOpt[5]; + real_t yOpt[5 + 2]; + + printf("getPrimalSolution = %d\n", example.getPrimalSolution(xOpt)); + printf("getDualSolution = %d\n", example.getDualSolution(yOpt)); + printf("\nxOpt = [ %e, %e, %e, %e, %e ]; objVal = %e\n\n", + xOpt[0], + xOpt[1], + xOpt[2], + xOpt[3], + xOpt[4], + example.getObjVal()); + + /* Compute KKT tolerances */ + real_t stat, feas, cmpl; + + getKktViolation(5, 2, H, g, A, lb, ub, lbA, ubA, xOpt, yOpt, stat, feas, cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TRUE(simpleStatus == -2); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_janick1.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_janick1.cpp new file mode 100644 index 0000000..64dd93a --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_janick1.cpp @@ -0,0 +1,494 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_janick1.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2011-2017 + * + * Example that causes troubles when hotstarting. + */ + +#include +#include + +#include + +//#define __MAKE_POS_DEF__ +#undef __MAKE_POS_DEF__ + +int main() +{ + USING_NAMESPACE_QPOASES + + int_t nWSR = 100; + /* Setting up QProblem object. */ + SQProblem example(11, 3); + + Options options; + options.setToFast(); + // options.setToDefault(); + // options.initialStatusBounds = qpOASES::ST_INACTIVE; + example.setOptions(options); + + /* Setup data of first QP. */ + real_t H[11 * 11] = {6.20100988531485e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -3.84861756786704e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -7.43268431723266e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 1.00000000000000e-01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -3.84861756786704e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 5.41188294952735e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 4.61304826562310e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.10000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 1.00000000000000e-01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.01000000000000e+01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.10000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -7.43268431723266e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 4.61304826562310e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.73544778892019e+01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.00000000000000e+01}; + real_t g[11] = {-1.28196485091041e-07, + 1.13322235104306e-08, + 4.52417455660281e-06, + 1.95881304363781e-07, + 1.61991589634459e-06, + 2.69786724710014e-09, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.18185813270785e+02, + 9.58903285459640e-06, + 3.82276791847511e-06}; + real_t zLow[11] = {-1.07876236159966e+01, + -1.00000000002784e+12, + -1.00000000000000e+12, + 0.00000000000000e+00, + -7.00000000000000e+00, + -2.60479553037772e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -4.50000000000000e+01, + -1.00000000000000e+12}; + real_t zUpp[11] = {9.99999999989212e+11, + 9.99999999972157e+11, + 1.00000000000000e+12, + 4.68471854329546e+01, + 7.00000000000000e+00, + 9.99999999997395e+11, + 1.00000000000000e+12, + 1.00000000000000e+12, + 0.00000000000000e+00, + 4.50000000000000e+01, + 1.00000000000000e+12}; + real_t D[11 * 3] = {1.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.00000000000000e-02, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -1.00000000000000e-02, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 1.00000000000000e+00, + 0.00000000000000e+00, + -1.00000000000000e-02, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00}; + real_t dLow[3] = {-1.00000000000000e+12, -1.00000000000000e+12, -1.00000000000000e+12}; + real_t dUpp[3] = {2.12376384003361e-01, 4.78762361599664e+00, 8.95204469622285e-01}; + +#ifdef __MAKE_POS_DEF__ + H[9 * 11 + 9] += 30; +#endif + returnValue status = example.init(H, g, D, zLow, zUpp, dLow, dUpp, nWSR); + printf("\nqpOASES_status = %d\n", (int)status); + + /* Get and print solution of first QP. */ + real_t xOpt[11]; + real_t yOpt[11 + 3]; + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + printf("first QP:\n"); + for (int_t ii = 0; ii < 11; ++ii) { + printf("x[%d] = %.3e\n", (int)ii, xOpt[ii]); + } + + /* Compute KKT tolerances */ + real_t stat, feas, cmpl; + SolutionAnalysis analyzer; + + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("\nstat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-9); + QPOASES_TEST_FOR_TOL(feas, 1e-7); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + nWSR = 100; + + /* Setup data of second QP. */ + real_t H2[11 * 11] = {6.20100988531485e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -3.84861756786704e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -7.43268433147671e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 1.00000000000000e-01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -3.84861756786704e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 5.41188294952735e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 4.61304827446359e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.10000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 1.00000000000000e-01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.01000000000000e+01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.10000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -7.43268433147671e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 4.61304827446359e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.73544778550554e+01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.00000000000000e+01}; + real_t g2[11] = {-6.57752219998813e-04, + 3.61759517784935e-04, + -7.51224940044046e-05, + 6.01232615232452e-04, + 1.23562395380546e-04, + 4.59040118744990e-05, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.18185813270785e+02, + 3.38813178901720e-21, + 0.00000000000000e+00}; + real_t zLow2[11] = {-2.41857058824735e-08, + -2.77410094895458e-10, + -9.90563843681406e-09, + -3.85694249871449e-08, + 4.50633213817586e-14, + -2.22044604925031e-15, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -4.49999952054836e+01, + -1.00000000000000e+12}; + real_t zUpp2[11] = { + -2.41857058824735e-08, + -2.77410094895458e-10, + -9.90563843681406e-09, + -3.85694249871449e-08, + 4.50633213817586e-14, + -2.22044604925031e-15, + 1.00000000000000e+12, + 1.00000000000000e+12, + 0.00000000000000e+00, + 4.50000047945164e+01, + 1.00000000000000e+12, + }; + real_t D2[11 * 3] = {1.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.00000000000000e-02, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -1.00000000000000e-02, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 1.00000000000000e+00, + 0.00000000000000e+00, + -1.00000000000000e-02, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00}; + real_t dLow2[3] = {-1.00000000000000e+12, -1.00000000000000e+12, -1.00000000000000e+12}; + real_t dUpp2[3] = {2.12376363329877e-01, 4.78762363667012e+00, 8.95204496600957e-01}; +#ifdef __MAKE_POS_DEF__ + H2[9 * 11 + 9] += 30; +#endif + + status = example.hotstart(H2, g2, D2, zLow2, zUpp2, dLow2, dUpp2, nWSR); + printf("qpOASES_status = %d\n", (int)status); + + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + printf("second QP:\n"); + for (int_t ii = 0; ii < 11; ++ii) { + printf("x[%d] = %.3e\n", (int)ii, xOpt[ii]); + } + + /* Compute KKT tolerances */ + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("stat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-9); + QPOASES_TEST_FOR_TOL(feas, 1e-7); + QPOASES_TEST_FOR_TOL(cmpl, 1e-12); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_janick2.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_janick2.cpp new file mode 100644 index 0000000..1388ebe --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_janick2.cpp @@ -0,0 +1,548 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_janick2.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2011-2017 + * + * Example that causes troubles when hotstarting. + */ + +#include +#include +#include + +#define __MAKE_POS_DEF__ +// #undef __MAKE_POS_DEF__ + +int main() +{ + USING_NAMESPACE_QPOASES + + int_t nWSR = 100; + /* Setting up QProblem object. */ + SQProblem example(11, 3); + + Options options; + options.setToFast(); + // options.setToDefault(); + options.initialStatusBounds = REFER_NAMESPACE_QPOASES ST_INACTIVE; + + // options.terminationTolerance = 1.e-12; + options.initialStatusBounds = REFER_NAMESPACE_QPOASES ST_INACTIVE; + // options.enableFarBounds = REFER_NAMESPACE_QPOASES BT_FALSE; + // options.enableRegularisation = REFER_NAMESPACE_QPOASES BT_FALSE; + + example.setOptions(options); + + /* Setup data of first QP. */ + real_t H[11 * 11] = { + 6.20100988531485e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -3.84861756786704e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -7.43268431723266e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 1.00000000000000e-01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -3.84861756786704e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 5.41188294952735e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 4.61304826562310e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.10000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 1.00000000000000e-01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.01000000000000e+01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.10000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -7.43268431723266e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 4.61304826562310e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.73544778892019e+01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.00000000000000e+01, + }; + real_t g[11] = { + // 9.13378607947379e-07, + // 0.00000000000000e+00, + // 0.00000000000000e+00, + // -1.12448469735682e-06, + // 0.00000000000000e+00, + // 0.00000000000000e+00, + // 0.00000000000000e+00, + // 0.00000000000000e+00, + // -1.18185650936822e+02, + // 0.00000000000000e+00, + // 0.00000000000000e+00, + -6.93766478421491e-04, + 3.84943289898669e-04, + -3.63779116055460e-05, + 6.38114176725135e-04, + 1.85797765355698e-04, + 6.21922122437904e-05, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.18185758699839e+02, + 1.54357580390960e-05, + 5.39852809009711e-06, + }; + real_t zLow[11] = { + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -4.50000000000000e+01, + -1.00000000000000e+12, + }; + real_t zUpp[11] = { + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 1.00000000000000e+12, + 1.00000000000000e+12, + 0.00000000000000e+00, + 4.50000000000000e+01, + 1.00000000000000e+12, + }; + real_t D[11 * 3] = { + 1.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.00000000000000e-02, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -1.00000000000000e-02, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 1.00000000000000e+00, + 0.00000000000000e+00, + -1.00000000000000e-02, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + }; + real_t dLow[3] = { + -1.00000000000000e+12, + -1.00000000000000e+12, + -1.00000000000000e+12, + }; + real_t dUpp[3] = { + 2.12376384003361e-01, + 4.78762361599664e+00, + 8.95204469622285e-01, + }; + +#ifdef __MAKE_POS_DEF__ + // H[9*11+9] += 30; + H[8 * 11 + 8] += 30; +#endif + returnValue status = example.init(H, g, D, zLow, zUpp, dLow, dUpp, nWSR); + printf("qpOASES_status = %d\n", (int)status); + + /* Get and print solution of second QP. */ + real_t xOpt[11]; + real_t yOpt[11 + 3]; + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + printf("first QP:\n"); + for (int_t ii = 0; ii < 11; ++ii) { + printf("x[%d] = %.3e\n", (int)ii, xOpt[ii]); + } + + /* Compute KKT tolerances */ + real_t stat, feas, cmpl; + SolutionAnalysis analyzer; + + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("\nstat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-9); + QPOASES_TEST_FOR_TOL(feas, 1e-7); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + nWSR = 100; + + /* Setup data of second QP. */ + real_t H2[11 * 11] = { + 6.20101055067033e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -3.84861780549400e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -7.43268533746787e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 1.00000000000000e-01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -3.84861780549400e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 5.41188396792859e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 4.61304896387257e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.10000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 1.00000000000000e-01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.01000000000000e+01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.10000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -7.43268533746787e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 4.61304896387257e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.73544780086860e+01, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 2.00000000000000e+01, + }; + real_t g2[11] = { + -8.92227256391600e-08, + 6.89531726031141e-08, + -1.91970120006650e-07, + 1.77206607789402e-07, + -3.83145267945144e-09, + -1.88284265021358e-08, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.18185657392775e+02, + 1.45337027424899e-17, + -6.04156175796480e-20, + }; + real_t zLow2[11] = { + -1.07876236566374e+01, + -1.00000000002784e+12, + -1.00000000000000e+12, + -8.30554585107279e-08, + -7.00000003695781e+00, + -2.60479531522807e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -4.50000000018062e+01, + -1.00000000000000e+12, + }; + real_t zUpp2[11] = { + 9.99999999989212e+11, + 9.99999999972157e+11, + 1.00000000000000e+12, + 4.68471853498991e+01, + 6.99999996304219e+00, + 9.99999999997395e+11, + 1.00000000000000e+12, + 1.00000000000000e+12, + 0.00000000000000e+00, + 4.49999999981938e+01, + 1.00000000000000e+12, + }; + real_t D2[11 * 3] = { + 1.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.00000000000000e-02, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + -1.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -1.00000000000000e-02, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + -0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + 1.00000000000000e+00, + 0.00000000000000e+00, + -1.00000000000000e-02, + 0.00000000000000e+00, + 0.00000000000000e+00, + 0.00000000000000e+00, + }; + real_t dLow2[3] = { + -1.00000000000000e+12, + -1.00000000000000e+12, + -1.00000000000000e+12, + }; + real_t dUpp2[3] = { + 2.12376343362616e-01, + 4.78762365663739e+00, + 8.95204684771929e-01, + }; +#ifdef __MAKE_POS_DEF__ + H2[8 * 11 + 8] += 30; + // H2[9*11+9] += 30; +#endif + + status = example.hotstart(H2, g2, D2, zLow2, zUpp2, dLow2, dUpp2, nWSR); + printf("qpOASES_status = %d\n", (int)status); + + example.getPrimalSolution(xOpt); + example.getDualSolution(yOpt); + printf("second QP:\n"); + for (int_t ii = 0; ii < 11; ++ii) { + printf("x[%d] = %.3e\n", (int)ii, xOpt[ii]); + } + + printf("\nQP objective value: %.3e\n", example.getObjVal()); + + /* Compute KKT tolerances */ + analyzer.getKktViolation(&example, &stat, &feas, &cmpl); + printf("\nstat = %e\nfeas = %e\ncmpl = %e\n", stat, feas, cmpl); + + QPOASES_TEST_FOR_TOL(stat, 1e-9); + QPOASES_TEST_FOR_TOL(feas, 1e-7); + QPOASES_TEST_FOR_TOL(cmpl, 1e-15); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_matrices.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_matrices.cpp new file mode 100644 index 0000000..d02a469 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_matrices.cpp @@ -0,0 +1,966 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_matrices.cpp + * \author Andreas Potschka, Christian Kirches, Hans Joachim Ferreau + * \version 3.2 + * \date 2010-2017 + * + * Unit test for Matrix classes. + */ + +#include +#include + +USING_NAMESPACE_QPOASES + +/** Compare deviations when computing dot product. */ +int sumOfSquares() +{ + int_t i; + + /* sum of first n squares */ + const int_t N = 100; + real_t * av = new real_t[N]; + real_t * aTv = new real_t[N]; + real_t * bv = new real_t[N]; + real_t c; + + for (i = 0; i < N; i++) + av[i] = (real_t)i + 1.0; + for (i = 0; i < N; i++) + aTv[i] = (real_t)i + 1.0; + for (i = 0; i < N; i++) + bv[i] = (real_t)i + 1.0; + + DenseMatrix a(1, N, N, av); + DenseMatrix aT(N, 1, 1, aTv); + + a.times(1, 1.0, bv, N, 0.0, &c, 1); + real_t err = c - (1.0 / 6.0) * N * (N + 1) * (2 * N + 1); + fprintf(stdFile, "Dot product; Error in sum of first %d squares: %9.2e\n", (int)N, err); + + aT.transTimes(1, 1.0, bv, N, 0.0, &c, 1); + real_t errT = c - (1.0 / 6.0) * N * (N + 1) * (2 * N + 1); + fprintf(stdFile, "Transpose; Error in sum of first %d squares: %9.2e\n", (int)N, errT); + + delete[] bv; + aT.free(); // or delete[] aTv; + a.free(); // or delete[] av; + + QPOASES_TEST_FOR_TOL(err, 1e-10) + QPOASES_TEST_FOR_TOL(errT, 1e-10) + + return TEST_PASSED; +} + +/** Compare deviations when multiplying Hilbert matrix with its inverse. */ +int hilbert() +{ + int_t i, j; + real_t d, err; + + /* permuted 4x4 Hilbert matrix, row major format */ + real_t _Av[] = {1.0 / 3.0, + 1.0, + 0.5, + 0.25, + 0.25, + 0.5, + 1.0 / 3.0, + 0.2, + 0.2, + 1.0 / 3.0, + 0.25, + 1.0 / 6.0, + 1.0 / 6.0, + 0.25, + 0.2, + 1.0 / 7.0}; + /* and its inverse, column major format */ + real_t Bv[] = { + 240, 16, -120, -140, -2700, -120, 1200, 1680, 6480, 240, -2700, -4200, -4200, -140, 1680, 2800}; + + /* result */ + real_t * Av = new real_t[4 * 4]; + real_t * Cv = new real_t[4 * 4]; + + DenseMatrix A(4, 4, 4, Av); + + for (i = 0; i < 16; i++) + Av[i] = _Av[i]; + + A.times(4, 1.0, Bv, 4, 0.0, Cv, 4); + + err = 0.0; + for (j = 0; j < 4; j++) { + for (i = 0; i < 4; i++) { + d = getAbs(Cv[j * 4 + i] - static_cast(i == j)); + if (d > err) + err = d; + } + } + fprintf(stdFile, "Hilbert; Deviation from identity: %9.2e\n", err); + + delete[] Cv; + A.free(); // or delete[] Av; + + QPOASES_TEST_FOR_TOL(err, 1e-12) + + return TEST_PASSED; +} + +/** Compare deviations when multiplying sub-matrices. */ +int submatrix() +{ + int_t i, j; + real_t d, err; + + /* 2x3 transposed submatrix */ + real_t _Asubv[] = {1.0 / 3.0, 0.25, 1.0, 0.5, 0.5, 1.0 / 3.0, 0.25, 0.2}; + real_t Bsubv[] = {240, 16, -120, -140, -2700, -120, 1200, 1680}; + real_t Csubv[2 * 2]; + + real_t * Asubv = new real_t[2 * 4]; + + for (i = 0; i < 8; i++) + Asubv[i] = _Asubv[i]; + + DenseMatrix Asub(4, 2, 2, Asubv); + + Asub.transTimes(2, 1.0, Bsubv, 4, 0.0, Csubv, 2); + + err = 0.0; + for (j = 0; j < 2; j++) { + for (i = 0; i < 2; i++) { + d = getAbs(Csubv[j * 2 + i] - static_cast(i == j)); + if (d > err) + err = d; + } + } + fprintf(stdFile, "Submatrix transpose; Deviation from identity: %9.2e\n", err); + + Asub.free(); // or delete[] Asubv; + + QPOASES_TEST_FOR_TOL(err, 1e-13) + + return TEST_PASSED; +} + +/** Compare deviations when multiplying dense sub-matrices via index lists. */ +int indexDenseSubmatrix() +{ + /* dense submatrices via index lists */ + const int_t M = 20, N = 15, K = 5; + int_t i, j, k, m, n; + Indexlist rows(N), cols(N); + int_t *rNum, *cNum; + real_t err = 0.0, errT = 0.0; + real_t *Av, *X, *Y, *x, *y, *xc, *yc; + + // prepare index lists + m = (M - 3) / 4; + n = (N - 3) / 4; + for (i = 0; i < m; i++) { + rows.addNumber(M - 1 - 2 * i); + rows.addNumber(2 * i); + } + for (i = 0; i < n; i++) { + cols.addNumber(N - 1 - 2 * i); + cols.addNumber(2 * i); + } + m *= 2; + n *= 2; + + rows.getNumberArray(&rNum); + fprintf(stdFile, "Rows: "); + for (i = 0; i < m; i++) + fprintf(stdFile, " %2d", (int)(rNum[i])); + fprintf(stdFile, "\n"); + + cols.getNumberArray(&cNum); + fprintf(stdFile, "Cols: "); + for (i = 0; i < n; i++) + fprintf(stdFile, " %2d", (int)(cNum[i])); + fprintf(stdFile, "\n"); + + // prepare input matrices + Av = new real_t[M * N]; + X = new real_t[n * K]; + Y = new real_t[m * K]; + x = new real_t[n * K]; + y = new real_t[m * K]; + xc = new real_t[n * K]; + yc = new real_t[m * K]; + + DenseMatrix A(M, N, N, Av); + for (i = 0; i < M * N; i++) + Av[i] = -0.5 * N * M + (real_t)i; + for (i = 0; i < n * K; i++) + X[i] = 1.0 / (real_t)(i + 1); + for (i = 0; i < m * K; i++) + Y[i] = 1.0 / (real_t)(i + 1); + + // multiply + A.times(&rows, &cols, K, 1.0, X, n, 0.0, y, m); + + // check result + for (j = 0; j < m; j++) { + for (k = 0; k < K; k++) { + yc[j + k * m] = -y[j + k * m]; + for (i = 0; i < n; i++) + yc[j + k * m] += Av[cNum[i] + rNum[j] * N] * X[i + k * n]; + if (getAbs(yc[j + k * m]) > err) + err = getAbs(yc[j + k * m]); + } + } + fprintf(stdFile, "Indexlist submatrix; error: %9.2e\n", err); + + // transpose multiply + A.transTimes(&rows, &cols, K, 1.0, Y, m, 0.0, x, n); + + // check result + errT = 0.0; + for (j = 0; j < n; j++) { + for (k = 0; k < K; k++) { + xc[j + k * n] = -x[j + k * n]; + for (i = 0; i < m; i++) + xc[j + k * n] += Av[cNum[j] + rNum[i] * N] * Y[i + k * m]; + if (getAbs(xc[j + k * n]) > errT) + errT = getAbs(xc[j + k * n]); + } + } + fprintf(stdFile, "Indexlist transpose submatrix; error: %9.2e\n", errT); + + // check result + + // clean up + delete[] yc; + delete[] xc; + delete[] y; + delete[] x; + delete[] Y; + delete[] X; + A.free(); // or delete[] Av; + + QPOASES_TEST_FOR_TOL(err, 1e-13) + QPOASES_TEST_FOR_TOL(errT, 2e-14) + + return TEST_PASSED; +} + +/** Obtain column of sparse matrix. */ +int spGetCol() +{ + long j, i; + sparse_int_t * ir = new sparse_int_t[10]; + sparse_int_t * jc = new sparse_int_t[4]; + real_t * val = new real_t[10]; + real_t * col = new real_t[4]; + + /* Test matrix: + * + * [ 0 3 6 ] + * [ 1 0 7 ] + * [ 2 0 8 ] + * [ 0 4 9 ] + * [ 0 5 10 ] + */ + + jc[0] = 0; + jc[1] = 2; + jc[2] = 5; + jc[3] = 10; + ir[0] = 1; + ir[1] = 2; + ir[2] = 0; + ir[3] = 3; + ir[4] = 4; + ir[5] = 0; + ir[6] = 1; + ir[7] = 2; + ir[8] = 3; + ir[9] = 4; + for (i = 0; i < 10; i++) + val[i] = 1.0 + (double)i; + + SparseMatrix A(5, 3, ir, jc, val); + + Indexlist rows(4); + + rows.addNumber(2); + rows.addNumber(4); + rows.addNumber(3); + rows.addNumber(0); + + /* Indexed matrix: + * + * [ 2 0 8 ] + * [ 0 5 10 ] + * [ 0 4 9 ] + * [ 0 3 6 ] + */ + + for (j = 0; j < 3; j++) { + fprintf(stdFile, "Column %ld:\n", j); + A.getCol((int_t)j, &rows, 1.0, col); + for (i = 0; i < 4; i++) + fprintf(stdFile, " %3.0f\n", col[i]); + } + + delete[] col; + A.free(); // or delete[] val,jc,ir; + + return TEST_PASSED; +} + +/** Obtain row of sparse matrix. */ +int spGetRow() +{ + long j, i; + sparse_int_t * ir = new sparse_int_t[10]; + sparse_int_t * jc = new sparse_int_t[6]; + real_t * val = new real_t[10]; + real_t * row = new real_t[4]; + + /* Test matrix: + * + * [ 0 3 4 6 0 ] + * [ 1 0 0 7 9 ] + * [ 2 0 5 8 10 ] + */ + + jc[0] = 0; + jc[1] = 2; + jc[2] = 3; + jc[3] = 5; + jc[4] = 8; + jc[5] = 10; + ir[0] = 1; + ir[1] = 2; + ir[2] = 0; + ir[3] = 0; + ir[4] = 2; + ir[5] = 0; + ir[6] = 1; + ir[7] = 2; + ir[8] = 1; + ir[9] = 2; + for (i = 0; i < 10; i++) + val[i] = 1.0 + (double)i; + + SparseMatrix A(3, 4, ir, jc, val); + + Indexlist cols(4); + + cols.addNumber(2); + cols.addNumber(4); + cols.addNumber(3); + cols.addNumber(1); + + /* Indexed matrix: + * + * [ 4 0 6 3 ] + * [ 0 9 7 0 ] + * [ 5 10 8 0 ] + */ + + for (j = 0; j < 3; j++) { + A.getRow((int_t)j, &cols, 1.0, row); + for (i = 0; i < 4; i++) + fprintf(stdFile, " %3.0f", row[i]); + fprintf(stdFile, "\n"); + } + + delete[] row; + A.free(); + + return TEST_PASSED; +} + +/** Compare deviations when multiplying sparse matrix. */ +int spTimes() +{ + long i; + sparse_int_t * ir = new sparse_int_t[10]; + sparse_int_t * jc = new sparse_int_t[6]; + real_t * val = new real_t[10]; + + real_t * x = new real_t[5 * 2]; + real_t * y = new real_t[3 * 2]; + + real_t Ax[] = {-23, -11, -26, 42, 74, 99}; + real_t ATy[] = {-63, -69, -222, -423, -359, 272, 126, 663, 1562, 1656}; + real_t err = 0.0, errT = 0.0; + + for (i = 0; i < 10; i++) + x[i] = -4.0 + (double)i; + + /* Test matrix: + * + * [ 0 3 4 6 0 ] + * [ 1 0 0 7 9 ] + * [ 2 0 5 8 10 ] + */ + + jc[0] = 0; + jc[1] = 2; + jc[2] = 3; + jc[3] = 5; + jc[4] = 8; + jc[5] = 10; + ir[0] = 1; + ir[1] = 2; + ir[2] = 0; + ir[3] = 0; + ir[4] = 2; + ir[5] = 0; + ir[6] = 1; + ir[7] = 2; + ir[8] = 1; + ir[9] = 2; + for (i = 0; i < 10; i++) + val[i] = 1.0 + (double)i; + + SparseMatrix A(3, 5, ir, jc, val); // reference to ir, jc, val + + A.times(2, 1.0, x, 5, 0.0, y, 3); + + for (i = 0; i < 6; i++) + if (getAbs(y[i] - Ax[i]) > err) + err = getAbs(y[i] - Ax[i]); + fprintf(stdFile, "Error in sparse A*x: %9.2e\n", err); + + A.transTimes(2, 1.0, y, 3, 0.0, x, 5); + + errT = 0.0; + for (i = 0; i < 10; i++) + if (getAbs(x[i] - ATy[i]) > errT) + errT = getAbs(x[i] - ATy[i]); + fprintf(stdFile, "Error in sparse A'*x: %9.2e\n", errT); + + A.free(); // or delete[] val,ir,jc + delete[] y; + delete[] x; + + QPOASES_TEST_FOR_TOL(err, 1e-15) + QPOASES_TEST_FOR_TOL(errT, 1e-15) + + return TEST_PASSED; +} + +/** Compare deviations when multiplying sparse matrix via index lists. */ +int spIndTimes() +{ + const long N = 4; + long i, j; + long nRows = 2 * N + 1; + long nCols = N; + long nnz = 3 * N; + sparse_int_t * ir = new sparse_int_t[nnz]; + sparse_int_t * jc = new sparse_int_t[nCols + 1]; + real_t * val = new real_t[nnz]; + real_t * xc = new real_t[3 * 2]; + real_t * yc = new real_t[4 * 2]; + real_t Ax[] = {0.31, 0.05, 0.06, 0.30, 0.76, 0.20, 0.24, 0.60}; + real_t ATy[] = {0.278, 0.000, 0.548, 0.776, 0.000, 1.208}; + real_t err = 0.0, errT = 0.0; + + Indexlist rows(4), cols(3), allcols((int_t)nCols); + + rows.addNumber(2); + rows.addNumber(4); + rows.addNumber(3); + rows.addNumber(0); + + cols.addNumber(1); + cols.addNumber(3); + cols.addNumber(0); + + for (i = 0; i < nCols; i++) + allcols.addNumber((int_t)i); + + // build test matrix + for (i = 0; i <= N; i++) + jc[i] = (sparse_int_t)(3 * i); + for (j = 0; j < N; j++) + for (i = 0; i < 3; i++) { + ir[j * 3 + i] = (sparse_int_t)(2 * j + i); + val[j * 3 + i] = 1.0 - 0.1 * (double)(j * 3 + i); + } + SparseMatrix A((int_t)nRows, (int_t)nCols, ir, jc, val); + + fprintf(stdFile, "Test matrix A =\n"); + for (j = 0; j < nRows; j++) { + A.getRow((int_t)j, &allcols, 1.0, xc); + for (i = 0; i < nCols; i++) + fprintf(stdFile, "%6.2f", xc[i]); + fprintf(stdFile, "\n"); + } + + for (i = 0; i < 6; i++) + xc[i] = (1.0 + (double)i) * 0.1; + + A.times(&rows, &cols, 2, 1.0, xc, 3, 0.0, yc, 4, BT_TRUE); + + for (i = 0; i < 8; i++) + if (getAbs(yc[i] - Ax[i]) > err) + err = getAbs(yc[i] - Ax[i]); + fprintf(stdFile, "Error in sparse indexed A*x: %9.2e\n", err); + + A.transTimes(&rows, &cols, 2, 1.0, yc, 4, 0.0, xc, 3); + errT = 0.0; + for (i = 0; i < 6; i++) + if (getAbs(xc[i] - ATy[i]) > errT) + errT = getAbs(xc[i] - ATy[i]); + fprintf(stdFile, "Error in sparse indexed A'*y: %9.2e\n", errT); + + delete[] xc; + delete[] yc; + A.free(); + + QPOASES_TEST_FOR_TOL(err, 1e-15) + QPOASES_TEST_FOR_TOL(errT, 1e-15) + + return TEST_PASSED; +} + +/** Obtain column of sparse row matrix. */ +int sprGetCol() +{ + long j, i; + sparse_int_t * ir = new sparse_int_t[10]; + sparse_int_t * jc = new sparse_int_t[4]; + real_t * val = new real_t[10]; + real_t * col = new real_t[4]; + + /* Test matrix: + * + * [ 0 3 6 ] + * [ 1 0 7 ] + * [ 2 0 8 ] + * [ 0 4 9 ] + * [ 0 5 10 ] + */ + + jc[0] = 0; + jc[1] = 2; + jc[2] = 5; + jc[3] = 10; + ir[0] = 1; + ir[1] = 2; + ir[2] = 0; + ir[3] = 3; + ir[4] = 4; + ir[5] = 0; + ir[6] = 1; + ir[7] = 2; + ir[8] = 3; + ir[9] = 4; + for (i = 0; i < 10; i++) + val[i] = 1.0 + (double)i; + + SparseMatrix Ac(5, 3, ir, jc, val); + real_t * Acv = Ac.full(); // row major format + SparseMatrixRow A(5, 3, 3, Acv); + delete[] Acv; + Ac.free(); // or delete[] val,jc,ir; + + Indexlist rows(4); + + rows.addNumber(2); + rows.addNumber(4); + rows.addNumber(3); + rows.addNumber(0); + + /* Indexed matrix: + * + * [ 2 0 8 ] + * [ 0 5 10 ] + * [ 0 4 9 ] + * [ 0 3 6 ] + */ + + for (j = 0; j < 3; j++) { + fprintf(stdFile, "Column %ld:\n", j); + A.getCol((int_t)j, &rows, 1.0, col); + for (i = 0; i < 4; i++) + fprintf(stdFile, " %3.0f\n", col[i]); + } + + delete[] col; + A.free(); // or delete[] val,jc,ir; + + return TEST_PASSED; +} + +/** Obtain row of sparse row matrix. */ +int sprGetRow() +{ + long j, i; + sparse_int_t * ir = new sparse_int_t[10]; + sparse_int_t * jc = new sparse_int_t[6]; + real_t * val = new real_t[10]; + real_t * row = new real_t[4]; + + /* Test matrix: + * + * [ 0 3 4 6 0 ] + * [ 1 0 0 7 9 ] + * [ 2 0 5 8 10 ] + */ + + jc[0] = 0; + jc[1] = 2; + jc[2] = 3; + jc[3] = 5; + jc[4] = 8; + jc[5] = 10; + ir[0] = 1; + ir[1] = 2; + ir[2] = 0; + ir[3] = 0; + ir[4] = 2; + ir[5] = 0; + ir[6] = 1; + ir[7] = 2; + ir[8] = 1; + ir[9] = 2; + for (i = 0; i < 10; i++) + val[i] = 1.0 + (double)i; + + SparseMatrix Ac(3, 5, ir, jc, val); + real_t * Acv = Ac.full(); // row major format + SparseMatrixRow A(3, 5, 5, Acv); + delete[] Acv; + Ac.free(); // or delete[] val,jc,ir; + + Indexlist cols(4); + + cols.addNumber(2); + cols.addNumber(4); + cols.addNumber(3); + cols.addNumber(1); + + /* Indexed matrix: + * + * [ 4 0 6 3 ] + * [ 0 9 7 0 ] + * [ 5 10 8 0 ] + */ + + for (j = 0; j < 3; j++) { + A.getRow((int_t)j, &cols, 1.0, row); + for (i = 0; i < 4; i++) + fprintf(stdFile, " %3.0f", row[i]); + fprintf(stdFile, "\n"); + } + + delete[] row; + A.free(); + + return TEST_PASSED; +} + +/** Compare deviations when multiplying sparse row matrix. */ +int sprTimes() +{ + long i; + sparse_int_t * ir = new sparse_int_t[10]; + sparse_int_t * jc = new sparse_int_t[6]; + real_t * val = new real_t[10]; + + real_t * x = new real_t[5 * 2]; + real_t * y = new real_t[3 * 2]; + + real_t Ax[] = {-23, -11, -26, 42, 74, 99}; + real_t ATy[] = {-63, -69, -222, -423, -359, 272, 126, 663, 1562, 1656}; + real_t err = 0.0, errT = 0.0; + + for (i = 0; i < 10; i++) + x[i] = -4.0 + (double)i; + + /* Test matrix: + * + * [ 0 3 4 6 0 ] + * [ 1 0 0 7 9 ] + * [ 2 0 5 8 10 ] + */ + + jc[0] = 0; + jc[1] = 2; + jc[2] = 3; + jc[3] = 5; + jc[4] = 8; + jc[5] = 10; + ir[0] = 1; + ir[1] = 2; + ir[2] = 0; + ir[3] = 0; + ir[4] = 2; + ir[5] = 0; + ir[6] = 1; + ir[7] = 2; + ir[8] = 1; + ir[9] = 2; + for (i = 0; i < 10; i++) + val[i] = 1.0 + (double)i; + + SparseMatrix Ac(3, 5, ir, jc, val); // reference to ir, jc, val + real_t * Acv = Ac.full(); // row major format + SparseMatrixRow A(3, 5, 5, Acv); + delete[] Acv; + Ac.free(); // or delete[] val,jc,ir; + + A.times(2, 1.0, x, 5, 0.0, y, 3); + + for (i = 0; i < 6; i++) + if (getAbs(y[i] - Ax[i]) > err) + err = getAbs(y[i] - Ax[i]); + fprintf(stdFile, "Error in sparse A*x: %9.2e\n", err); + + A.transTimes(2, 1.0, y, 3, 0.0, x, 5); + + errT = 0.0; + for (i = 0; i < 10; i++) + if (getAbs(x[i] - ATy[i]) > errT) + errT = getAbs(x[i] - ATy[i]); + fprintf(stdFile, "Error in sparse A'*x: %9.2e\n", errT); + + A.free(); // or delete[] val,ir,jc + delete[] y; + delete[] x; + + QPOASES_TEST_FOR_TOL(err, 1e-15) + QPOASES_TEST_FOR_TOL(errT, 1e-15) + + return TEST_PASSED; +} + +/** Compare deviations when multiplying sparse row matrix via index lists. */ +int sprIndTimes() +{ + const long N = 4; + long i, j; + long nRows = 2 * N + 1; + long nCols = N; + long nnz = 3 * N; + sparse_int_t * ir = new sparse_int_t[nnz]; + sparse_int_t * jc = new sparse_int_t[nCols + 1]; + real_t * val = new real_t[nnz]; + real_t * xc = new real_t[3 * 2]; + real_t * yc = new real_t[4 * 2]; + real_t Ax[] = {0.31, 0.05, 0.06, 0.30, 0.76, 0.20, 0.24, 0.60}; + real_t ATy[] = {0.278, 0.000, 0.548, 0.776, 0.000, 1.208}; + real_t err = 0.0, errT = 0.0; + + Indexlist rows(4), cols(3), allcols((int_t)nCols); + + rows.addNumber(2); + rows.addNumber(4); + rows.addNumber(3); + rows.addNumber(0); + + cols.addNumber(1); + cols.addNumber(3); + cols.addNumber(0); + + for (i = 0; i < nCols; i++) + allcols.addNumber((int_t)i); + + // build test matrix + for (i = 0; i <= N; i++) + jc[i] = (sparse_int_t)(3 * i); + for (j = 0; j < N; j++) + for (i = 0; i < 3; i++) { + ir[j * 3 + i] = (sparse_int_t)(2 * j + i); + val[j * 3 + i] = 1.0 - 0.1 * (double)(j * 3 + i); + } + SparseMatrix Ac((int_t)nRows, (int_t)nCols, ir, jc, val); + real_t * Acv = Ac.full(); // row major format + SparseMatrixRow A((int_t)nRows, (int_t)nCols, (int_t)nCols, Acv); + delete[] Acv; + Ac.free(); // or delete[] val,jc,ir; + + fprintf(stdFile, "Test matrix A =\n"); + for (j = 0; j < nRows; j++) { + A.getRow((int_t)j, &allcols, 1.0, xc); + for (i = 0; i < nCols; i++) + fprintf(stdFile, "%6.2f", xc[i]); + fprintf(stdFile, "\n"); + } + + for (i = 0; i < 6; i++) + xc[i] = (1.0 + (double)i) * 0.1; + + A.times(&rows, &cols, 2, 1.0, xc, 3, 0.0, yc, 4, BT_TRUE); + + for (i = 0; i < 8; i++) + if (getAbs(yc[i] - Ax[i]) > err) + err = getAbs(yc[i] - Ax[i]); + fprintf(stdFile, "Error in sparse indexed A*x: %9.2e\n", err); + + A.transTimes(&rows, &cols, 2, 1.0, yc, 4, 0.0, xc, 3); + for (i = 0; i < 3; i++) { + for (j = 0; j < 2; j++) + fprintf(stdFile, "%6.2f", ATy[i + j * 3]); + fprintf(stdFile, "\n"); + } + for (i = 0; i < 3; i++) { + for (j = 0; j < 2; j++) + fprintf(stdFile, "%6.2f", xc[i + j * 3]); + fprintf(stdFile, "\n"); + } + for (i = 0; i < 6; i++) + if (getAbs(xc[i] - ATy[i]) > errT) + errT = getAbs(xc[i] - ATy[i]); + fprintf(stdFile, "Error in sparse indexed A'*y: %9.2e\n", errT); + + delete[] xc; + delete[] yc; + A.free(); + + QPOASES_TEST_FOR_TOL(err, 1e-15) + QPOASES_TEST_FOR_TOL(errT, 1e-15) + + return TEST_PASSED; +} + +/** Compare deviations when using bilinear multiplication with dense matrix. */ +int symmetry() +{ + int_t i, j; + real_t * Hv = new real_t[6 * 6]; + real_t * Z = new real_t[6 * 3]; + real_t * ZHZd = new real_t[3 * 3]; + real_t * ZHZs = new real_t[3 * 3]; + real_t ZHZv[] = {0.144, 0.426, 0.708, 0.426, 1.500, 2.574, 0.708, 2.574, 4.440}; + real_t err = 0.0, errS = 0.0; + SymDenseMat * Hd; + SymSparseMat * Hs; + Indexlist * cols = new Indexlist(6); + + for (i = 0; i < 36; i++) + Hv[i] = 0.0; + for (i = 0; i < 6; i++) + Hv[i * 7] = 1.0 - 0.1 * (real_t)i; + for (i = 0; i < 5; i++) + Hv[i * 7 + 1] = Hv[i * 7 + 6] = -0.1 * ((real_t)i + 1.0); + + Hd = new SymDenseMat(6, 6, 6, Hv); // deep-copy from Hv + Hs = new SymSparseMat(6, 6, 6, Hv); // deep-copy from Hv + Hs->createDiagInfo(); + + for (i = 0; i < 6; ++i) { + for (j = 0; j < 6; ++j) + fprintf(stdFile, "%3.3f ", Hv[i * 6 + j]); + fprintf(stdFile, "\n"); + } + fprintf(stdFile, "\n"); + + cols->addNumber(3); + cols->addNumber(0); + cols->addNumber(4); + cols->addNumber(1); + for (i = 0; i < 18; i++) + Z[i] = 0.1 * ((real_t)i + 1.0); + + fprintf(stdFile, "\n"); + for (i = 0; i < 6; ++i) { + for (j = 0; j < 3; ++j) + fprintf(stdFile, "%3.3f ", Z[i + j * 6]); + fprintf(stdFile, "\n"); + } + fprintf(stdFile, "\n"); + + Hd->bilinear(cols, 3, Z, 6, ZHZd, 3); + + for (i = 0; i < 9; i++) + if (getAbs(ZHZd[i] - ZHZv[i]) > err) + err = getAbs(ZHZd[i] - ZHZv[i]); + fprintf(stdFile, "Error in indexed dense bilinear form: %9.2e\n", err); + + Hs->bilinear(cols, 3, Z, 6, ZHZs, 3); + + for (i = 0; i < 3; ++i) { + for (j = 0; j < 3; ++j) + fprintf(stdFile, "%3.3f ", ZHZd[i * 3 + j]); + fprintf(stdFile, "\n"); + } + fprintf(stdFile, "\n"); + + for (i = 0; i < 3; ++i) { + for (j = 0; j < 3; ++j) + fprintf(stdFile, "%3.3f ", ZHZv[i * 3 + j]); + fprintf(stdFile, "\n"); + } + fprintf(stdFile, "\n"); + + for (i = 0; i < 9; i++) + if (getAbs(ZHZs[i] - ZHZv[i]) > errS) + errS = getAbs(ZHZs[i] - ZHZv[i]); + fprintf(stdFile, "Error in indexed sparse bilinear form: %9.2e\n", errS); + + delete cols; + delete Hs; + delete Hd; + delete[] ZHZs; + delete[] ZHZd; + delete[] Z; + delete[] Hv; + + QPOASES_TEST_FOR_TOL(err, 1e-15) + QPOASES_TEST_FOR_TOL(errS, 1e-15) + + return TEST_PASSED; +} + +/** Run various tests on matrix classes. */ +int main() +{ + int errorCount = TEST_PASSED; + + errorCount += sumOfSquares(); + errorCount += hilbert(); + errorCount += submatrix(); + errorCount += indexDenseSubmatrix(); + + errorCount += spGetCol(); + errorCount += spGetRow(); + errorCount += spTimes(); + errorCount += spIndTimes(); + + errorCount += sprGetCol(); + errorCount += sprGetRow(); + errorCount += sprTimes(); + errorCount += sprIndTimes(); + + errorCount += symmetry(); + + return errorCount; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_matrices2.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_matrices2.cpp new file mode 100644 index 0000000..c369edb --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_matrices2.cpp @@ -0,0 +1,104 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_matrices2.cpp + * \author Hans Joachim Ferreau,Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2014-2017 + * + * Unit test for Matrix classes. + */ + +#include + +#include +#include + +#include "test_qrecipe_data.hpp" + +/** Compare deviations when performing matrix operations. */ +int main() +{ + USING_NAMESPACE_QPOASES + + int_t i; + + real_t errH = 0.0, errA = 0.0; + real_t v[180]; + real_t resHs[180]; + real_t resHd[180]; + real_t resAs[91]; + real_t resAd[91]; + + /* create sparse matrices */ + SymSparseMat * H = new SymSparseMat(180, 180, H_ir, H_jc, H_val); + SparseMatrix * A = new SparseMatrix(91, 180, A_ir, A_jc, A_val); + + H->createDiagInfo(); + + real_t * H_full = H->full(); + real_t * A_full = A->full(); + + // print( A_full,91,180 ); + + SymDenseMat * Hd = new SymDenseMat(180, 180, 180, H_full); + DenseMatrix * Ad = new DenseMatrix(91, 180, 180, A_full); + + for (i = 0; i < 180; ++i) + v[i] = 2.0 * ((real_t)rand()) / ((real_t)RAND_MAX) - 1.0; + + H->times(1, 1.0, v, 180, 0.0, resHs, 180); + Hd->times(1, 1.0, v, 180, 0.0, resHd, 180); + + A->times(1, 1.0, v, 180, 0.0, resAs, 91); + Ad->times(1, 1.0, v, 180, 0.0, resAd, 91); + + for (i = 0; i < 180; ++i) + if (getAbs(resHs[i] - resHd[i]) > errH) + errH = getAbs(resHs[i] - resHd[i]); + + fprintf(stdFile, "maximum difference in H*v: %9.2e\n", errH); + + for (i = 0; i < 91; ++i) + if (getAbs(resAs[i] - resAd[i]) > errA) + errA = getAbs(resAs[i] - resAd[i]); + + fprintf(stdFile, "maximum difference in A*v: %9.2e\n", errA); + + delete H; + delete A; + delete[] H_full; + delete[] A_full; + delete Hd; + delete Ad; + + QPOASES_TEST_FOR_TOL(errH, 1e-13) + QPOASES_TEST_FOR_TOL(errA, 1e-13) + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_matrices3.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_matrices3.cpp new file mode 100644 index 0000000..10e7685 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_matrices3.cpp @@ -0,0 +1,84 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_matrices3.cpp + * \author Hans Joachim Ferreau,Andreas Potschka, Christian Kirches + * \version 3.2 + * \date 2014-2017 + * + * Unit test for Matrix classes. + */ + +#include + +#include +#include + +#include "test_qrecipe_data.hpp" + +/** Compare deviations when performing matrix operations. */ +int main() +{ + USING_NAMESPACE_QPOASES + + int_t i; + + real_t errH = 0.0; + real_t v[180]; + real_t resHn[180]; + real_t resHt[180]; + + /* create sparse matrices */ + SymSparseMat * H = new SymSparseMat(180, 180, H_ir, H_jc, H_val); + + H->createDiagInfo(); + + real_t * H_full = H->full(); + + SymDenseMat * Hd = new SymDenseMat(180, 180, 180, H_full); + + for (i = 0; i < 180; ++i) + v[i] = 2.0 * ((real_t)rand()) / ((real_t)RAND_MAX) - 1.0; + + Hd->times(1, 1.0, v, 180, 0.0, resHn, 180); + Hd->transTimes(1, 1.0, v, 180, 0.0, resHt, 180); + + for (i = 0; i < 180; ++i) + if (getAbs(resHn[i] - resHt[i]) > errH) + errH = getAbs(resHn[i] - resHt[i]); + + fprintf(stdFile, "maximum difference in H*v vs. H'*v: %9.2e\n", errH); + + delete H; + delete[] H_full; + delete Hd; + + QPOASES_TEST_FOR_TOL(errH, 1e-15) + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_qrecipe.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_qrecipe.cpp new file mode 100644 index 0000000..b1e81df --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_qrecipe.cpp @@ -0,0 +1,137 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_qrecipe.cpp + * \author Andreas Potschka + * \version 3.2 + * \date 2007-2017 + * + * QRECIPE example from the CUTEr test set with sparse matrices. + */ + +#include +#include + +#include "test_qrecipe_data.hpp" + +int main() +{ + USING_NAMESPACE_QPOASES + + long i; + int_t nWSR; + real_t tic, toc; + real_t errP = 0.0, errD = 0.0; + real_t * x1 = new real_t[180]; + real_t * y1 = new real_t[271]; + real_t * x2 = new real_t[180]; + real_t * y2 = new real_t[271]; + + /* create sparse matrices */ + SymSparseMat * H = new SymSparseMat(180, 180, H_ir, H_jc, H_val); + SparseMatrix * A = new SparseMatrix(91, 180, A_ir, A_jc, A_val); + + H->createDiagInfo(); + + real_t * H_full = H->full(); + real_t * A_full = A->full(); + + SymDenseMat * Hd = new SymDenseMat(180, 180, 180, H_full); + DenseMatrix * Ad = new DenseMatrix(91, 180, 180, A_full); + + /* solve with dense matrices */ + nWSR = 1000; + QProblem qrecipeD(180, 91); + tic = getCPUtime(); + qrecipeD.init(Hd, g, Ad, lb, ub, lbA, ubA, nWSR, 0); + toc = getCPUtime(); + qrecipeD.getPrimalSolution(x1); + qrecipeD.getDualSolution(y1); + + fprintf(stdFile, "Solved dense problem in %d iterations, %.3f seconds.\n", (int)nWSR, toc - tic); + + /* Compute KKT tolerances */ + real_t statD, feasD, cmplD; + SolutionAnalysis analyzerD; + + analyzerD.getKktViolation(&qrecipeD, &statD, &feasD, &cmplD); + printf("stat = %e\nfeas = %e\ncmpl = %e\n\n", statD, feasD, cmplD); + + /* solve with sparse matrices */ + nWSR = 1000; + QProblem qrecipeS(180, 91); + tic = getCPUtime(); + qrecipeS.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + toc = getCPUtime(); + qrecipeS.getPrimalSolution(x2); + qrecipeS.getDualSolution(y2); + + fprintf(stdFile, "Solved sparse problem in %d iterations, %.3f seconds.\n", (int)nWSR, toc - tic); + + /* Compute KKT tolerances */ + real_t statS, feasS, cmplS; + SolutionAnalysis analyzerS; + + analyzerS.getKktViolation(&qrecipeS, &statS, &feasS, &cmplS); + printf("stat = %e\nfeas = %e\ncmpl = %e\n\n", statS, feasS, cmplS); + + /* check distance of solutions */ + for (i = 0; i < 180; i++) + if (getAbs(x1[i] - x2[i]) > errP) + errP = getAbs(x1[i] - x2[i]); + fprintf(stdFile, "Primal error: %9.2e\n", errP); + + for (i = 0; i < 271; i++) + if (getAbs(y1[i] - y2[i]) > errD) + errD = getAbs(y1[i] - y2[i]); + fprintf(stdFile, "Dual error: %9.2e (might not be unique)\n", errD); + + delete H; + delete A; + delete[] H_full; + delete[] A_full; + delete Hd; + delete Ad; + + delete[] y2; + delete[] x2; + delete[] y1; + delete[] x1; + + QPOASES_TEST_FOR_TOL(statD, 1e-14); + QPOASES_TEST_FOR_TOL(feasD, 1e-14); + QPOASES_TEST_FOR_TOL(cmplD, 1e-13); + + QPOASES_TEST_FOR_TOL(statS, 1e-14); + QPOASES_TEST_FOR_TOL(feasS, 1e-14); + QPOASES_TEST_FOR_TOL(cmplS, 1e-13); + + QPOASES_TEST_FOR_TOL(errP, 1e-13); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_qrecipeSchur.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_qrecipeSchur.cpp new file mode 100644 index 0000000..50105a5 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_qrecipeSchur.cpp @@ -0,0 +1,175 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_qrecipeSchur.cpp + * \author Dennis Janka + * \version 3.2 + * \date 2007-2017 + * + * QRECIPE example from the CUTEr test set with sparse matrices. + * Comparison between nullspace factorization (dense and sparse) and + * Schur complement approach. + */ + +#include +#include + +#include "test_qrecipe_data.hpp" + +int main() +{ + USING_NAMESPACE_QPOASES + + long i; + int_t nWSR; + real_t errP1, errP2, errP3, errD1, errD2, errD3, tic, toc; + real_t * x1 = new real_t[180]; + real_t * y1 = new real_t[271]; + real_t * x2 = new real_t[180]; + real_t * y2 = new real_t[271]; + real_t * x3 = new real_t[180]; + real_t * y3 = new real_t[271]; + + Options options; + options.setToDefault(); + options.enableEqualities = BT_TRUE; + + /* create sparse matrices */ + SymSparseMat * H = new SymSparseMat(180, 180, H_ir, H_jc, H_val); + SparseMatrix * A = new SparseMatrix(91, 180, A_ir, A_jc, A_val); + + H->createDiagInfo(); + + real_t * H_full = H->full(); + real_t * A_full = A->full(); + + SymDenseMat * Hd = new SymDenseMat(180, 180, 180, H_full); + DenseMatrix * Ad = new DenseMatrix(91, 180, 180, A_full); + + /* solve with dense matrices */ + nWSR = 1000; + QProblem qrecipeD(180, 91); + qrecipeD.setOptions(options); + tic = getCPUtime(); + qrecipeD.init(Hd, g, Ad, lb, ub, lbA, ubA, nWSR, 0); + toc = getCPUtime(); + qrecipeD.getPrimalSolution(x1); + qrecipeD.getDualSolution(y1); + + fprintf(stdFile, "Solved dense problem in %d iterations, %.3f seconds.\n", (int)nWSR, toc - tic); + + /* solve with sparse matrices (nullspace factorization) */ + nWSR = 1000; + QProblem qrecipeS(180, 91); + /* for some reason this is necessary to pass the test when using MUMPS */ +#if USE_SOLVER == MUMPS + options.enableEqualities = BT_FALSE; +#endif + qrecipeS.setOptions(options); + tic = getCPUtime(); + qrecipeS.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + toc = getCPUtime(); + qrecipeS.getPrimalSolution(x2); + qrecipeS.getDualSolution(y2); + + fprintf(stdFile, "Solved sparse problem in %d iterations, %.3f seconds.\n", (int)nWSR, toc - tic); + +/* solve with sparse matrices (Schur complement) */ +#ifndef SOLVER_NONE + nWSR = 1000; + SQProblemSchur qrecipeSchur(180, 91); + qrecipeSchur.setOptions(options); + tic = getCPUtime(); + qrecipeSchur.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + toc = getCPUtime(); + qrecipeSchur.getPrimalSolution(x3); + qrecipeSchur.getDualSolution(y3); + + fprintf(stdFile, + "Solved sparse problem (Schur complement approach) in %d iterations, %.3f seconds.\n", + (int)nWSR, + toc - tic); +#endif /* SOLVER_NONE */ + + /* check distance of solutions */ + errP1 = 0.0; + errP2 = 0.0; + errP3 = 0.0; +#ifndef SOLVER_NONE + for (i = 0; i < 180; i++) + if (getAbs(x1[i] - x2[i]) > errP1) + errP1 = getAbs(x1[i] - x2[i]); + for (i = 0; i < 180; i++) + if (getAbs(x1[i] - x3[i]) > errP2) + errP2 = getAbs(x1[i] - x3[i]); + for (i = 0; i < 180; i++) + if (getAbs(x2[i] - x3[i]) > errP3) + errP3 = getAbs(x2[i] - x3[i]); +#endif /* SOLVER_NONE */ + fprintf(stdFile, "Primal error (dense and sparse): %9.2e\n", errP1); + fprintf(stdFile, "Primal error (dense and Schur): %9.2e\n", errP2); + fprintf(stdFile, "Primal error (sparse and Schur): %9.2e\n", errP3); + + errD1 = 0.0; + errD2 = 0.0; + errD3 = 0.0; + for (i = 0; i < 271; i++) + if (getAbs(y1[i] - y2[i]) > errD1) + errD1 = getAbs(y1[i] - y2[i]); +#ifndef SOLVER_NONE + for (i = 0; i < 271; i++) + if (getAbs(y1[i] - y3[i]) > errD2) + errD2 = getAbs(y1[i] - y3[i]); + for (i = 0; i < 271; i++) + if (getAbs(y2[i] - y3[i]) > errD3) + errD3 = getAbs(y2[i] - y3[i]); +#endif /* SOLVER_NONE */ + fprintf(stdFile, "Dual error (dense and sparse): %9.2e (might not be unique)\n", errD1); + fprintf(stdFile, "Dual error (dense and Schur): %9.2e (might not be unique)\n", errD2); + fprintf(stdFile, "Dual error (sparse and Schur): %9.2e (might not be unique)\n", errD3); + + delete H; + delete A; + delete[] H_full; + delete[] A_full; + delete Hd; + delete Ad; + + delete[] y3; + delete[] x3; + delete[] y2; + delete[] x2; + delete[] y1; + delete[] x1; + + QPOASES_TEST_FOR_TOL(errP1, 1e-13); + QPOASES_TEST_FOR_TOL(errP2, 1e-13); + QPOASES_TEST_FOR_TOL(errP3, 1e-13); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_qrecipe_data.hpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_qrecipe_data.hpp new file mode 100644 index 0000000..2ad54ce --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_qrecipe_data.hpp @@ -0,0 +1,2619 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_qrecipe.cpp + * \author Andreas Potschka + * \version 3.2 + * \date 2007-2017 + * + * QRECIPE example from the CUTEr test set with sparse matrices. + */ + +USING_NAMESPACE_QPOASES + +const real_t Inf = INFTY; + +sparse_int_t H_jc[] = {0, + 4, + 8, + 12, + 16, + 20, + 20, + 20, + 20, + 20, + 20, + 24, + 28, + 32, + 36, + 40, + 40, + 40, + 40, + 40, + 40, + 44, + 48, + 52, + 56, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 64, + 68, + 72, + 76, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80, + 80}; + +sparse_int_t H_ir[] = {0, + 10, + 20, + 34, + 1, + 11, + 21, + 35, + 2, + 12, + 22, + 36, + 3, + 13, + 23, + 37, + 4, + 14, + 24, + 38, + 0, + 10, + 20, + 34, + 1, + 11, + 21, + 35, + 2, + 12, + 22, + 36, + 3, + 13, + 23, + 37, + 4, + 14, + 24, + 38, + 0, + 10, + 20, + 34, + 1, + 11, + 21, + 35, + 2, + 12, + 22, + 36, + 3, + 13, + 23, + 37, + 4, + 14, + 24, + 38, + 0, + 10, + 20, + 34, + 1, + 11, + 21, + 35, + 2, + 12, + 22, + 36, + 3, + 13, + 23, + 37, + 4, + 14, + 24, + 38}; + +real_t H_val[] = {10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10, + 1, + 1, + 1, + 10}; + +sparse_int_t A_jc[] = {0, + 10, + 20, + 30, + 40, + 50, + 60, + 70, + 80, + 90, + 100, + 110, + 120, + 130, + 140, + 150, + 160, + 170, + 180, + 190, + 200, + 210, + 220, + 230, + 240, + 250, + 260, + 270, + 280, + 290, + 300, + 301, + 302, + 303, + 304, + 305, + 306, + 307, + 308, + 309, + 310, + 311, + 312, + 313, + 314, + 318, + 319, + 320, + 321, + 322, + 323, + 324, + 325, + 326, + 327, + 328, + 329, + 331, + 333, + 335, + 337, + 339, + 341, + 343, + 345, + 347, + 349, + 351, + 353, + 355, + 357, + 359, + 361, + 363, + 365, + 367, + 369, + 371, + 373, + 383, + 393, + 403, + 405, + 408, + 410, + 413, + 415, + 418, + 420, + 422, + 424, + 426, + 428, + 430, + 432, + 434, + 436, + 438, + 440, + 442, + 444, + 446, + 448, + 450, + 452, + 454, + 456, + 458, + 460, + 462, + 472, + 482, + 492, + 494, + 497, + 499, + 502, + 504, + 507, + 509, + 511, + 513, + 515, + 517, + 519, + 521, + 523, + 525, + 527, + 529, + 531, + 533, + 535, + 537, + 539, + 541, + 543, + 545, + 547, + 549, + 551, + 561, + 571, + 581, + 583, + 586, + 588, + 591, + 593, + 596, + 597, + 598, + 599, + 600, + 601, + 602, + 603, + 604, + 605, + 606, + 607, + 608, + 609, + 610, + 611, + 612, + 613, + 614, + 615, + 616, + 617, + 618, + 628, + 638, + 648, + 650, + 653, + 655, + 658, + 660, + 663}; + +sparse_int_t A_ir[] = {0, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 1, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 2, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 3, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 4, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 5, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 6, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 7, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 8, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 9, + 14, + 35, + 36, + 71, + 72, + 85, + 86, + 87, + 88, + 0, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 1, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 2, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 3, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 4, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 5, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 6, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 7, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 8, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 9, + 15, + 37, + 38, + 69, + 70, + 79, + 80, + 81, + 82, + 0, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 1, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 2, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 3, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 4, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 5, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 6, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 7, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 8, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 9, + 16, + 39, + 40, + 67, + 68, + 73, + 74, + 75, + 76, + 10, + 11, + 12, + 13, + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 47, + 48, + 49, + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + 47, + 58, + 48, + 59, + 49, + 60, + 50, + 61, + 51, + 62, + 52, + 63, + 53, + 64, + 54, + 65, + 55, + 66, + 46, + 56, + 45, + 57, + 47, + 58, + 48, + 59, + 49, + 60, + 50, + 61, + 51, + 62, + 52, + 63, + 53, + 64, + 54, + 65, + 55, + 66, + 46, + 56, + 45, + 57, + 10, + 14, + 71, + 72, + 85, + 86, + 87, + 88, + 89, + 90, + 11, + 15, + 69, + 70, + 79, + 80, + 81, + 82, + 83, + 84, + 12, + 16, + 67, + 68, + 73, + 74, + 75, + 76, + 77, + 78, + 35, + 90, + 36, + 89, + 90, + 37, + 84, + 38, + 83, + 84, + 39, + 78, + 40, + 77, + 78, + 44, + 58, + 43, + 59, + 42, + 60, + 41, + 61, + 34, + 62, + 33, + 63, + 32, + 64, + 31, + 65, + 30, + 66, + 29, + 46, + 28, + 45, + 44, + 58, + 43, + 59, + 42, + 60, + 41, + 61, + 34, + 62, + 33, + 63, + 32, + 64, + 31, + 65, + 30, + 66, + 29, + 46, + 28, + 45, + 10, + 14, + 71, + 72, + 85, + 86, + 87, + 88, + 89, + 90, + 11, + 15, + 69, + 70, + 79, + 80, + 81, + 82, + 83, + 84, + 12, + 16, + 67, + 68, + 73, + 74, + 75, + 76, + 77, + 78, + 35, + 90, + 36, + 89, + 90, + 37, + 84, + 38, + 83, + 84, + 39, + 78, + 40, + 77, + 78, + 27, + 44, + 26, + 43, + 25, + 42, + 24, + 41, + 23, + 34, + 22, + 33, + 21, + 32, + 20, + 31, + 19, + 30, + 18, + 29, + 17, + 28, + 27, + 44, + 26, + 43, + 25, + 42, + 24, + 41, + 23, + 34, + 22, + 33, + 21, + 32, + 20, + 31, + 19, + 30, + 18, + 29, + 17, + 28, + 10, + 14, + 71, + 72, + 85, + 86, + 87, + 88, + 89, + 90, + 11, + 15, + 69, + 70, + 79, + 80, + 81, + 82, + 83, + 84, + 12, + 16, + 67, + 68, + 73, + 74, + 75, + 76, + 77, + 78, + 35, + 90, + 36, + 89, + 90, + 37, + 84, + 38, + 83, + 84, + 39, + 78, + 40, + 77, + 78, + 27, + 26, + 25, + 24, + 23, + 22, + 21, + 20, + 19, + 18, + 17, + 27, + 26, + 25, + 24, + 23, + 22, + 21, + 20, + 19, + 18, + 17, + 10, + 14, + 71, + 72, + 85, + 86, + 87, + 88, + 89, + 90, + 11, + 15, + 69, + 70, + 79, + 80, + 81, + 82, + 83, + 84, + 12, + 16, + 67, + 68, + 73, + 74, + 75, + 76, + 77, + 78, + 35, + 90, + 36, + 89, + 90, + 37, + 84, + 38, + 83, + 84, + 39, + 78, + 40, + 77, + 78}; + +real_t A_val[] = {-1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.8678200000000004e+01, + 9.3617050000000006e+01, + 1.6000000000000000e+01, + 8.1999999999999993e+00, + 9.9000000000000000e+01, + 8.0000000000000000e+01, + 1.2000000000000000e+01, + 9.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.0062830000000005e+01, + 9.9224010000000007e+01, + 1.0000000000000000e+02, + 2.1100000000000001e+01, + 1.0000000000000000e+02, + 1.0000000000000000e+02, + 1.1400000000000000e+02, + 1.1680000000000000e+02, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.4697360000000003e+01, + 8.3801220000000001e+01, + -8.1999999999999993e+00, + 2.0000000000000000e+00, + 9.0000000000000000e+01, + 2.3999999999999999e+00, + -1.2000000000000000e+01, + -1.4800000000000001e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.9194209999999998e+01, + 9.0175110000000004e+01, + 4.3000000000000000e+01, + 8.0000000000000000e+00, + 1.0000000000000000e+02, + 9.5000000000000000e+01, + 9.0000000000000000e+00, + 2.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.8568219999999997e+01, + 8.5996200000000002e+01, + -1.2500000000000000e+01, + 1.0000000000000000e+00, + 9.6500000000000000e+01, + 4.0000000000000000e+00, + -1.8000000000000000e+01, + -2.1899999999999999e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.2922240000000002e+01, + 8.6963380000000001e+01, + 6.5000000000000000e+01, + 1.2500000000000000e+01, + 1.0000000000000000e+02, + 9.8000000000000000e+01, + 4.9000000000000000e+01, + 3.7000000000000000e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.2592740000000006e+01, + 9.3147599999999997e+01, + -1.2000000000000000e+01, + 1.0000000000000000e+00, + 9.6500000000000000e+01, + 4.0000000000000000e+00, + -1.8000000000000000e+01, + -2.1899999999999999e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.6506460000000004e+01, + 7.8210250000000002e+01, + 7.9000000000000000e+01, + 1.2000000000000000e+01, + 1.0000000000000000e+02, + 9.5000000000000000e+01, + 6.8000000000000000e+01, + 6.1000000000000000e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.8357460000000003e+01, + 9.4257840000000002e+01, + 1.2500000000000000e+02, + 6.1299999999999997e+01, + 1.0000000000000000e+02, + 1.0000000000000000e+02, + 1.4500000000000000e+02, + 1.4500000000000000e+02, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 9.0590469999999996e+01, + 1.0582863000000000e+02, + 6.2000000000000002e+00, + 6.0000000000000000e+00, + 9.7000000000000000e+01, + 2.8500000000000000e+01, + 4.0000000000000000e+00, + 3.6000000000000001e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.8678200000000004e+01, + 9.3617050000000006e+01, + 1.6000000000000000e+01, + 8.1999999999999993e+00, + 9.9000000000000000e+01, + 8.0000000000000000e+01, + 1.2000000000000000e+01, + 9.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.0062830000000005e+01, + 9.9224010000000007e+01, + 1.0000000000000000e+02, + 2.1100000000000001e+01, + 1.0000000000000000e+02, + 1.0000000000000000e+02, + 1.1400000000000000e+02, + 1.1680000000000000e+02, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.4697360000000003e+01, + 8.3801220000000001e+01, + -8.1999999999999993e+00, + 2.0000000000000000e+00, + 9.0000000000000000e+01, + 2.3999999999999999e+00, + -1.2000000000000000e+01, + -1.4800000000000001e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.9194209999999998e+01, + 9.0175110000000004e+01, + 4.3000000000000000e+01, + 8.0000000000000000e+00, + 1.0000000000000000e+02, + 9.5000000000000000e+01, + 9.0000000000000000e+00, + 2.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.8568219999999997e+01, + 8.5996200000000002e+01, + -1.2500000000000000e+01, + 1.0000000000000000e+00, + 9.6500000000000000e+01, + 4.0000000000000000e+00, + -1.8000000000000000e+01, + -2.1899999999999999e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.2922240000000002e+01, + 8.6963380000000001e+01, + 6.5000000000000000e+01, + 1.2500000000000000e+01, + 1.0000000000000000e+02, + 9.8000000000000000e+01, + 4.9000000000000000e+01, + 3.7000000000000000e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.2592740000000006e+01, + 9.3147599999999997e+01, + -1.2000000000000000e+01, + 1.0000000000000000e+00, + 9.6500000000000000e+01, + 4.0000000000000000e+00, + -1.8000000000000000e+01, + -2.1899999999999999e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.6506460000000004e+01, + 7.8210250000000002e+01, + 7.9000000000000000e+01, + 1.2000000000000000e+01, + 1.0000000000000000e+02, + 9.5000000000000000e+01, + 6.8000000000000000e+01, + 6.1000000000000000e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.8357460000000003e+01, + 9.4257840000000002e+01, + 1.2500000000000000e+02, + 6.1299999999999997e+01, + 1.0000000000000000e+02, + 1.0000000000000000e+02, + 1.4500000000000000e+02, + 1.4500000000000000e+02, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 9.0590469999999996e+01, + 1.0582863000000000e+02, + 6.2000000000000002e+00, + 6.0000000000000000e+00, + 9.7000000000000000e+01, + 2.8500000000000000e+01, + 4.0000000000000000e+00, + 3.6000000000000001e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.8678200000000004e+01, + 9.3617050000000006e+01, + 1.6000000000000000e+01, + 8.1999999999999993e+00, + 9.9000000000000000e+01, + 8.0000000000000000e+01, + 1.2000000000000000e+01, + 9.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.0062830000000005e+01, + 9.9224010000000007e+01, + 1.0000000000000000e+02, + 2.1100000000000001e+01, + 1.0000000000000000e+02, + 1.0000000000000000e+02, + 1.1400000000000000e+02, + 1.1680000000000000e+02, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.4697360000000003e+01, + 8.3801220000000001e+01, + -8.1999999999999993e+00, + 2.0000000000000000e+00, + 9.0000000000000000e+01, + 2.3999999999999999e+00, + -1.2000000000000000e+01, + -1.4800000000000001e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.9194209999999998e+01, + 9.0175110000000004e+01, + 4.3000000000000000e+01, + 8.0000000000000000e+00, + 1.0000000000000000e+02, + 9.5000000000000000e+01, + 9.0000000000000000e+00, + 2.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.8568219999999997e+01, + 8.5996200000000002e+01, + -1.2500000000000000e+01, + 1.0000000000000000e+00, + 9.6500000000000000e+01, + 4.0000000000000000e+00, + -1.8000000000000000e+01, + -2.1899999999999999e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.2922240000000002e+01, + 8.6963380000000001e+01, + 6.5000000000000000e+01, + 1.2500000000000000e+01, + 1.0000000000000000e+02, + 9.8000000000000000e+01, + 4.9000000000000000e+01, + 3.7000000000000000e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.2592740000000006e+01, + 9.3147599999999997e+01, + -1.2000000000000000e+01, + 1.0000000000000000e+00, + 9.6500000000000000e+01, + 4.0000000000000000e+00, + -1.8000000000000000e+01, + -2.1899999999999999e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 7.6506460000000004e+01, + 7.8210250000000002e+01, + 7.9000000000000000e+01, + 1.2000000000000000e+01, + 1.0000000000000000e+02, + 9.5000000000000000e+01, + 6.8000000000000000e+01, + 6.1000000000000000e+01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 8.8357460000000003e+01, + 9.4257840000000002e+01, + 1.2500000000000000e+02, + 6.1299999999999997e+01, + 1.0000000000000000e+02, + 1.0000000000000000e+02, + 1.4500000000000000e+02, + 1.4500000000000000e+02, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 9.0590469999999996e+01, + 1.0582863000000000e+02, + 6.2000000000000002e+00, + 6.0000000000000000e+00, + 9.7000000000000000e+01, + 2.8500000000000000e+01, + 4.0000000000000000e+00, + 3.6000000000000001e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.2000000000000000e-01, + -3.8000000000000000e-01, + -5.0000000000000000e-01, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.3000000000000000e+01, + -8.9000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -8.9000000000000000e+01, + -8.5000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.1000000000000000e+01, + -8.8000000000000000e+01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.3000000000000000e+01, + -8.9000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -8.9000000000000000e+01, + -8.5000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.1000000000000000e+01, + -8.8000000000000000e+01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.3000000000000000e+01, + -8.9000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -8.9000000000000000e+01, + -8.5000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.1000000000000000e+01, + -8.8000000000000000e+01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.3000000000000000e+01, + -8.9000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -8.9000000000000000e+01, + -8.5000000000000000e+01, + 1.0000000000000000e+00, + -1.0000000000000000e+00, + -4.7000000000000000e+01, + -8.6999999999999993e+00, + -9.0000000000000000e+01, + -5.0000000000000000e+01, + -1.0000000000000000e+01, + -1.0000000000000000e+01, + -9.1000000000000000e+01, + -8.8000000000000000e+01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 5.0000000000000000e-01, + -1.0000000000000000e+00, + 1.0000000000000000e+00, + 5.0000000000000000e-01}; + +real_t g[] = {+0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + -2e+00, + -2e+00, + -2e+00, + -2e+00, + -2e+00, + -2e+00, + -2e+00, + -2e+00, + +0e+00, + -2e+00, + +0e+00, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +1e-03, + +2e-03, + +2e-03, + +2e-03, + +0e+00, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -1e-03, + -2e-03, + -2e-03, + -2e-03, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +1e-03, + +2e-03, + +2e-03, + +2e-03, + +0e+00, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -1e-03, + -2e-03, + -2e-03, + -2e-03, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +2e-03, + +1e-03, + +2e-03, + +2e-03, + +2e-03, + +0e+00, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -2e-03, + -1e-03, + -2e-03, + -2e-03, + -2e-03, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +1e-01, + +1e-01, + +1e-01, + +1e-01, + +1e-01, + +1e-01, + +1e-01, + +1e-01, + +1e-01, + +1e-01, + +0e+00, + -1e-01, + -1e-01, + -1e-01, + -1e-01, + -1e-01, + -1e-01, + -1e-01, + -1e-01, + -1e-01, + -1e-01, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00, + +0e+00}; + +real_t lb[] = {0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + -Inf, + 0, + -Inf, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 10, + 5, + 10, + 5, + 0, + 10, + 0, + 2, + 0, + 10, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 10, + 5, + 10, + 5, + 0, + 10, + 0, + 5, + 0, + 10, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 10, + 5, + 10, + 5, + 0, + 10, + 0, + 5, + 0, + 10, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0}; + +real_t ub[] = {Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + 0, + 92, + 39, + 87, + 29, + 0, + 20, + 0, + 28, + 20, + 71, + Inf, + 130, + 45, + 53, + 55, + 75, + 112, + 0, + 73, + 480, + 154, + 121, + 50, + 30, + 77, + 20, + 0, + 18, + 0, + 5, + 20, + 71, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + 130, + 55, + 93, + 60, + 75, + 115, + 0, + 67, + 480, + 154, + 121, + 50, + 20, + 37, + 15, + 0, + 15, + 0, + 8, + 20, + 71, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + 130, + 55, + 93, + 60, + 75, + 105, + 0, + 67, + 4980, + 154, + 110, + 50, + 20, + 37, + 15, + 0, + 25, + 0, + 8, + 20, + 71, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + 20, + 20, + 20, + 20, + 0, + 20, + 0, + 20, + 0, + 20, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf}; + +real_t lbA[] = {0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + -Inf, + -Inf, + -Inf, + -Inf, + -Inf, + -Inf, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0}; + +real_t ubA[] = {0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf, + Inf}; + +long H_nnz = sizeof(H_val) / sizeof(real_t); +long A_nnz = sizeof(A_val) / sizeof(real_t); diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_runAllOqpExamples.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_runAllOqpExamples.cpp new file mode 100644 index 0000000..1e7fb92 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_runAllOqpExamples.cpp @@ -0,0 +1,174 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_runAllOqpExamples.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2013-2017 + * + * Use qpOASES for solving all QP sequences of the Online QP Benchmark + * Collection. In order to run it, you have to download all examples + * from http://www.qpOASES.org/onlineQP/. + */ + +#include +#include + +/** Example for qpOASES main function using the OQP interface. */ +int main() +{ + USING_NAMESPACE_QPOASES + + /* 1) Define benchmark arguments. */ + BooleanType isSparse = BT_FALSE; + BooleanType useHotstarts; + + Options options; + options.setToMPC(); + options.printLevel = PL_LOW; + + int_t maxAllowedNWSR; + real_t maxNWSR, avgNWSR, maxCPUtime, avgCPUtime; + real_t maxStationarity, maxFeasibility, maxComplementarity; + + const int_t numBenchmarks = 4; // 5 + const char * benchmarkPath[numBenchmarks]; + benchmarkPath[0] = "../testing/cpp/data/oqp/chain80/"; + benchmarkPath[1] = "../testing/cpp/data/oqp/chain80w/"; + benchmarkPath[2] = "../testing/cpp/data/oqp/diesel/"; + benchmarkPath[3] = "../testing/cpp/data/oqp/crane/"; + // benchmarkPath[4] = "../testing/cpp/data/oqp/CDU/"; + + /* 2) Run all benchmarks in a loop */ + for (int_t ii = 0; ii < 2 * numBenchmarks; ++ii) { + if (ii % 2 == 0) + useHotstarts = BT_FALSE; + else + useHotstarts = BT_TRUE; + + maxAllowedNWSR = 1000; + maxNWSR = 0.0; + avgNWSR = 0.0; + maxCPUtime = 1000.0; /* seconds */ + avgCPUtime = 0.0; /* seconds */ + maxStationarity = 0.0; + maxFeasibility = 0.0; + maxComplementarity = 0.0; + + if (runOqpBenchmark(benchmarkPath[ii / 2], + isSparse, + useHotstarts, + options, + maxAllowedNWSR, + maxNWSR, + avgNWSR, + maxCPUtime, + avgCPUtime, + maxStationarity, + maxFeasibility, + maxComplementarity) != SUCCESSFUL_RETURN) { + myPrintf("Something went wrong when running benchmark!\n"); + return TEST_DATA_NOT_FOUND; + } + + /* 3) Print results. */ + printf("\n\n"); + if (useHotstarts == BT_FALSE) + printf("OQP Benchmark Results for %s (cold-starts):\n", benchmarkPath[ii / 2]); + else + printf("OQP Benchmark Results for %s (hot-starts):\n", benchmarkPath[ii / 2]); + + printf("===========================================================================\n\n"); + printf("maximum CPU time: %.2f milliseconds\n", 1000.0 * maxCPUtime); + printf("average CPU time: %.2f milliseconds\n", 1000.0 * avgCPUtime); + printf("\n"); + printf("maximum iterations: %.1f\n", maxNWSR); + printf("average iterations: %.1f\n", avgNWSR); + printf("\n"); + printf("maximum violation stationarity: %.3e\n", maxStationarity); + printf("maximum violation feasibility: %.3e\n", maxFeasibility); + printf("maximum violation complementarity: %.3e\n", maxComplementarity); + printf("\n"); + + QPOASES_TEST_FOR_TOL(maxStationarity, 1e-9); + QPOASES_TEST_FOR_TOL(maxFeasibility, 2e-11); + QPOASES_TEST_FOR_TOL(maxComplementarity, 2e-10); + + switch (ii) { + case 0: + /* chain80 (cold) */ + QPOASES_TEST_FOR_TRUE(maxNWSR <= 62.5); + QPOASES_TEST_FOR_TRUE(avgNWSR <= 7.5); + break; + + case 1: + /* chain80 (hot) */ + QPOASES_TEST_FOR_TRUE(maxNWSR <= 19.5); + QPOASES_TEST_FOR_TRUE(avgNWSR <= 2.4); + break; + + case 2: + /* chain80w (cold) */ + QPOASES_TEST_FOR_TRUE(maxNWSR <= 84.5); + QPOASES_TEST_FOR_TRUE(avgNWSR <= 10.1); + break; + + case 3: + /* chain80w (hot) */ + QPOASES_TEST_FOR_TRUE(maxNWSR <= 16.5); + QPOASES_TEST_FOR_TRUE(avgNWSR <= 2.7); + break; + + case 4: + /* diesel (cold) */ + QPOASES_TEST_FOR_TRUE(maxNWSR <= 26.5); + QPOASES_TEST_FOR_TRUE(avgNWSR <= 0.5); + break; + + case 5: + /* diesel (hot) */ + QPOASES_TEST_FOR_TRUE(maxNWSR <= 22.5); + QPOASES_TEST_FOR_TRUE(avgNWSR <= 0.3); + break; + + case 6: + /* crane (cold) */ + QPOASES_TEST_FOR_TRUE(maxNWSR <= 64.5); + QPOASES_TEST_FOR_TRUE(avgNWSR <= 44.0); + break; + + case 7: + /* crane (hot) */ + QPOASES_TEST_FOR_TRUE(maxNWSR <= 42.5); + QPOASES_TEST_FOR_TRUE(avgNWSR <= 0.4); + break; + } + } + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_sebastien1.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_sebastien1.cpp new file mode 100644 index 0000000..55cffb1 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_sebastien1.cpp @@ -0,0 +1,71 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_sebastien1.cpp + * \author Sebastien B. + * \version 3.2 + * \date 2007-2017 + * + * Example that caused troubles in an earlier release. + */ + +#include +#include + +/** qpOASES main function defining a unit test. */ +int main() +{ + REFER_NAMESPACE_QPOASES real_t solution[2] = {0.0f, 0.0f}; + REFER_NAMESPACE_QPOASES real_t expectedFirst[2] = {0.5f, -1.5f}; + + REFER_NAMESPACE_QPOASES real_t H[2 * 2] = {1.0f, 0.0f, 0.0f, 0.5f}; + REFER_NAMESPACE_QPOASES real_t g[2] = {1.5f, 1.0f}; + + REFER_NAMESPACE_QPOASES real_t A[1 * 2] = {1.0f, 1.0f}; + REFER_NAMESPACE_QPOASES real_t lbA[1] = {-1.0f}; + REFER_NAMESPACE_QPOASES real_t ubA[1] = {2.0f}; + + REFER_NAMESPACE_QPOASES real_t lb[2] = {0.5f, -2.0f}; + REFER_NAMESPACE_QPOASES real_t ub[2] = {5.0f, 2.0f}; + + REFER_NAMESPACE_QPOASES QProblem example(2, 1); + REFER_NAMESPACE_QPOASES Options options = example.getOptions(); + // options.enableFarBounds = REFER_NAMESPACE_QPOASES BT_FALSE; + example.setOptions(options); + example.setPrintLevel(REFER_NAMESPACE_QPOASES PL_NONE); + + // Solve first QP. + REFER_NAMESPACE_QPOASES int_t nWSR = 10; + QPOASES_TEST_FOR_TRUE( + example.init(H, g, A, lb, ub, lbA, ubA, nWSR, NULL) == REFER_NAMESPACE_QPOASES SUCCESSFUL_RETURN); + QPOASES_TEST_FOR_TRUE(example.isSolved() == REFER_NAMESPACE_QPOASES BT_TRUE); + example.getPrimalSolution(solution); + + printf("\nxOpt = [ %e, %e ];\n\n", solution[0], solution[1]); + + for (REFER_NAMESPACE_QPOASES uint_t i = 0; i < 2; i++) + QPOASES_TEST_FOR_NEAR(solution[i], expectedFirst[i]); + + return TEST_PASSED; +} diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_smallSchur.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_smallSchur.cpp new file mode 100644 index 0000000..c8c7f78 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_smallSchur.cpp @@ -0,0 +1,152 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_smallSchur.cpp + * \author Dennis Janka + * \version 3.2 + * \date 2007-2017 + * + */ + +#include +#include + +int main() +{ + USING_NAMESPACE_QPOASES + + int_t i; + const int_t m = 200; + const int_t n = 2 * m + 1; + + /* problem data */ + sparse_int_t H_jc[n + 1], H_ir[n], A_jc[n + 1], A_ir[m]; + real_t H_val[n], A_val[m], g[n], lb[n], ub[n], lbA[m], ubA[m]; + for (i = 0; i < n + 1; i++) + H_jc[i] = i; + for (i = 0; i < n; i++) + H_ir[i] = i; + for (i = 0; i < n; i++) + H_val[i] = 2.0; + for (i = 0; i < m; i++) + A_jc[i] = i; + for (i = m; i < n + 1; i++) + A_jc[i] = m; + for (i = 0; i < m; i++) + A_ir[i] = i; + for (i = 0; i < m; i++) + A_val[i] = 1.0; + for (i = 0; i < n; i++) + g[i] = 0.0; + for (i = 0; i < n; i++) + lb[i] = -1.0; + for (i = 0; i < n; i++) + ub[i] = 1.0; + for (i = 0; i < m; i++) + lbA[i] = 0.5; + for (i = 0; i < m; i++) + ubA[i] = 0.5; + + int_t nWSR; + real_t errP, errD, tic, toc; + real_t * xref = new real_t[n]; + real_t * yref = new real_t[n + m]; + real_t * x = new real_t[n]; + real_t * y = new real_t[n + m]; + + Options options; + options.setToDefault(); + options.printLevel = PL_TABULAR; + options.initialStatusBounds = ST_UPPER; + /* options.enableEqualities = BT_FALSE; */ + + /* create sparse matrices */ + SymSparseMat * H = new SymSparseMat(n, n, H_ir, H_jc, H_val); + SparseMatrix * A = new SparseMatrix(m, n, A_ir, A_jc, A_val); + + H->createDiagInfo(); + + /* solve with dense matrices */ + nWSR = 1000; + QProblem qpD(n, m); + qpD.setOptions(options); + tic = getCPUtime(); + qpD.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + toc = getCPUtime(); + qpD.getPrimalSolution(xref); + qpD.getDualSolution(yref); + + fprintf(stdFile, "Solved problem with dense LA in %d iterations, %.3f seconds.\n", (int)nWSR, toc - tic); + +/* solve with sparse matrices (Schur complement) */ +#ifndef SOLVER_NONE + nWSR = 10000; + SQProblemSchur qp(n, m); + // qp.setOptions(options); + tic = getCPUtime(); + qp.init(H, g, A, lb, ub, lbA, ubA, nWSR, 0); + toc = getCPUtime(); + qp.getPrimalSolution(x); + qp.getDualSolution(y); + + fprintf(stdFile, + "Solved problem with Schur complement approach in %d iterations, %.3f seconds.\n", + (int)nWSR, + toc - tic); +#endif /* SOLVER_NONE */ + + /* check distance of solutions */ + errP = 0.0; +#ifndef SOLVER_NONE + for (i = 0; i < n; i++) + if (getAbs(x[i] - xref[i]) > errP) + errP = getAbs(x[i] - xref[i]); +#endif /* SOLVER_NONE */ + fprintf(stdFile, "Primal error: %9.2e\n", errP); + + errD = 0.0; +#ifndef SOLVER_NONE + for (i = 0; i < n + m; i++) + if (getAbs(y[i] - yref[i]) > errD) + errD = getAbs(y[i] - yref[i]); +#endif /* SOLVER_NONE */ + fprintf(stdFile, "Dual error: %9.2e\n", errD); + + delete H; + delete A; + + delete[] y; + delete[] x; + delete[] yref; + delete[] xref; + + QPOASES_TEST_FOR_TOL(errP, 1e-12); + QPOASES_TEST_FOR_TOL(errD, 1e-12); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_vanBarelsUnboundedQP.cpp b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_vanBarelsUnboundedQP.cpp new file mode 100644 index 0000000..b7f307b --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/cpp/test_vanBarelsUnboundedQP.cpp @@ -0,0 +1,63 @@ +/* + * This file is part of qpOASES. + * + * qpOASES -- An Implementation of the Online Active Set Strategy. + * Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, + * Christian Kirches et al. All rights reserved. + * + * qpOASES is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * qpOASES is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with qpOASES; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** + * \file testing/cpp/test_vanBarelsUnboundedQP.cpp + * \author Hans Joachim Ferreau + * \version 3.2 + * \date 2007-2017 + * + * Example that causes troubles when hotstarting. + */ + +#include +#include + +#include + +int main() +{ + USING_NAMESPACE_QPOASES + + real_t H[2 * 2] = {1.0, 0.0, 0.0, 0.0}; + real_t g[2] = {1.5, 1.0}; + + Options options; + // options.enableFarBounds = BT_FALSE; + + QProblemB qp(2); + qp.setOptions(options); + + int_t iter = 10; + qp.init(H, g, 0, 0, iter); + + real_t xOpt[2]; + qp.getPrimalSolution(xOpt); + print(xOpt, 2); + + return TEST_PASSED; +} + +/* + * end of file + */ diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/generateExample.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/generateExample.m new file mode 100755 index 0000000..9476d7e --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/generateExample.m @@ -0,0 +1,25 @@ +function [ qpData ] = generateExample( nV,nC, isSparseH,isSparseA, hasLowerB,hasUpperB,hasLowerC,hasUpperC, seed, givenH,givenA ) + + if ( nargin < 11 ) + givenA = []; + if ( nargin < 10 ) + givenH = []; + end + end + + qpFeatures = setupQpFeaturesStruct( ); + + qpFeatures.nV = nV; + qpFeatures.nC = nC; + + qpFeatures.isSparseH = isSparseH; + qpFeatures.isSparseA = isSparseA; + + qpFeatures.hasLowerB = hasLowerB; + qpFeatures.hasUpperB = hasUpperB; + qpFeatures.hasLowerC = hasLowerC; + qpFeatures.hasUpperC = hasUpperC; + + qpData = generateRandomQp( qpFeatures,seed, givenH,givenA ); + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/generateRandomQp.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/generateRandomQp.m new file mode 100755 index 0000000..3fd4fd3 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/generateRandomQp.m @@ -0,0 +1,110 @@ +function [ qpData ] = generateRandomQp( qpFeatures,randSeed, givenH,givenA ) + + if ( nargin < 4 ) + givenA = []; + if ( nargin < 3 ) + givenH = []; + end + end + + if ( isoctave == 0 ) + if ( nargin < 2 ) + s = RandStream( 'mt19937ar', 'Seed','shuffle' ); + RandStream.setGlobalStream(s); + else + s = RandStream( 'mt19937ar', 'Seed',randSeed ); + RandStream.setGlobalStream(s); + end + end + + + qpData = setupQpDataStruct( ); + qpData.nV = qpFeatures.nV; + qpData.nC = qpFeatures.nC; + + + % generate random optimal primal solution + xFeas = rand( qpFeatures.nV,1 ); + + % generate random optimal dual solution + %yOpt = zeros( qpFeatures.nV+qpFeatures.nC,1 ); + + if ( isempty(givenH) > 0 ) + + switch ( qpFeatures.hessianType ) + + case 0 + qpData.H = 100 * rand( qpData.nV,qpData.nV ) - 50; + qpData.H = qpData.H' * qpData.H / 2; + + case 1 + qpData.H = 100 * rand( qpData.nV,round(qpData.nV/2) ) - 50; + qpData.H = qpData.H' * qpData.H / 2; + + case 2 + qpData.H = eye( qpData.nV ); + + case 3 + qpData.H = zeros( qpData.nV,qpData.nV ); + + end + + else + qpData.H = givenH; + end + + qpData.g = 1000 * rand( qpFeatures.nV,1 ) - 500; + + if ( isempty(givenA) > 0 ) + + if ( qpFeatures.nC > 0 ) + qpData.Ain = 100 * rand( qpData.nC,qpData.nV ) - 50; + else + qpData.Ain = []; + end + + else + qpData.Ain = givenA; + end + + if ( qpFeatures.makeInfeas > 0 ) + alpha = -0.1; + beta = -0.001; + else + alpha = 1; + beta = 1; + end + + if ( qpFeatures.hasLowerB > 0 ) + qpData.lb = xFeas - 3*rand( qpData.nV,1 ); + else + qpData.lb = []; + end + + if ( qpFeatures.hasUpperB > 0 ) + qpData.ub = xFeas + alpha*3*rand( qpData.nV,1 ); + else + qpData.ub = []; + end + + if ( ( qpFeatures.hasLowerC > 0 ) && ( qpData.nC > 0 ) ) + qpData.lbA = qpData.Ain*xFeas - 100*rand( qpData.nC,1 ); + else + qpData.lbA = []; + end + + if ( ( qpFeatures.hasUpperC > 0 ) && ( qpData.nC > 0 ) ) + qpData.ubA = qpData.Ain*xFeas + beta*100*rand( qpData.nC,1 ); + else + qpData.ubA = []; + end + + if ( qpFeatures.isSparseH > 0 ) + qpData.H = sparse( qpData.H ); + end + + if ( qpFeatures.isSparseA > 0 ) + qpData.Ain = sparse( qpData.Ain ); + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/getKktResidual.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/getKktResidual.m new file mode 100755 index 0000000..55b17a0 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/getKktResidual.m @@ -0,0 +1,134 @@ +function [kkt,stat,feas,cmpl] = getKktResidual( H,g,A,lb,ub,lbA,ubA, x,y ) + + % Tolerance for dual variables considered zero. + dualActiveTolerance = 1.0e3 * eps; + + % Initialize residuals + stat = 0.0; + feas = 0.0; + cmpl = 0.0; + + if ( isempty(H) == 0 ) + nV = size( H,1 ); + else + nV = size( g,2 ); + end + + if ( isempty(A) == 0 ) + nC = size( A,1 ); + else + nC = 0; + end + + + %% check stationarity + for i=1:nV + + % g term and variable bounds dual term + if ( isempty(g) == 0 ) + sum = g(i) - y(i); + else + sum = 0 - y(i); + end + + % H*x term + if ( isempty(H) == 0 ) + sum = sum + H(i,:) * x; + end + + % A'*y term + if ( isempty(A) == 0 ) + sum = sum - A(:,i)' * y(nV+1:nV+nC); + end + + % update stat + if (abs(sum) > stat) + stat = abs(sum); + end + + end + + %% check primal feasibility and complementarity + % variable bounds + for i=1:nV + + % feasibility + if ( isempty(lb) == 0 ) + if (lb(i) - x(i) > feas) + feas = lb(i) - x(i); + end + end + + if ( isempty(ub) == 0 ) + if (x(i) - ub(i) > feas) + feas = x(i) - ub(i); + end + end + + % complementarity + prod = 0.0; + + if ( isempty(lb) == 0 ) + if (y(i) > dualActiveTolerance) % lower bound + prod = (x(i) - lb(i)) * y(i); + end + end + + if ( isempty(ub) == 0 ) + if (y(i) < -dualActiveTolerance) % upper bound + prod = (x(i) - ub(i)) * y(i); + end + end + + if (abs(prod) > cmpl) + cmpl = abs(prod); + end + + end + + % A*x bounds + for i=1:nC + + % compute sum = (A*x)_i + sum = 0.0; + if ( isempty(A) == 0 ) + sum = sum + A(i,:) * x; + end + + % feasibility + if ( isempty(lbA) == 0 ) + if (lbA(i) - sum > feas) + feas = lbA(i) - sum; + end + end + + if ( isempty(ubA) == 0 ) + if (sum - ubA(i) > feas) + feas = sum - ubA(i); + end + end + + % complementarity + prod = 0.0; + + if ( isempty(lbA) == 0 ) + if (y(nV+i) > dualActiveTolerance) % lower bound + prod = (sum - lbA(i)) * y(nV+i); + end + end + + if ( isempty(ubA) == 0 ) + if (y(nV+i) < -dualActiveTolerance) % upper bound + prod = (sum - ubA(i)) * y(nV+i); + end + end + + if (abs(prod) > cmpl) + cmpl = abs(prod); + end + + end + + kkt = max( [stat,feas,cmpl] ); + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/isoctave.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/isoctave.m new file mode 100755 index 0000000..e4726d4 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/isoctave.m @@ -0,0 +1,21 @@ + +% ISOCTAVE True if the operating environment is octave. +% Usage: t=isoctave(); +% +% Returns 1 if the operating environment is octave, otherwise +% 0 (Matlab) +% +% --------------------------------------------------------------- +function t=isoctave() +%ISOCTAVE True if the operating environment is octave. +% Usage: t=isoctave(); +% +% Returns 1 if the operating environment is octave, otherwise +% 0 (Matlab) + +if exist('OCTAVE_VERSION') + % Only Octave has this variable. + t=1; +else + t=0; +end; diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/setupQpDataStruct.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/setupQpDataStruct.m new file mode 100755 index 0000000..93d9e3c --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/setupQpDataStruct.m @@ -0,0 +1,18 @@ +function [ qpData ] = setupQpDataStruct( ) + + qpData = struct( 'H', [], ... % Hessian matrix + 'g', [], ... % gradient vector + 'Aeq', [], ... % equality constraints matrix + 'beq', [], ... % equality constraints vector + 'lb', [], ... % lower bound vector + 'ub', [], ... % upper bound vector + 'Ain', [], ... % inequality constraints matrix + 'lbA', [], ... % lower constraints vector + 'ubA', [], ... % upper constraints vector + 'x0', [], ... % primal initial guess + 'options', [], ... % QP solver options + 'nV', 0, ... % number of QP variables + 'nC', 0 ... % number of constraints + ); + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/setupQpFeaturesStruct.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/setupQpFeaturesStruct.m new file mode 100755 index 0000000..903a891 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/auxFiles/setupQpFeaturesStruct.m @@ -0,0 +1,21 @@ +function [ qpFeatures ] = setupQpFeaturesStruct( ) + + qpFeatures = struct( 'nV', 0, ... + 'nIB', 0, ... + 'nEB', 0, ... + 'nC', 0, ... + 'nIC', 0, ... + 'nEC', 0, ... + 'nActB', 0, ... + 'nActC', 0, ... + 'hasLowerB', 0, ... + 'hasUpperB', 0, ... + 'hasLowerC', 0, ... + 'hasUpperC', 0, ... + 'isSparseH', 0, ... + 'isSparseA', 0, ... + 'makeInfeas', 0, ... + 'hessianType', 0 ... % 0 = pos def; 1 = pos sem def; 2 = id; 3 = zero + ); + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/data/fetch_matlab_data b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/data/fetch_matlab_data new file mode 100755 index 0000000..aaac94b --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/data/fetch_matlab_data @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: testing/matlab/data/fetch_matlab_data +## Author: Hans Joachim Ferreau +## Version: 3.2 +## Date: 2014-2017 + + +svn export https://projects.coin-or.org/svn/qpOASES/misc/testingdata/matlab . --force diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/runAllTests.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/runAllTests.m new file mode 100755 index 0000000..f17b0a0 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/runAllTests.m @@ -0,0 +1,152 @@ +function [ successFlag ] = runAllTests( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 1; + + curWarnLevel = warning; + warning('off'); + + % add sub-folders to Matlab path + setupTestingPaths(); + + clc; + + %% run interface tests + fprintf( 'Running qpOASES interface tests... ' ) + successFlag = updateSuccessFlag( successFlag, runInterfaceTest( 10,20, doPrint,42 ) ); + + fprintf( 'Running qpOASES_sequence interface tests... ' ) + successFlag = updateSuccessFlag( successFlag, runInterfaceSeqTest( 8,5, doPrint,42 ) ); + + + %% run functional tests + fprintf( 'Running tests with random QPs having identity Hessian... ' ) + successFlag = updateSuccessFlag( successFlag, runRandomIdHessian( 12,12, doPrint,4242 ) ); + + fprintf( 'Running tests with random QPs having zero Hessian... ' ) + successFlag = updateSuccessFlag( successFlag, runRandomZeroHessian( 11,41, doPrint,4242 ) ); + + fprintf( 'Running qpOASES passing an empty Hessian matrix argument... ' ) + successFlag = updateSuccessFlag( successFlag, runEmptyHessianTests( doPrint ) ); + + fprintf( 'Running alternativeX0 test... ' ) + successFlag = updateSuccessFlag( successFlag, runAlternativeX0Test( 50,300,doPrint,4242 ) ); + + fprintf( 'Running testAPrioriKnownSeq1... ' ) + successFlag = updateSuccessFlag( successFlag, runTestAPrioriKnownSeq1( doPrint ) ); + + fprintf( 'Running testSeq... ' ) + successFlag = updateSuccessFlag( successFlag, runTestSeq( doPrint ) ); + + fprintf( 'Running testSparse... ' ) + successFlag = updateSuccessFlag( successFlag, runTestSparse( doPrint ) ); + + fprintf( 'Running testSparse2... ' ) + successFlag = updateSuccessFlag( successFlag, runTestSparse2( doPrint ) ); + + fprintf( 'Running testSparse3... ' ) + successFlag = updateSuccessFlag( successFlag, runTestSparse3( doPrint ) ); + + fprintf( 'Running testSparse4... ' ) + successFlag = updateSuccessFlag( successFlag, runTestSparse4( doPrint ) ); + + fprintf( 'Running simpleSpringExample... ' ) + successFlag = updateSuccessFlag( successFlag, runSimpleSpringExample( doPrint ) ); + + fprintf( 'Running vanBarelsUnboundedQP... ' ) + successFlag = updateSuccessFlag( successFlag, runVanBarelsUnboundedQP( doPrint ) ); + + fprintf( 'Running alexInfeas1... ' ) + successFlag = updateSuccessFlag( successFlag, runAlexInfeas1( doPrint ) ); + + %fprintf( 'Running alexInfeas2... ' ) + %successFlag = updateSuccessFlag( successFlag, runAlexInfeas2( doPrint ) ); + + %fprintf( 'Running QAP8... ' ) + %successFlag = updateSuccessFlag( successFlag, runQAP( doPrint ) ); + + fprintf( 'Running testWorkingSetLI... ' ) + successFlag = updateSuccessFlag( successFlag, runTestWorkingSetLI( doPrint ) ); + + fprintf( 'Running runExternalCholeskyTests... ' ) + successFlag = updateSuccessFlag( successFlag, runExternalCholeskyTests( doPrint ) ); + + fprintf( 'Running EXAMPEL1... ' ); + successFlag = updateSuccessFlag( successFlag, runBenchmarkEXAMPLE1( 10,doPrint ) ); + + fprintf( 'Running EXAMPLE1A... ' ); + successFlag = updateSuccessFlag( successFlag, runBenchmarkEXAMPLE1A( 10,doPrint ) ); + + fprintf( 'Running EXAMPLE1B... ' ); + successFlag = updateSuccessFlag( successFlag, runBenchmarkEXAMPLE1B( 10,doPrint ) ); + + fprintf( 'Running CHAIN1... ' ); + successFlag = updateSuccessFlag( successFlag, runBenchmarkCHAIN1( 20,doPrint ) ); + + fprintf( 'Running CHAIN1A... ' ); + successFlag = updateSuccessFlag( successFlag, runBenchmarkCHAIN1A( 20,doPrint ) ); + + fprintf( 'Running CRANE1... ' ); + successFlag = updateSuccessFlag( successFlag, runBenchmarkCRANE1( 100,doPrint ) ); + + fprintf( 'Running CRANE2... ' ); + successFlag = updateSuccessFlag( successFlag, runBenchmarkCRANE2( 100,doPrint ) ); + + fprintf( 'Running CRANE3... ' ); + successFlag = updateSuccessFlag( successFlag, runBenchmarkCRANE3( 100,doPrint ) ); + + fprintf( 'Running EQUALITY1... ' ); + successFlag = updateSuccessFlag( successFlag, runBenchmarkEQUALITY1( 100,doPrint ) ); + + fprintf( 'Running EQUALITY2... ' ); + successFlag = updateSuccessFlag( successFlag, runBenchmarkEQUALITY2( 3200,doPrint ) ); + + %fprintf( 'Running IDHESSIAN1... ' ); + %successFlag = updateSuccessFlag( successFlag, runBenchmarkIDHESSIAN1( 1200,doPrint ) ); + + fprintf( 'Running DIESEL... ' ); + successFlag = updateSuccessFlag( successFlag, runBenchmarkDIESEL( 230,doPrint ) ); + + fprintf( 'Running QSHARE1B... ' ) + successFlag = updateSuccessFlag( successFlag, runQSHARE1B( doPrint ) ); + + + + %% display results + disp( ' ' ); + + if ( successFlag == 0 ) + disp( 'At least one test failed!' ); + else + disp( 'All available tests passed successfully!' ); + end + + warning( curWarnLevel ); + +end + + +function [ newSuccessFlag ] = updateSuccessFlag( curSuccessFlag,curResult ) + + switch ( curResult ) + + case 0 + newSuccessFlag = 0; + fprintf( 'failed!\n' ); + + case 1 + newSuccessFlag = curSuccessFlag; + fprintf( 'passed!\n' ); + + case -1 + newSuccessFlag = curSuccessFlag; + fprintf( 'problem data missing!\n' ); + + otherwise + error( 'Unknown success flag!' ); + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/setupTestingPaths.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/setupTestingPaths.m new file mode 100755 index 0000000..6373d11 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/setupTestingPaths.m @@ -0,0 +1,14 @@ +function [] = setupTestingPaths( ) + + addpath(genpath(pwd)); + addpath(genpath([pwd 'auxFiles'])); + addpath(genpath([pwd 'data'])); + addpath(genpath([pwd 'tests'])); + + if isoctave + addpath('../../interfaces/octave/'); + else + addpath('../../interfaces/matlab/'); + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runAlexInfeas1.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runAlexInfeas1.m new file mode 100755 index 0000000..d1977ed --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runAlexInfeas1.m @@ -0,0 +1,30 @@ +function [ successFlag ] = runAlexInfeas1( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 0; + + try + data = load( 'alexInfeas1.mat' ); + catch + successFlag = -1; + return; + end + + options1 = qpOASES_options( 'default', 'printLevel',-2*doPrint ); + + [x1,dummy,exitflag1] = qpOASES( data.H,data.g,data.A, ... + data.lb,data.ub,data.lbA,data.ubA, options1 ); %#ok<*NASGU> + + % should return "QP infeasible" + if ( exitflag1 == -2 ) + successFlag = 1; + else + if ( doPrint > 0 ) + disp( [data.lbA data.A*x1 data.ubA] ); + end + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runAlexInfeas2.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runAlexInfeas2.m new file mode 100755 index 0000000..730a01c --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runAlexInfeas2.m @@ -0,0 +1,35 @@ +function [ successFlag ] = runAlexInfeas2( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 0; + + try + data = load( 'alexInfeas2.mat' ); + catch + successFlag = -1; + return; + end + + options1 = qpOASES_options( 'default', 'printLevel',-2*doPrint,... + 'maxIter',7000, 'enableFlippingBounds',0,... + 'terminationTolerance',1e7*eps); + + options2 = qpOASES_options( 'MPC', 'printLevel',-2*doPrint,... + 'maxIter',3000, 'terminationTolerance',1e8*eps ); + + [x1,dummy,exitflag1] = qpOASES( data.H,data.g,data.A, ... + data.lb,data.ub,data.lbA,data.ubA, options1 ); %#ok<*NASGU> + + % should return "QP infeasible" + if ( exitflag1 == -2 ) + successFlag = 1; + else + if ( doPrint > 0 ) + %disp( [data.lbA data.A*x1 data.ubA] ); + end + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runAlternativeX0Test.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runAlternativeX0Test.m new file mode 100755 index 0000000..3178ed2 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runAlternativeX0Test.m @@ -0,0 +1,84 @@ +function [ successFlag ] = runAlternativeX0Test( nV,nC, doPrint,seed ) + + if ( nargin < 4 ) + seed = 4242; + if ( nargin < 3 ) + doPrint = 0; + if ( nargin < 2 ) + nC = 300; + if ( nargin < 1 ) + nV = 50; + end + end + end + end + + successFlag = 1; + TOL = eps; + + qpData = generateExample( nV,nC, 0,0, 0,1,1,1, seed ); + + H = qpData.H; + g = qpData.g; + A = [qpData.Aeq;qpData.Ain]; + lb = qpData.lb; + ub = qpData.ub; + lbA = [qpData.beq;qpData.lbA]; + ubA = [qpData.beq;qpData.ubA]; + + x0 = nV*rand( nV,1 ); + + options = qpOASES_options( 'default', 'printLevel',2*doPrint ); + auxInput = qpOASES_auxInput( 'x0',x0 ); + + [ x1,f1,e1,i1,l1 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],x0 ); + [ x2,f2,e2,i2,l2 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x3,f3,e3,i3,l3 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,x0 ); + [ x4,f4,e4,i4,l4 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + + if ( ( norm(x1-x2) > TOL ) || ... + ( norm(x1-x3) > TOL ) || ... + ( norm(x1-x4) > TOL ) ) + if ( doPrint > 0 ) + disp('diff in x') + end + successFlag = 0; + end + + if ( ( norm(f1-f2) > TOL ) || ... + ( norm(f1-f3) > TOL ) || ... + ( norm(f1-f4) > TOL ) ) + if ( doPrint > 0 ) + disp('diff in fval') + end + successFlag = 0; + end + + if ( ( norm(e1-e2) > TOL ) || ... + ( norm(e1-e3) > TOL ) || ... + ( norm(e1-e4) > TOL ) ) + if ( doPrint > 0 ) + disp('diff in exitflag') + end + successFlag = 0; + end + + if ( ( norm(i1-i2) > TOL ) || ... + ( norm(i1-i3) > TOL ) || ... + ( norm(i1-i4) > TOL ) ) + if ( doPrint > 0 ) + disp('diff in iter') + end + successFlag = 0; + end + + if ( ( norm(l1-l2) > TOL ) || ... + ( norm(l1-l3) > TOL ) || ... + ( norm(l1-l4) > TOL ) ) + if ( doPrint > 0 ) + disp('diff in lambda') + end + successFlag = 0; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkCHAIN1.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkCHAIN1.m new file mode 100755 index 0000000..4aa70b1 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkCHAIN1.m @@ -0,0 +1,60 @@ +function [ successFlag ] = runBenchmarkCHAIN1( nWSR,doPrint ) + + if ( nargin < 2 ) + doPrint = 0; + end + + successFlag = 0; + maxViolation = 0; + + clear H g A lb ub lbA ubA; + + try + load 'benchmarkCHAIN1.mat'; + catch + successFlag = -1; + return; + end + + if ( exist( 'A','var' ) ) + [nC,nV] = size(A); + else + nC = 0; + end + [nV,nP] = size(g); + + xOpt = zeros(nV,nP); + yOpt = zeros(nV+nC,nP); + objOpt = zeros(1,nP); + iter = zeros(1,nP); + + options = qpOASES_options( 'fast','maxIter',nWSR, 'printLevel',2*doPrint ); + %options = qpOASES_options( 'maxIter',nWSR ); + + for i=1:nP + %disp(i); + + if ( i == 1 ) + [QP,x,obj,status,nWSRout,lambda,ws] = qpOASES_sequence( 'i',H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + %disp(ws') + else + [x,obj,status,nWSRout,lambda,ws] = qpOASES_sequence( 'h',QP,g(:,i),lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + %disp(ws') + end + + [ maxViolationTMP ] = getKktResidual( H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i), x,lambda ); + maxViolation = max( [maxViolation,maxViolationTMP] ); + + xOpt(:,i) = x; + yOpt(:,i) = lambda; + objOpt(:,i) = obj; + iter(:,i) = nWSRout; + end + + qpOASES_sequence( 'c',QP ); + + if ( ( maxViolation < 9e-13 ) && ( status == 0 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkCHAIN1A.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkCHAIN1A.m new file mode 100755 index 0000000..65311f6 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkCHAIN1A.m @@ -0,0 +1,61 @@ +function [ successFlag ] = runBenchmarkCHAIN1A( nWSR,doPrint ) + + if ( nargin < 2 ) + doPrint = 0; + end + + successFlag = 0; + maxViolation = 0; + + clear H g A lb ub lbA ubA; + + try + load 'benchmarkCHAIN1A.mat'; + catch + successFlag = -1; + return; + end + + if ( exist( 'A','var' ) ) + [nC,nV] = size(A); + else + nC = 0; + end + [nV,nP] = size(g); + + xOpt = zeros(nV,nP); + yOpt = zeros(nV+nC,nP); + objOpt = zeros(1,nP); + + options = qpOASES_options( 'fast','maxIter',nWSR, 'printLevel',2*doPrint ); + %options = qpOASES_options( 'reliable', 'maxIter',500,'printLevel',1 ); +% ,'enableRamping',0,'enableFlippingBounds',0,'enableFullLITests',0,'enableDriftCorrection',0 + + + for jj=1:1 + + for i=1:nP + %disp(i); + if ( i == 1 ) + [QP,x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'i',H,g(:,i),lb(:,i),ub(:,i),options ); + else + [x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'h',QP,g(:,i),lb(:,i),ub(:,i),options ); + end + + [ maxViolationTMP ] = getKktResidual( H,g(:,i),[],lb(:,i),ub(:,i),[],[], x,lambda ); + maxViolation = max( [maxViolation,maxViolationTMP] ); + + xOpt(:,i) = x; + yOpt(:,i) = lambda; + objOpt(:,i) = obj; + end + + qpOASES_sequence( 'c',QP ); + + end + + if ( ( maxViolation < 1e-14 ) && ( status == 0 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkCRANE1.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkCRANE1.m new file mode 100755 index 0000000..4243ccf --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkCRANE1.m @@ -0,0 +1,55 @@ +function [ successFlag ] = runBenchmarkCRANE1( nWSR,doPrint ) + + if ( nargin < 2 ) + doPrint = 0; + end + + successFlag = 0; + maxViolation = 0; + + clear H g A lb ub lbA ubA; + + try + load 'benchmarkCRANE1.mat'; + catch + successFlag = -1; + return; + end + + if ( exist( 'A','var' ) ) + [nC,nV] = size(A); + else + nC = 0; + end + [nV,nP] = size(g); + + xOpt = zeros(nV,nP); + yOpt = zeros(nV+nC,nP); + objOpt = zeros(1,nP); + + options = qpOASES_options( 'fast','maxIter',nWSR, 'printLevel',2*doPrint ); + + for i=1:nP + %disp(i); + + if ( i == 1 ) + [QP,x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'i',H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + else + [x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'h',QP,g(:,i),lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + end + + [ maxViolationTMP ] = getKktResidual( H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i), x,lambda ); + maxViolation = max( [maxViolation,maxViolationTMP] ); + + xOpt(:,i) = x; + yOpt(:,i) = lambda; + objOpt(:,i) = obj; + end + + qpOASES_sequence( 'c',QP ); + + if ( ( maxViolation < 3e-9 ) && ( status == 0 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkCRANE2.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkCRANE2.m new file mode 100755 index 0000000..7f7d47f --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkCRANE2.m @@ -0,0 +1,56 @@ +function [ successFlag ] = runBenchmarkCRANE2( nWSR,doPrint ) + + if ( nargin < 2 ) + doPrint = 0; + end + + successFlag = 0; + maxViolation = 0; + + clear H g A lb ub lbA ubA; + + try + load 'benchmarkCRANE2.mat'; + catch + successFlag = -1; + return; + end + + if ( exist( 'A','var' ) ) + [nC,nV] = size(A); + else + nC = 0; + end + [nV,nP] = size(g); + + xOpt = zeros(nV,nP); + yOpt = zeros(nV+nC,nP); + objOpt = zeros(1,nP); + + %options = qpOASES_options( 'maxIter',nWSR ); + options = qpOASES_options( 'fast','maxIter',nWSR, 'printLevel',2*doPrint ); + + for i=1:nP + %disp(i); + + if ( i == 1 ) + [QP,x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'i',H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + else + [x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'm',QP,H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + end + + [ maxViolationTMP ] = getKktResidual( H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i), x,lambda ); + maxViolation = max( [maxViolation,maxViolationTMP] ); + + xOpt(:,i) = x; + yOpt(:,i) = lambda; + objOpt(:,i) = obj; + end + + qpOASES_sequence( 'c',QP ); + + if ( ( maxViolation < 1e-11 ) && ( status == 0 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkCRANE3.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkCRANE3.m new file mode 100755 index 0000000..80caac9 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkCRANE3.m @@ -0,0 +1,55 @@ +function [ successFlag ] = runBenchmarkCRANE3( nWSR,doPrint ) + + if ( nargin < 2 ) + doPrint = 0; + end + + successFlag = 0; + maxViolation = 0; + + clear H g A lb ub lbA ubA; + try + load 'benchmarkCRANE3.mat'; + catch + successFlag = -1; + return; + end + + if ( exist( 'A','var' ) ) + [nC,nV] = size(A); + else + nC = 0; + end + [nV,nP] = size(g); + + xOpt = zeros(nV,nP); + yOpt = zeros(nV+nC,nP); + objOpt = zeros(1,nP); + + %options = qpOASES_options( 'maxIter',nWSR ); + options = qpOASES_options( 'fast','maxIter',nWSR, 'printLevel',2*doPrint ); + + for i=1:nP + %disp(i); + + if ( i == 1 ) + [QP,x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'i',H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + else + [x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'h',QP,g(:,i),lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + end + + [ maxViolationTMP ] = getKktResidual( H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i), x,lambda ); + maxViolation = max( [maxViolation,maxViolationTMP] ); + + xOpt(:,i) = x; + yOpt(:,i) = lambda; + objOpt(:,i) = obj; + end + + qpOASES_sequence( 'c',QP ); + + if ( ( maxViolation < 5e-11 ) && ( status == 0 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkDIESEL.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkDIESEL.m new file mode 100755 index 0000000..ad6c585 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkDIESEL.m @@ -0,0 +1,59 @@ +function [ successFlag ] = runBenchmarkDIESEL( nWSR,doPrint ) + + if ( nargin < 2 ) + doPrint = 0; + end + + successFlag = 0; + maxViolation = 0; + + clear H g A lb ub lbA ubA; + try + load 'benchmarkDIESEL.mat'; + catch + successFlag = -1; + return; + end + + if ( exist( 'A','var' ) ) + [nC,nV] = size(A); + else + nC = 0; + nEC = 0; + end + [nV,nP] = size(g); + + xOpt = zeros(nV,nP); + yOpt = zeros(nV+nC,nP); + objOpt = zeros(1,nP); + iter = zeros(1,nP); + + options = qpOASES_options( 'fast','maxIter',nWSR, 'printLevel',2*doPrint ); + %options = qpOASES_options( 'maxIter',nWSR ); + %options = qpOASES_options( 'maxIter',nWSR, 'initialStatusBounds',0 ); + + for i=1:nP + %disp(i); + + if ( i == 1 ) + [QP,x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'i',H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + else + [x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'h',QP,g(:,i),lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + end + + [ maxViolationTMP ] = getKktResidual( H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i), x,lambda ); + maxViolation = max( [maxViolation,maxViolationTMP] ); + + xOpt(:,i) = x; + yOpt(:,i) = lambda; + objOpt(:,i) = obj; + iter(:,i) = nWSRout; + end + + qpOASES_sequence( 'c',QP ); + + if ( ( maxViolation < 6e-13 ) && ( status == 0 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkEQUALITY1.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkEQUALITY1.m new file mode 100755 index 0000000..b304b42 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkEQUALITY1.m @@ -0,0 +1,56 @@ +function [ successFlag ] = runBenchmarkEQUALITY1( nWSR,doPrint ) + + if ( nargin < 2 ) + doPrint = 0; + end + + successFlag = 0; + maxViolation = 0; + + clear H g A lb ub lbA ubA; + + try + load 'benchmarkEQUALITY1.mat'; + catch + successFlag = -1; + return; + end + + if ( exist( 'A','var' ) ) + [nC,nV] = size(A); + else + nC = 0; + end + [nV,nP] = size(g); + + xOpt = zeros(nV,nP); + yOpt = zeros(nV+nC,nP); + objOpt = zeros(1,nP); + + %options = qpOASES_options( 'maxIter',nWSR ); + options = qpOASES_options( 'fast','maxIter',nWSR, 'printLevel',2*doPrint ); + + for i=1:nP + %disp(i); + + if ( i == 1 ) + [QP,x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'i',H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + else + [x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'h',QP,g(:,i),lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + end + + [ maxViolationTMP ] = getKktResidual( H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i), x,lambda ); + maxViolation = max( [maxViolation,maxViolationTMP] ); + + xOpt(:,i) = x; + yOpt(:,i) = lambda; + objOpt(:,i) = obj; + end + + qpOASES_sequence( 'c',QP ); + + if ( ( maxViolation < 4e-15 ) && ( status == 0 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkEQUALITY2.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkEQUALITY2.m new file mode 100755 index 0000000..bd7c48d --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkEQUALITY2.m @@ -0,0 +1,60 @@ +function [ successFlag ] = runBenchmarkEQUALITY2( nWSR,doPrint ) + + if ( nargin < 2 ) + doPrint = 0; + end + + successFlag = 0; + maxViolation = 0; + + clear H g A lb ub lbA ubA; + + try + load 'benchmarkEQUALITY2.mat'; + catch + successFlag = -1; + return; + end + + if ( exist( 'A','var' ) ) + [nC,nV] = size(A); + else + nC = 0; + end + [nV,nP] = size(g); + + xOpt = zeros(nV,nP); + yOpt = zeros(nV+nC,nP); + objOpt = zeros(1,nP); + + %H = H; + %lbA(65:320) = lbA(65:320) - 0.000000000; + %ubA(65:320) = ubA(65:320) + 0.000000000; + + options = qpOASES_options( 'maxIter',nWSR, 'enableEqualities',1, 'printLevel',2*doPrint ); + %options = qpOASES_options( 'fast','maxIter',nWSR, 'printLevel',-2 ); + + for i=1:nP + %disp(i); + + if ( i == 1 ) + [QP,x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'i',H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + else + [x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'h',QP,g(:,i),lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + end + + [ maxViolationTMP ] = getKktResidual( H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i), x,lambda ); + maxViolation = max( [maxViolation,maxViolationTMP] ); + + xOpt(:,i) = x; + yOpt(:,i) = lambda; + objOpt(:,i) = obj; + end + + qpOASES_sequence( 'c',QP ); + + if ( ( maxViolation < 3e-7 ) && ( status == 0 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkEXAMPLE1.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkEXAMPLE1.m new file mode 100755 index 0000000..7706aff --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkEXAMPLE1.m @@ -0,0 +1,56 @@ +function [ successFlag ] = runBenchmarkEXAMPLE1( nWSR,doPrint ) + + if ( nargin < 2 ) + doPrint = 0; + end + + successFlag = 0; + maxViolation = 0; + + clear H g A lb ub lbA ubA; + + try + load 'benchmarkEXAMPLE1.mat'; + catch + successFlag = -1; + return; + end + + if ( exist( 'A','var' ) ) + [nC,nV] = size(A); + else + nC = 0; + end + [nV,nP] = size(g); + + xOpt = zeros(nV,nP); + yOpt = zeros(nV+nC,nP); + objOpt = zeros(1,nP); + + %options = qpOASES_options( 'maxIter',nWSR ); + options = qpOASES_options( 'fast','maxIter',nWSR, 'printLevel',2*doPrint ); + + for i=1:nP + %disp(i); + + if ( i == 1 ) + [QP,x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'i',H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + else + [x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'h',QP,g(:,i),lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + end + + [ maxViolationTMP ] = getKktResidual( H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i), x,lambda ); + maxViolation = max( [maxViolation,maxViolationTMP] ); + + xOpt(:,i) = x; + yOpt(:,i) = lambda; + objOpt(:,i) = obj; + end + + qpOASES_sequence( 'c',QP ); + + if ( ( maxViolation < 1e-12 ) && ( status == 0 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkEXAMPLE1A.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkEXAMPLE1A.m new file mode 100755 index 0000000..ba91b9e --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkEXAMPLE1A.m @@ -0,0 +1,56 @@ +function [ successFlag ] = runBenchmarkEXAMPLE1A( nWSR,doPrint ) + + if ( nargin < 2 ) + doPrint = 0; + end + + successFlag = 0; + maxViolation = 0; + + clear H g A lb ub lbA ubA; + + try + load 'benchmarkEXAMPLE1A.mat'; + catch + successFlag = -1; + return; + end + + if ( exist( 'A','var' ) ) + [nC,nV] = size(A); + else + nC = 0; + end + [nV,nP] = size(g); + + xOpt = zeros(nV,nP); + yOpt = zeros(nV+nC,nP); + objOpt = zeros(1,nP); + + %options = qpOASES_options( 'maxIter',nWSR ); + options = qpOASES_options( 'fast','maxIter',nWSR, 'printLevel',2*doPrint ); + + for i=1:2 + %disp(i); + + if ( i == 1 ) + [QP,x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'i',H(:,:,i),g(:,i),A(:,:,i),lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + else + [x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'm',QP,H(:,:,i),g(:,i),A(:,:,i),lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + end + + [ maxViolationTMP ] = getKktResidual( H(:,:,i),g(:,i),A(:,:,i),lb(:,i),ub(:,i),lbA(:,i),ubA(:,i), x,lambda ); + maxViolation = max( [maxViolation,maxViolationTMP] ); + + xOpt(:,i) = x; + yOpt(:,i) = lambda; + objOpt(:,i) = obj; + end + + qpOASES_sequence( 'c',QP ); + + if ( ( maxViolation < 3e-13 ) && ( status == 0 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkEXAMPLE1B.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkEXAMPLE1B.m new file mode 100755 index 0000000..36e933f --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkEXAMPLE1B.m @@ -0,0 +1,56 @@ +function [ successFlag ] = runBenchmarkEXAMPLE1B( nWSR,doPrint ) + + if ( nargin < 2 ) + doPrint = 0; + end + + successFlag = 0; + maxViolation = 0; + + clear H g A lb ub lbA ubA; + + try + load 'benchmarkEXAMPLE1B.mat'; + catch + successFlag = -1; + return; + end + + if ( exist( 'A','var' ) ) + [nC,nV] = size(A); + else + nC = 0; + end + [nV,nP] = size(g); + + xOpt = zeros(nV,nP); + yOpt = zeros(nV+nC,nP); + objOpt = zeros(1,nP); + + %options = qpOASES_options( 'maxIter',nWSR ); + options = qpOASES_options( 'fast','maxIter',nWSR, 'printLevel',2*doPrint ); + + for i=1:nP + %disp(i); + + if ( i == 1 ) + [QP,x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'i',H,g(:,i),lb(:,i),ub(:,i),options ); + else + [x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'h',QP,g(:,i),lb(:,i),ub(:,i),options ); + end + + [ maxViolationTMP ] = getKktResidual( H,g(:,i),[],lb(:,i),ub(:,i),[],[], x,lambda ); + maxViolation = max( [maxViolation,maxViolationTMP] ); + + xOpt(:,i) = x; + yOpt(:,i) = lambda; + objOpt(:,i) = obj; + end + + qpOASES_sequence( 'c',QP ); + + if ( ( maxViolation < 3e-12 ) && ( status == 0 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkIDHESSIAN1.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkIDHESSIAN1.m new file mode 100755 index 0000000..d97797f --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runBenchmarkIDHESSIAN1.m @@ -0,0 +1,59 @@ +function [ successFlag ] = runBenchmarkIDHESSIAN1( nWSR,doPrint ) + + if ( nargin < 2 ) + doPrint = 0; + end + + successFlag = 0; + maxViolation = 0; + + clear H g A lb ub lbA ubA; + + try + load 'benchmarkIDHESSIAN1.mat'; + catch + successFlag = -1; + return; + end + + if ( exist( 'A','var' ) ) + [nC,nV] = size(A); + else + nC = 0; + end + [nV,nP] = size(g); + + xOpt = zeros(nV,nP); + yOpt = zeros(nV+nC,nP); + objOpt = zeros(1,nP); + + options = qpOASES_options( 'maxIter',nWSR, 'printLevel',-2*doPrint ); + %options = qpOASES_options( 'fast','maxIter',nWSR, 'printLevel',2 ); + + + for i=1:nP + %disp(i); + + if ( i == 1 ) + [QP,x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'i',H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i)-1e-11,ubA(:,i)+1e-11,options ); + %disp(status); + else + [x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'h',QP,g(:,i),lb(:,i),ub(:,i),lbA(:,i)-1e-11,ubA(:,i)+1e-11,options ); + %disp(status); + end + + [ maxViolationTMP ] = getKktResidual( H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i), x,lambda ); + maxViolation = max( [maxViolation,maxViolationTMP] ); + + xOpt(:,i) = x; + yOpt(:,i) = lambda; + objOpt(:,i) = obj; + end + + qpOASES_sequence( 'c',QP ); + + if ( ( maxViolation < 8e-6 ) && ( status == 0 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runEmptyHessianTests.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runEmptyHessianTests.m new file mode 100755 index 0000000..46ade51 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runEmptyHessianTests.m @@ -0,0 +1,261 @@ +function [ successFlag ] = runEmptyHessianTests( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 1; + + TOL = 100*eps; + + options = qpOASES_options( 'maxIter',100, 'enableEqualities',1, 'printLevel',-2*doPrint ); + auxInput0 = qpOASES_auxInput( 'hessianType',0 ); + auxInput1 = qpOASES_auxInput( 'hessianType',1 ); + auxInputErr = qpOASES_auxInput( 'hessianType',2 ); + + + load 'benchmarkEXAMPLE1.mat'; + + %% test qpOASES with zero Hessian + [ x1,obj1,status1,nWSRout1,lambda1 ] = qpOASES( 0*H,g(:,1),A,lb(:,1),ub(:,1),lbA(:,1),ubA(:,1),options ); + [ x2,obj2,status2,nWSRout2,lambda2 ] = qpOASES( [],g(:,1),A,lb(:,1),ub(:,1),lbA(:,1),ubA(:,1),options ); + [ x3,obj3,status3,nWSRout3,lambda3 ] = qpOASES( [],g(:,1),A,lb(:,1),ub(:,1),lbA(:,1),ubA(:,1),options,auxInput0 ); + [ x4,obj4,status4,nWSRout4,lambda4 ] = qpOASES( [],g(:,1),A,lb(:,1),ub(:,1),lbA(:,1),ubA(:,1),options,auxInputErr ); + + if ( status1 ~= 0 ) || ( status2 ~= 0 ) || ( status3 ~= 0 ) || ( status4 ~= 0 ) + if doPrint + disp( 'error' ); + end + successFlag = 0; + end + + if ( norm(x1-x2) > TOL ) || ( norm(x1-x3) > TOL ) || ( norm(x1-x4) > TOL ) + if doPrint + disp( 'error in primal solution' ); + end + successFlag = 0; + end + + if ( norm(obj1-obj2) > TOL ) || ( norm(obj1-obj3) > TOL ) || ( norm(obj1-obj4) > TOL ) + if doPrint + disp( 'error in objective function value' ); + end + successFlag = 0; + end + + if ( norm(lambda1-lambda2) > TOL ) || ( norm(lambda1-lambda3) > TOL ) || ( norm(lambda1-lambda4) > TOL ) + if doPrint + disp( 'error in dual solution' ); + end + successFlag = 0; + end + + + %% test qpOASES_sequence with zero Hessian + [QP,x0,obj0,status0,nWSRout0,lambda0] = qpOASES_sequence( 'i',0*H,g(:,1),A,lb(:,1),ub(:,1),lbA(:,1),ubA(:,1),options ); %#ok + [x1,obj1,status1,nWSRout1,lambda1] = qpOASES_sequence( 'h',QP,g(:,2),lb(:,2),ub(:,2),lbA(:,2),ubA(:,2),options ); + qpOASES_sequence( 'c',QP ); + + [QP,x0,obj0,status0,nWSRout0,lambda0] = qpOASES_sequence( 'i',[],g(:,1),A,lb(:,1),ub(:,1),lbA(:,1),ubA(:,1),options ); %#ok + [x2,obj2,status2,nWSRout2,lambda2] = qpOASES_sequence( 'h',QP,g(:,2),lb(:,2),ub(:,2),lbA(:,2),ubA(:,2),options ); + qpOASES_sequence( 'c',QP ); + + [QP,x0,obj0,status0,nWSRout0,lambda0] = qpOASES_sequence( 'i',[],g(:,1),A,lb(:,1),ub(:,1),lbA(:,1),ubA(:,1),options,auxInput0 ); %#ok + [x3,obj3,status3,nWSRout3,lambda3] = qpOASES_sequence( 'h',QP,g(:,2),lb(:,2),ub(:,2),lbA(:,2),ubA(:,2),options ); + qpOASES_sequence( 'c',QP ); + + [QP,x0,obj0,status0,nWSRout0,lambda0] = qpOASES_sequence( 'i',[],g(:,1),A,lb(:,1),ub(:,1),lbA(:,1),ubA(:,1),options,auxInputErr ); %#ok + [x4,obj4,status4,nWSRout4,lambda4] = qpOASES_sequence( 'h',QP,g(:,2),lb(:,2),ub(:,2),lbA(:,2),ubA(:,2),options ); + qpOASES_sequence( 'c',QP ); + + if ( status1 ~= 0 ) || ( status2 ~= 0 ) || ( status3 ~= 0 ) || ( status4 ~= 0 ) + if doPrint + disp( 'error' ); + end + successFlag = 0; + end + + if ( norm(x1-x2) > TOL ) || ( norm(x1-x3) > TOL ) || ( norm(x1-x4) > TOL ) + if doPrint + disp( 'error in primal solution' ); + end + successFlag = 0; + end + + if ( norm(obj1-obj2) > TOL ) || ( norm(obj1-obj3) > TOL ) || ( norm(obj1-obj4) > TOL ) + if doPrint + disp( 'error in objective function value' ); + end + successFlag = 0; + end + + if ( norm(lambda1-lambda2) > TOL ) || ( norm(lambda1-lambda3) > TOL ) || ( norm(lambda1-lambda4) > TOL ) + if doPrint + disp( 'error in dual solution' ); + end + successFlag = 0; + end + + + %% test qpOASES with ID Hessian + [ x1,obj1,status1,nWSRout1,lambda1 ] = qpOASES( eye(2),g(:,1),A,lb(:,1),ub(:,1),lbA(:,1),ubA(:,1),options ); + [ x2,obj2,status2,nWSRout2,lambda2 ] = qpOASES( [],g(:,1),A,lb(:,1),ub(:,1),lbA(:,1),ubA(:,1),options,auxInput1 ); + + if ( status1 ~= 0 ) || ( status2 ~= 0 ) + if doPrint + disp( 'error' ); + end + successFlag = 0; + end + + if ( norm(x1-x2) > TOL ) + if doPrint + disp( 'error in primal solution' ); + end + successFlag = 0; + end + + if ( norm(obj1-obj2) > TOL ) + if doPrint + disp( 'error in objective function value' ); + end + successFlag = 0; + end + + if ( norm(nWSRout1-nWSRout2) > 0.5 ) + if doPrint + disp( 'error in numer of iterations' ); + end + successFlag = 0; + end + + if ( norm(lambda1-lambda2) > TOL ) + if doPrint + disp( 'error in dual solution' ); + end + successFlag = 0; + end + + + %% test qpOASES_sequence with ID Hessian + [QP,x0,obj0,status0,nWSRout0,lambda0] = qpOASES_sequence( 'i',eye(2),g(:,1),A,lb(:,1),ub(:,1),lbA(:,1),ubA(:,1),options ); %#ok + [x1,obj1,status1,nWSRout1,lambda1] = qpOASES_sequence( 'h',QP,g(:,2),lb(:,2),ub(:,2),lbA(:,2),ubA(:,2),options ); + qpOASES_sequence( 'c',QP ); + + [QP,x0,obj0,status0,nWSRout0,lambda0] = qpOASES_sequence( 'i',[],g(:,1),A,lb(:,1),ub(:,1),lbA(:,1),ubA(:,1),options,auxInput1 ); %#ok + [x2,obj2,status2,nWSRout2,lambda2] = qpOASES_sequence( 'h',QP,g(:,2),lb(:,2),ub(:,2),lbA(:,2),ubA(:,2),options ); + qpOASES_sequence( 'c',QP ); + + if ( status1 ~= 0 ) || ( status2 ~= 0 ) + if doPrint + disp( 'error' ); + end + successFlag = 0; + end + + if ( norm(x1-x2) > TOL ) + if doPrint + disp( 'error in primal solution' ); + end + successFlag = 0; + end + + if ( norm(obj1-obj2) > TOL ) + if doPrint + disp( 'error in objective function value' ); + end + successFlag = 0; + end + + if ( norm(nWSRout1-nWSRout2) > 0.5 ) + if doPrint + disp( 'error in numer of iterations' ); + end + successFlag = 0; + end + + if ( norm(lambda1-lambda2) > TOL ) + if doPrint + disp( 'error in dual solution' ); + end + successFlag = 0; + end + + + load 'benchmarkEXAMPLE1B.mat'; + + %% test qpOASES (simply bounded) with zero Hessian + [ x1,obj1,status1,nWSRout1,lambda1 ] = qpOASES( 0*H,g(:,1),lb(:,1),ub(:,1),options ); + [ x2,obj2,status2,nWSRout2,lambda2 ] = qpOASES( [],g(:,1),lb(:,1),ub(:,1),options ); + [ x3,obj3,status3,nWSRout3,lambda3 ] = qpOASES( [],g(:,1),lb(:,1),ub(:,1),options,auxInput0 ); + [ x4,obj4,status4,nWSRout4,lambda4 ] = qpOASES( [],g(:,1),lb(:,1),ub(:,1),options,auxInputErr ); + + if ( status1 ~= 0 ) || ( status2 ~= 0 ) || ( status3 ~= 0 ) || ( status4 ~= 0 ) + if doPrint + disp( 'error' ); + end + successFlag = 0; + end + + if ( norm(x1-x2) > TOL ) || ( norm(x1-x3) > TOL ) || ( norm(x1-x4) > TOL ) + if doPrint + disp( 'error in primal solution' ); + end + successFlag = 0; + end + + if ( norm(obj1-obj2) > TOL ) || ( norm(obj1-obj3) > TOL ) || ( norm(obj1-obj4) > TOL ) + if doPrint + disp( 'error in objective function value' ); + end + successFlag = 0; + end + + if ( norm(lambda1-lambda2) > TOL ) || ( norm(lambda1-lambda3) > TOL ) || ( norm(lambda1-lambda4) > TOL ) + if doPrint + disp( 'error in dual solution' ); + end + successFlag = 0; + end + + + %% test qpOASES (simply bounded) with ID Hessian + [ x1,obj1,status1,nWSRout1,lambda1 ] = qpOASES( eye(2),g(:,1),lb(:,1),ub(:,1),options ); + [ x2,obj2,status2,nWSRout2,lambda2 ] = qpOASES( [],g(:,1),lb(:,1),ub(:,1),options,auxInput1 ); + + if ( status1 ~= 0 ) || ( status2 ~= 0 ) + if doPrint + disp( 'error' ); + end + successFlag = 0; + end + + if ( norm(x1-x2) > TOL ) + if doPrint + disp( 'error in primal solution' ); + end + successFlag = 0; + end + + if ( norm(obj1-obj2) > TOL ) + if doPrint + disp( 'error in objective function value' ); + end + successFlag = 0; + end + + if ( norm(nWSRout1-nWSRout2) > 0.5 ) + if doPrint + disp( 'error in numer of iterations' ); + end + successFlag = 0; + end + + if ( norm(lambda1-lambda2) > TOL ) + if doPrint + disp( 'error in dual solution' ); + end + successFlag = 0; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runExternalCholeskyTests.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runExternalCholeskyTests.m new file mode 100755 index 0000000..2434478 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runExternalCholeskyTests.m @@ -0,0 +1,214 @@ +function [ successFlag ] = runExternalCholeskyTests( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 1; + + TOL = 1e4*eps; + + load 'benchmarkCHAIN1.mat'; + + options = qpOASES_options( 'MPC', 'printLevel',2*doPrint ); + auxInput = qpOASES_auxInput( 'R',chol(H) ); + + %% test qpOASES + [ x1,obj1,status1,nWSRout1,lambda1,auxOut1 ] = qpOASES( H,g(:,10),A,lb(:,10),ub(:,10),lbA(:,10),ubA(:,10),options ); + [ x2,obj2,status2,nWSRout2,lambda2,auxOut2 ] = qpOASES( H,g(:,10),A,lb(:,10),ub(:,10),lbA(:,10),ubA(:,10),options,auxInput ); + + if doPrint + disp( ['Runtime without R: ', num2str(auxOut1.cpuTime),'s'] ) + disp( ['Runtime with R: ', num2str(auxOut2.cpuTime),'s'] ) + disp( ' ' ); + end + + if ( status1 ~= 0 ) || ( status2 ~= 0 ) + if doPrint + disp( 'error' ); + end + successFlag = 0; + end + + if ( norm(x1-x2) > TOL ) + if doPrint + disp( 'error in primal solution' ); + end + successFlag = 0; + end + + if ( norm(obj1-obj2) > TOL ) + if doPrint + disp( 'error in objective function value' ); + end + successFlag = 0; + end + + if ( norm(nWSRout1-nWSRout2) > 0.5 ) + if doPrint + disp( 'error in numer of iterations' ); + end + successFlag = 0; + end + + if ( norm(lambda1-lambda2) > TOL ) + if doPrint + disp( 'error in dual solution' ); + end + successFlag = 0; + end + + + %% test qpOASES_sequence + [QP,x0,obj0,status0,nWSRout0,lambda0,auxOut1] = qpOASES_sequence( 'i',H,g(:,1),A,lb(:,1),ub(:,1),lbA(:,1),ubA(:,1),options ); + [x1,obj1,status1,nWSRout1,lambda1] = qpOASES_sequence( 'h',QP,g(:,2),lb(:,2),ub(:,2),lbA(:,2),ubA(:,2),options ); + qpOASES_sequence( 'c',QP ); + + [QP,x0,obj0,status0,nWSRout0,lambda0,auxOut2] = qpOASES_sequence( 'i',H,g(:,1),A,lb(:,1),ub(:,1),lbA(:,1),ubA(:,1),options,auxInput ); + [x2,obj2,status2,nWSRout2,lambda2] = qpOASES_sequence( 'h',QP,g(:,2),lb(:,2),ub(:,2),lbA(:,2),ubA(:,2),options ); + qpOASES_sequence( 'c',QP ); + + if doPrint + disp( ['Runtime without R: ', num2str(auxOut1.cpuTime),'s'] ) + disp( ['Runtime with R: ', num2str(auxOut2.cpuTime),'s'] ) + disp( ' ' ) + end + + if ( status1 ~= 0 ) || ( status2 ~= 0 ) + if doPrint + disp( 'error' ); + end + successFlag = 0; + end + + if ( norm(x1-x2) > TOL ) + if doPrint + disp( 'error in primal solution' ); + end + successFlag = 0; + end + + if ( norm(obj1-obj2) > TOL ) + if doPrint + disp( 'error in objective function value' ); + end + successFlag = 0; + end + + if ( norm(nWSRout1-nWSRout2) > 0.5 ) + if doPrint + disp( 'error in numer of iterations' ); + end + successFlag = 0; + end + + if ( norm(lambda1-lambda2) > TOL ) + if doPrint + disp( 'error in dual solution' ); + end + successFlag = 0; + end + + + %% test simply bounded QP + load 'benchmarkCHAIN1A.mat'; + + options = qpOASES_options( 'MPC', 'printLevel',0*doPrint ); + auxInput = qpOASES_auxInput( 'R',chol(H) ); + + %% test qpOASES + [ x1,obj1,status1,nWSRout1,lambda1,auxOut1 ] = qpOASES( H,g(:,10),lb(:,10),ub(:,10),options ); + [ x2,obj2,status2,nWSRout2,lambda2,auxOut2 ] = qpOASES( H,g(:,10),lb(:,10),ub(:,10),options,auxInput ); + + if doPrint + disp( ['Runtime without R: ', num2str(auxOut1.cpuTime),'s'] ) + disp( ['Runtime with R: ', num2str(auxOut2.cpuTime),'s'] ) + disp( ' ' ); + end + + if ( status1 ~= 0 ) || ( status2 ~= 0 ) + if doPrint + disp( 'error' ); + end + successFlag = 0; + end + + if ( norm(x1-x2) > TOL ) + if doPrint + disp( 'error in primal solution' ); + end + successFlag = 0; + end + + if ( norm(obj1-obj2) > TOL ) + if doPrint + disp( 'error in objective function value' ); + end + successFlag = 0; + end + + if ( norm(nWSRout1-nWSRout2) > 0.5 ) + if doPrint + disp( 'error in numer of iterations' ); + end + successFlag = 0; + end + + if ( norm(lambda1-lambda2) > TOL ) + if doPrint + disp( 'error in dual solution' ); + end + successFlag = 0; + end + + %% test qpOASES_sequence + [QP,x0,obj0,status0,nWSRout0,lambda0,auxOut1] = qpOASES_sequence( 'i',H,g(:,1),lb(:,1),ub(:,1),options ); + [x1,obj1,status1,nWSRout1,lambda1] = qpOASES_sequence( 'h',QP,g(:,2),lb(:,2),ub(:,2),options ); + qpOASES_sequence( 'c',QP ); + + [QP,x0,obj0,status0,nWSRout0,lambda0,auxOut2] = qpOASES_sequence( 'i',H,g(:,1),lb(:,1),ub(:,1),options,auxInput ); + [x2,obj2,status2,nWSRout2,lambda2] = qpOASES_sequence( 'h',QP,g(:,2),lb(:,2),ub(:,2),options ); + qpOASES_sequence( 'c',QP ); + + if doPrint + disp( ['Runtime without R: ', num2str(auxOut1.cpuTime),'s'] ) + disp( ['Runtime with R: ', num2str(auxOut2.cpuTime),'s'] ) + disp( ' ' ) + end + + if ( status1 ~= 0 ) || ( status2 ~= 0 ) + if doPrint + disp( 'error' ); + end + successFlag = 0; + end + + if ( norm(x1-x2) > TOL ) + if doPrint + disp( 'error in primal solution' ); + end + successFlag = 0; + end + + if ( norm(obj1-obj2) > TOL ) + if doPrint + disp( 'error in objective function value' ); + end + successFlag = 0; + end + + if ( norm(nWSRout1-nWSRout2) > 0.5 ) + if doPrint + disp( 'error in numer of iterations' ); + end + successFlag = 0; + end + + if ( norm(lambda1-lambda2) > TOL ) + if doPrint + disp( 'error in dual solution' ); + end + successFlag = 0; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runInterfaceSeqTest.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runInterfaceSeqTest.m new file mode 100755 index 0000000..88c06ec --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runInterfaceSeqTest.m @@ -0,0 +1,436 @@ +function [ successFlag ] = runInterfaceSeqTest( nV,nC, doPrint,seed ) + + if ( nargin < 4 ) + seed = 42; + if ( nargin < 3 ) + doPrint = 1; + if ( nargin < 2 ) + nC = 10; + if ( nargin < 1 ) + nV = 5; + end + end + end + end + + successFlag = 1; + + for isSparseH=0:1 + for isSparseA=0:1 + successFlag = runSeveralInterfaceSeqTests( successFlag, nV,nC,isSparseH,isSparseA, doPrint,seed ); + end + end + +end + + + +function [ successFlag ] = runSeveralInterfaceSeqTests( successFlag, nV,nC, isSparseH,isSparseA, doPrint,seed ) + + %% test without or empty A matrix + for hasA=0:1 + for changeMat=0:hasA % cannot change matrices if QProblemB object is instantiated + for hasLowerB=0:1 + for hasUpperB=0:1 + for hasOptions=0:2 + for hasX0=0:2 + for hasWS=0:2 + curSuccessFLAG = runSingleInterfaceSeqTest( nV,0,hasA,isSparseH,isSparseA, hasLowerB,hasUpperB,0,0,hasOptions,hasX0,hasWS,changeMat, doPrint,seed ); + successFlag = min( successFlag,curSuccessFLAG ); + end + end + end + end + end + end + end + + %% test with non-empty A matrix + for hasLowerB=0:1 + for hasUpperB=0:1 + for hasLowerC=0:1 + for hasUpperC=0:1 + for hasOptions=0:2 + for hasX0=0:2 + for hasWS=0:2 + for changeMat=0:1 + curSuccessFLAG = runSingleInterfaceSeqTest( nV,nC,1,isSparseH,isSparseA, hasLowerB,hasUpperB,hasLowerC,hasUpperC,hasOptions,hasX0,hasWS,changeMat, doPrint,seed ); + successFlag = min( successFlag,curSuccessFLAG ); + end + end + end + end + end + end + end + end + +end + + +function [ successFlag ] = runSingleInterfaceSeqTest( nV,nC,hasA,isSparseH,isSparseA, hasLowerB,hasUpperB,hasLowerC,hasUpperC,hasOptions,hasX0,hasWS,changeMat, doPrint,seed ) + + successFlag = 0; + + qpData1 = generateExample( nV,nC, isSparseH,isSparseA, hasLowerB,hasUpperB,hasLowerC,hasUpperC, seed ); + if ( changeMat > 0 ) + qpData2 = generateExample( nV,nC, isSparseH,isSparseA, hasLowerB,hasUpperB,hasLowerC,hasUpperC, seed+1 ); + else + qpData2 = generateExample( nV,nC, isSparseH,isSparseA, hasLowerB,hasUpperB,hasLowerC,hasUpperC, seed+1,qpData1.H,qpData1.Ain ); + end + + if ( changeMat == 0 ) + string = 'Testing qpOASES_sequence( ''i/h/c'',H'; + else + string = 'Testing qpOASES_sequence( ''i/m/c'',H'; + end + + if ( isSparseH > 0 ) + string = [string,'s,g']; + else + string = [string,'d,g']; + end + + if ( nC > 0 ) + if ( isSparseA > 0 ) + string = [string,',As']; + else + string = [string,',Ad']; + end + else + if ( hasA > 0 ) + string = [string,',[]']; + end + end + + if ( hasLowerB > 0 ) + string = [string,',lb']; + else + string = [string,',[]']; + end + + if ( hasUpperB > 0 ) + string = [string,',ub']; + else + string = [string,',[]']; + end + + if ( hasLowerC > 0 ) + string = [string,',lbA']; + else + if ( hasA > 0 ) + string = [string,',[] ']; + end + end + + if ( hasUpperC > 0 ) + string = [string,',ubA']; + else + if ( hasA > 0 ) + string = [string,',[] ']; + end + end + + switch ( hasOptions ) + case 1 + string = [string,',opt']; + + case 2 + string = [string,',[] ']; + + case 0 + if ( ( hasX0 > 0 ) || ( hasWS > 0 ) ) + string = [string,',[] ']; + end + end + + switch ( hasX0 ) + case 1 + string = [string,',{x0']; + + case 2 + string = [string,',{[]']; + + case 0 + if ( hasWS > 0 ) + string = [string,',{[]']; + end + end + + switch ( hasWS ) + case 1 + string = [string,',WS}']; + + case 2 + string = [string,',[]}']; + end + + string = [string,' )... ']; + if ( doPrint > 0 ) + disp( string ); + end + + curSuccessFlag = callQpOasesSeq( qpData1,qpData2,hasA,hasOptions,hasX0,hasWS,changeMat ); + if ( curSuccessFlag > 0 ) + string = [string,'pass!']; + successFlag = 1; + else + string = [string,'fail!']; + end + + if ( doPrint > 0 ) + disp( string ); + if ( curSuccessFlag == 0 ) + pause(0.1); + end + end + +end + +function [ successFlag ] = callQpOasesSeq( qpData1,qpData2,hasA,hasOptions,hasX0,hasWS,changeMat, doPrint ) + + if ( nargin < 8 ) + doPrint = 1; + end + + %TOL = 1e-15; + KKTTOL = 1e-6; + + successFlag = 0; + + H1 = qpData1.H; + g1 = qpData1.g; + A1 = [qpData1.Aeq;qpData1.Ain]; + lb1 = qpData1.lb; + ub1 = qpData1.ub; + lbA1 = [qpData1.beq;qpData1.lbA]; + ubA1 = [qpData1.beq;qpData1.ubA]; + + if ( changeMat > 0 ) + H2 = qpData2.H; + else + H2 = H1; + end + g2 = qpData2.g; + if ( changeMat > 0 ) + A2 = [qpData2.Aeq;qpData2.Ain]; + else + A2 = A1; + end + lb2 = qpData2.lb; + ub2 = qpData2.ub; + lbA2 = [qpData2.beq;qpData2.lbA]; + ubA2 = [qpData2.beq;qpData2.ubA]; + + [nV,dummy] = size(H1); %#ok + [nC,dummy] = size(A1); %#ok + + if ( hasWS > 0 ) + if ( hasWS == 1 ) + wsB = 0 * ones( nV,1 ); + wsC = 0 * ones( nC,1 ); + else + wsB = []; + wsC = []; + end + + if ( hasX0 > 0 ) + if ( hasX0 == 1 ) + x0 = -1e-3 * ones( nV,1 ); + else + x0 = []; + end + + auxInput = qpOASES_auxInput( 'x0',x0,'guessedWorkingSetB',wsB,'guessedWorkingSetC',wsC ); + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options(); + else + options = []; + end + + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,options,auxInput ); %#ok + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2,options ); %#ok + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2,options ); %#ok + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,options,auxInput ); %#ok + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,options ); %#ok + qpOASES_sequence( 'c',QP ); + end + else + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,[],auxInput ); %#ok + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2 ); %#ok + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2 ); %#ok + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,[],auxInput ); %#ok + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2 ); %#ok + qpOASES_sequence( 'c',QP ); + end + end + + else % hasX0 == 0 + + %auxInput = qpOASES_auxInput( 'guessedWorkingSetB',wsB,'guessedWorkingSetC',wsC ); + auxInput = qpOASES_auxInput( 'guessedWorkingSetB',wsB ); + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options(); + else + options = []; + end + + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,options,auxInput ); %#ok + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2,options ); %#ok + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2,options ); %#ok + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,options,auxInput ); %#ok + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,options ); %#ok + qpOASES_sequence( 'c',QP ); + end + else + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,[],auxInput ); %#ok + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2,[] ); %#ok + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2,[] ); %#ok + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,[],auxInput ); %#ok + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2 ); %#ok + qpOASES_sequence( 'c',QP ); + end + end + + end % hasX0 + + else % hasWS == 0 + + if ( hasX0 > 0 ) + if ( hasX0 == 1 ) + x0 = -1e-3 * ones( nV,1 ); + else + x0 = []; + end + + auxInput = qpOASES_auxInput( 'x0',x0 ); + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options(); + else + options = []; + end + + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,options,auxInput ); %#ok + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2,options ); %#ok + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2,options ); %#ok + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,options,auxInput ); %#ok + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,options ); %#ok + qpOASES_sequence( 'c',QP ); + end + + else + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,[],auxInput ); %#ok + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2 ); %#ok + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2 ); %#ok + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,[],auxInput ); %#ok + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2 ); %#ok + qpOASES_sequence( 'c',QP ); + end + end + + else % hasX0 == 0 + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options(); + else + options = []; + end + + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,options ); %#ok + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2,options ); %#ok + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2,options ); %#ok + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,options ); %#ok + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,options ); %#ok + qpOASES_sequence( 'c',QP ); + end + else + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1 ); %#ok + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2 ); %#ok + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2 ); %#ok + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1 ); %#ok + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2 ); %#ok + qpOASES_sequence( 'c',QP ); + end + end + + end % hasX0 + + end % hasWS + + + kktTol1 = getKktResidual( H1,g1,A1,lb1,ub1,lbA1,ubA1, x1,l1 ); + + if ( changeMat > 0 ) + kktTol2 = getKktResidual( H2,g2,A2,lb2,ub2,lbA2,ubA2, x2,l2 ); + else + kktTol2 = getKktResidual( H1,g2,A1,lb2,ub2,lbA2,ubA2, x2,l2 ); + end + + if ( ( kktTol1 <= KKTTOL ) && ( e1 >= 0 ) && ( kktTol2 <= KKTTOL ) && ( e2 >= 0 ) ) + successFlag = 1; + else + if ( doPrint > 0 ) + if ( ( kktTol1 > KKTTOL ) || ( kktTol2 > KKTTOL ) ) + disp( ['kkt error: ',num2str(kktTol1),'/',num2str(kktTol2)] ) + else + disp('exitflag<0') + end + end + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runInterfaceTest.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runInterfaceTest.m new file mode 100755 index 0000000..55a5c7b --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runInterfaceTest.m @@ -0,0 +1,462 @@ +function [ successFlag ] = runInterfaceTest( nV,nC, doPrint,seed ) + + if ( nargin < 4 ) + seed = 42; + if ( nargin < 3 ) + doPrint = 1; + if ( nargin < 2 ) + nC = 10; + if ( nargin < 1 ) + nV = 5; + end + end + end + end + + successFlag = 1; + + for isSparseH=0:1 + for isSparseA=0:1 + successFlag = runSeveralInterfaceTests( successFlag, nV,nC,isSparseH,isSparseA, doPrint,seed ); + end + end + +end + + + +function [ successFLAG ] = runSeveralInterfaceTests( successFLAG, nV,nC, isSparseH,isSparseA, doPrint,seed ) + + %% test without or empty A matrix + for hasA=0:1 + for hasLowerB=0:1 + for hasUpperB=0:1 + for hasOptions=0:2 + for hasX0=0:1 + for hasWS=0:2 + if ( ( hasWS ~= 2 ) || ( hasA ~= 0 ) || ( hasOptions == 1 ) || ( hasX0 ~= 0 ) ) + curSuccessFLAG = runSingleInterfaceTest( nV,0,hasA,isSparseH,isSparseA, hasLowerB,hasUpperB,0,0,hasOptions,hasX0,hasWS, doPrint,seed ); + successFLAG = min( successFLAG,curSuccessFLAG ); + end + end + end + end + end + end + end + + %% test with non-empty A matrix + for hasLowerB=0:1 + for hasUpperB=0:1 + for hasLowerC=0:1 + for hasUpperC=0:1 + for hasOptions=0:2 + for hasX0=0:1 + for hasWS=0:2 + curSuccessFLAG = runSingleInterfaceTest( nV,nC,1,isSparseH,isSparseA, hasLowerB,hasUpperB,hasLowerC,hasUpperC,hasOptions,hasX0,hasWS, doPrint,seed ); + successFLAG = min( successFLAG,curSuccessFLAG ); + end + end + end + end + end + end + end + +end + + +function [ successFLAG ] = runSingleInterfaceTest( nV,nC,hasA,isSparseH,isSparseA, hasLowerB,hasUpperB,hasLowerC,hasUpperC,hasOptions,hasX0,hasWS, doPrint,seed ) + + successFLAG = 0; + + qpData = generateExample( nV,nC, isSparseH,isSparseA, hasLowerB,hasUpperB,hasLowerC,hasUpperC, seed ); + + string = 'Testing qpOASES( H'; + + if ( isSparseH > 0 ) + string = [string,'s,g']; + else + string = [string,'d,g']; + end + + if ( nC > 0 ) + if ( isSparseA > 0 ) + string = [string,',As']; + else + string = [string,',Ad']; + end + else + if ( hasA > 0 ) + string = [string,',[]']; + end + end + + if ( hasLowerB > 0 ) + string = [string,',lb']; + else + string = [string,',[]']; + end + + if ( hasUpperB > 0 ) + string = [string,',ub']; + else + string = [string,',[]']; + end + + if ( hasLowerC > 0 ) + string = [string,',lbA']; + else + if ( hasA > 0 ) + string = [string,',[] ']; + end + end + + if ( hasUpperC > 0 ) + string = [string,',ubA']; + else + if ( hasA > 0 ) + string = [string,',[] ']; + end + end + + switch ( hasOptions ) + case 1 + string = [string,',opt']; + + case 2 + string = [string,',[] ']; + + case 0 + if ( ( hasX0 > 0 ) || ( hasWS > 0 ) ) + string = [string,',[] ']; + end + end + + switch ( hasX0 ) + case 1 + string = [string,',{x0']; + + case 2 + string = [string,',{[]']; + + case 0 + if ( hasWS > 0 ) + string = [string,',{[]']; + end + end + + switch ( hasWS ) + case 1 + string = [string,',WS}']; + + case 2 + string = [string,',[]}']; + end + + string = [string,' )... ']; + if ( doPrint > 0 ) + %disp( string ); + end + + curSuccessFlag = callQpOases( qpData,hasA,hasOptions,hasX0,hasWS, 1 ); + if ( curSuccessFlag > 0 ) + string = [string,'pass!']; + successFLAG = 1; + else + string = [string,'fail!']; + end + + if ( doPrint > 0 ) + disp( string ); + if ( curSuccessFlag == 0 ) + pause; + end + end + +end + +function [ successFLAG ] = callQpOases( qpData,hasA,hasOptions,hasX0,hasWS, doPrint ) + + if ( nargin < 6 ) + doPrint = 1; + end + + TOL = 1e-15; + KKTTOL = 1e-6; + + successFLAG = 0; + + H = qpData.H; + g = qpData.g; + A = [qpData.Aeq;qpData.Ain]; + lb = qpData.lb; + ub = qpData.ub; + lbA = [qpData.beq;qpData.lbA]; + ubA = [qpData.beq;qpData.ubA]; + + [nV,dummy] = size(H); %#ok + [nC,dummy] = size(A); %#ok + + if ( hasWS > 0 ) + if ( hasWS == 1 ) + wsB = 0 * ones( nV,1 ); + wsC = 0 * ones( nC,1 ); + else + wsB = []; + wsC = []; + end + + if ( hasX0 > 0 ) + if ( hasX0 == 1 ) + x0 = -1e-3 * ones( nV,1 ); + else + x0 = []; + end + + auxInput = qpOASES_auxInput( 'x0',x0,'guessedWorkingSetB',wsB,'guessedWorkingSetC',wsC ); + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options(); + else + options = []; + end + + if ( hasA > 0 ) + [ x1 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + [ x2,f2 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + [ x3,f3,e3 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); %#ok + else + [ x1 ] = qpOASES( H,g,lb,ub,options,auxInput ); + [ x2,f2 ] = qpOASES( H,g,lb,ub,options,auxInput ); + [ x3,f3,e3 ] = qpOASES( H,g,lb,ub,options,auxInput ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,lb,ub,options,auxInput ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,lb,ub,options,auxInput ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,lb,ub,options,auxInput ); %#ok + end + else + if ( hasA > 0 ) + [ x1 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x2,f2 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x3,f3,e3 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); %#ok + else + [ x1 ] = qpOASES( H,g,lb,ub,[],auxInput ); + [ x2,f2 ] = qpOASES( H,g,lb,ub,[],auxInput ); + [ x3,f3,e3 ] = qpOASES( H,g,lb,ub,[],auxInput ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,lb,ub,[],auxInput ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,lb,ub,[],auxInput ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,lb,ub,[],auxInput ); %#ok + end + end + + else % hasX0 == 0 + + %auxInput = qpOASES_auxInput( 'guessedWorkingSetB',wsB,'guessedWorkingSetC',wsC ); + auxInput = qpOASES_auxInput( 'guessedWorkingSetC',wsC ); + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options(); + else + options = []; + end + + if ( hasA > 0 ) + [ x1 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + [ x2,f2 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + [ x3,f3,e3 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); %#ok + else + [ x1 ] = qpOASES( H,g,lb,ub,options,auxInput ); + [ x2,f2 ] = qpOASES( H,g,lb,ub,options,auxInput ); + [ x3,f3,e3 ] = qpOASES( H,g,lb,ub,options,auxInput ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,lb,ub,options,auxInput ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,lb,ub,options,auxInput ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,lb,ub,options,auxInput ); %#ok + end + else + if ( hasA > 0 ) + [ x1 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x2,f2 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x3,f3,e3 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); %#ok + else + [ x1 ] = qpOASES( H,g,lb,ub,[],auxInput ); + [ x2,f2 ] = qpOASES( H,g,lb,ub,[],auxInput ); + [ x3,f3,e3 ] = qpOASES( H,g,lb,ub,[],auxInput ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,lb,ub,[],auxInput ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,lb,ub,[],auxInput ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,lb,ub,[],auxInput ); %#ok + end + end + + end % hasX0 + + else % hasWS == 0 + + if ( hasX0 > 0 ) + if ( hasX0 == 1 ) + x0 = -1e-3 * ones( nV,1 ); + else + x0 = []; + end + + auxInput = qpOASES_auxInput( 'x0',x0 ); + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options(); + else + options = []; + end + + if ( hasA > 0 ) + [ x1 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + [ x2,f2 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + [ x3,f3,e3 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); %#ok + else + [ x1 ] = qpOASES( H,g,lb,ub,options,auxInput ); + [ x2,f2 ] = qpOASES( H,g,lb,ub,options,auxInput ); + [ x3,f3,e3 ] = qpOASES( H,g,lb,ub,options,auxInput ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,lb,ub,options,auxInput ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,lb,ub,options,auxInput ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,lb,ub,options,auxInput ); %#ok + end + + else + if ( hasA > 0 ) + [ x1 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x2,f2 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x3,f3,e3 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,[],auxInput ); %#ok + else + [ x1 ] = qpOASES( H,g,lb,ub,[],auxInput ); + [ x2,f2 ] = qpOASES( H,g,lb,ub,[],auxInput ); + [ x3,f3,e3 ] = qpOASES( H,g,lb,ub,[],auxInput ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,lb,ub,[],auxInput ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,lb,ub,[],auxInput ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,lb,ub,[],auxInput ); %#ok + end + end + + else % hasX0 == 0 + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options(); + else + options = []; + end + + if ( hasA > 0 ) + [ x1 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options ); + [ x2,f2 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options ); + [ x3,f3,e3 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,A,lb,ub,lbA,ubA,options ); %#ok + else + [ x1 ] = qpOASES( H,g,lb,ub,options ); + [ x2,f2 ] = qpOASES( H,g,lb,ub,options ); + [ x3,f3,e3 ] = qpOASES( H,g,lb,ub,options ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,lb,ub,options ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,lb,ub,options ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,lb,ub,options ); %#ok + end + else + if ( hasA > 0 ) + [ x1 ] = qpOASES( H,g,A,lb,ub,lbA,ubA ); + [ x2,f2 ] = qpOASES( H,g,A,lb,ub,lbA,ubA ); + [ x3,f3,e3 ] = qpOASES( H,g,A,lb,ub,lbA,ubA ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,A,lb,ub,lbA,ubA ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,A,lb,ub,lbA,ubA ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,A,lb,ub,lbA,ubA ); %#ok + else + [ x1 ] = qpOASES( H,g,lb,ub ); + [ x2,f2 ] = qpOASES( H,g,lb,ub ); + [ x3,f3,e3 ] = qpOASES( H,g,lb,ub ); + [ x4,f4,e4,i4 ] = qpOASES( H,g,lb,ub ); + [ x5,f5,e5,i5,l5 ] = qpOASES( H,g,lb,ub ); + [ x6,f6,e6,i6,l6,w6 ] = qpOASES( H,g,lb,ub ); %#ok + end + end + + end % hasX0 + + end % hasWS + + % check whether all calls lead to same optimal solution + % independent from output arguments + if ( ( norm(x1-x2) > TOL ) || ... + ( norm(x1-x3) > TOL ) || ... + ( norm(x1-x4) > TOL ) || ... + ( norm(x1-x5) > TOL ) || ... + ( norm(x1-x6) > TOL ) ) + if ( doPrint > 0 ) + disp('diff in x') + end + return; + end + + if ( ( norm(f2-f3) > TOL ) || ... + ( norm(f2-f4) > TOL ) || ... + ( norm(f2-f5) > TOL ) || ... + ( norm(f2-f6) > TOL ) ) + if ( doPrint > 0 ) + disp('diff in fval') + end + return; + end + + if ( ( norm(e3-e4) > TOL ) || ... + ( norm(e3-e5) > TOL ) || ... + ( norm(e3-e6) > TOL ) ) + if ( doPrint > 0 ) + disp('diff in exitflag') + end + return; + end + + if ( ( norm(i4-i5) > TOL ) || ... + ( norm(i4-i6) > TOL ) ) + if ( doPrint > 0 ) + disp('diff in iter') + end + return; + end + + if ( norm(l5-l6) > TOL ) + if ( doPrint > 0 ) + disp('diff in lambda') + end + return; + end + + + kktTol = getKktResidual( H,g,A,lb,ub,lbA,ubA, x6,l6 ); + + if ( ( kktTol <= KKTTOL ) && ( e6 >= 0 ) ) + successFLAG = 1; + else + if ( doPrint > 0 ) + disp( ['kkt error: ',num2str(kktTol)] ) + end + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runQAP8.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runQAP8.m new file mode 100755 index 0000000..58660d9 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runQAP8.m @@ -0,0 +1,37 @@ +function [ successFlag ] = runQAP8( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 0; + + try + load 'QAP8.mat'; + catch + successFlag = -1; + return; + end + + options = qpOASES_options('default', 'maxIter',30000, 'printLevel',-2*doPrint ); + tic + [x, fval, status, nWSRout, y] = qpOASES(sparse(QP.H), QP.f, ... + sparse(QP.C), QP.lb, QP.ub, QP.cl, QP.cu, options); + t = toc; + + if ( doPrint > 0 ) + disp( ['solution time: ',num2str(t),' seconds'] ); + end + + if ( ( status == 0 ) && ( nWSRout < 23200 ) ) + successFlag = 1; + end + + % check error and print + if doPrint + [stat, feas, cmpl] = qpresidual(S.B, S.b1, S.C, S.cl1, S.cu1, x, -y); + fprintf( '%d iters in %.3fs to tolerance %.2e\n', nWSRout, t, max([stat,feas,cmpl]) ); + fprintf( 'Status: %d\n', status ); + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runQSHARE1B.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runQSHARE1B.m new file mode 100755 index 0000000..c1ba1e2 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runQSHARE1B.m @@ -0,0 +1,44 @@ +function [ successFlag ] = runQSHARE1B( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 0; + + try + load 'QSHARE1B.mat'; + catch + successFlag = -1; + return; + end + + options = qpOASES_options('default', 'maxIter',600, 'maxCpuTime',2.0, 'printLevel',-2*doPrint ); + auxInput = qpOASES_auxInput( 'hessianType',[] ); + tic + [xD,fvalD,exitflagD,iterD,lambdaD] = qpOASES( H,g,A,lb,ub,lbA,ubA,options,auxInput ); + tD = toc; + kktD = getKktResidual( H,g,A,lb,ub,lbA,ubA, xD,lambdaD ); + + if ( doPrint > 0 ) + disp( ['dense kkt tol: ',num2str(kktD, '%.3e')] ); + disp( ['dense solution time: ',num2str(tD),' seconds'] ); + disp( ['dense #iterations: ',num2str(iterD),] ); + end + + tic + [xS,fvalS,exitflagS,iterS,lambdaS] = qpOASES( sparse(H),g,sparse(A),lb,ub,lbA,ubA,options ); + tS = toc; + kktS = getKktResidual( H,g,A,lb,ub,lbA,ubA, xS,lambdaS ); + + if ( doPrint > 0 ) + disp( ['sparse kkt tol: ',num2str(kktS, '%.3e')] ); + disp( ['sparse solution time: ',num2str(tS),' seconds'] ); + disp( ['sparse #iterations: ',num2str(iterS),] ); + end + + if ( ( exitflagD == 0 ) && ( kktD < 1e-6 ) && ( exitflagS == 0 ) && ( kktS < 1e-6 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runRandomIdHessian.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runRandomIdHessian.m new file mode 100755 index 0000000..81199f7 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runRandomIdHessian.m @@ -0,0 +1,435 @@ +function [ successFlag ] = runRandomIdHessian( nV,nC, doPrint,seed ) + + if ( nargin < 4 ) + seed = 42; + if ( nargin < 3 ) + doPrint = 1; + if ( nargin < 2 ) + nC = 10; + if ( nargin < 1 ) + nV = 5; + end + end + end + end + + successFlag = 1; + + for isSparseH=0:1 + for isSparseA=0:1 + successFlag = runSeveralIdSeqTests( successFlag, nV,nC,isSparseH,isSparseA, doPrint,seed ); + end + end + +end + + +function [ successFlag ] = runSeveralIdSeqTests( successFlag, nV,nC, isSparseH,isSparseA, doPrint,seed ) + + %% test without or empty A matrix + for hasA=0:1 + for changeMat=0:hasA % cannot change matrices if QProblemB object is instantiated + for hasLowerB=0:1 + for hasUpperB=0:1 + for hasOptions=0:1 + for hasX0=0:2 + for hasWS=0:2 + curSuccessFLAG = runSingleIdSeqTest( nV,0,hasA,isSparseH,isSparseA, hasLowerB,hasUpperB,0,0,hasOptions,hasX0,hasWS,changeMat, doPrint,seed ); + successFlag = min( successFlag,curSuccessFLAG ); + end + end + end + end + end + end + end + + %% test with non-empty A matrix + for hasLowerB=0:1 + for hasUpperB=0:1 + for hasLowerC=0:1 + for hasUpperC=0:1 + for hasOptions=0:1 + for hasX0=0:2 + for hasWS=0:2 + for changeMat=0:1 + curSuccessFLAG = runSingleIdSeqTest( nV,nC,1,isSparseH,isSparseA, hasLowerB,hasUpperB,hasLowerC,hasUpperC,hasOptions,hasX0,hasWS,changeMat, doPrint,seed ); + successFlag = min( successFlag,curSuccessFLAG ); + end + end + end + end + end + end + end + end + +end + + +function [ successFlag ] = runSingleIdSeqTest( nV,nC,hasA,isSparseH,isSparseA, hasLowerB,hasUpperB,hasLowerC,hasUpperC,hasOptions,hasX0,hasWS,changeMat, doPrint,seed ) + + successFlag = 0; + + qpFeatures = setupQpFeaturesStruct( ); + + qpFeatures.nV = nV; + qpFeatures.nC = nC; + + qpFeatures.isSparseH = isSparseH; + qpFeatures.isSparseA = isSparseA; + + qpFeatures.hasLowerB = hasLowerB; + qpFeatures.hasUpperB = hasUpperB; + qpFeatures.hasLowerC = hasLowerC; + qpFeatures.hasUpperC = hasUpperC; + + qpFeatures.hessianType = 2; + + qpData1 = generateRandomQp( qpFeatures,seed ); + qpData2 = generateRandomQp( qpFeatures,seed ); + + if ( changeMat == 0 ) + string = 'Testing qpOASES_sequence( ''i/h/c'',ID'; + else + string = 'Testing qpOASES_sequence( ''i/m/c'',ID'; + end + + if ( isSparseH > 0 ) + string = [string,'s,g']; + else + string = [string,'d,g']; + end + + if ( nC > 0 ) + if ( isSparseA > 0 ) + string = [string,',As']; + else + string = [string,',Ad']; + end + else + if ( hasA > 0 ) + string = [string,',[]']; + end + end + + if ( hasLowerB > 0 ) + string = [string,',lb']; + else + string = [string,',[]']; + end + + if ( hasUpperB > 0 ) + string = [string,',ub']; + else + string = [string,',[]']; + end + + if ( hasLowerC > 0 ) + string = [string,',lbA']; + else + if ( hasA > 0 ) + string = [string,',[] ']; + end + end + + if ( hasUpperC > 0 ) + string = [string,',ubA']; + else + if ( hasA > 0 ) + string = [string,',[] ']; + end + end + + switch ( hasOptions ) + case 1 + string = [string,',opt']; + + case 2 + string = [string,',[] ']; + + case 0 + if ( ( hasX0 > 0 ) || ( hasWS > 0 ) ) + string = [string,',[] ']; + end + end + + switch ( hasX0 ) + case 1 + string = [string,',{x0']; + + case 2 + string = [string,',{[]']; + + case 0 + if ( hasWS > 0 ) + string = [string,',{[]']; + end + end + + switch ( hasWS ) + case 1 + string = [string,',WS}']; + + case 2 + string = [string,',[]}']; + end + + string = [string,' )... ']; + if ( doPrint > 0 ) + %disp( string ); + end + + curSuccessFlag = callQpOasesSeq( qpData1,qpData2,hasA,hasOptions,hasX0,hasWS,changeMat,doPrint ); + if ( curSuccessFlag > 0 ) + string = [string,'pass!']; + successFlag = 1; + else + string = [string,'fail!']; + end + + if ( doPrint > 0 ) + disp( string ); + if ( curSuccessFlag == 0 ) + pause; + end + end + +end + + + +function [ successFlag ] = callQpOasesSeq( qpData1,qpData2,hasA,hasOptions,hasX0,hasWS,changeMat, doPrint ) + + if ( nargin < 8 ) + doPrint = 1; + end + + TOL = 1e-15; + KKTTOL = 1e-6; + + successFlag = 0; + + H1 = qpData1.H; + g1 = qpData1.g; + A1 = [qpData1.Aeq;qpData1.Ain]; + lb1 = qpData1.lb; + ub1 = qpData1.ub; + lbA1 = [qpData1.beq;qpData1.lbA]; + ubA1 = [qpData1.beq;qpData1.ubA]; + + H2 = qpData2.H; + g2 = qpData2.g; + A2 = [qpData2.Aeq;qpData2.Ain]; + lb2 = qpData2.lb; + ub2 = qpData2.ub; + lbA2 = [qpData2.beq;qpData2.lbA]; + ubA2 = [qpData2.beq;qpData2.ubA]; + + [nV,dummy] = size(H1); + [nC,dummy] = size(A1); + + if ( hasWS > 0 ) + if ( hasWS == 1 ) + wsB = 0 * ones( nV,1 ); + wsC = 0 * ones( nC,1 ); + else + wsB = []; + wsC = []; + end + + if ( hasX0 > 0 ) + if ( hasX0 == 1 ) + x0 = -1e-3 * ones( nV,1 ); + else + x0 = []; + end + + auxInput = qpOASES_auxInput( 'x0',x0,'guessedWorkingSetB',wsB,'guessedWorkingSetC',wsC ); + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options(); + else + options = []; + end + + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,options,auxInput ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2,options ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2,options ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,options,auxInput ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,options ); + qpOASES_sequence( 'c',QP ); + end + else + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,[],auxInput ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2 ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2 ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,[],auxInput ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2 ); + qpOASES_sequence( 'c',QP ); + end + end + + else % hasX0 == 0 + + auxInput = qpOASES_auxInput( 'guessedWorkingSetB',wsB,'guessedWorkingSetC',wsC ); + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options(); + else + options = []; + end + + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,options,auxInput ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2,options ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2,options ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,options,auxInput ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,options ); + qpOASES_sequence( 'c',QP ); + end + else + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,[],auxInput ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2,[] ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2,[] ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,[],auxInput ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2 ); + qpOASES_sequence( 'c',QP ); + end + end + + end % hasX0 + + else % hasWS == 0 + + if ( hasX0 > 0 ) + if ( hasX0 == 1 ) + x0 = -1e-3 * ones( nV,1 ); + else + x0 = []; + end + + auxInput = qpOASES_auxInput( 'x0',x0 ); + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options(); + else + options = []; + end + + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,options,auxInput ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2,options ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2,options ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,options,auxInput ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,options ); + qpOASES_sequence( 'c',QP ); + end + + else + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,[],auxInput ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2 ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2 ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,[],auxInput ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2 ); + qpOASES_sequence( 'c',QP ); + end + end + + else % hasX0 == 0 + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options(); + else + options = []; + end + + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,options ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2,options ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2,options ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,options ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,options ); + qpOASES_sequence( 'c',QP ); + end + else + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1 ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2 ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2 ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1 ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2 ); + qpOASES_sequence( 'c',QP ); + end + end + + end % hasX0 + + end % hasWS + + + kktTol1 = getKktResidual( H1,g1,A1,lb1,ub1,lbA1,ubA1, x1,l1 ); + + if ( changeMat > 0 ) + kktTol2 = getKktResidual( H2,g2,A2,lb2,ub2,lbA2,ubA2, x2,l2 ); + else + kktTol2 = getKktResidual( H1,g2,A1,lb2,ub2,lbA2,ubA2, x2,l2 ); + end + + if ( ( kktTol1 <= KKTTOL ) && ( e1 >= 0 ) && ( kktTol2 <= KKTTOL ) && ( e2 >= 0 ) ) + successFlag = 1; + else + if ( doPrint > 0 ) + disp( ['kkt error: ',num2str(kktTol1),'/',num2str(kktTol2)] ) + end + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runRandomZeroHessian.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runRandomZeroHessian.m new file mode 100755 index 0000000..5fc4b91 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runRandomZeroHessian.m @@ -0,0 +1,433 @@ +function [ successFlag ] = runRandomZeroHessian( nV,nC, doPrint,seed ) + + if ( nargin < 4 ) + seed = 42; + if ( nargin < 3 ) + doPrint = 1; + if ( nargin < 2 ) + nC = 10; + if ( nargin < 1 ) + nV = 5; + end + end + end + end + + successFlag = 1; + + for isSparseH=0:1 + for isSparseA=0:1 + successFlag = runSeveralIdSeqTests( successFlag, nV,nC,isSparseH,isSparseA, doPrint,seed ); + end + end + +end + + +function [ successFlag ] = runSeveralIdSeqTests( successFlag, nV,nC, isSparseH,isSparseA, doPrint,seed ) + + %% test without or empty A matrix + % { + for hasA=0:1 + for changeMat=0:hasA % cannot change matrices if QProblemB object is instantiated + for hasOptions=1:1 + for hasX0=0:2 + for hasWS=0:2 + curSuccessFLAG = runSingleIdSeqTest( nV,0,hasA,isSparseH,isSparseA, 1,1,0,0,hasOptions,hasX0,hasWS,changeMat, doPrint,seed ); + successFlag = min( successFlag,curSuccessFLAG ); + end + end + end + end + end + %} + + %% test with non-empty A matrix + for hasLowerC=0:1 + for hasUpperC=0:1 + for hasOptions=1:1 + for hasX0=0:2 + for hasWS=0:2 + for changeMat=0:1 + curSuccessFLAG = runSingleIdSeqTest( nV,nC,1,isSparseH,isSparseA, 1,1,hasLowerC,hasUpperC,hasOptions,hasX0,hasWS,changeMat, doPrint,seed ); + successFlag = min( successFlag,curSuccessFLAG ); + end + end + end + end + end + end + +end + + +function [ successFlag ] = runSingleIdSeqTest( nV,nC,hasA,isSparseH,isSparseA, hasLowerB,hasUpperB,hasLowerC,hasUpperC,hasOptions,hasX0,hasWS,changeMat, doPrint,seed ) + + successFlag = 0; + + qpFeatures = setupQpFeaturesStruct( ); + + qpFeatures.nV = nV; + qpFeatures.nC = nC; + + qpFeatures.isSparseH = isSparseH; + qpFeatures.isSparseA = isSparseA; + + qpFeatures.hasLowerB = hasLowerB; + qpFeatures.hasUpperB = hasUpperB; + qpFeatures.hasLowerC = hasLowerC; + qpFeatures.hasUpperC = hasUpperC; + + qpFeatures.hessianType = 3; + + qpData1 = generateRandomQp( qpFeatures,seed ); + qpData2 = generateRandomQp( qpFeatures,seed ); + + if ( changeMat == 0 ) + string = 'Testing qpOASES_sequence( ''i/h/c'',0'; + else + string = 'Testing qpOASES_sequence( ''i/m/c'',0'; + end + + if ( isSparseH > 0 ) + string = [string,'s,g']; + else + string = [string,'d,g']; + end + + if ( nC > 0 ) + if ( isSparseA > 0 ) + string = [string,',As']; + else + string = [string,',Ad']; + end + else + if ( hasA > 0 ) + string = [string,',[]']; + end + end + + if ( hasLowerB > 0 ) + string = [string,',lb']; + else + string = [string,',[]']; + end + + if ( hasUpperB > 0 ) + string = [string,',ub']; + else + string = [string,',[]']; + end + + if ( hasLowerC > 0 ) + string = [string,',lbA']; + else + if ( hasA > 0 ) + string = [string,',[] ']; + end + end + + if ( hasUpperC > 0 ) + string = [string,',ubA']; + else + if ( hasA > 0 ) + string = [string,',[] ']; + end + end + + switch ( hasOptions ) + case 1 + string = [string,',opt']; + + case 2 + string = [string,',[] ']; + + case 0 + if ( ( hasX0 > 0 ) || ( hasWS > 0 ) ) + string = [string,',[] ']; + end + end + + switch ( hasX0 ) + case 1 + string = [string,',{x0']; + + case 2 + string = [string,',{[]']; + + case 0 + if ( hasWS > 0 ) + string = [string,',{[]']; + end + end + + switch ( hasWS ) + case 1 + string = [string,',WS}']; + + case 2 + string = [string,',[]}']; + end + + string = [string,' )... ']; + if ( doPrint > 0 ) + %disp( string ); + end + + %try + curSuccessFlag = callQpOasesSeq( qpData1,qpData2,hasA,hasOptions,hasX0,hasWS,changeMat,doPrint ); + %catch + %curSuccessFlag = 0; + %end + if ( curSuccessFlag > 0 ) + string = [string,'pass!']; + successFlag = 1; + else + string = [string,'fail!']; + end + + if ( doPrint > 0 ) + disp( string ); + if ( curSuccessFlag == 0 ) + %pause; + end + end + +end + + + +function [ successFlag ] = callQpOasesSeq( qpData1,qpData2,hasA,hasOptions,hasX0,hasWS,changeMat, doPrint ) + + if ( nargin < 8 ) + doPrint = 1; + end + + TOL = 1e-15; + KKTTOL = 1e-6; + + successFlag = 0; + + H1 = qpData1.H; + g1 = qpData1.g; + A1 = [qpData1.Aeq;qpData1.Ain]; + lb1 = qpData1.lb; + ub1 = qpData1.ub; + lbA1 = [qpData1.beq;qpData1.lbA]; + ubA1 = [qpData1.beq;qpData1.ubA]; + + H2 = qpData2.H; + g2 = qpData2.g; + A2 = [qpData2.Aeq;qpData2.Ain]; + lb2 = qpData2.lb; + ub2 = qpData2.ub; + lbA2 = [qpData2.beq;qpData2.lbA]; + ubA2 = [qpData2.beq;qpData2.ubA]; + + [nV,dummy] = size(H1); + [nC,dummy] = size(A1); + + if ( hasWS > 0 ) + if ( hasWS == 1 ) + wsB = 0 * ones( nV,1 ); + wsC = 0 * ones( nC,1 ); + else + wsB = []; + wsC = []; + end + + if ( hasX0 > 0 ) + if ( hasX0 == 1 ) + x0 = -1e-3 * ones( nV,1 ); + else + x0 = []; + end + + auxInput = qpOASES_auxInput( 'x0',x0,'guessedWorkingSetB',wsB,'guessedWorkingSetC',wsC ); + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options( 'fast' ); + else + options = []; + end + + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,options,auxInput ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2,options ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2,options ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,options,auxInput ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,options ); + qpOASES_sequence( 'c',QP ); + end + else + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,[],auxInput ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2 ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2 ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,[],auxInput ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2 ); + qpOASES_sequence( 'c',QP ); + end + end + + else % hasX0 == 0 + + auxInput = qpOASES_auxInput( 'guessedWorkingSetB',wsB,'guessedWorkingSetC',wsC ); + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options( 'fast' ); + else + options = []; + end + + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,options,auxInput ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2,options ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2,options ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,options,auxInput ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,options ); + qpOASES_sequence( 'c',QP ); + end + else + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,[],auxInput ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2,[] ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2,[] ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,[],auxInput ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2 ); + qpOASES_sequence( 'c',QP ); + end + end + + end % hasX0 + + else % hasWS == 0 + + if ( hasX0 > 0 ) + if ( hasX0 == 1 ) + x0 = -1e-3 * ones( nV,1 ); + else + x0 = []; + end + + auxInput = qpOASES_auxInput( 'x0',x0 ); + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options( 'fast' ); + else + options = []; + end + + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,options,auxInput ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2,options ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2,options ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,options,auxInput ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,options ); + qpOASES_sequence( 'c',QP ); + end + + else + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,[],auxInput ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2 ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2 ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,[],auxInput ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2 ); + qpOASES_sequence( 'c',QP ); + end + end + + else % hasX0 == 0 + + if ( hasOptions > 0 ) + if ( hasOptions == 1 ) + options = qpOASES_options( 'fast' ); + else + options = []; + end + + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1,options ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2,options ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2,options ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1,options ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,options ); + qpOASES_sequence( 'c',QP ); + end + else + if ( hasA > 0 ) + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,A1,lb1,ub1,lbA1,ubA1 ); + if ( changeMat > 0 ) + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'm',QP,H2,g2,A2,lb2,ub2,lbA2,ubA2 ); + else + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2,lbA2,ubA2 ); + end + qpOASES_sequence( 'c',QP ); + else + [ QP,x1,f1,e1,i1,l1,w1 ] = qpOASES_sequence( 'i',H1,g1,lb1,ub1 ); + [ x2,f2,e2,i2,l2,w2 ] = qpOASES_sequence( 'h',QP,g2,lb2,ub2 ); + qpOASES_sequence( 'c',QP ); + end + end + + end % hasX0 + + end % hasWS + + + kktTol1 = getKktResidual( H1,g1,A1,lb1,ub1,lbA1,ubA1, x1,l1 ); + + if ( changeMat > 0 ) + kktTol2 = getKktResidual( H2,g2,A2,lb2,ub2,lbA2,ubA2, x2,l2 ); + else + kktTol2 = getKktResidual( H1,g2,A1,lb2,ub2,lbA2,ubA2, x2,l2 ); + end + + if ( ( kktTol1 <= KKTTOL ) && ( e1 >= 0 ) && ( kktTol2 <= KKTTOL ) && ( e2 >= 0 ) ) + successFlag = 1; + else + if ( doPrint > 0 ) + disp( ['kkt error: ',num2str(kktTol1),'/',num2str(kktTol2)] ) + end + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runSimpleSpringExample.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runSimpleSpringExample.m new file mode 100755 index 0000000..2f494a6 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runSimpleSpringExample.m @@ -0,0 +1,34 @@ +function [ successFlag ] = runSimpleSpringExample( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 0; + + % parameter + k1 = 100; + k2 = 100; + + m = 1; + g = 9.81; + + % QP data + H = [ k1,0; 0,k2 ]; + g = [ m*g; 0 ]; + + lb = [ 0; 0 ]; + ub = [ 1; 1 ]; + + A = [ 1,1 ]; + lbA = 1; + ubA = 1; + + options = qpOASES_options( 'default', 'printLevel',2*doPrint ); + [x,fval,exitflag,iter] = qpOASES( H,g,A,lb,ub,lbA,ubA,options ); + + if ( ( exitflag == 0 ) && ( iter < 5 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestAPrioriKnownSeq1.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestAPrioriKnownSeq1.m new file mode 100755 index 0000000..7f963cd --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestAPrioriKnownSeq1.m @@ -0,0 +1,87 @@ +function [ successFlag ] = runTestAPrioriKnownSeq1( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 1; + TOL = eps; + + clear H g A lb ub lbA ubA; + + try + load 'benchmarkCRANE1.mat'; + catch + successFlag = -1; + return; + end + + [nC,nV] = size(A); + [nV,nP] = size(g); + + xOptSeq = zeros(nV,nP); + objOptSeq = zeros(1,nP); + statusSeq = zeros(1,nP); + iterSeq = zeros(1,nP); + yOptSeq = zeros(nV+nC,nP); + + options = qpOASES_options( 'fast','maxIter',100, 'printLevel',2*doPrint ); + + for i=1:nP + %disp(i); + + if ( i == 1 ) + [QP,x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'i',H,g(:,i),A,lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + else + [x,obj,status,nWSRout,lambda] = qpOASES_sequence( 'h',QP,g(:,i),lb(:,i),ub(:,i),lbA(:,i),ubA(:,i),options ); + end + + xOptSeq(:,i) = x; + objOptSeq(:,i) = obj; + statusSeq(:,i) = status; + iterSeq(:,i) = nWSRout; + yOptSeq(:,i) = lambda; + + end + + qpOASES_sequence( 'c',QP ); + + + [xOptAPKSeq,objOptAPKSeq,statusAPKSeq,iterAPKSeq,yOptAPKSeq] = qpOASES( H,g,A,lb,ub,lbA,ubA,options ); + + if ( norm( xOptSeq-xOptAPKSeq ) > TOL ) + successFlag = 0; + if ( doPrint > 0 ) + disp( 'xOpt error' ) + end + end + + if ( norm( objOptSeq-objOptAPKSeq ) > TOL ) + successFlag = 0; + if ( doPrint > 0 ) + disp( 'objOpt error' ) + end + end + + if ( sum( statusSeq~=statusAPKSeq ) > 0 ) + successFlag = 0; + if ( doPrint > 0 ) + disp( 'status error' ) + end + end + + if ( sum( iterSeq~=iterAPKSeq ) > 0 ) + successFlag = 0; + if ( doPrint > 0 ) + disp( 'iter error' ) + end + end + + if ( norm( yOptSeq-yOptAPKSeq ) > TOL ) + successFlag = 0; + if ( doPrint > 0 ) + disp( 'yOpt error' ) + end + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestSeq.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestSeq.m new file mode 100755 index 0000000..00c4fe8 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestSeq.m @@ -0,0 +1,104 @@ +function [ successFlag ] = runTestSeq( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 1; + + + % test case constants + m = 50; + n = 100; + nMajSeq = 8; + nMinSeq = 4; + nSeq = nMajSeq * nMinSeq; + p = 2; % interpolation monomial power + fldim = 5; % feedback law dimension + + % generate start and end problem + Ls = sprand(n, n, 0.03); + Hs = Ls' * Ls + 1e-8 * eye(n); + As = sprand(m, n, 0.05); + + % negative (!) definite Hessian + Le = sprand(n, n, 0.03); + He = -Le' * Le; + Ae = sprand(m, n, 0.05); + + lbAs = -rand(m,1); + ubAs = rand(m,1); + ubs = ones(n,1); + lbs = -ones(n,1); + gs = 10*rand(n,1); + + lbAe = -rand(m,1); + ubAe = rand(m,1); + ube = ones(n,1); + lbe = -ones(n,1); + ge = 10*rand(n,1); + + % monomial interpolation + tmaj = 1 - (1:1/(1-nMajSeq):0).^p; + for i = 1:nMajSeq + tau = tmaj(i); + H{i} = (1-tau) * Hs + tau * He; + A{i} = (1-tau) * As + tau * Ae; + end + t = 1 - (1:1/(1-nSeq):0).^p; + for i = 1:nSeq + tau = t(i); + lbA{i} = (1-tau) * lbAs + tau * lbAe; + ubA{i} = (1-tau) * ubAs + tau * ubAe; + lb{i} = (1-tau) * lbs + tau * lbe; + ub{i} = (1-tau) * ubs + tau * ube; + g{i} = (1-tau) * gs + tau * ge; + end + + x = zeros(n,1); + + if ~exist('cumIters', 'var') + cumIters = zeros(nSeq, 1); + end + + % solve sequence of QPs + if ( doPrint > 0 ) + fprintf('%3s %5s\n', 'seq', 'iters') + end + + for i = 1:nSeq + if i == 1 + [QP, x, fval, exitflag, iter, lambda] = qpOASES_sequence('i', ... + H{i}, g{i}, A{i}, lb{i}, ub{i}, lbA{i}, ubA{i}, x); + else + if mod(i-1, nMinSeq) == 0 + j = (i-1) / nMinSeq + 1; + [x, fval, exitflag, iter, lambda] = qpOASES_sequence('m', QP, ... + H{j}, g{i}, A{j}, lb{i}, ub{i}, lbA{i}, ubA{i}); + else + [x, fval, exitflag, iter, lambda] = qpOASES_sequence('h', QP, ... + g{i}, lb{i}, ub{i}, lbA{i}, ubA{i}); + end + end + + if ( doPrint > 0 ) + fprintf('%3d %5d\n', i, iter) + end + + cumIters(i) = cumIters(i) + iter; + + if ( exitflag ~= 0 ) + successFlag = 0; + end + end + + % solve EQP + V0 = zeros(n, fldim); + Lambda = eye(m, fldim); + [X, Y] = qpOASES_sequence('e', QP, V0, V0, V0, Lambda, Lambda); + FL = X(1:fldim,:); + + % clear + qpOASES_sequence('c', QP) + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestSparse.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestSparse.m new file mode 100755 index 0000000..272c689 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestSparse.m @@ -0,0 +1,33 @@ +function [ successFlag ] = runTestSparse( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 0; + + + m = 50; + n = 100; + + L = sprand(n, n, 0.03); + H = L' * L; + A = sprand(m, n, 0.05); + + lbA = -rand(m,1); + ubA = rand(m,1); + ub = ones(n,1); + lb = -ones(n,1); + g = 10*rand(n,1); + + options = qpOASES_options( 'default', 'printLevel',2*doPrint ); + + [x1,dummy1,exitflag1,iter1] = qpOASES(full(H), g, full(A), lb, ub, lbA, ubA, options); + [x2,dummy1,exitflag2,iter2] = qpOASES(H, g, A, lb, ub, lbA, ubA, options); + + if ( ( exitflag1 == 0 ) && ( exitflag2 == 0 ) && ( iter1 == iter2 ) ... + && ( norm(x1-x2) < 1e-10 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestSparse2.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestSparse2.m new file mode 100755 index 0000000..fc1f816 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestSparse2.m @@ -0,0 +1,33 @@ +function [ successFlag ] = runTestSparse2( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 0; + + + m = 50; + n = 100; + + L = sprand(n, n, 0.03); + H = L' * L; + A = sprand(m, n, 0.05); + + lbA = -rand(m,1); + ubA = rand(m,1); + ub = ones(n,1); + lb = -ones(n,1); + g = 10*rand(n,1); + + options = qpOASES_options( 'default', 'printLevel',2*doPrint ); + + [QP,dummy1,dummy2,exitflag1] = qpOASES_sequence( 'i', H, g, A, lb, ub, lbA, ubA, options ); + [dummy1,dummy2,exitflag2] = qpOASES_sequence( 'h',QP, g*2, lb, ub, lbA, ubA ); + qpOASES_sequence( 'c',QP ); + + if ( ( exitflag1 == 0 ) && ( exitflag2 == 0 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestSparse3.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestSparse3.m new file mode 100755 index 0000000..c4f870c --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestSparse3.m @@ -0,0 +1,39 @@ +function [ successFlag ] = runTestSparse3( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 0; + + + m = 50; + n = 100; + + L = sprand(n, n, 0.03); + H = L' * L; + A = sprand(m, n, 0.05); + + lbA = -rand(m,1); + ubA = rand(m,1); + ub = ones(n,1); + lb = -ones(n,1); + g = 10*rand(n,1); + + options = qpOASES_options( 'default', 'printLevel',2*doPrint ); + + + [QP,dummy1,dummy2,exitflag1] = qpOASES_sequence( 'i', H, g, A, lb, ub, lbA, ubA, options ); + + L = sprand(n, n, 0.03); + H = L' * L; + A = sprand(m, n, 0.05); + + [dummy1,dummy2,exitflag2] = qpOASES_sequence( 'm',QP, H, g*2, A, lb, ub, lbA, ubA ); + qpOASES_sequence( 'c',QP ); + + if ( ( exitflag1 == 0 ) && ( exitflag2 == 0 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestSparse4.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestSparse4.m new file mode 100755 index 0000000..7c468e4 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestSparse4.m @@ -0,0 +1,29 @@ +function [ successFlag ] = runTestSparse4( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 0; + + + n = 100; + + L = sprand(n, n, 0.03); + H = L' * L; + + ub = ones(n,1); + lb = -ones(n,1); + g = 10*rand(n,1); + + options = qpOASES_options( 'default', 'printLevel',2*doPrint ); + + [QP,dummy1,dummy2,exitflag1] = qpOASES_sequence( 'i', H, g, lb, ub, options ); + [dummy1,dummy2,exitflag2] = qpOASES_sequence( 'h',QP, g*2, lb, ub ); + qpOASES_sequence( 'c',QP ); + + if ( ( exitflag1 == 0 ) && ( exitflag2 == 0 ) ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestWorkingSetLI.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestWorkingSetLI.m new file mode 100755 index 0000000..3cdfeb4 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runTestWorkingSetLI.m @@ -0,0 +1,50 @@ +function [ successFlag ] = runTestWorkingSetLI( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 1; + + qpFeatures = setupQpFeaturesStruct( ); + + qpFeatures.nV = 20; + qpFeatures.nC = 100; + + qpFeatures.isSparseH = 0; + qpFeatures.isSparseA = 0; + + qpFeatures.hasLowerB = 1; + qpFeatures.hasUpperB = 1; + qpFeatures.hasLowerC = 1; + qpFeatures.hasUpperC = 1; + + qpFeatures.makeInfeas = 1; + + options = qpOASES_options( 'default', 'printLevel',2*doPrint, 'initialStatusBounds',0 ); + + exitflag = 0; + counter = 0; + + while ( ( exitflag ~= -42 ) && ( counter < 100 ) ) + + counter = counter+1; + + qpData = generateRandomQp( qpFeatures ); + B = [ eye( qpFeatures.nV ); qpData.Ain ]; + + [x,dummy1,exitflag,dummy2,dummy3,auxOutput] = qpOASES( qpData.H,qpData.g,qpData.Ain, ... + qpData.lb,qpData.ub,qpData.lbA,qpData.ubA, options ); %#ok<*NASGU> + + WS = [auxOutput.workingSetB; auxOutput.workingSetC]; + nAct = sum( WS~=0 ); + Bact = B( WS~=0,: ); + + if ( nAct ~= rank(Bact) ) + successFlag = 0; + return; + end + + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runVanBarelsUnboundedQP.m b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runVanBarelsUnboundedQP.m new file mode 100755 index 0000000..9198342 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/matlab/tests/runVanBarelsUnboundedQP.m @@ -0,0 +1,25 @@ +function [ successFlag ] = runVanBarelsUnboundedQP( doPrint ) + + if ( nargin < 1 ) + doPrint = 0; + end + + successFlag = 0; + + try + data = load( 'vanBarelsUnboundedQP.mat' ); + catch + successFlag = -1; + return; + end + + options1 = qpOASES_options( 'default', 'printLevel',-1*doPrint ); + + [dummy1,dummy2,exitflag1,iter1] = qpOASES( data.H,data.g,data.lb,data.ub,options1 ); %#ok<*NASGU> + + % should return "QP unbounded" + if ( exitflag1 == -3 ) + successFlag = 1; + end + +end diff --git a/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/runUnitTests b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/runUnitTests new file mode 100755 index 0000000..09c9f10 --- /dev/null +++ b/minco_ws/src/navigation/minco_controller/third_party/qpOASES/testing/runUnitTests @@ -0,0 +1,111 @@ +#!/usr/bin/env bash + +## +## This file is part of qpOASES. +## +## qpOASES -- An Implementation of the Online Active Set Strategy. +## Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +## Christian Kirches et al. All rights reserved. +## +## qpOASES is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## qpOASES is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with qpOASES; if not, write to the Free Software +## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +## + + + +## +## Filename: testing/runUnitTests +## Author: Hans Joachim Ferreau +## Version: 3.2 +## Date: 2014-2017 + +# defining colors for output +red='\e[0;31m' +green='\e[0;32m' +NC='\e[0m' # No Color + +# runs a number of examples to detect malfunctioning of the code + +function runTest { + echo -n "Running unit test $2 $3... " + + $2 $3 > dummy.txt; + retVal=$?; + rm -rf dummy.txt; + + if [ $retVal == 0 ]; then + echo -e "${green}passed!${NC}" + else + if [ $retVal == 99 ]; then + echo "problem data missing!" + else + echo -e "${red}failed!${NC}" + counter=$[counter+1]; + fi + fi +} + + +cd ..; +make testing; +cd testing; + +counter=0; + +# run unit tests +runTest $counter ../bin/test_matrices; +runTest $counter ../bin/test_matrices2; +runTest $counter ../bin/test_matrices3; +runTest $counter ../bin/test_indexlist; + +runTest $counter ../bin/test_example1; +runTest $counter ../bin/test_example1a; +runTest $counter ../bin/test_example1b; +runTest $counter ../bin/test_example2; +runTest $counter ../bin/test_example4; +runTest $counter ../bin/test_example5; +runTest $counter ../bin/test_exampleLP; +runTest $counter ../bin/test_qrecipe; +runTest $counter ../bin/test_qrecipeSchur; +runTest $counter ../bin/test_smallSchur; +runTest $counter ../bin/test_infeasible1; +runTest $counter ../bin/test_hs268; + +runTest $counter ../bin/test_example6; +runTest $counter ../bin/test_example7; +runTest $counter ../bin/test_sebastien1; +runTest $counter ../bin/test_vanBarelsUnboundedQP; +runTest $counter ../bin/test_janick1; +runTest $counter ../bin/test_janick2; +runTest $counter ../bin/test_constraintProduct1; +runTest $counter ../bin/test_constraintProduct2; +runTest $counter ../bin/test_guessedWS1; +runTest $counter ../bin/test_externalChol1; +runTest $counter ../bin/test_gradientShift; +runTest $counter ../bin/test_runAllOqpExamples; + +runTest $counter ../bin/test_bench Odd; +runTest $counter ../bin/test_bench Ods; +#runTest $counter ../bin/test_bench Ord; +#runTest $counter ../bin/test_bench Ors; +runTest $counter ../bin/test_bench Omd; +#runTest $counter ../bin/test_bench Oms; + + +if [ $counter == 0 ]; then + echo -e "${green}All available tests passed successfully!${NC}" +else + echo -e "${red}$counter test(s) failed!${NC}" + exit 1 +fi diff --git a/minco_ws/src/navigation/minco_planner/CMakeLists.txt b/minco_ws/src/navigation/minco_planner/CMakeLists.txt new file mode 100755 index 0000000..776a9b8 --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/CMakeLists.txt @@ -0,0 +1,138 @@ +cmake_minimum_required(VERSION 3.8) +project(minco_planner) + +if(CMAKE_COMPILER_ID MATCHES "Clang|GNU") + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_EXTENSIONS OFF) # �用编译器扩展 + add_compile_options(-Wall -Wextra -Wpedantic) + set(CMAKE_BUILD_TYPE "Release") + add_compile_options(-Werror -Wno-error=unused-variable -Wno-error=unused-parameter) +endif() + +find_package(ament_cmake REQUIRED) +find_package(backward_ros REQUIRED) +find_package(builtin_interfaces REQUIRED) +find_package(geometry_msgs REQUIRED) +find_package(nav2_common REQUIRED) +find_package(nav2_core REQUIRED) +find_package(nav2_costmap_2d REQUIRED) +find_package(nav2_util REQUIRED) +find_package(nav_msgs REQUIRED) +find_package(rcl_interfaces REQUIRED) +find_package(pluginlib REQUIRED) +find_package(rclcpp REQUIRED) +find_package(rclcpp_lifecycle REQUIRED) +find_package(tf2_ros REQUIRED) +find_package(ros_interfaces REQUIRED) +find_package(rog_map REQUIRED) +find_package(yaml-cpp REQUIRED) +find_package(OpenMP REQUIRED) + +nav2_package() + +set(library_name minco_planner) + +file(GLOB UTILS_SOURCES "src/utils/*.cpp") +file(GLOB SMAC_SEARCH_SOURCES "src/smac_search/*.cpp") +set(MINCO_CORE_SOURCES + src/minco_core/astar.cpp + src/minco_core/corridor_generator.cpp + src/minco_core/components/global_path_searcher.cpp + src/minco_core/components/local_path_processor.cpp + src/minco_core/components/map_query_adapters.cpp + src/minco_core/components/planner_mode_context.cpp + src/minco_core/components/recovery_behaivor.cpp + src/minco_core/components/trajectory_safety_checker.cpp + src/minco_core/minco_fsm.cpp + src/minco_core/minco_planner.cpp + src/minco_core/minco_utils.cpp + src/minco_core/visualizer.cpp + src/performance/planner_performance_monitor.cpp +) +file(GLOB TRAJ_OPT_SOURCES "src/traj_opt/*.cpp") + +add_library(${library_name} SHARED + ${UTILS_SOURCES} + ${SMAC_SEARCH_SOURCES} + ${MINCO_CORE_SOURCES} + ${TRAJ_OPT_SOURCES} +) + +target_compile_definitions(${library_name} +PUBLIC + ROOT_DIR="${CMAKE_CURRENT_SOURCE_DIR}/" + ORIGIN_AT_CORNER + USE_ROS2 +) + +target_compile_options(${library_name} +PRIVATE + -Wno-error=unused-parameter + -Wno-error=unused-function + -Wno-error=ignored-qualifiers +) + +target_include_directories(${library_name} +PUBLIC + $ + $ +PRIVATE + ${EIGEN3_INCLUDE_DIR} +) + +ament_target_dependencies(${library_name} + builtin_interfaces + geometry_msgs + nav2_core + nav2_costmap_2d + nav2_util + nav_msgs + pluginlib + rcl_interfaces + rclcpp + rclcpp_lifecycle + tf2_ros + ros_interfaces + rog_map +) + +target_link_libraries(${library_name} + OpenMP::OpenMP_CXX + yaml-cpp +) + +pluginlib_export_plugin_description_file(nav2_core global_planner_plugin.xml) + +install(TARGETS ${library_name} + EXPORT ${library_name} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin +) + +install(DIRECTORY include/ + DESTINATION include/${PROJECT_NAME} +) + +install(FILES global_planner_plugin.xml + DESTINATION share/${PROJECT_NAME} +) + +ament_export_include_directories(include/${PROJECT_NAME}) +ament_export_libraries(${library_name}) +ament_export_dependencies( + geometry_msgs + nav2_core + nav2_costmap_2d + nav2_util + nav_msgs + rclcpp + rclcpp_lifecycle + rcl_interfaces + tf2_ros + ros_interfaces + rog_map +) +ament_export_targets(${library_name}) +ament_package() diff --git a/minco_ws/src/navigation/minco_planner/README.md b/minco_ws/src/navigation/minco_planner/README.md new file mode 100755 index 0000000..cdf194e --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/README.md @@ -0,0 +1,226 @@ +# 🧭 MincoPlanner + +> �� RoboMaster 哨兵机器人的 Nav2 全局规划�件:以离散�索�供拓扑引导,以 ROGMap / ESDF �供局部环境约�,以 MINCO 生��实时执行的平滑轨迹。 + +[返回项目主页](../../../README.md) · [MPC 控制器](../minco_controller/README.md) · [ROGMap](../../perception/rog_map/README.md) + +## ✨ 模�定� + +`minco_planner::MincoPlanner` 实现 `nav2_core::GlobalPlanner`。Nav2 调用 `createPlan()` 时,�件完��标系归一化并更新待处�目标;真正的�索�优化��规划与安全检查由内部 FSM 周期执行。规划结果通过自定义轨迹消���给 MPC,而�是仅输出离散 `nav_msgs/Path`。 + +核心能力: + +- `PRIORMAP`:基于 Nav2 全局代价地图进行全局�索,适�先验地图导航。 +- `EXPLORATION`:基于 ROGMap �索局部�达区域�边界候选。 +- 路径�剪�稀�化与时间分�,�低优化维度。 +- MINCO 多项�轨迹优化,�时约�速度�加速度�障��离与终端状�。 +- 轨迹热�动�在线�规划�连续安全检查与�控��。 +- 直接查询 ROGMap / ESDF,��为规划查询���列化大地图。 + +## 🧠 模��程图 + +```mermaid +flowchart LR + G[Nav2 Goal] --> N[�标系归一化] + N --> S{planner_mode} + S -->|PRIORMAP| C[A* / SMAC 2D �索] + S -->|EXPLORATION| R[ROGMap �达边界�索] + C --> P[局部截� + ROGMap 边界�剪] + R --> P + P --> W[视线稀�化 + 转角�速] + W --> T[梯形 / 三角加�速时间分�] + T --> H{冷�动 / 热�动} + H --> M[MINCO 控制点与时间��优化] + M --> E[动力学 + 终点 + ESDF 采样校验] + E --> O["/opt_path"] + E -->|失败或阻塞| F[�规划 / Recovery] + F --> P +``` + +### �程概述 + +技术主线�概括为: + +```text +A* / SMAC �索 + → 按机器人当��置截�局部�视段 + → 按 ROGMap 有效边界�剪 + → line-of-sight 稀�化 + → 转角�速与梯形/三角加�速预分� + → 冷/热�动�值 + → MINCO 优化 + → �布�硬校验 +``` + +�索层�供离散拓扑引导;局部处�层把长路径压缩为有��视范围内的少�控制点;时间预分�根�段长�转角�速度和加速度给出接近�行的�值;MINCO ���优化分段多项�控制点与�续时间。�布�以 `0.05 s` 步长检查严�速度/加速度越界和终点误差;ROGMap/ESDF 碰撞检查�时以 `0.05 s` 和地图分辨率约�采样间隔,并显�检查轨迹终点。 + +## 🧪 技术方� + +- `PRIORMAP` 使用 Nav2 costmap 上的 A*/SMAC �索�供全局拓扑,ROGMap 负责局部动�查询;`EXPLORATION` 直接从 ROGMap �索�达边界。 +- `LocalPathProcessor` 先按 `lookahead_dist` 截�,�按 ROGMap 边界和 margin �剪,��优化器访问无有效局部地图的区域。 +- 稀�路径�过 line-of-sight 检查�转角局部�速����速度传播,以�梯形/三角加�速时间分�。 +- �置轨迹采用 MINCO 分段多项�;代价包�平滑�ESDF �置�速度�加速度�waypoint �引�时间和时间�障等软代价。 +- FSM 管�目标等待�生��跟踪��续安全检查和��;当�轨迹�安全或规划失败时进入�规划/��链路。 + +## ⚡ 性能方� + +- 局部�视截�和路径稀�化是�制优化规模的主�手段,��将完整全局路径直接作为优化��。 +- ROGMap 通过进程内 `MapQueryInterface` �供 occupancy�projection 和 ESDF 查询,�为�次优化�列化完整地图。 +- odom 订阅使用 `KeepLast(1) + best_effort + volatile`,强调 latest-state,��高频里程计积压。 +- `/opt_path` 与普通路径�视化使用深度 1;候选轨迹�A* 路径和控制点�视化使用 `transient_local` 深度 1,便于 RViz �加入时�得最近结果。 +- `PlannerPerformanceMonitor` �按开关记录�索�局部处��优化�总�规划耗时�规划频率��功状�和失败原因;详细字段�“性能观测�。 + +## 🔄 状�机 + +主�状�为: + +| 状� | �责 | +|---|---| +| `INIT` | 等待里程计�地图查询接�等必��件 | +| `WAIT_GOAL` | 等待新目标;已有目标更新时进入规划 | +| `GENERATE_TRAJ` | �索路径�构造�值并执行轨迹优化 | +| `FOLLOW_TRAJ` | �布并监测当�轨迹,按�件触��规划 | +| `RECOVERING` | 执行局部脱困并在�功��新规划 | + +> 状���等于所有分支�处于当�主路径。判断实际行为时应以 `minco_fsm.cpp` 中未注释的状�转移为准。 + +## 📡 ROS 接� + +### 输入 + +| 类型 | �称 | 说明 | +|---|---|---| +| Nav2 API | `createPlan(start, goal)` | 接收规划请求并更新内部目标 | +| `nav_msgs/msg/Odometry` | `/aft_mapped_to_init` | �姿�速度与轨迹起始状� | +| 内部查询 | `MapQueryInterface` | ROGMap ���投影层与 ESDF 查询 | +| Nav2 Costmap | `planner_server` costmap | `PRIORMAP` 模�的全局�索�� | + +### 输出与�视化 + +| Topic | 类型 / 用途 | 当� QoS �点 | +|---|---|---| +| `/opt_path` | `ros_interfaces/msg/MpcPositionCommand`,MPC 主�考轨迹 | `KeepLast(1)` | +| `/backup_path` | 兼容性轨迹通�;当�文档�将其作为主规划能力 | `KeepLast(1)` | +| `/opt_path_vis` | 已接�优化轨迹 | `KeepLast(1)` | +| `/minco_candidate_path_vis` | �布�候选轨迹与拒�诊断 | `KeepLast(1) + transient_local` | +| `/astar_path_vis` | 离散�索路径 | `KeepLast(1) + transient_local` | +| `/minco_control_points_vis` | MINCO 控制点 | `KeepLast(1) + transient_local` | +| `/recover_path`, `/recover_goal` | ��过程诊断 | `KeepLast(1)` | + +## ⚙� 关键�置 + +主�置�于 `src/navigation/navi2_bringup/params/sentry1.yaml` 的 `planner_server.ros__parameters.MincoPlanner`。 + +### 模�与�标系 + +| �数 | 当�典型值 | �义 | +|---|---:|---| +| `planner_mode` | `PRIORMAP` | `PRIORMAP` / `EXPLORATION` | +| `odom_topic` | `/aft_mapped_to_init` | Point-LIO 里程计 | +| `frames.map_frame` | `map` | 先验地图规划�标系 | +| `frames.rog_frame` | `camera_init` | ROGMap 与局部轨迹�标系 | +| `use_smac` | `true` | 先验地图模�使用 SMAC 2D �索 | + +### 轨迹与安全 + +| �数组 | 作用 | 调�影� | +|---|---|---| +| `minco_optimizer.max_velocity`, `max_acceleration` | 线速度�线加速度上� | 过高会增加跟踪压力,过低会�低机动性 | +| `minco_optimizer.safe_dist` | ESDF 优化�轨迹安全余� | 应与车体外形和地图膨胀共�确定 | +| `minco_optimizer.collision_dist` | 预留碰撞�离�数 | 当��布�碰撞检查以 `safe_dist` �置的安全检查器为准 | +| `minco_optimizer.lookahead_dist` | 局部优化�视长度 | 越大越平滑,但控制点�计算�与局部地图�赖增加 | +| `minco_optimizer.integral_res` | 代价积分采样密度 | 越高越精细,也越耗时 | +| `minco_optimizer.enable_yaw_opt` | 是�优化��轨迹 | 隧��侧移和高速转�需结�控制器验� | +| `recovery_server.*` | 连续失败阈值�冷�与脱困�数 | 影�阻塞�的��激进程度 | + +### � Planner �臂补� + +`lidar_offset_x/y` �述雷达/里程计�考点相对底盘控制�考点的平��移。当�典型�置为: + +```yaml +lidar_offset_x: 0.0 +lidar_offset_y: -0.20 +``` + +该补�会影�规划�始状�。它必须与 Point-LIO �布的�考点�控制器中的���移�实体安装方�一致。��通过修改该�数修补错误的 TF;先确认�标轴方�和�移定义。 + +## 🚀 �动与检查 + +本模�通常�完整导航�动,�建议独立�动�件: + +```bash +ros2 launch navi2 navigation2.launch.py +``` + +�动��检查: + +```bash +ros2 topic hz /aft_mapped_to_init +ros2 topic hz /opt_path +ros2 topic echo /opt_path --once +ros2 param get /planner_server MincoPlanner.planner_mode +``` + +推�在 RViz �时观察 `/astar_path_vis`�`/opt_path_vis`�ROGMap ��层和 ESDF,区分“�索��达�“优化失败�和“地图输入异常�。 + +## 📈 性能观测 + +`performance.enable` 是性能监视总开关;`print_enable`�`detailed_csv_enable` 和 `odom_sub_debug_enable` 分别控制终端摘���次 CSV 和 odom 订阅统计。当�比赛 YAML 默认关闭 Planner 性能统计。详细 CSV 默认写入: + +```text +/tmp/minco_perf_detailed.csv +``` + +CSV 记录 `planner_mode`�`success`�`failure_reason`�`global_search_time_ms`�`local_search_time_ms`�`optimizer_time_ms`�`total_replan_time_ms` 和 `planner_hz`,并�附带 `run_id/scenario/variant`。`csv_flush_every_n` 控制批� flush,���行�步刷盘�为新的实时性瓶颈。 + +在线调�时应�时观察 P95/P99 耗时�失败原因�轨迹接�率和实际�执行性;�次优化很快并�等于动��障链路足够��。 + +## ⚠� 已知问题与改进方� + +### 热�动是当�实车折中 + +电控速度闭环存在稳�跟踪误差,冷�动若直接采用实测速度,会压低新轨迹的�始速度�馈。当� `determinePlanningState()` 在�置误差或速度误差超阈值时�返回 `HOT_START`,强制继承旧轨迹速度/加速度,以维�速度�馈。这是实车跟�问题下的工程折中,�是�想热�动判�。 + +热�动边界状�目�混用了两套��: + +- 起始�置使用最新 odom:`start_pose.position`; +- 起始速度�加速度使用旧轨迹在 `t_dur` 的期望值; +- ��中“使用旧轨迹期望�置�的实现�被注释。 + +因此,新轨迹起点��与实车�置连续,但 P/V/A 并��自�一个轨迹状�。跟踪误差较大时�能造�边界状��一致;�续应在电控跟踪�轨迹连续性和�行性之间�新验�热�动策略。 + +### 主优化缺少安全走廊硬约� + +当�主 MINCO 优化�赖 ESDF�动力学和 waypoint 等软代价,没有把�索路径对应的安全走廊作为优化��的硬几何约�。`corridor` 生�器目�用于 backup trajectory,�约�主优化轨迹。�布�虽有动力学�终点和 ESDF 离散采样校验,但它属于事�拒�,�能从求解空间中排除所有畸形候选。 + +此外,总代价上� `max_allowed_cost` 的拒�逻辑当�被注释,优化结果�先检查 `final_cost` 是�有�,�进入轨迹采样校验。�端�值�地图梯度或代价��组�下��能出现形状异常但数值有�的候选解;应优先评估安全走廊约��尺度归一化和更明确的质�门控,而�是继续堆�未�验�的固定��。 + +### 动��障�应�够�� + +动��障能力由点云与地图刷新�全局/局部路径更新�FSM �规划触��旧轨迹�用�安全门控和新轨迹接�共�决定,�是优化耗时一个指标。当�策略在动�障�出现��能继续�用�被判定安全的旧轨迹,或因新轨迹被门控拒�而延迟切�;现场表现为�障�应�够��。 + +改进时应先用 CSV 和�视化对�“障�进入地图 → ESDF 更新 → �规划开始 → 新轨迹接��的时间线,�调整�规划触�和轨迹接�策略,���纯�高规划频率或��安全�离。 + +## 🛠� 常�问题 + +| 现象 | 优先检查 | +|---|---| +| 一直�留在 `INIT` | 里程计�ROGMap 创建��标系与生命周期状� | +| 有�索路径但无 `/opt_path` | 时间分���值�ESDF�安全�离和优化器返回状� | +| 轨迹贴障或穿障 | 点云时延�ROGMap 投影高度�ESDF 更新�安全/碰撞�离 | +| 频��规划 | 地图抖动�目标更新频率��规划�件�速度/加速度约� | +| 起步方�或速度异常 | Planner 与 Controller �臂�数�odom �考点和 yaw 定义 | +| `EXPLORATION` 无结果 | 起点是��于 ROGMap�局部边界是�存在�达候选 | + +## 🗂� 关键�� + +- `src/minco_core/minco_planner.cpp`:�件�置�目标接入�地图创建与�数更新。 +- `src/minco_core/minco_fsm.cpp`:规划状�机与�规划逻辑。 +- `src/minco_core/components/global_path_searcher.cpp`:两�模�的全局/局部�索。 +- `src/traj_opt/minco_optimizer.cpp`:MINCO 优化入�。 +- `src/minco_core/components/trajectory_safety_checker.cpp`:轨迹安全查询。 +- `include/minco_core/`:�件�FSM 与组件接�。 + +## 📚 延伸阅读 + +系统级安装��动顺�与完整�数关系�[项目主 README](../../../README.md)。地图内部结构� [ROGMap 文档](../../perception/rog_map/README.md),轨迹执行� [MPC 控制器文档](../minco_controller/README.md)。 diff --git a/minco_ws/src/navigation/minco_planner/global_planner_plugin.xml b/minco_ws/src/navigation/minco_planner/global_planner_plugin.xml new file mode 100755 index 0000000..1ada46b --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/global_planner_plugin.xml @@ -0,0 +1,7 @@ + + + + A global planner that uses A* search and Minco trajectory optimization. + + + diff --git a/minco_ws/src/navigation/minco_planner/include/cereal/access.hpp b/minco_ws/src/navigation/minco_planner/include/cereal/access.hpp new file mode 100644 index 0000000..e462d35 --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/include/cereal/access.hpp @@ -0,0 +1,390 @@ +/*! \file access.hpp + \brief Access control and default construction */ +/* + Copyright (c) 2014, Randolph Voorhies, Shane Grant + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef CEREAL_ACCESS_HPP_ +#define CEREAL_ACCESS_HPP_ + +#include +#include +#include +#include + +#include "cereal/details/helpers.hpp" +#include "cereal/macros.hpp" +#include "cereal/specialize.hpp" + +namespace cereal { +// ###################################################################### +//! A class that allows cereal to load smart pointers to types that have no default constructor +/*! If your class does not have a default constructor, cereal will not be able + to load any smart pointers to it unless you overload LoadAndConstruct + for your class, and provide an appropriate load_and_construct method. You can also + choose to define a member static function instead of specializing this class. + + The specialization of LoadAndConstruct must be placed within the cereal namespace: + + @code{.cpp} + struct MyType + { + MyType( int x ); // note: no default ctor + int myX; + + // Define a serialize or load/save pair as you normally would + template + void serialize( Archive & ar ) + { + ar( myX ); + } + }; + + // Provide a specialization for LoadAndConstruct for your type + namespace cereal + { + template <> struct LoadAndConstruct + { + // load_and_construct will be passed the archive that you will be loading + // from as well as a construct object which you can use as if it were the + // constructor for your type. cereal will handle all memory management for you. + template + static void load_and_construct( Archive & ar, cereal::construct & construct ) + { + int x; + ar( x ); + construct( x ); + } + + // if you require versioning, simply add a const std::uint32_t as the final parameter, e.g.: + // load_and_construct( Archive & ar, cereal::construct & construct, std::uint32_t const + version ) + }; + } // end namespace cereal + @endcode + + Please note that just as in using external serialization functions, you cannot get + access to non-public members of your class by befriending cereal::access. If you + have the ability to modify the class you wish to serialize, it is recommended that you + use member serialize functions and a static member load_and_construct function. + + load_and_construct functions, regardless of whether they are static members of your class or + whether you create one in the LoadAndConstruct specialization, have the following signature: + + @code{.cpp} + // generally Archive will be templated, but it can be specific if desired + template + static void load_and_construct( Archive & ar, cereal::construct & construct ); + // with an optional last parameter specifying the version: const std::uint32_t version + @endcode + + Versioning behaves the same way as it does for standard serialization functions. + + @tparam T The type to specialize for + @ingroup Access */ +template struct LoadAndConstruct +{ +}; + +// forward decl for construct +//! @cond PRIVATE_NEVERDEFINED +namespace memory_detail { +template struct LoadAndConstructLoadWrapper; +} +namespace boost_variant_detail { +template struct LoadAndConstructLoadWrapper; +} +//! @endcond + +//! Used to construct types with no default constructor +/*! When serializing a type that has no default constructor, cereal + will attempt to call either the class static function load_and_construct + or the appropriate template specialization of LoadAndConstruct. cereal + will pass that function a reference to the archive as well as a reference + to a construct object which should be used to perform the allocation once + data has been appropriately loaded. + + @code{.cpp} + struct MyType + { + // note the lack of default constructor + MyType( int xx, int yy ); + + int x, y; + double notInConstructor; + + template + void serialize( Archive & ar ) + { + ar( x, y ); + ar( notInConstructor ); + } + + template + static void load_and_construct( Archive & ar, cereal::construct & construct ) + { + int x, y; + ar( x, y ); + + // use construct object to initialize with loaded data + construct( x, y ); + + // access to member variables and functions via -> operator + ar( construct->notInConstructor ); + + // could also do the above section by: + double z; + ar( z ); + construct->notInConstructor = z; + } + }; + @endcode + + @tparam T The class type being serialized + */ +template class construct +{ +public: + //! Construct and initialize the type T with the given arguments + /*! This will forward all arguments to the underlying type T, + calling an appropriate constructor. + + Calling this function more than once will result in an exception + being thrown. + + @param args The arguments to the constructor for T + @throw Exception If called more than once */ + template void operator()(Args &&... args); + // implementation deferred due to reliance on cereal::access + + //! Get a reference to the initialized underlying object + /*! This must be called after the object has been initialized. + + @return A reference to the initialized object + @throw Exception If called before initialization */ + T * operator->() + { + if (!itsValid) + throw Exception("Object must be initialized prior to accessing members"); + + return itsPtr; + } + + //! Returns a raw pointer to the initialized underlying object + /*! This is mainly intended for use with passing an instance of + a constructed object to cereal::base_class. + + It is strongly recommended to avoid using this function in + any other circumstance. + + @return A raw pointer to the initialized type */ + T * ptr() { return operator->(); } + +private: + template friend struct ::cereal::memory_detail::LoadAndConstructLoadWrapper; + template friend struct ::cereal::boost_variant_detail::LoadAndConstructLoadWrapper; + + construct(T * p) + : itsPtr(p), itsEnableSharedRestoreFunction([]() { + }), + itsValid(false) + { + } + construct(T * p, std::function enableSharedFunc) + : // g++4.7 ice with default lambda to std func + itsPtr(p), itsEnableSharedRestoreFunction(enableSharedFunc), itsValid(false) + { + } + construct(construct const &) = delete; + construct & operator=(construct const &) = delete; + + T * itsPtr; + std::function itsEnableSharedRestoreFunction; + bool itsValid; +}; + +// ###################################################################### +//! A class that can be made a friend to give cereal access to non public functions +/*! If you desire non-public serialization functions within a class, cereal can only + access these if you declare cereal::access a friend. + + @code{.cpp} + class MyClass + { + private: + friend class cereal::access; // gives access to the private serialize + + template + void serialize( Archive & ar ) + { + // some code + } + }; + @endcode + @ingroup Access */ +class access +{ +public: + // ####### Standard Serialization ######################################## + template + inline static auto member_serialize(Archive & ar, T & t) -> decltype(t.CEREAL_SERIALIZE_FUNCTION_NAME(ar)) + { + return t.CEREAL_SERIALIZE_FUNCTION_NAME(ar); + } + + template + inline static auto member_save(Archive & ar, T const & t) -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar)) + { + return t.CEREAL_SAVE_FUNCTION_NAME(ar); + } + + template + inline static auto member_save_non_const(Archive & ar, T & t) -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar)) + { + return t.CEREAL_SAVE_FUNCTION_NAME(ar); + } + + template + inline static auto member_load(Archive & ar, T & t) -> decltype(t.CEREAL_LOAD_FUNCTION_NAME(ar)) + { + return t.CEREAL_LOAD_FUNCTION_NAME(ar); + } + + template + inline static auto member_save_minimal(Archive const & ar, T const & t) + -> decltype(t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar)) + { + return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar); + } + + template + inline static auto member_save_minimal_non_const(Archive const & ar, T & t) + -> decltype(t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar)) + { + return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar); + } + + template + inline static auto member_load_minimal(Archive const & ar, T & t, U && u) + -> decltype(t.CEREAL_LOAD_MINIMAL_FUNCTION_NAME(ar, std::forward(u))) + { + return t.CEREAL_LOAD_MINIMAL_FUNCTION_NAME(ar, std::forward(u)); + } + + // ####### Versioned Serialization ####################################### + template + inline static auto member_serialize(Archive & ar, T & t, const std::uint32_t version) + -> decltype(t.CEREAL_SERIALIZE_FUNCTION_NAME(ar, version)) + { + return t.CEREAL_SERIALIZE_FUNCTION_NAME(ar, version); + } + + template + inline static auto member_save(Archive & ar, T const & t, const std::uint32_t version) + -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar, version)) + { + return t.CEREAL_SAVE_FUNCTION_NAME(ar, version); + } + + template + inline static auto member_save_non_const(Archive & ar, T & t, const std::uint32_t version) + -> decltype(t.CEREAL_SAVE_FUNCTION_NAME(ar, version)) + { + return t.CEREAL_SAVE_FUNCTION_NAME(ar, version); + } + + template + inline static auto member_load(Archive & ar, T & t, const std::uint32_t version) + -> decltype(t.CEREAL_LOAD_FUNCTION_NAME(ar, version)) + { + return t.CEREAL_LOAD_FUNCTION_NAME(ar, version); + } + + template + inline static auto member_save_minimal(Archive const & ar, T const & t, const std::uint32_t version) + -> decltype(t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar, version)) + { + return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar, version); + } + + template + inline static auto member_save_minimal_non_const(Archive const & ar, T & t, const std::uint32_t version) + -> decltype(t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar, version)) + { + return t.CEREAL_SAVE_MINIMAL_FUNCTION_NAME(ar, version); + } + + template + inline static auto member_load_minimal(Archive const & ar, T & t, U && u, const std::uint32_t version) + -> decltype(t.CEREAL_LOAD_MINIMAL_FUNCTION_NAME(ar, std::forward(u), version)) + { + return t.CEREAL_LOAD_MINIMAL_FUNCTION_NAME(ar, std::forward(u), version); + } + + // ####### Other Functionality ########################################## + // for detecting inheritance from enable_shared_from_this + template inline static auto shared_from_this(T & t) -> decltype(t.shared_from_this()); + + // for placement new + template inline static void construct(T *& ptr, Args &&... args) + { + new (ptr) T(std::forward(args)...); + } + + // for non-placement new with a default constructor + template inline static T * construct() { return new T(); } + + template inline static std::false_type load_and_construct(...) { return std::false_type(); } + + template + inline static auto load_and_construct(Archive & ar, ::cereal::construct & construct) + -> decltype(T::load_and_construct(ar, construct)) + { + T::load_and_construct(ar, construct); + } + + template + inline static auto load_and_construct( + Archive & ar, ::cereal::construct & construct, const std::uint32_t version) + -> decltype(T::load_and_construct(ar, construct, version)) + { + T::load_and_construct(ar, construct, version); + } +}; // end class access + +// ###################################################################### +// Deferred Implementation, see construct for more information +template template inline void construct::operator()(Args &&... args) +{ + if (itsValid) + throw Exception("Attempting to construct an already initialized object"); + + ::cereal::access::construct(itsPtr, std::forward(args)...); + itsEnableSharedRestoreFunction(); + itsValid = true; +} +} // namespace cereal + +#endif // CEREAL_ACCESS_HPP_ diff --git a/minco_ws/src/navigation/minco_planner/include/cereal/archives/adapters.hpp b/minco_ws/src/navigation/minco_planner/include/cereal/archives/adapters.hpp new file mode 100644 index 0000000..5c0d9bf --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/include/cereal/archives/adapters.hpp @@ -0,0 +1,156 @@ +/*! \file adapters.hpp + \brief Archive adapters that provide additional functionality + on top of an existing archive */ +/* + Copyright (c) 2014, Randolph Voorhies, Shane Grant + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef CEREAL_ARCHIVES_ADAPTERS_HPP_ +#define CEREAL_ARCHIVES_ADAPTERS_HPP_ + +#include "cereal/details/helpers.hpp" +#include + +namespace cereal { +#ifdef CEREAL_FUTURE_EXPERIMENTAL + +// Forward declaration for friend access +template U & get_user_data(A &); + +//! Wraps an archive and gives access to user data +/*! This adapter is useful if you require access to + either raw pointers or references within your + serialization functions. + + While cereal does not directly support serialization + raw pointers or references, it is sometimes the case + that you may want to supply something such as a raw + pointer or global reference to some constructor. + In this situation this adapter would likely be used + with the construct class to allow for non-default + constructors. + + @note This feature is experimental and may be altered or removed in a future release. See issue #46. + + @code{.cpp} + struct MyUserData + { + int * myRawPointer; + std::reference_wrapper myReference; + }; + + struct MyClass + { + // Note the raw pointer parameter + MyClass( int xx, int * rawP ); + + int x; + + template + void serialize( Archive & ar ) + { ar( x ); } + + template + static void load_and_construct( Archive & ar, cereal::construct & construct ) + { + int xx; + ar( xx ); + // note the need to use get_user_data to retrieve user data from the archive + construct( xx, cereal::get_user_data( ar ).myRawPointer ); + } + }; + + int main() + { + { + MyUserData md; + md.myRawPointer = &something; + md.myReference = someInstanceOfType; + + std::ifstream is( "data.xml" ); + cereal::UserDataAdapter ar( md, is ); + + std::unique_ptr sc; + ar( sc ); // use as normal + } + + return 0; + } + @endcode + + @relates get_user_data + + @tparam UserData The type to give the archive access to + @tparam Archive The archive to wrap */ +template class UserDataAdapter : public Archive +{ +public: + //! Construct the archive with some user data struct + /*! This will forward all arguments (other than the user + data) to the wrapped archive type. The UserDataAdapter + can then be used identically to the wrapped archive type + + @tparam Args The arguments to pass to the constructor of + the archive. */ + template + UserDataAdapter(UserData & ud, Args &&... args) : Archive(std::forward(args)...), userdata(ud) + { + } + +private: + //! Overload the rtti function to enable dynamic_cast + void rtti() {} + friend UserData & get_user_data(Archive & ar); + UserData & userdata; //!< The actual user data +}; + +//! Retrieves user data from an archive wrapped by UserDataAdapter +/*! This will attempt to retrieve the user data associated with + some archive wrapped by UserDataAdapter. If this is used on + an archive that is not wrapped, a run-time exception will occur. + + @note This feature is experimental and may be altered or removed in a future release. See issue #46. + + @note The correct use of this function cannot be enforced at compile + time. + + @relates UserDataAdapter + @tparam UserData The data struct contained in the archive + @tparam Archive The archive, which should be wrapped by UserDataAdapter + @param ar The archive + @throws Exception if the archive this is used upon is not wrapped with + UserDataAdapter. */ +template UserData & get_user_data(Archive & ar) +{ + try { + return dynamic_cast &>(ar).userdata; + } catch (std::bad_cast const &) { + throw ::cereal::Exception("Attempting to get user data from archive not wrapped in UserDataAdapter"); + } +} +#endif // CEREAL_FUTURE_EXPERIMENTAL +} // namespace cereal + +#endif // CEREAL_ARCHIVES_ADAPTERS_HPP_ diff --git a/minco_ws/src/navigation/minco_planner/include/cereal/archives/binary.hpp b/minco_ws/src/navigation/minco_planner/include/cereal/archives/binary.hpp new file mode 100644 index 0000000..5a6a541 --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/include/cereal/archives/binary.hpp @@ -0,0 +1,168 @@ +/*! \file binary.hpp + \brief Binary input and output archives */ +/* + Copyright (c) 2014, Randolph Voorhies, Shane Grant + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef CEREAL_ARCHIVES_BINARY_HPP_ +#define CEREAL_ARCHIVES_BINARY_HPP_ + +#include "cereal/cereal.hpp" +#include + +namespace cereal { +// ###################################################################### +//! An output archive designed to save data in a compact binary representation +/*! This archive outputs data to a stream in an extremely compact binary + representation with as little extra metadata as possible. + + This archive does nothing to ensure that the endianness of the saved + and loaded data is the same. If you need to have portability over + architectures with different endianness, use PortableBinaryOutputArchive. + + When using a binary archive and a file stream, you must use the + std::ios::binary format flag to avoid having your data altered + inadvertently. + + \ingroup Archives */ +class BinaryOutputArchive : public OutputArchive +{ +public: + //! Construct, outputting to the provided stream + /*! @param stream The stream to output to. Can be a stringstream, a file stream, or + even cout! */ + BinaryOutputArchive(std::ostream & stream) + : OutputArchive(this), itsStream(stream) + { + } + + ~BinaryOutputArchive() CEREAL_NOEXCEPT = default; + + //! Writes size bytes of data to the output stream + void saveBinary(const void * data, std::streamsize size) + { + auto const writtenSize = itsStream.rdbuf()->sputn(reinterpret_cast(data), size); + + if (writtenSize != size) + throw Exception("Failed to write " + std::to_string(size) + " bytes to output stream! Wrote " + + std::to_string(writtenSize)); + } + +private: + std::ostream & itsStream; +}; + +// ###################################################################### +//! An input archive designed to load data saved using BinaryOutputArchive +/* This archive does nothing to ensure that the endianness of the saved + and loaded data is the same. If you need to have portability over + architectures with different endianness, use PortableBinaryOutputArchive. + + When using a binary archive and a file stream, you must use the + std::ios::binary format flag to avoid having your data altered + inadvertently. + + \ingroup Archives */ +class BinaryInputArchive : public InputArchive +{ +public: + //! Construct, loading from the provided stream + BinaryInputArchive(std::istream & stream) + : InputArchive(this), itsStream(stream) + { + } + + ~BinaryInputArchive() CEREAL_NOEXCEPT = default; + + //! Reads size bytes of data from the input stream + void loadBinary(void * const data, std::streamsize size) + { + auto const readSize = itsStream.rdbuf()->sgetn(reinterpret_cast(data), size); + + if (readSize != size) + throw Exception("Failed to read " + std::to_string(size) + " bytes from input stream! Read " + + std::to_string(readSize)); + } + +private: + std::istream & itsStream; +}; + +// ###################################################################### +// Common BinaryArchive serialization functions + +//! Saving for POD types to binary +template +inline typename std::enable_if::value, void>::type CEREAL_SAVE_FUNCTION_NAME( + BinaryOutputArchive & ar, T const & t) +{ + ar.saveBinary(std::addressof(t), sizeof(t)); +} + +//! Loading for POD types from binary +template +inline typename std::enable_if::value, void>::type CEREAL_LOAD_FUNCTION_NAME( + BinaryInputArchive & ar, T & t) +{ + ar.loadBinary(std::addressof(t), sizeof(t)); +} + +//! Serializing NVP types to binary +template +inline CEREAL_ARCHIVE_RESTRICT(BinaryInputArchive, BinaryOutputArchive) + CEREAL_SERIALIZE_FUNCTION_NAME(Archive & ar, NameValuePair & t) +{ + ar(t.value); +} + +//! Serializing SizeTags to binary +template +inline CEREAL_ARCHIVE_RESTRICT(BinaryInputArchive, BinaryOutputArchive) + CEREAL_SERIALIZE_FUNCTION_NAME(Archive & ar, SizeTag & t) +{ + ar(t.size); +} + +//! Saving binary data +template inline void CEREAL_SAVE_FUNCTION_NAME(BinaryOutputArchive & ar, BinaryData const & bd) +{ + ar.saveBinary(bd.data, static_cast(bd.size)); +} + +//! Loading binary data +template inline void CEREAL_LOAD_FUNCTION_NAME(BinaryInputArchive & ar, BinaryData & bd) +{ + ar.loadBinary(bd.data, static_cast(bd.size)); +} +} // namespace cereal + +// register archives for polymorphic support +CEREAL_REGISTER_ARCHIVE(cereal::BinaryOutputArchive) +CEREAL_REGISTER_ARCHIVE(cereal::BinaryInputArchive) + +// tie input and output archives together +CEREAL_SETUP_ARCHIVE_TRAITS(cereal::BinaryInputArchive, cereal::BinaryOutputArchive) + +#endif // CEREAL_ARCHIVES_BINARY_HPP_ diff --git a/minco_ws/src/navigation/minco_planner/include/cereal/archives/binary_file_handler.hpp b/minco_ws/src/navigation/minco_planner/include/cereal/archives/binary_file_handler.hpp new file mode 100644 index 0000000..1947ad7 --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/include/cereal/archives/binary_file_handler.hpp @@ -0,0 +1,68 @@ +// Created by yunfan on 10/29/24 + +#ifndef BINARY_FILE_HANDLER_HPP +#define BINARY_FILE_HANDLER_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +// Use const std::string for color definitions with meaningful names +const std::string COLOR_RESET = "\033[0m"; +const std::string COLOR_ERROR = "\033[31m"; // Red for errors +const std::string COLOR_SUCCESS = "\033[32m"; // Green for success + +// Template utility class for binary file operations +template class BinaryFileHandler +{ +public: + static std::string getCurrentTimeStr() + { + // 获�当�时间 + std::time_t now = std::time(nullptr); + std::tm localTime = *std::localtime(&now); + + // 使用 stringstream 格�化时间为 YYMMDD-HHMMSS + std::ostringstream oss; + oss << std::setfill('0') << std::setw(2) << (localTime.tm_year % 100) // 年份�两� + << std::setw(2) << (localTime.tm_mon + 1) // 月份 (tm_mon 从 0 开始) + << std::setw(2) << localTime.tm_mday // 日期 + << "-" // 分隔符 + << std::setw(2) << localTime.tm_hour // �时 + << std::setw(2) << localTime.tm_min // 分钟 + << std::setw(2) << localTime.tm_sec; // 秒 + + return oss.str(); + } + // Static method: Save data to a binary file + static void save(const std::string & filename, const T & data) + { + std::ofstream ofs(filename, std::ios::binary); + if (!ofs) { + std::cerr << COLOR_ERROR << "Error: Could not open file for writing.\n" << COLOR_RESET; + return; + } + cereal::BinaryOutputArchive archive(ofs); + archive(data); + std::cout << COLOR_SUCCESS << "Data saved successfully to " << filename << COLOR_RESET << '\n'; + } + + // Static method: Load data from a binary file + static void load(const std::string & filename, T & data) + { + std::ifstream ifs(filename, std::ios::binary); + if (!ifs) { + std::cerr << COLOR_ERROR << "Error: Could not open file for reading.\n" << COLOR_RESET; + return; + } + cereal::BinaryInputArchive archive(ifs); + archive(data); + std::cout << COLOR_SUCCESS << "Data loaded successfully from " << filename << COLOR_RESET << '\n'; + } +}; + +#endif // BINARY_FILE_HANDLER_HPP diff --git a/minco_ws/src/navigation/minco_planner/include/cereal/archives/json.hpp b/minco_ws/src/navigation/minco_planner/include/cereal/archives/json.hpp new file mode 100644 index 0000000..7e67eea --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/include/cereal/archives/json.hpp @@ -0,0 +1,1133 @@ +/*! \file json.hpp + \brief JSON input and output archives */ +/* + Copyright (c) 2014, Randolph Voorhies, Shane Grant + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef CEREAL_ARCHIVES_JSON_HPP_ +#define CEREAL_ARCHIVES_JSON_HPP_ + +#include "cereal/cereal.hpp" +#include "cereal/details/util.hpp" + +namespace cereal { +//! An exception thrown when rapidjson fails an internal assertion +/*! @ingroup Utility */ +struct RapidJSONException : Exception +{ + RapidJSONException(const char * what_) : Exception(what_) {} +}; +} // namespace cereal + +// Inform rapidjson that assert will throw +#ifndef CEREAL_RAPIDJSON_ASSERT_THROWS +#define CEREAL_RAPIDJSON_ASSERT_THROWS +#endif // CEREAL_RAPIDJSON_ASSERT_THROWS + +// Override rapidjson assertions to throw exceptions by default +#ifndef CEREAL_RAPIDJSON_ASSERT +#define CEREAL_RAPIDJSON_ASSERT(x) \ +if (!(x)) { \ +throw ::cereal::RapidJSONException("rapidjson internal assertion failure: " #x); \ +} +#endif // RAPIDJSON_ASSERT + +// Enable support for parsing of nan, inf, -inf +#ifndef CEREAL_RAPIDJSON_WRITE_DEFAULT_FLAGS +#define CEREAL_RAPIDJSON_WRITE_DEFAULT_FLAGS kWriteNanAndInfFlag +#endif + +// Enable support for parsing of nan, inf, -inf +#ifndef CEREAL_RAPIDJSON_PARSE_DEFAULT_FLAGS +#define CEREAL_RAPIDJSON_PARSE_DEFAULT_FLAGS kParseFullPrecisionFlag | kParseNanAndInfFlag +#endif + +#include "cereal/external/base64.hpp" +#include "cereal/external/rapidjson/document.h" +#include "cereal/external/rapidjson/istreamwrapper.h" +#include "cereal/external/rapidjson/ostreamwrapper.h" +#include "cereal/external/rapidjson/prettywriter.h" + +#include +#include +#include +#include +#include + +namespace cereal { +// ###################################################################### +//! An output archive designed to save data to JSON +/*! This archive uses RapidJSON to build serialize data to JSON. + + JSON archives provides a human readable output but at decreased + performance (both in time and space) compared to binary archives. + + JSON archives are only guaranteed to finish flushing their contents + upon destruction and should thus be used in an RAII fashion. + + JSON benefits greatly from name-value pairs, which if present, will + name the nodes in the output. If these are not present, each level + of the output will be given an automatically generated delimited name. + + The precision of the output archive controls the number of decimals output + for floating point numbers and should be sufficiently large (i.e. at least 20) + if there is a desire to have binary equality between the numbers output and + those read in. In general you should expect a loss of precision when going + from floating point to text and back. + + JSON archives do not output the size information for any dynamically sized structure + and instead infer it from the number of children for a node. This means that data + can be hand edited for dynamic sized structures and will still be readable. This + is accomplished through the cereal::SizeTag object, which will cause the archive + to output the data as a JSON array (e.g. marked by [] instead of {}), which indicates + that the container is variable sized and may be edited. + + \ingroup Archives */ +class JSONOutputArchive +: public OutputArchive +, public traits::TextArchive +{ + enum class NodeType + { + StartObject, + InObject, + StartArray, + InArray + }; + + using WriteStream = CEREAL_RAPIDJSON_NAMESPACE::OStreamWrapper; + using JSONWriter = CEREAL_RAPIDJSON_NAMESPACE::PrettyWriter; + +public: + /*! @name Common Functionality + Common use cases for directly interacting with an JSONOutputArchive */ + //! @{ + + //! A class containing various advanced options for the JSON archive + class Options + { + public: + //! Default options + static Options Default() { return Options(); } + + //! Default options with no indentation + static Options NoIndent() + { + return Options(JSONWriter::kDefaultMaxDecimalPlaces, IndentChar::space, 0); + } + + //! The character to use for indenting + enum class IndentChar : char + { + space = ' ', + tab = '\t', + newline = '\n', + carriage_return = '\r' + }; + + //! Specify specific options for the JSONOutputArchive + /*! @param precision The precision used for floating point numbers + @param indentChar The type of character to indent with + @param indentLength The number of indentChar to use for indentation + (0 corresponds to no indentation) */ + explicit Options(int precision = JSONWriter::kDefaultMaxDecimalPlaces, + IndentChar indentChar = IndentChar::space, + unsigned int indentLength = 4) + : itsPrecision(precision), itsIndentChar(static_cast(indentChar)), itsIndentLength(indentLength) + { + } + + private: + friend class JSONOutputArchive; + int itsPrecision; + char itsIndentChar; + unsigned int itsIndentLength; + }; + + //! Construct, outputting to the provided stream + /*! @param stream The stream to output to. + @param options The JSON specific options to use. See the Options struct + for the values of default parameters */ + JSONOutputArchive(std::ostream & stream, Options const & options = Options::Default()) + : OutputArchive(this), itsWriteStream(stream), itsWriter(itsWriteStream), + itsNextName(nullptr) + { + itsWriter.SetMaxDecimalPlaces(options.itsPrecision); + itsWriter.SetIndent(options.itsIndentChar, options.itsIndentLength); + itsNameCounter.push(0); + itsNodeStack.push(NodeType::StartObject); + } + + //! Destructor, flushes the JSON + ~JSONOutputArchive() CEREAL_NOEXCEPT + { + if (itsNodeStack.top() == NodeType::InObject) + itsWriter.EndObject(); + else if (itsNodeStack.top() == NodeType::InArray) + itsWriter.EndArray(); + } + + //! Saves some binary data, encoded as a base64 string, with an optional name + /*! This will create a new node, optionally named, and insert a value that consists of + the data encoded as a base64 string */ + void saveBinaryValue(const void * data, size_t size, const char * name = nullptr) + { + setNextName(name); + writeName(); + + auto base64string = base64::encode(reinterpret_cast(data), size); + saveValue(base64string); + }; + + //! @} + /*! @name Internal Functionality + Functionality designed for use by those requiring control over the inner mechanisms of + the JSONOutputArchive */ + //! @{ + + //! Starts a new node in the JSON output + /*! The node can optionally be given a name by calling setNextName prior + to creating the node + + Nodes only need to be started for types that are themselves objects or arrays */ + void startNode() + { + writeName(); + itsNodeStack.push(NodeType::StartObject); + itsNameCounter.push(0); + } + + //! Designates the most recently added node as finished + void finishNode() + { + // if we ended up serializing an empty object or array, writeName + // will never have been called - so start and then immediately end + // the object/array. + // + // We'll also end any object/arrays we happen to be in + switch (itsNodeStack.top()) { + case NodeType::StartArray: + itsWriter.StartArray(); + // fall through + case NodeType::InArray: + itsWriter.EndArray(); + break; + case NodeType::StartObject: + itsWriter.StartObject(); + // fall through + case NodeType::InObject: + itsWriter.EndObject(); + break; + } + + itsNodeStack.pop(); + itsNameCounter.pop(); + } + + //! Sets the name for the next node created with startNode + void setNextName(const char * name) { itsNextName = name; } + + //! Saves a bool to the current node + void saveValue(bool b) { itsWriter.Bool(b); } + //! Saves an int to the current node + void saveValue(int i) { itsWriter.Int(i); } + //! Saves a uint to the current node + void saveValue(unsigned u) { itsWriter.Uint(u); } + //! Saves an int64 to the current node + void saveValue(int64_t i64) { itsWriter.Int64(i64); } + //! Saves a uint64 to the current node + void saveValue(uint64_t u64) { itsWriter.Uint64(u64); } + //! Saves a double to the current node + void saveValue(double d) { itsWriter.Double(d); } + //! Saves a string to the current node + void saveValue(std::string const & s) + { + itsWriter.String(s.c_str(), static_cast(s.size())); + } + //! Saves a const char * to the current node + void saveValue(char const * s) { itsWriter.String(s); } + //! Saves a nullptr to the current node + void saveValue(std::nullptr_t) { itsWriter.Null(); } + +private: + // Some compilers/OS have difficulty disambiguating the above for various flavors of longs, so we provide + // special overloads to handle these cases. + + //! 32 bit signed long saving to current node + template ::value> = traits::sfinae> + inline void saveLong(T l) + { + saveValue(static_cast(l)); + } + + //! non 32 bit signed long saving to current node + template ::value> = traits::sfinae> + inline void saveLong(T l) + { + saveValue(static_cast(l)); + } + + //! 32 bit unsigned long saving to current node + template ::value> = traits::sfinae> + inline void saveLong(T lu) + { + saveValue(static_cast(lu)); + } + + //! non 32 bit unsigned long saving to current node + template ::value> = traits::sfinae> + inline void saveLong(T lu) + { + saveValue(static_cast(lu)); + } + +public: +#if defined(_MSC_VER) && _MSC_VER < 1916 + //! MSVC only long overload to current node + void saveValue(unsigned long lu) + { + saveLong(lu); + }; +#else // _MSC_VER + //! Serialize a long if it would not be caught otherwise + template ::value, + !std::is_same::value, + !std::is_same::value> = traits::sfinae> + inline void saveValue(T t) + { + saveLong(t); + } + + //! Serialize an unsigned long if it would not be caught otherwise + template ::value, + !std::is_same::value, + !std::is_same::value> = traits::sfinae> + inline void saveValue(T t) + { + saveLong(t); + } +#endif // _MSC_VER + + //! Save exotic arithmetic as strings to current node + /*! Handles long long (if distinct from other types), unsigned long (if distinct), and long double */ + template ::value, + !std::is_same::value, + !std::is_same::value, + !std::is_same::value, + !std::is_same::value, + (sizeof(T) >= sizeof(long double) || sizeof(T) >= sizeof(long long))> = traits::sfinae> + inline void saveValue(T const & t) + { + std::stringstream ss; + ss.precision(std::numeric_limits::max_digits10); + ss << t; + saveValue(ss.str()); + } + + //! Write the name of the upcoming node and prepare object/array state + /*! Since writeName is called for every value that is output, regardless of + whether it has a name or not, it is the place where we will do a deferred + check of our node state and decide whether we are in an array or an object. + + The general workflow of saving to the JSON archive is: + + 1. (optional) Set the name for the next node to be created, usually done by an NVP + 2. Start the node + 3. (if there is data to save) Write the name of the node (this function) + 4. (if there is data to save) Save the data (with saveValue) + 5. Finish the node + */ + void writeName() + { + NodeType const & nodeType = itsNodeStack.top(); + + // Start up either an object or an array, depending on state + if (nodeType == NodeType::StartArray) { + itsWriter.StartArray(); + itsNodeStack.top() = NodeType::InArray; + } else if (nodeType == NodeType::StartObject) { + itsNodeStack.top() = NodeType::InObject; + itsWriter.StartObject(); + } + + // Array types do not output names + if (nodeType == NodeType::InArray) + return; + + if (itsNextName == nullptr) { + std::string name = "value" + std::to_string(itsNameCounter.top()++) + "\0"; + saveValue(name); + } else { + saveValue(itsNextName); + itsNextName = nullptr; + } + } + + //! Designates that the current node should be output as an array, not an object + void makeArray() + { + itsNodeStack.top() = NodeType::StartArray; + } + + //! @} + +private: + WriteStream itsWriteStream; //!< Rapidjson write stream + JSONWriter itsWriter; //!< Rapidjson writer + char const * itsNextName; //!< The next name + std::stack itsNameCounter; //!< Counter for creating unique names for unnamed nodes + std::stack itsNodeStack; +}; // JSONOutputArchive + +// ###################################################################### +//! An input archive designed to load data from JSON +/*! This archive uses RapidJSON to read in a JSON archive. + + As with the output JSON archive, the preferred way to use this archive is in + an RAII fashion, ensuring its destruction after all data has been read. + + Input JSON should have been produced by the JSONOutputArchive. Data can + only be added to dynamically sized containers (marked by JSON arrays) - + the input archive will determine their size by looking at the number of child nodes. + Only JSON originating from a JSONOutputArchive is officially supported, but data + from other sources may work if properly formatted. + + The JSONInputArchive does not require that nodes are loaded in the same + order they were saved by JSONOutputArchive. Using name value pairs (NVPs), + it is possible to load in an out of order fashion or otherwise skip/select + specific nodes to load. + + The default behavior of the input archive is to read sequentially starting + with the first node and exploring its children. When a given NVP does + not match the read in name for a node, the archive will search for that + node at the current level and load it if it exists. After loading an out of + order node, the archive will then proceed back to loading sequentially from + its new position. + + Consider this simple example where loading of some data is skipped: + + @code{cpp} + // imagine the input file has someData(1-9) saved in order at the top level node + ar( someData1, someData2, someData3 ); // XML loads in the order it sees in the file + ar( cereal::make_nvp( "hello", someData6 ) ); // NVP given does not + // match expected NVP name, so we search + // for the given NVP and load that value + ar( someData7, someData8, someData9 ); // with no NVP given, loading resumes at its + // current location, proceeding sequentially + @endcode + + \ingroup Archives */ +class JSONInputArchive +: public InputArchive +, public traits::TextArchive +{ +private: + using ReadStream = CEREAL_RAPIDJSON_NAMESPACE::IStreamWrapper; + typedef CEREAL_RAPIDJSON_NAMESPACE::GenericValue> JSONValue; + typedef JSONValue::ConstMemberIterator MemberIterator; + typedef JSONValue::ConstValueIterator ValueIterator; + typedef CEREAL_RAPIDJSON_NAMESPACE::Document::GenericValue GenericValue; + +public: + /*! @name Common Functionality + Common use cases for directly interacting with an JSONInputArchive */ + //! @{ + + //! Construct, reading from the provided stream + /*! @param stream The stream to read from */ + JSONInputArchive(std::istream & stream) + : InputArchive(this), itsNextName(nullptr), itsReadStream(stream) + { + itsDocument.ParseStream<>(itsReadStream); + if (itsDocument.IsArray()) + itsIteratorStack.emplace_back(itsDocument.Begin(), itsDocument.End()); + else + itsIteratorStack.emplace_back(itsDocument.MemberBegin(), itsDocument.MemberEnd()); + } + + ~JSONInputArchive() CEREAL_NOEXCEPT = default; + + //! Loads some binary data, encoded as a base64 string + /*! This will automatically start and finish a node to load the data, and can be called directly by + users. + + Note that this follows the same ordering rules specified in the class description in regards + to loading in/out of order */ + void loadBinaryValue(void * data, size_t size, const char * name = nullptr) + { + itsNextName = name; + + std::string encoded; + loadValue(encoded); + auto decoded = base64::decode(encoded); + + if (size != decoded.size()) + throw Exception("Decoded binary data size does not match specified size"); + + std::memcpy(data, decoded.data(), decoded.size()); + itsNextName = nullptr; + }; + +private: + //! @} + /*! @name Internal Functionality + Functionality designed for use by those requiring control over the inner mechanisms of + the JSONInputArchive */ + //! @{ + + //! An internal iterator that handles both array and object types + /*! This class is a variant and holds both types of iterators that + rapidJSON supports - one for arrays and one for objects. */ + class Iterator + { + public: + Iterator() : itsIndex(0), itsType(Null_) {} + + Iterator(MemberIterator begin, MemberIterator end) + : itsMemberItBegin(begin), itsMemberItEnd(end), itsIndex(0), itsSize(std::distance(begin, end)), + itsType(Member) + { + if (itsSize == 0) + itsType = Null_; + } + + Iterator(ValueIterator begin, ValueIterator end) + : itsValueItBegin(begin), itsIndex(0), itsSize(std::distance(begin, end)), itsType(Value) + { + if (itsSize == 0) + itsType = Null_; + } + + //! Advance to the next node + Iterator & operator++() + { + ++itsIndex; + return *this; + } + + //! Get the value of the current node + GenericValue const & value() + { + if (itsIndex >= itsSize) + throw cereal::Exception("No more objects in input"); + + switch (itsType) { + case Value: + return itsValueItBegin[itsIndex]; + case Member: + return itsMemberItBegin[itsIndex].value; + default: + throw cereal::Exception( + "JSONInputArchive internal error: null or empty iterator to object or array!"); + } + } + + //! Get the name of the current node, or nullptr if it has no name + const char * name() const + { + if (itsType == Member && (itsMemberItBegin + itsIndex) != itsMemberItEnd) + return itsMemberItBegin[itsIndex].name.GetString(); + else + return nullptr; + } + + //! Adjust our position such that we are at the node with the given name + /*! @throws Exception if no such named node exists */ + inline void search(const char * searchName) + { + const auto len = std::strlen(searchName); + size_t index = 0; + for (auto it = itsMemberItBegin; it != itsMemberItEnd; ++it, ++index) { + const auto currentName = it->name.GetString(); + if ((std::strncmp(searchName, currentName, len) == 0) && (std::strlen(currentName) == len)) { + itsIndex = index; + return; + } + } + + throw Exception("JSON Parsing failed - provided NVP (" + std::string(searchName) + ") not found"); + } + + private: + MemberIterator itsMemberItBegin, itsMemberItEnd; //!< The member iterator (object) + ValueIterator itsValueItBegin; //!< The value iterator (array) + size_t itsIndex, itsSize; //!< The current index of this iterator + enum Type + { + Value, + Member, + Null_ + } itsType; //!< Whether this holds values (array) or members (objects) or nothing + }; + + //! Searches for the expectedName node if it doesn't match the actualName + /*! This needs to be called before every load or node start occurs. This function will + check to see if an NVP has been provided (with setNextName) and if so, see if that name matches the + actual next name given. If the names do not match, it will search in the current level of the JSON for + that name. If the name is not found, an exception will be thrown. + + Resets the NVP name after called. + + @throws Exception if an expectedName is given and not found */ + inline void search() + { + // store pointer to itsNextName locally and reset to nullptr in case search() throws + auto localNextName = itsNextName; + itsNextName = nullptr; + + // The name an NVP provided with setNextName() + if (localNextName) { + // The actual name of the current node + auto const actualName = itsIteratorStack.back().name(); + + // Do a search if we don't see a name coming up, or if the names don't match + if (!actualName || std::strcmp(localNextName, actualName) != 0) + itsIteratorStack.back().search(localNextName); + } + } + +public: + //! Starts a new node, going into its proper iterator + /*! This places an iterator for the next node to be parsed onto the iterator stack. If the next + node is an array, this will be a value iterator, otherwise it will be a member iterator. + + By default our strategy is to start with the document root node and then recursively iterate through + all children in the order they show up in the document. + We don't need to know NVPs to do this; we'll just blindly load in the order things appear in. + + If we were given an NVP, we will search for it if it does not match our the name of the next node + that would normally be loaded. This functionality is provided by search(). */ + void startNode() + { + search(); + + if (itsIteratorStack.back().value().IsArray()) + itsIteratorStack.emplace_back( + itsIteratorStack.back().value().Begin(), itsIteratorStack.back().value().End()); + else + itsIteratorStack.emplace_back( + itsIteratorStack.back().value().MemberBegin(), itsIteratorStack.back().value().MemberEnd()); + } + + //! Finishes the most recently started node + void finishNode() + { + itsIteratorStack.pop_back(); + ++itsIteratorStack.back(); + } + + //! Retrieves the current node name + /*! @return nullptr if no name exists */ + const char * getNodeName() const { return itsIteratorStack.back().name(); } + + //! Sets the name for the next node created with startNode + void setNextName(const char * name) { itsNextName = name; } + + //! Loads a value from the current node - small signed overload + template ::value, sizeof(T) < sizeof(int64_t)> = traits::sfinae> + inline void loadValue(T & val) + { + search(); + + val = static_cast(itsIteratorStack.back().value().GetInt()); + ++itsIteratorStack.back(); + } + + //! Loads a value from the current node - small unsigned overload + template ::value, + sizeof(T) < sizeof(uint64_t), + !std::is_same::value> = traits::sfinae> + inline void loadValue(T & val) + { + search(); + + val = static_cast(itsIteratorStack.back().value().GetUint()); + ++itsIteratorStack.back(); + } + + //! Loads a value from the current node - bool overload + void loadValue(bool & val) + { + search(); + val = itsIteratorStack.back().value().GetBool(); + ++itsIteratorStack.back(); + } + //! Loads a value from the current node - int64 overload + void loadValue(int64_t & val) + { + search(); + val = itsIteratorStack.back().value().GetInt64(); + ++itsIteratorStack.back(); + } + //! Loads a value from the current node - uint64 overload + void loadValue(uint64_t & val) + { + search(); + val = itsIteratorStack.back().value().GetUint64(); + ++itsIteratorStack.back(); + } + //! Loads a value from the current node - float overload + void loadValue(float & val) + { + search(); + val = static_cast(itsIteratorStack.back().value().GetDouble()); + ++itsIteratorStack.back(); + } + //! Loads a value from the current node - double overload + void loadValue(double & val) + { + search(); + val = itsIteratorStack.back().value().GetDouble(); + ++itsIteratorStack.back(); + } + //! Loads a value from the current node - string overload + void loadValue(std::string & val) + { + search(); + val = itsIteratorStack.back().value().GetString(); + ++itsIteratorStack.back(); + } + //! Loads a nullptr from the current node + void loadValue(std::nullptr_t &) + { + search(); + CEREAL_RAPIDJSON_ASSERT(itsIteratorStack.back().value().IsNull()); + ++itsIteratorStack.back(); + } + +// Special cases to handle various flavors of long, which tend to conflict with +// the int32_t or int64_t on various compiler/OS combinations. MSVC doesn't need any of this. +#ifndef _MSC_VER +private: + //! 32 bit signed long loading from current node + template + inline typename std::enable_if::value, void>::type + loadLong(T & l) + { + loadValue(reinterpret_cast(l)); + } + + //! non 32 bit signed long loading from current node + template + inline typename std::enable_if::value, void>::type + loadLong(T & l) + { + loadValue(reinterpret_cast(l)); + } + + //! 32 bit unsigned long loading from current node + template + inline + typename std::enable_if::value, void>::type + loadLong(T & lu) + { + loadValue(reinterpret_cast(lu)); + } + + //! non 32 bit unsigned long loading from current node + template + inline + typename std::enable_if::value, void>::type + loadLong(T & lu) + { + loadValue(reinterpret_cast(lu)); + } + +public: + //! Serialize a long if it would not be caught otherwise + template + inline typename std::enable_if::value && sizeof(T) >= sizeof(std::int64_t) && + !std::is_same::value, + void>::type + loadValue(T & t) + { + loadLong(t); + } + + //! Serialize an unsigned long if it would not be caught otherwise + template + inline + typename std::enable_if::value && sizeof(T) >= sizeof(std::uint64_t) && + !std::is_same::value, + void>::type + loadValue(T & t) + { + loadLong(t); + } +#endif // _MSC_VER + +private: + //! Convert a string to a long long + void stringToNumber(std::string const & str, long long & val) + { + val = std::stoll(str); + } + //! Convert a string to an unsigned long long + void stringToNumber(std::string const & str, unsigned long long & val) + { + val = std::stoull(str); + } + //! Convert a string to a long double + void stringToNumber(std::string const & str, long double & val) + { + val = std::stold(str); + } + +public: + //! Loads a value from the current node - long double and long long overloads + template ::value, + !std::is_same::value, + !std::is_same::value, + !std::is_same::value, + !std::is_same::value, + (sizeof(T) >= sizeof(long double) || sizeof(T) >= sizeof(long long))> = traits::sfinae> + inline void loadValue(T & val) + { + std::string encoded; + loadValue(encoded); + stringToNumber(encoded, val); + } + + //! Loads the size for a SizeTag + void loadSize(size_type & size) + { + if (itsIteratorStack.size() == 1) + size = itsDocument.Size(); + else + size = (itsIteratorStack.rbegin() + 1)->value().Size(); + } + + //! @} + +private: + const char * itsNextName; //!< Next name set by NVP + ReadStream itsReadStream; //!< Rapidjson write stream + std::vector itsIteratorStack; //!< 'Stack' of rapidJSON iterators + CEREAL_RAPIDJSON_NAMESPACE::Document itsDocument; //!< Rapidjson document +}; + +// ###################################################################### +// JSONArchive prologue and epilogue functions +// ###################################################################### + +// ###################################################################### +//! Prologue for NVPs for JSON archives +/*! NVPs do not start or finish nodes - they just set up the names */ +template inline void prologue(JSONOutputArchive &, NameValuePair const &) +{ +} + +//! Prologue for NVPs for JSON archives +template inline void prologue(JSONInputArchive &, NameValuePair const &) +{ +} + +// ###################################################################### +//! Epilogue for NVPs for JSON archives +/*! NVPs do not start or finish nodes - they just set up the names */ +template inline void epilogue(JSONOutputArchive &, NameValuePair const &) +{ +} + +//! Epilogue for NVPs for JSON archives +/*! NVPs do not start or finish nodes - they just set up the names */ +template inline void epilogue(JSONInputArchive &, NameValuePair const &) +{ +} + +// ###################################################################### +//! Prologue for deferred data for JSON archives +/*! Do nothing for the defer wrapper */ +template inline void prologue(JSONOutputArchive &, DeferredData const &) +{ +} + +//! Prologue for deferred data for JSON archives +template inline void prologue(JSONInputArchive &, DeferredData const &) +{ +} + +// ###################################################################### +//! Epilogue for deferred for JSON archives +/*! NVPs do not start or finish nodes - they just set up the names */ +template inline void epilogue(JSONOutputArchive &, DeferredData const &) +{ +} + +//! Epilogue for deferred for JSON archives +/*! Do nothing for the defer wrapper */ +template inline void epilogue(JSONInputArchive &, DeferredData const &) +{ +} + +// ###################################################################### +//! Prologue for SizeTags for JSON archives +/*! SizeTags are strictly ignored for JSON, they just indicate + that the current node should be made into an array */ +template inline void prologue(JSONOutputArchive & ar, SizeTag const &) +{ + ar.makeArray(); +} + +//! Prologue for SizeTags for JSON archives +template inline void prologue(JSONInputArchive &, SizeTag const &) +{ +} + +// ###################################################################### +//! Epilogue for SizeTags for JSON archives +/*! SizeTags are strictly ignored for JSON */ +template inline void epilogue(JSONOutputArchive &, SizeTag const &) +{ +} + +//! Epilogue for SizeTags for JSON archives +template inline void epilogue(JSONInputArchive &, SizeTag const &) +{ +} + +// ###################################################################### +//! Prologue for all other types for JSON archives (except minimal types) +/*! Starts a new node, named either automatically or by some NVP, + that may be given data by the type about to be archived + + Minimal types do not start or finish nodes */ +template ::value, + !traits::has_minimal_base_class_serialization::value, + !traits::has_minimal_output_serialization::value> = traits::sfinae> +inline void prologue(JSONOutputArchive & ar, T const &) +{ + ar.startNode(); +} + +//! Prologue for all other types for JSON archives +template ::value, + !traits::has_minimal_base_class_serialization::value, + !traits::has_minimal_input_serialization::value> = traits::sfinae> +inline void prologue(JSONInputArchive & ar, T const &) +{ + ar.startNode(); +} + +// ###################################################################### +//! Epilogue for all other types other for JSON archives (except minimal types) +/*! Finishes the node created in the prologue + + Minimal types do not start or finish nodes */ +template ::value, + !traits::has_minimal_base_class_serialization::value, + !traits::has_minimal_output_serialization::value> = traits::sfinae> +inline void epilogue(JSONOutputArchive & ar, T const &) +{ + ar.finishNode(); +} + +//! Epilogue for all other types other for JSON archives +template ::value, + !traits::has_minimal_base_class_serialization::value, + !traits::has_minimal_input_serialization::value> = traits::sfinae> +inline void epilogue(JSONInputArchive & ar, T const &) +{ + ar.finishNode(); +} + +// ###################################################################### +//! Prologue for arithmetic types for JSON archives +inline void prologue(JSONOutputArchive & ar, std::nullptr_t const &) +{ + ar.writeName(); +} + +//! Prologue for arithmetic types for JSON archives +inline void prologue(JSONInputArchive &, std::nullptr_t const &) +{ +} + +// ###################################################################### +//! Epilogue for arithmetic types for JSON archives +inline void epilogue(JSONOutputArchive &, std::nullptr_t const &) +{ +} + +//! Epilogue for arithmetic types for JSON archives +inline void epilogue(JSONInputArchive &, std::nullptr_t const &) +{ +} + +// ###################################################################### +//! Prologue for arithmetic types for JSON archives +template ::value> = traits::sfinae> +inline void prologue(JSONOutputArchive & ar, T const &) +{ + ar.writeName(); +} + +//! Prologue for arithmetic types for JSON archives +template ::value> = traits::sfinae> +inline void prologue(JSONInputArchive &, T const &) +{ +} + +// ###################################################################### +//! Epilogue for arithmetic types for JSON archives +template ::value> = traits::sfinae> +inline void epilogue(JSONOutputArchive &, T const &) +{ +} + +//! Epilogue for arithmetic types for JSON archives +template ::value> = traits::sfinae> +inline void epilogue(JSONInputArchive &, T const &) +{ +} + +// ###################################################################### +//! Prologue for strings for JSON archives +template +inline void prologue(JSONOutputArchive & ar, std::basic_string const &) +{ + ar.writeName(); +} + +//! Prologue for strings for JSON archives +template +inline void prologue(JSONInputArchive &, std::basic_string const &) +{ +} + +// ###################################################################### +//! Epilogue for strings for JSON archives +template +inline void epilogue(JSONOutputArchive &, std::basic_string const &) +{ +} + +//! Epilogue for strings for JSON archives +template +inline void epilogue(JSONInputArchive &, std::basic_string const &) +{ +} + +// ###################################################################### +// Common JSONArchive serialization functions +// ###################################################################### +//! Serializing NVP types to JSON +template inline void CEREAL_SAVE_FUNCTION_NAME(JSONOutputArchive & ar, NameValuePair const & t) +{ + ar.setNextName(t.name); + ar(t.value); +} + +template inline void CEREAL_LOAD_FUNCTION_NAME(JSONInputArchive & ar, NameValuePair & t) +{ + ar.setNextName(t.name); + ar(t.value); +} + +//! Saving for nullptr to JSON +inline void CEREAL_SAVE_FUNCTION_NAME(JSONOutputArchive & ar, std::nullptr_t const & t) +{ + ar.saveValue(t); +} + +//! Loading arithmetic from JSON +inline void CEREAL_LOAD_FUNCTION_NAME(JSONInputArchive & ar, std::nullptr_t & t) +{ + ar.loadValue(t); +} + +//! Saving for arithmetic to JSON +template ::value> = traits::sfinae> +inline void CEREAL_SAVE_FUNCTION_NAME(JSONOutputArchive & ar, T const & t) +{ + ar.saveValue(t); +} + +//! Loading arithmetic from JSON +template ::value> = traits::sfinae> +inline void CEREAL_LOAD_FUNCTION_NAME(JSONInputArchive & ar, T & t) +{ + ar.loadValue(t); +} + +//! saving string to JSON +template +inline void CEREAL_SAVE_FUNCTION_NAME( + JSONOutputArchive & ar, std::basic_string const & str) +{ + ar.saveValue(str); +} + +//! loading string from JSON +template +inline void CEREAL_LOAD_FUNCTION_NAME(JSONInputArchive & ar, std::basic_string & str) +{ + ar.loadValue(str); +} + +// ###################################################################### +//! Saving SizeTags to JSON +template inline void CEREAL_SAVE_FUNCTION_NAME(JSONOutputArchive &, SizeTag const &) +{ + // nothing to do here, we don't explicitly save the size +} + +//! Loading SizeTags from JSON +template inline void CEREAL_LOAD_FUNCTION_NAME(JSONInputArchive & ar, SizeTag & st) +{ + ar.loadSize(st.size); +} +} // namespace cereal + +// register archives for polymorphic support +CEREAL_REGISTER_ARCHIVE(cereal::JSONInputArchive) +CEREAL_REGISTER_ARCHIVE(cereal::JSONOutputArchive) + +// tie input and output archives together +CEREAL_SETUP_ARCHIVE_TRAITS(cereal::JSONInputArchive, cereal::JSONOutputArchive) + +#endif // CEREAL_ARCHIVES_JSON_HPP_ diff --git a/minco_ws/src/navigation/minco_planner/include/cereal/archives/portable_binary.hpp b/minco_ws/src/navigation/minco_planner/include/cereal/archives/portable_binary.hpp new file mode 100644 index 0000000..c22eb8b --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/include/cereal/archives/portable_binary.hpp @@ -0,0 +1,335 @@ +/*! \file binary.hpp + \brief Binary input and output archives */ +/* + Copyright (c) 2014, Randolph Voorhies, Shane Grant + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef CEREAL_ARCHIVES_PORTABLE_BINARY_HPP_ +#define CEREAL_ARCHIVES_PORTABLE_BINARY_HPP_ + +#include "cereal/cereal.hpp" +#include +#include + +namespace cereal { +namespace portable_binary_detail { +//! Returns true if the current machine is little endian +/*! @ingroup Internal */ +inline std::uint8_t is_little_endian() +{ + static std::int32_t test = 1; + return *reinterpret_cast(&test) == 1; +} + +//! Swaps the order of bytes for some chunk of memory +/*! @param data The data as a uint8_t pointer + @tparam DataSize The true size of the data + @ingroup Internal */ +template inline void swap_bytes(std::uint8_t * data) +{ + for (std::size_t i = 0, end = DataSize / 2; i < end; ++i) + std::swap(data[i], data[DataSize - i - 1]); +} +} // end namespace portable_binary_detail + +// ###################################################################### +//! An output archive designed to save data in a compact binary representation portable over different +//! architectures +/*! This archive outputs data to a stream in an extremely compact binary + representation with as little extra metadata as possible. + + This archive will record the endianness of the data as well as the desired in/out endianness + and assuming that the user takes care of ensuring serialized types are the same size + across machines, is portable over different architectures. + + When using a binary archive and a file stream, you must use the + std::ios::binary format flag to avoid having your data altered + inadvertently. + + \warning This archive has not been thoroughly tested across different architectures. + Please report any issues, optimizations, or feature requests at + the project github. + + \ingroup Archives */ +class PortableBinaryOutputArchive +: public OutputArchive +{ +public: + //! A class containing various advanced options for the PortableBinaryOutput archive + class Options + { + public: + //! Represents desired endianness + enum class Endianness : std::uint8_t + { + big, + little + }; + + //! Default options, preserve system endianness + static Options Default() { return Options(); } + + //! Save as little endian + static Options LittleEndian() { return Options(Endianness::little); } + + //! Save as big endian + static Options BigEndian() { return Options(Endianness::big); } + + //! Specify specific options for the PortableBinaryOutputArchive + /*! @param outputEndian The desired endianness of saved (output) data */ + explicit Options(Endianness outputEndian = getEndianness()) : itsOutputEndianness(outputEndian) {} + + private: + //! Gets the endianness of the system + inline static Endianness getEndianness() + { + return portable_binary_detail::is_little_endian() ? Endianness::little : Endianness::big; + } + + //! Checks if Options is set for little endian + inline std::uint8_t is_little_endian() const { return itsOutputEndianness == Endianness::little; } + + friend class PortableBinaryOutputArchive; + Endianness itsOutputEndianness; + }; + + //! Construct, outputting to the provided stream + /*! @param stream The stream to output to. Should be opened with std::ios::binary flag. + @param options The PortableBinary specific options to use. See the Options struct + for the values of default parameters */ + PortableBinaryOutputArchive(std::ostream & stream, Options const & options = Options::Default()) + : OutputArchive(this), itsStream(stream), + itsConvertEndianness(portable_binary_detail::is_little_endian() ^ options.is_little_endian()) + { + this->operator()(options.is_little_endian()); + } + + ~PortableBinaryOutputArchive() CEREAL_NOEXCEPT = default; + + //! Writes size bytes of data to the output stream + template inline void saveBinary(const void * data, std::streamsize size) + { + std::streamsize writtenSize = 0; + + if (itsConvertEndianness) { + for (std::streamsize i = 0; i < size; i += DataSize) + for (std::streamsize j = 0; j < DataSize; ++j) + writtenSize += + itsStream.rdbuf()->sputn(reinterpret_cast(data) + DataSize - j - 1 + i, 1); + } else + writtenSize = itsStream.rdbuf()->sputn(reinterpret_cast(data), size); + + if (writtenSize != size) + throw Exception("Failed to write " + std::to_string(size) + " bytes to output stream! Wrote " + + std::to_string(writtenSize)); + } + +private: + std::ostream & itsStream; + const uint8_t itsConvertEndianness; //!< If set to true, we will need to swap bytes upon saving +}; + +// ###################################################################### +//! An input archive designed to load data saved using PortableBinaryOutputArchive +/*! This archive outputs data to a stream in an extremely compact binary + representation with as little extra metadata as possible. + + This archive will load the endianness of the serialized data and + if necessary transform it to match that of the local machine. This comes + at a significant performance cost compared to non portable archives if + the transformation is necessary, and also causes a small performance hit + even if it is not necessary. + + It is recommended to use portable archives only if you know that you will + be sending binary data to machines with different endianness. + + The archive will do nothing to ensure types are the same size - that is + the responsibility of the user. + + When using a binary archive and a file stream, you must use the + std::ios::binary format flag to avoid having your data altered + inadvertently. + + \warning This archive has not been thoroughly tested across different architectures. + Please report any issues, optimizations, or feature requests at + the project github. + + \ingroup Archives */ +class PortableBinaryInputArchive : public InputArchive +{ +public: + //! A class containing various advanced options for the PortableBinaryInput archive + class Options + { + public: + //! Represents desired endianness + enum class Endianness : std::uint8_t + { + big, + little + }; + + //! Default options, preserve system endianness + static Options Default() { return Options(); } + + //! Load into little endian + static Options LittleEndian() { return Options(Endianness::little); } + + //! Load into big endian + static Options BigEndian() { return Options(Endianness::big); } + + //! Specify specific options for the PortableBinaryInputArchive + /*! @param inputEndian The desired endianness of loaded (input) data */ + explicit Options(Endianness inputEndian = getEndianness()) : itsInputEndianness(inputEndian) {} + + private: + //! Gets the endianness of the system + inline static Endianness getEndianness() + { + return portable_binary_detail::is_little_endian() ? Endianness::little : Endianness::big; + } + + //! Checks if Options is set for little endian + inline std::uint8_t is_little_endian() const { return itsInputEndianness == Endianness::little; } + + friend class PortableBinaryInputArchive; + Endianness itsInputEndianness; + }; + + //! Construct, loading from the provided stream + /*! @param stream The stream to read from. Should be opened with std::ios::binary flag. + @param options The PortableBinary specific options to use. See the Options struct + for the values of default parameters */ + PortableBinaryInputArchive(std::istream & stream, Options const & options = Options::Default()) + : InputArchive(this), itsStream(stream), + itsConvertEndianness(false) + { + uint8_t streamLittleEndian; + this->operator()(streamLittleEndian); + itsConvertEndianness = options.is_little_endian() ^ streamLittleEndian; + } + + ~PortableBinaryInputArchive() CEREAL_NOEXCEPT = default; + + //! Reads size bytes of data from the input stream + /*! @param data The data to save + @param size The number of bytes in the data + @tparam DataSize T The size of the actual type of the data elements being loaded */ + template inline void loadBinary(void * const data, std::streamsize size) + { + // load data + auto const readSize = itsStream.rdbuf()->sgetn(reinterpret_cast(data), size); + + if (readSize != size) + throw Exception("Failed to read " + std::to_string(size) + " bytes from input stream! Read " + + std::to_string(readSize)); + + // flip bits if needed + if (itsConvertEndianness) { + std::uint8_t * ptr = reinterpret_cast(data); + for (std::streamsize i = 0; i < size; i += DataSize) + portable_binary_detail::swap_bytes(ptr + i); + } + } + +private: + std::istream & itsStream; + uint8_t itsConvertEndianness; //!< If set to true, we will need to swap bytes upon loading +}; + +// ###################################################################### +// Common BinaryArchive serialization functions + +//! Saving for POD types to portable binary +template +inline typename std::enable_if::value, void>::type CEREAL_SAVE_FUNCTION_NAME( + PortableBinaryOutputArchive & ar, T const & t) +{ + static_assert(!std::is_floating_point::value || + (std::is_floating_point::value && std::numeric_limits::is_iec559), + "Portable binary only supports IEEE 754 standardized floating point"); + ar.template saveBinary(std::addressof(t), sizeof(t)); +} + +//! Loading for POD types from portable binary +template +inline typename std::enable_if::value, void>::type CEREAL_LOAD_FUNCTION_NAME( + PortableBinaryInputArchive & ar, T & t) +{ + static_assert(!std::is_floating_point::value || + (std::is_floating_point::value && std::numeric_limits::is_iec559), + "Portable binary only supports IEEE 754 standardized floating point"); + ar.template loadBinary(std::addressof(t), sizeof(t)); +} + +//! Serializing NVP types to portable binary +template +inline CEREAL_ARCHIVE_RESTRICT(PortableBinaryInputArchive, PortableBinaryOutputArchive) + CEREAL_SERIALIZE_FUNCTION_NAME(Archive & ar, NameValuePair & t) +{ + ar(t.value); +} + +//! Serializing SizeTags to portable binary +template +inline CEREAL_ARCHIVE_RESTRICT(PortableBinaryInputArchive, PortableBinaryOutputArchive) + CEREAL_SERIALIZE_FUNCTION_NAME(Archive & ar, SizeTag & t) +{ + ar(t.size); +} + +//! Saving binary data to portable binary +template +inline void CEREAL_SAVE_FUNCTION_NAME(PortableBinaryOutputArchive & ar, BinaryData const & bd) +{ + typedef typename std::remove_pointer::type TT; + static_assert(!std::is_floating_point::value || + (std::is_floating_point::value && std::numeric_limits::is_iec559), + "Portable binary only supports IEEE 754 standardized floating point"); + + ar.template saveBinary(bd.data, static_cast(bd.size)); +} + +//! Loading binary data from portable binary +template +inline void CEREAL_LOAD_FUNCTION_NAME(PortableBinaryInputArchive & ar, BinaryData & bd) +{ + typedef typename std::remove_pointer::type TT; + static_assert(!std::is_floating_point::value || + (std::is_floating_point::value && std::numeric_limits::is_iec559), + "Portable binary only supports IEEE 754 standardized floating point"); + + ar.template loadBinary(bd.data, static_cast(bd.size)); +} +} // namespace cereal + +// register archives for polymorphic support +CEREAL_REGISTER_ARCHIVE(cereal::PortableBinaryOutputArchive) +CEREAL_REGISTER_ARCHIVE(cereal::PortableBinaryInputArchive) + +// tie input and output archives together +CEREAL_SETUP_ARCHIVE_TRAITS(cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive) + +#endif // CEREAL_ARCHIVES_PORTABLE_BINARY_HPP_ diff --git a/minco_ws/src/navigation/minco_planner/include/cereal/archives/xml.hpp b/minco_ws/src/navigation/minco_planner/include/cereal/archives/xml.hpp new file mode 100644 index 0000000..dcf2154 --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/include/cereal/archives/xml.hpp @@ -0,0 +1,936 @@ +/*! \file xml.hpp + \brief XML input and output archives */ +/* + Copyright (c) 2014, Randolph Voorhies, Shane Grant + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef CEREAL_ARCHIVES_XML_HPP_ +#define CEREAL_ARCHIVES_XML_HPP_ +#include "cereal/cereal.hpp" +#include "cereal/details/util.hpp" + +#include "cereal/external/base64.hpp" +#include "cereal/external/rapidxml/rapidxml.hpp" +#include "cereal/external/rapidxml/rapidxml_print.hpp" + +#include +#include +#include +#include +#include +#include +#include + +namespace cereal { +namespace xml_detail { +#ifndef CEREAL_XML_STRING_VALUE +//! The default name for the root node in a cereal xml archive. +/*! You can define CEREAL_XML_STRING_VALUE to be different assuming you do so + before this file is included. */ +#define CEREAL_XML_STRING_VALUE "cereal" +#endif // CEREAL_XML_STRING_VALUE + +//! The name given to the root node in a cereal xml archive +static const char * CEREAL_XML_STRING = CEREAL_XML_STRING_VALUE; + +//! Returns true if the character is whitespace +inline bool isWhitespace(char c) +{ + return c == ' ' || c == '\t' || c == '\n' || c == '\r'; +} +} // namespace xml_detail + +// ###################################################################### +//! An output archive designed to save data to XML +/*! This archive uses RapidXML to build an in memory XML tree of the + data it serializes before outputting it to its stream upon destruction. + This archive should be used in an RAII fashion, letting + the automatic destruction of the object cause the flush to its stream. + + XML archives provides a human readable output but at decreased + performance (both in time and space) compared to binary archives. + + XML benefits greatly from name-value pairs, which if present, will + name the nodes in the output. If these are not present, each level + of the output tree will be given an automatically generated delimited name. + + The precision of the output archive controls the number of decimals output + for floating point numbers and should be sufficiently large (i.e. at least 20) + if there is a desire to have binary equality between the numbers output and + those read in. In general you should expect a loss of precision when going + from floating point to text and back. + + XML archives can optionally print the type of everything they serialize, which + adds an attribute to each node. + + XML archives do not output the size information for any dynamically sized structure + and instead infer it from the number of children for a node. This means that data + can be hand edited for dynamic sized structures and will still be readable. This + is accomplished through the cereal::SizeTag object, which will also add an attribute + to its parent field. + \ingroup Archives */ +class XMLOutputArchive +: public OutputArchive +, public traits::TextArchive +{ +public: + /*! @name Common Functionality + Common use cases for directly interacting with an XMLOutputArchive */ + //! @{ + + //! A class containing various advanced options for the XML archive + /*! Options can either be directly passed to the constructor, or chained using the + modifier functions for an interface analogous to named parameters */ + class Options + { + public: + //! Default options + static Options Default() { return Options(); } + + //! Specify specific options for the XMLOutputArchive + /*! @param precision_ The precision used for floating point numbers + @param indent_ Whether to indent each line of XML + @param outputType_ Whether to output the type of each serialized object as an attribute + @param sizeAttributes_ Whether dynamically sized containers output the size=dynamic attribute */ + explicit Options(int precision_ = std::numeric_limits::max_digits10, + bool indent_ = true, + bool outputType_ = false, + bool sizeAttributes_ = true) + : itsPrecision(precision_), itsIndent(indent_), itsOutputType(outputType_), + itsSizeAttributes(sizeAttributes_) + { + } + + /*! @name Option Modifiers + An interface for setting option settings analogous to named parameters. + + @code{cpp} + cereal::XMLOutputArchive ar( myStream, + cereal::XMLOutputArchive::Options() + .indent(true) + .sizeAttributes(false) ); + @endcode + */ + //! @{ + + //! Sets the precision used for floaing point numbers + Options & precision(int value) + { + itsPrecision = value; + return *this; + } + //! Whether to indent each line of XML + Options & indent(bool enable) + { + itsIndent = enable; + return *this; + } + //! Whether to output the type of each serialized object as an attribute + Options & outputType(bool enable) + { + itsOutputType = enable; + return *this; + } + //! Whether dynamically sized containers (e.g. vector) output the size=dynamic attribute + Options & sizeAttributes(bool enable) + { + itsSizeAttributes = enable; + return *this; + } + + //! @} + + private: + friend class XMLOutputArchive; + int itsPrecision; + bool itsIndent; + bool itsOutputType; + bool itsSizeAttributes; + }; + + //! Construct, outputting to the provided stream upon destruction + /*! @param stream The stream to output to. Note that XML is only guaranteed to flush + its output to the stream upon destruction. + @param options The XML specific options to use. See the Options struct + for the values of default parameters */ + XMLOutputArchive(std::ostream & stream, Options const & options = Options::Default()) + : OutputArchive(this), itsStream(stream), itsOutputType(options.itsOutputType), + itsIndent(options.itsIndent), itsSizeAttributes(options.itsSizeAttributes) + { + // rapidxml will delete all allocations when xml_document is cleared + auto node = itsXML.allocate_node(rapidxml::node_declaration); + node->append_attribute(itsXML.allocate_attribute("version", "1.0")); + node->append_attribute(itsXML.allocate_attribute("encoding", "utf-8")); + itsXML.append_node(node); + + // allocate root node + auto root = itsXML.allocate_node(rapidxml::node_element, xml_detail::CEREAL_XML_STRING); + itsXML.append_node(root); + itsNodes.emplace(root); + + // set attributes on the streams + itsStream << std::boolalpha; + itsStream.precision(options.itsPrecision); + itsOS << std::boolalpha; + itsOS.precision(options.itsPrecision); + } + + //! Destructor, flushes the XML + ~XMLOutputArchive() CEREAL_NOEXCEPT + { + const int flags = itsIndent ? 0x0 : rapidxml::print_no_indenting; + rapidxml::print(itsStream, itsXML, flags); + itsXML.clear(); + } + + //! Saves some binary data, encoded as a base64 string, with an optional name + /*! This can be called directly by users and it will automatically create a child node for + the current XML node, populate it with a base64 encoded string, and optionally name + it. The node will be finished after it has been populated. */ + void saveBinaryValue(const void * data, size_t size, const char * name = nullptr) + { + itsNodes.top().name = name; + + startNode(); + + auto base64string = base64::encode(reinterpret_cast(data), size); + saveValue(base64string); + + if (itsOutputType) + itsNodes.top().node->append_attribute(itsXML.allocate_attribute("type", "cereal binary data")); + + finishNode(); + } + + //! @} + /*! @name Internal Functionality + Functionality designed for use by those requiring control over the inner mechanisms of + the XMLOutputArchive */ + //! @{ + + //! Creates a new node that is a child of the node at the top of the stack + /*! Nodes will be given a name that has either been pre-set by a name value pair, + or generated based upon a counter unique to the parent node. If you want to + give a node a specific name, use setNextName prior to calling startNode. + + The node will then be pushed onto the node stack. */ + void startNode() + { + // generate a name for this new node + const auto nameString = itsNodes.top().getValueName(); + + // allocate strings for all of the data in the XML object + auto namePtr = itsXML.allocate_string(nameString.data(), nameString.length() + 1); + + // insert into the XML + auto node = itsXML.allocate_node(rapidxml::node_element, namePtr, nullptr, nameString.size()); + itsNodes.top().node->append_node(node); + itsNodes.emplace(node); + } + + //! Designates the most recently added node as finished + void finishNode() { itsNodes.pop(); } + + //! Sets the name for the next node created with startNode + void setNextName(const char * name) { itsNodes.top().name = name; } + + //! Saves some data, encoded as a string, into the current top level node + /*! The data will be be named with the most recent name if one exists, + otherwise it will be given some default delimited value that depends upon + the parent node */ + template inline void saveValue(T const & value) + { + itsOS.clear(); + itsOS.seekp(0, std::ios::beg); + itsOS << value << std::ends; + + auto strValue = itsOS.str(); + + // itsOS.str() may contain data from previous calls after the first '\0' that was just inserted + // and this data is counted in the length call. We make sure to remove that section so that the + // whitespace validation is done properly + strValue.resize(std::strlen(strValue.c_str())); + + // If the first or last character is a whitespace, add xml:space attribute + const auto len = strValue.length(); + if (len > 0 && (xml_detail::isWhitespace(strValue[0]) || xml_detail::isWhitespace(strValue[len - 1]))) { + itsNodes.top().node->append_attribute(itsXML.allocate_attribute("xml:space", "preserve")); + } + + // allocate strings for all of the data in the XML object + auto dataPtr = itsXML.allocate_string(strValue.c_str(), strValue.length() + 1); + + // insert into the XML + itsNodes.top().node->append_node(itsXML.allocate_node(rapidxml::node_data, nullptr, dataPtr)); + } + + //! Overload for uint8_t prevents them from being serialized as characters + void saveValue(uint8_t const & value) { saveValue(static_cast(value)); } + + //! Overload for int8_t prevents them from being serialized as characters + void saveValue(int8_t const & value) { saveValue(static_cast(value)); } + + //! Causes the type to be appended as an attribute to the most recently made node if output type is set to + //! true + template inline void insertType() + { + if (!itsOutputType) + return; + + // generate a name for this new node + const auto nameString = util::demangledName(); + + // allocate strings for all of the data in the XML object + auto namePtr = itsXML.allocate_string(nameString.data(), nameString.length() + 1); + + itsNodes.top().node->append_attribute(itsXML.allocate_attribute("type", namePtr)); + } + + //! Appends an attribute to the current top level node + void appendAttribute(const char * name, const char * value) + { + auto namePtr = itsXML.allocate_string(name); + auto valuePtr = itsXML.allocate_string(value); + itsNodes.top().node->append_attribute(itsXML.allocate_attribute(namePtr, valuePtr)); + } + + bool hasSizeAttributes() const { return itsSizeAttributes; } + +protected: + //! A struct that contains metadata about a node + struct NodeInfo + { + NodeInfo(rapidxml::xml_node<> * n = nullptr, const char * nm = nullptr) : node(n), counter(0), name(nm) + { + } + + rapidxml::xml_node<> * node; //!< A pointer to this node + size_t counter; //!< The counter for naming child nodes + const char * name; //!< The name for the next child node + + //! Gets the name for the next child node created from this node + /*! The name will be automatically generated using the counter if + a name has not been previously set. If a name has been previously + set, that name will be returned only once */ + std::string getValueName() + { + if (name) { + auto n = name; + name = nullptr; + return {n}; + } else + return "value" + std::to_string(counter++) + "\0"; + } + }; // NodeInfo + + //! @} + +private: + std::ostream & itsStream; //!< The output stream + rapidxml::xml_document<> itsXML; //!< The XML document + std::stack itsNodes; //!< A stack of nodes added to the document + std::ostringstream itsOS; //!< Used to format strings internally + bool itsOutputType; //!< Controls whether type information is printed + bool itsIndent; //!< Controls whether indenting is used + bool itsSizeAttributes; //!< Controls whether lists have a size attribute +}; // XMLOutputArchive + +// ###################################################################### +//! An output archive designed to load data from XML +/*! This archive uses RapidXML to build an in memory XML tree of the + data in the stream it is given before loading any types serialized. + + As with the output XML archive, the preferred way to use this archive is in + an RAII fashion, ensuring its destruction after all data has been read. + + Input XML should have been produced by the XMLOutputArchive. Data can + only be added to dynamically sized containers - the input archive will + determine their size by looking at the number of child nodes. Data that + did not originate from an XMLOutputArchive is not officially supported, + but may be possible to use if properly formatted. + + The XMLInputArchive does not require that nodes are loaded in the same + order they were saved by XMLOutputArchive. Using name value pairs (NVPs), + it is possible to load in an out of order fashion or otherwise skip/select + specific nodes to load. + + The default behavior of the input archive is to read sequentially starting + with the first node and exploring its children. When a given NVP does + not match the read in name for a node, the archive will search for that + node at the current level and load it if it exists. After loading an out of + order node, the archive will then proceed back to loading sequentially from + its new position. + + Consider this simple example where loading of some data is skipped: + + @code{cpp} + // imagine the input file has someData(1-9) saved in order at the top level node + ar( someData1, someData2, someData3 ); // XML loads in the order it sees in the file + ar( cereal::make_nvp( "hello", someData6 ) ); // NVP given does not + // match expected NVP name, so we search + // for the given NVP and load that value + ar( someData7, someData8, someData9 ); // with no NVP given, loading resumes at its + // current location, proceeding sequentially + @endcode + + \ingroup Archives */ +class XMLInputArchive +: public InputArchive +, public traits::TextArchive +{ +public: + /*! @name Common Functionality + Common use cases for directly interacting with an XMLInputArchive */ + //! @{ + + //! Construct, reading in from the provided stream + /*! Reads in an entire XML document from some stream and parses it as soon + as serialization starts + + @param stream The stream to read from. Can be a stringstream or a file. */ + XMLInputArchive(std::istream & stream) + : InputArchive(this), + itsData(std::istreambuf_iterator(stream), std::istreambuf_iterator()) + { + try { + itsData.push_back('\0'); // rapidxml will do terrible things without the data being null terminated + itsXML.parse(reinterpret_cast(itsData.data())); + } catch (rapidxml::parse_error const &) { + // std::cerr << "-----Original-----" << std::endl; + // stream.seekg(0); + // std::cout << std::string( std::istreambuf_iterator( stream ), + // std::istreambuf_iterator() ) << std::endl; + + // std::cerr << "-----Error-----" << std::endl; + // std::cerr << e.what() << std::endl; + // std::cerr << e.where() << std::endl; + throw Exception("XML Parsing failed - likely due to invalid characters or invalid naming"); + } + + // Parse the root + auto root = itsXML.first_node(xml_detail::CEREAL_XML_STRING); + if (root == nullptr) + throw Exception("Could not detect cereal root node - likely due to empty or invalid input"); + else + itsNodes.emplace(root); + } + + ~XMLInputArchive() CEREAL_NOEXCEPT = default; + + //! Loads some binary data, encoded as a base64 string, optionally specified by some name + /*! This will automatically start and finish a node to load the data, and can be called directly by + users. + + Note that this follows the same ordering rules specified in the class description in regards + to loading in/out of order */ + void loadBinaryValue(void * data, size_t size, const char * name = nullptr) + { + setNextName(name); + startNode(); + + std::string encoded; + loadValue(encoded); + + auto decoded = base64::decode(encoded); + + if (size != decoded.size()) + throw Exception("Decoded binary data size does not match specified size"); + + std::memcpy(data, decoded.data(), decoded.size()); + + finishNode(); + } + + //! @} + /*! @name Internal Functionality + Functionality designed for use by those requiring control over the inner mechanisms of + the XMLInputArchive */ + //! @{ + + //! Prepares to start reading the next node + /*! This places the next node to be parsed onto the nodes stack. + + By default our strategy is to start with the document root node and then + recursively iterate through all children in the order they show up in the document. + We don't need to know NVPs do to this; we'll just blindly load in the order things appear in. + + We check to see if the specified NVP matches what the next automatically loaded node is. If they + match, we just continue as normal, going in order. If they don't match, we attempt to find a node + named after the NVP that is being loaded. If that NVP does not exist, we throw an exception. */ + void startNode() + { + auto next = itsNodes.top().child; // By default we would move to the next child node + auto const expectedName = itsNodes.top().name; // this is the expected name from the NVP, if provided + + // If we were given an NVP name, look for it in the current level of the document. + // We only need to do this if either we have exhausted the siblings of the current level or + // the NVP name does not match the name of the node we would normally read next + if (expectedName && (next == nullptr || std::strcmp(next->name(), expectedName) != 0)) { + next = itsNodes.top().search(expectedName); + + if (next == nullptr) + throw Exception("XML Parsing failed - provided NVP (" + std::string(expectedName) + ") not found"); + } + + itsNodes.emplace(next); + } + + //! Finishes reading the current node + void finishNode() + { + // remove current + itsNodes.pop(); + + // advance parent + itsNodes.top().advance(); + + // Reset name + itsNodes.top().name = nullptr; + } + + //! Retrieves the current node name + //! will return @c nullptr if the node does not have a name + const char * getNodeName() const { return itsNodes.top().getChildName(); } + + //! Sets the name for the next node created with startNode + void setNextName(const char * name) { itsNodes.top().name = name; } + + //! Loads a bool from the current top node + template ::value, std::is_same::value> = traits::sfinae> + inline void loadValue(T & value) + { + std::istringstream is(itsNodes.top().node->value()); + is.setf(std::ios::boolalpha); + is >> value; + } + + //! Loads a char (signed or unsigned) from the current top node + template ::value, !std::is_same::value, sizeof(T) == sizeof(char)> = + traits::sfinae> + inline void loadValue(T & value) + { + value = *reinterpret_cast(itsNodes.top().node->value()); + } + + //! Load an int8_t from the current top node (ensures we parse entire number) + void loadValue(int8_t & value) + { + int32_t val; + loadValue(val); + value = static_cast(val); + } + + //! Load a uint8_t from the current top node (ensures we parse entire number) + void loadValue(uint8_t & value) + { + uint32_t val; + loadValue(val); + value = static_cast(val); + } + + //! Loads a type best represented as an unsigned long from the current top node + template ::value, + !std::is_same::value, + !std::is_same::value, + !std::is_same::value, + sizeof(T) < sizeof(long long)> = traits::sfinae> + inline void loadValue(T & value) + { + value = static_cast(std::stoul(itsNodes.top().node->value())); + } + + //! Loads a type best represented as an unsigned long long from the current top node + template ::value, + !std::is_same::value, + sizeof(T) >= sizeof(long long)> = traits::sfinae> + inline void loadValue(T & value) + { + value = static_cast(std::stoull(itsNodes.top().node->value())); + } + + //! Loads a type best represented as an int from the current top node + template ::value, !std::is_same::value, sizeof(T) <= sizeof(int)> = + traits::sfinae> + inline void loadValue(T & value) + { + value = static_cast(std::stoi(itsNodes.top().node->value())); + } + + //! Loads a type best represented as a long from the current top node + template ::value, (sizeof(T) > sizeof(int)), sizeof(T) <= sizeof(long)> = + traits::sfinae> + inline void loadValue(T & value) + { + value = static_cast(std::stol(itsNodes.top().node->value())); + } + + //! Loads a type best represented as a long long from the current top node + template ::value, (sizeof(T) > sizeof(long)), sizeof(T) <= sizeof(long long)> = + traits::sfinae> + inline void loadValue(T & value) + { + value = static_cast(std::stoll(itsNodes.top().node->value())); + } + + //! Loads a type best represented as a float from the current top node + void loadValue(float & value) + { + try { + value = std::stof(itsNodes.top().node->value()); + } catch (std::out_of_range const &) { + // special case for denormalized values + std::istringstream is(itsNodes.top().node->value()); + is >> value; + if (std::fpclassify(value) != FP_SUBNORMAL) + throw; + } + } + + //! Loads a type best represented as a double from the current top node + void loadValue(double & value) + { + try { + value = std::stod(itsNodes.top().node->value()); + } catch (std::out_of_range const &) { + // special case for denormalized values + std::istringstream is(itsNodes.top().node->value()); + is >> value; + if (std::fpclassify(value) != FP_SUBNORMAL) + throw; + } + } + + //! Loads a type best represented as a long double from the current top node + void loadValue(long double & value) + { + try { + value = std::stold(itsNodes.top().node->value()); + } catch (std::out_of_range const &) { + // special case for denormalized values + std::istringstream is(itsNodes.top().node->value()); + is >> value; + if (std::fpclassify(value) != FP_SUBNORMAL) + throw; + } + } + + //! Loads a string from the current node from the current top node + template + inline void loadValue(std::basic_string & str) + { + std::basic_istringstream is(itsNodes.top().node->value()); + + str.assign(std::istreambuf_iterator(is), std::istreambuf_iterator()); + } + + //! Loads the size of the current top node + template inline void loadSize(T & value) { value = getNumChildren(itsNodes.top().node); } + +protected: + //! Gets the number of children (usually interpreted as size) for the specified node + static size_t getNumChildren(rapidxml::xml_node<> * node) + { + size_t size = 0; + node = node->first_node(); // get first child + + while (node != nullptr) { + ++size; + node = node->next_sibling(); + } + + return size; + } + + //! A struct that contains metadata about a node + /*! Keeps track of some top level node, its number of + remaining children, and the current active child node */ + struct NodeInfo + { + NodeInfo(rapidxml::xml_node<> * n = nullptr) + : node(n), child(n->first_node()), size(XMLInputArchive::getNumChildren(n)), name(nullptr) + { + } + + //! Advances to the next sibling node of the child + /*! If this is the last sibling child will be null after calling */ + void advance() + { + if (size > 0) { + --size; + child = child->next_sibling(); + } + } + + //! Searches for a child with the given name in this node + /*! @param searchName The name to search for (must be null terminated) + @return The node if found, nullptr otherwise */ + rapidxml::xml_node<> * search(const char * searchName) + { + if (searchName) { + size_t new_size = XMLInputArchive::getNumChildren(node); + const size_t name_size = rapidxml::internal::measure(searchName); + + for (auto new_child = node->first_node(); new_child != nullptr; + new_child = new_child->next_sibling()) { + if (rapidxml::internal::compare( + new_child->name(), new_child->name_size(), searchName, name_size, true)) { + size = new_size; + child = new_child; + + return new_child; + } + --new_size; + } + } + + return nullptr; + } + + //! Returns the actual name of the next child node, if it exists + const char * getChildName() const { return child ? child->name() : nullptr; } + + rapidxml::xml_node<> * node; //!< A pointer to this node + rapidxml::xml_node<> * child; //!< A pointer to its current child + size_t size; //!< The remaining number of children for this node + const char * name; //!< The NVP name for next child node + }; // NodeInfo + + //! @} + +private: + std::vector itsData; //!< The raw data loaded + rapidxml::xml_document<> itsXML; //!< The XML document + std::stack itsNodes; //!< A stack of nodes read from the document +}; + +// ###################################################################### +// XMLArchive prologue and epilogue functions +// ###################################################################### + +// ###################################################################### +//! Prologue for NVPs for XML output archives +/*! NVPs do not start or finish nodes - they just set up the names */ +template inline void prologue(XMLOutputArchive &, NameValuePair const &) +{ +} + +//! Prologue for NVPs for XML input archives +template inline void prologue(XMLInputArchive &, NameValuePair const &) +{ +} + +// ###################################################################### +//! Epilogue for NVPs for XML output archives +/*! NVPs do not start or finish nodes - they just set up the names */ +template inline void epilogue(XMLOutputArchive &, NameValuePair const &) +{ +} + +//! Epilogue for NVPs for XML input archives +template inline void epilogue(XMLInputArchive &, NameValuePair const &) +{ +} + +// ###################################################################### +//! Prologue for deferred data for XML archives +/*! Do nothing for the defer wrapper */ +template inline void prologue(XMLOutputArchive &, DeferredData const &) +{ +} + +//! Prologue for deferred data for XML archives +template inline void prologue(XMLInputArchive &, DeferredData const &) +{ +} + +// ###################################################################### +//! Epilogue for deferred for XML archives +/*! NVPs do not start or finish nodes - they just set up the names */ +template inline void epilogue(XMLOutputArchive &, DeferredData const &) +{ +} + +//! Epilogue for deferred for XML archives +/*! Do nothing for the defer wrapper */ +template inline void epilogue(XMLInputArchive &, DeferredData const &) +{ +} + +// ###################################################################### +//! Prologue for SizeTags for XML output archives +/*! SizeTags do not start or finish nodes */ +template inline void prologue(XMLOutputArchive & ar, SizeTag const &) +{ + if (ar.hasSizeAttributes()) { + ar.appendAttribute("size", "dynamic"); + } +} + +template inline void prologue(XMLInputArchive &, SizeTag const &) +{ +} + +//! Epilogue for SizeTags for XML output archives +/*! SizeTags do not start or finish nodes */ +template inline void epilogue(XMLOutputArchive &, SizeTag const &) +{ +} + +template inline void epilogue(XMLInputArchive &, SizeTag const &) +{ +} + +// ###################################################################### +//! Prologue for all other types for XML output archives (except minimal types) +/*! Starts a new node, named either automatically or by some NVP, + that may be given data by the type about to be archived + + Minimal types do not start or end nodes */ +template ::value || + traits::has_minimal_output_serialization::value> = traits::sfinae> +inline void prologue(XMLOutputArchive & ar, T const &) +{ + ar.startNode(); + ar.insertType(); +} + +//! Prologue for all other types for XML input archives (except minimal types) +template ::value || + traits::has_minimal_input_serialization::value> = traits::sfinae> +inline void prologue(XMLInputArchive & ar, T const &) +{ + ar.startNode(); +} + +// ###################################################################### +//! Epilogue for all other types other for XML output archives (except minimal types) +/*! Finishes the node created in the prologue + + Minimal types do not start or end nodes */ +template ::value || + traits::has_minimal_output_serialization::value> = traits::sfinae> +inline void epilogue(XMLOutputArchive & ar, T const &) +{ + ar.finishNode(); +} + +//! Epilogue for all other types other for XML output archives (except minimal types) +template ::value || + traits::has_minimal_input_serialization::value> = traits::sfinae> +inline void epilogue(XMLInputArchive & ar, T const &) +{ + ar.finishNode(); +} + +// ###################################################################### +// Common XMLArchive serialization functions +// ###################################################################### + +//! Saving NVP types to XML +template inline void CEREAL_SAVE_FUNCTION_NAME(XMLOutputArchive & ar, NameValuePair const & t) +{ + ar.setNextName(t.name); + ar(t.value); +} + +//! Loading NVP types from XML +template inline void CEREAL_LOAD_FUNCTION_NAME(XMLInputArchive & ar, NameValuePair & t) +{ + ar.setNextName(t.name); + ar(t.value); +} + +// ###################################################################### +//! Saving SizeTags to XML +template inline void CEREAL_SAVE_FUNCTION_NAME(XMLOutputArchive &, SizeTag const &) +{ +} + +//! Loading SizeTags from XML +template inline void CEREAL_LOAD_FUNCTION_NAME(XMLInputArchive & ar, SizeTag & st) +{ + ar.loadSize(st.size); +} + +// ###################################################################### +//! Saving for POD types to xml +template ::value> = traits::sfinae> +inline void CEREAL_SAVE_FUNCTION_NAME(XMLOutputArchive & ar, T const & t) +{ + ar.saveValue(t); +} + +//! Loading for POD types from xml +template ::value> = traits::sfinae> +inline void CEREAL_LOAD_FUNCTION_NAME(XMLInputArchive & ar, T & t) +{ + ar.loadValue(t); +} + +// ###################################################################### +//! saving string to xml +template +inline void CEREAL_SAVE_FUNCTION_NAME( + XMLOutputArchive & ar, std::basic_string const & str) +{ + ar.saveValue(str); +} + +//! loading string from xml +template +inline void CEREAL_LOAD_FUNCTION_NAME(XMLInputArchive & ar, std::basic_string & str) +{ + ar.loadValue(str); +} +} // namespace cereal + +// register archives for polymorphic support +CEREAL_REGISTER_ARCHIVE(cereal::XMLOutputArchive) +CEREAL_REGISTER_ARCHIVE(cereal::XMLInputArchive) + +// tie input and output archives together +CEREAL_SETUP_ARCHIVE_TRAITS(cereal::XMLInputArchive, cereal::XMLOutputArchive) + +#endif // CEREAL_ARCHIVES_XML_HPP_ diff --git a/minco_ws/src/navigation/minco_planner/include/cereal/cereal.hpp b/minco_ws/src/navigation/minco_planner/include/cereal/cereal.hpp new file mode 100644 index 0000000..13879bd --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/include/cereal/cereal.hpp @@ -0,0 +1,1102 @@ +/*! \file cereal.hpp + \brief Main cereal functionality */ +/* + Copyright (c) 2014, Randolph Voorhies, Shane Grant + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef CEREAL_CEREAL_HPP_ +#define CEREAL_CEREAL_HPP_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cereal/details/helpers.hpp" +#include "cereal/details/traits.hpp" +#include "cereal/macros.hpp" +#include "cereal/types/base_class.hpp" + +namespace cereal { +// ###################################################################### +//! Creates a name value pair +/*! @relates NameValuePair + @ingroup Utility */ +template inline NameValuePair make_nvp(std::string const & name, T && value) +{ + return {name.c_str(), std::forward(value)}; +} + +//! Creates a name value pair +/*! @relates NameValuePair + @ingroup Utility */ +template inline NameValuePair make_nvp(const char * name, T && value) +{ + return {name, std::forward(value)}; +} + +//! Creates a name value pair for the variable T with the same name as the variable +/*! @relates NameValuePair + @ingroup Utility */ +#define CEREAL_NVP(T) ::cereal::make_nvp(#T, T) + +// ###################################################################### +//! Convenience function to create binary data for both const and non const pointers +/*! @param data Pointer to beginning of the data + @param size The size in bytes of the data + @relates BinaryData + @ingroup Utility */ +template inline BinaryData binary_data(T && data, size_t size) +{ + return {std::forward(data), size}; +} + +// ###################################################################### +//! Creates a size tag from some variable. +/*! Will normally be used to serialize size (e.g. size()) information for + variable size containers. If you have a variable sized container, + the very first thing it serializes should be its size, wrapped in + a SizeTag. + + @relates SizeTag + @ingroup Utility */ +template inline SizeTag make_size_tag(T && sz) +{ + return {std::forward(sz)}; +} + +// ###################################################################### +//! Marks data for deferred serialization +/*! cereal performs a recursive depth-first traversal of data it serializes. When + serializing smart pointers to large, nested, or cyclical data structures, it + is possible to encounter a stack overflow from excessive recursion when following + a chain of pointers. + + Deferment can help in these situations if the data can be serialized separately from + the pointers used to traverse the structure. For example, a graph structure can have its + nodes serialized before its edges: + + @code{.cpp} + struct MyEdge + { + std::shared_ptr connection; + int some_value; + + template + void serialize(Archive & archive) + { + // when we serialize an edge, we'll defer serializing the associated node + archive( cereal::defer( connection ), + some_value ); + } + }; + + struct MyGraphStructure + { + std::vector edges; + std::vector nodes; + + template + void serialize(Archive & archive) + { + // because of the deferment, we ensure all nodes are fully serialized + // before any connection pointers to those nodes are serialized + archive( edges, nodes ); + + // we have to explicitly inform the archive when it is safe to serialize + // the deferred data + archive.serializeDeferments(); + } + }; + @endcode + + @relates DeferredData + @ingroup Utility */ +template inline DeferredData defer(T && value) +{ + return {std::forward(value)}; +} + +// ###################################################################### +//! Called before a type is serialized to set up any special archive state +//! for processing some type +/*! If designing a serializer that needs to set up any kind of special + state or output extra information for a type, specialize this function + for the archive type and the types that require the extra information. + @ingroup Internal */ +template inline void prologue(Archive & /* archive */, T const & /* data */) +{ +} + +//! Called after a type is serialized to tear down any special archive state +//! for processing some type +/*! @ingroup Internal */ +template inline void epilogue(Archive & /* archive */, T const & /* data */) +{ +} + +// ###################################################################### +//! Special flags for archives +/*! AllowEmptyClassElision + This allows for empty classes to be serialized even if they do not provide + a serialization function. Classes with no data members are considered to be + empty. Be warned that if this is enabled and you attempt to serialize an + empty class with improperly formed serialize or load/save functions, no + static error will occur - the error will propogate silently and your + intended serialization functions may not be called. You can manually + ensure that your classes that have custom serialization are correct + by using the traits is_output_serializable and is_input_serializable + in cereal/details/traits.hpp. + @ingroup Internal */ +enum Flags +{ + AllowEmptyClassElision = 1 +}; + +// ###################################################################### +//! Registers a specific Archive type with cereal +/*! This registration should be done once per archive. A good place to + put this is immediately following the definition of your archive. + Archive registration is only strictly necessary if you wish to + support pointers to polymorphic data types. All archives that + come with cereal are already registered. + @ingroup Internal */ +#define CEREAL_REGISTER_ARCHIVE(Archive) \ +namespace cereal { \ +namespace detail { \ +template \ +typename polymorphic_serialization_support::type instantiate_polymorphic_binding( \ + T *, Archive *, BindingTag, adl_tag); \ +} \ +} /* end namespaces */ + +//! Helper macro to omit unused warning +#if defined(__GNUC__) +// GCC / clang don't want the function +#define CEREAL_UNUSED_FUNCTION +#else +#define CEREAL_UNUSED_FUNCTION \ +static void unused() \ +{ \ +(void)version; \ +} +#endif + +// ###################################################################### +//! Defines a class version for some type +/*! Versioning information is optional and adds some small amount of + overhead to serialization. This overhead will occur both in terms of + space in the archive (the version information for each class will be + stored exactly once) as well as runtime (versioned serialization functions + must check to see if they need to load or store version information). + + Versioning is useful if you plan on fundamentally changing the way some + type is serialized in the future. Versioned serialization functions + cannot be used to load non-versioned data. + + By default, all types have an assumed version value of zero. By + using this macro, you may change the version number associated with + some type. cereal will then use this value as a second parameter + to your serialization functions. + + The interface for the serialization functions is nearly identical + to non-versioned serialization with the addition of a second parameter, + const std::uint32_t version, which will be supplied with the correct + version number. Serializing the version number on a save happens + automatically. + + Versioning cannot be mixed with non-versioned serialization functions. + Having both types will result result in a compile time error. Data + serialized without versioning cannot be loaded by a serialization + function with added versioning support. + + Example interface for versioning on a non-member serialize function: + + @code{cpp} + CEREAL_CLASS_VERSION( Mytype, 77 ); // register class version + + template + void serialize( Archive & ar, Mytype & t, const std::uint32_t version ) + { + // When performing a load, the version associated with the class + // is whatever it was when that data was originally serialized + // + // When we save, we'll use the version that is defined in the macro + + if( version >= some_number ) + // do this + else + // do that + } + @endcode + + Interfaces for other forms of serialization functions is similar. This + macro should be placed at global scope. + @ingroup Utility */ + +//! On C++17, define the StaticObject as inline to merge the definitions across TUs +//! This prevents multiple definition errors when this macro appears in a header file +//! included in multiple TUs. +#ifdef CEREAL_HAS_CPP17 +#define CEREAL_CLASS_VERSION(TYPE, VERSION_NUMBER) \ +namespace cereal { \ +namespace detail { \ +template <> struct Version \ +{ \ +static std::uint32_t registerVersion() \ +{ \ +::cereal::detail::StaticObject::getInstance().mapping.emplace( \ + std::type_index(typeid(TYPE)).hash_code(), VERSION_NUMBER); \ +return VERSION_NUMBER; \ +} \ +static inline const std::uint32_t version = registerVersion(); \ +CEREAL_UNUSED_FUNCTION \ +}; /* end Version */ \ +} \ +} // end namespaces +#else +#define CEREAL_CLASS_VERSION(TYPE, VERSION_NUMBER) \ +namespace cereal { \ +namespace detail { \ +template <> struct Version \ +{ \ +static const std::uint32_t version; \ +static std::uint32_t registerVersion() \ +{ \ +::cereal::detail::StaticObject::getInstance().mapping.emplace( \ + std::type_index(typeid(TYPE)).hash_code(), VERSION_NUMBER); \ +return VERSION_NUMBER; \ +} \ +CEREAL_UNUSED_FUNCTION \ +}; /* end Version */ \ +const std::uint32_t Version::version = Version::registerVersion(); \ +} \ +} // end namespaces + +#endif + +// ###################################################################### +//! The base output archive class +/*! This is the base output archive for all output archives. If you create + a custom archive class, it should derive from this, passing itself as + a template parameter for the ArchiveType. + + The base class provides all of the functionality necessary to + properly forward data to the correct serialization functions. + + Individual archives should use a combination of prologue and + epilogue functions together with specializations of serialize, save, + and load to alter the functionality of their serialization. + + @tparam ArchiveType The archive type that derives from OutputArchive + @tparam Flags Flags to control advanced functionality. See the Flags + enum for more information. + @ingroup Internal */ +template class OutputArchive : public detail::OutputArchiveBase +{ +public: + //! Construct the output archive + /*! @param derived A pointer to the derived ArchiveType (pass this from the derived archive) */ + OutputArchive(ArchiveType * const derived) + : self(derived), itsCurrentPointerId(1), itsCurrentPolymorphicTypeId(1) + { + } + + OutputArchive & operator=(OutputArchive const &) = delete; + + //! Serializes all passed in data + /*! This is the primary interface for serializing data with an archive */ + template inline ArchiveType & operator()(Types &&... args) + { + self->process(std::forward(args)...); + return *self; + } + + //! Serializes any data marked for deferment using defer + /*! This will cause any data wrapped in DeferredData to be immediately serialized */ + void serializeDeferments() + { + for (auto & deferment : itsDeferments) + deferment(); + } + + /*! @name Boost Transition Layer + Functionality that mirrors the syntax for Boost. This is useful if you are transitioning + a large project from Boost to cereal. The preferred interface for cereal is using operator(). */ + //! @{ + + //! Indicates this archive is not intended for loading + /*! This ensures compatibility with boost archive types. If you are transitioning + from boost, you can check this value within a member or external serialize function + (i.e., Archive::is_loading::value) to disable behavior specific to loading, until + you can transition to split save/load or save_minimal/load_minimal functions */ + using is_loading = std::false_type; + + //! Indicates this archive is intended for saving + /*! This ensures compatibility with boost archive types. If you are transitioning + from boost, you can check this value within a member or external serialize function + (i.e., Archive::is_saving::value) to enable behavior specific to loading, until + you can transition to split save/load or save_minimal/load_minimal functions */ + using is_saving = std::true_type; + + //! Serializes passed in data + /*! This is a boost compatability layer and is not the preferred way of using + cereal. If you are transitioning from boost, use this until you can + transition to the operator() overload */ + template inline ArchiveType & operator&(T && arg) + { + self->process(std::forward(arg)); + return *self; + } + + //! Serializes passed in data + /*! This is a boost compatability layer and is not the preferred way of using + cereal. If you are transitioning from boost, use this until you can + transition to the operator() overload */ + template inline ArchiveType & operator<<(T && arg) + { + self->process(std::forward(arg)); + return *self; + } + + //! @} + + //! Registers a shared pointer with the archive + /*! This function is used to track shared pointer targets to prevent + unnecessary saves from taking place if multiple shared pointers + point to the same data. + + @internal + @param sharedPointer The shared pointer itself (the adress is taked via get()). + The archive takes a copy to prevent the memory location to be freed + as long as the address is used as id. This is needed to prevent CVE-2020-11105. + @return A key that uniquely identifies the pointer */ + inline std::uint32_t registerSharedPointer(const std::shared_ptr & sharedPointer) + { + void const * addr = sharedPointer.get(); + + // Handle null pointers by just returning 0 + if (addr == 0) + return 0; + itsSharedPointerStorage.push_back(sharedPointer); + + auto id = itsSharedPointerMap.find(addr); + if (id == itsSharedPointerMap.end()) { + auto ptrId = itsCurrentPointerId++; + itsSharedPointerMap.insert({addr, ptrId}); + return ptrId | detail::msb_32bit; // mask MSB to be 1 + } else + return id->second; + } + + //! Registers a polymorphic type name with the archive + /*! This function is used to track polymorphic types to prevent + unnecessary saves of identifying strings used by the polymorphic + support functionality. + + @internal + @param name The name to associate with a polymorphic type + @return A key that uniquely identifies the polymorphic type name */ + inline std::uint32_t registerPolymorphicType(char const * name) + { + auto id = itsPolymorphicTypeMap.find(name); + if (id == itsPolymorphicTypeMap.end()) { + auto polyId = itsCurrentPolymorphicTypeId++; + itsPolymorphicTypeMap.insert({name, polyId}); + return polyId | detail::msb_32bit; // mask MSB to be 1 + } else + return id->second; + } + +private: + //! Serializes data after calling prologue, then calls epilogue + template inline void process(T && head) + { + prologue(*self, head); + self->processImpl(head); + epilogue(*self, head); + } + + //! Unwinds to process all data + template inline void process(T && head, Other &&... tail) + { + self->process(std::forward(head)); + self->process(std::forward(tail)...); + } + + //! Serialization of a virtual_base_class wrapper + /*! \sa virtual_base_class */ + template inline ArchiveType & processImpl(virtual_base_class const & b) + { + traits::detail::base_class_id id(b.base_ptr); + if (itsBaseClassSet.count(id) == 0) { + itsBaseClassSet.insert(id); + self->processImpl(*b.base_ptr); + } + return *self; + } + + //! Serialization of a base_class wrapper + /*! \sa base_class */ + template inline ArchiveType & processImpl(base_class const & b) + { + self->processImpl(*b.base_ptr); + return *self; + } + + std::vector> itsDeferments; + + template inline ArchiveType & processImpl(DeferredData const & d) + { + std::function deferment([this, d]() { + self->process(d.value); + }); + itsDeferments.emplace_back(std::move(deferment)); + + return *self; + } + +//! Helper macro that expands the requirements for activating an overload +/*! Requirements: + Has the requested serialization function + Does not have version and unversioned at the same time + Is output serializable AND + is specialized for this type of function OR + has no specialization at all */ +#define PROCESS_IF(name) \ +traits::EnableIf::value, \ + !traits::has_invalid_output_versioning::value, \ + (traits::is_output_serializable::value && \ + (traits::is_specialized_##name::value || \ + !traits::is_specialized::value))> = traits::sfinae + + //! Member serialization + template inline ArchiveType & processImpl(T const & t) + { + access::member_serialize(*self, const_cast(t)); + return *self; + } + + //! Non member serialization + template inline ArchiveType & processImpl(T const & t) + { + CEREAL_SERIALIZE_FUNCTION_NAME(*self, const_cast(t)); + return *self; + } + + //! Member split (save) + template inline ArchiveType & processImpl(T const & t) + { + access::member_save(*self, t); + return *self; + } + + //! Non member split (save) + template inline ArchiveType & processImpl(T const & t) + { + CEREAL_SAVE_FUNCTION_NAME(*self, t); + return *self; + } + + //! Member split (save_minimal) + template inline ArchiveType & processImpl(T const & t) + { + self->process(access::member_save_minimal(*self, t)); + return *self; + } + + //! Non member split (save_minimal) + template inline ArchiveType & processImpl(T const & t) + { + self->process(CEREAL_SAVE_MINIMAL_FUNCTION_NAME(*self, t)); + return *self; + } + + //! Empty class specialization + template ::value, + std::is_empty::value> = traits::sfinae> + inline ArchiveType & processImpl(T const &) + { + return *self; + } + + //! No matching serialization + /*! Invalid if we have invalid output versioning or + we are not output serializable, and either + don't allow empty class ellision or allow it but are not serializing an empty class */ + template ::value || + (!traits::is_output_serializable::value && + (!(Flags & AllowEmptyClassElision) || + ((Flags & AllowEmptyClassElision) && !std::is_empty::value)))> = traits::sfinae> + inline ArchiveType & processImpl(T const &) + { + static_assert(traits::detail::count_output_serializers::value != 0, + "cereal could not find any output serialization functions for the provided type and archive " + "combination. \n\n " + "Types must either have a serialize function, load/save pair, or load_minimal/save_minimal pair (you " + "may not mix these). \n " + "Serialize functions generally have the following signature: \n\n " + "template \n " + " void serialize(Archive & ar) \n " + " { \n " + " ar( member1, member2, member3 ); \n " + " } \n\n "); + + static_assert(traits::detail::count_output_serializers::value < 2, + "cereal found more than one compatible output serialization function for the provided type and " + "archive combination. \n\n " + "Types must either have a serialize function, load/save pair, or load_minimal/save_minimal pair (you " + "may not mix these). \n " + "Use specialization (see access.hpp) if you need to disambiguate between serialize vs load/save " + "functions. \n " + "Note that serialization functions can be inherited which may lead to the aforementioned " + "ambiguities. \n " + "In addition, you may not mix versioned with non-versioned serialization functions. \n\n "); + + return *self; + } + + //! Registers a class version with the archive and serializes it if necessary + /*! If this is the first time this class has been serialized, we will record its + version number and serialize that. + + @tparam T The type of the class being serialized */ + template inline std::uint32_t registerClassVersion() + { + static const auto hash = std::type_index(typeid(T)).hash_code(); + const auto insertResult = itsVersionedTypes.insert(hash); + const auto lock = detail::StaticObject::lock(); + const auto version = + detail::StaticObject::getInstance().find(hash, detail::Version::version); + + if (insertResult.second) // insertion took place, serialize the version number + process(make_nvp("cereal_class_version", version)); + + return version; + } + + //! Member serialization + /*! Versioning implementation */ + template inline ArchiveType & processImpl(T const & t) + { + access::member_serialize(*self, const_cast(t), registerClassVersion()); + return *self; + } + + //! Non member serialization + /*! Versioning implementation */ + template + inline ArchiveType & processImpl(T const & t) + { + CEREAL_SERIALIZE_FUNCTION_NAME(*self, const_cast(t), registerClassVersion()); + return *self; + } + + //! Member split (save) + /*! Versioning implementation */ + template inline ArchiveType & processImpl(T const & t) + { + access::member_save(*self, t, registerClassVersion()); + return *self; + } + + //! Non member split (save) + /*! Versioning implementation */ + template inline ArchiveType & processImpl(T const & t) + { + CEREAL_SAVE_FUNCTION_NAME(*self, t, registerClassVersion()); + return *self; + } + + //! Member split (save_minimal) + /*! Versioning implementation */ + template + inline ArchiveType & processImpl(T const & t) + { + self->process(access::member_save_minimal(*self, t, registerClassVersion())); + return *self; + } + + //! Non member split (save_minimal) + /*! Versioning implementation */ + template + inline ArchiveType & processImpl(T const & t) + { + self->process(CEREAL_SAVE_MINIMAL_FUNCTION_NAME(*self, t, registerClassVersion())); + return *self; + } + +#undef PROCESS_IF + +private: + ArchiveType * const self; + + //! A set of all base classes that have been serialized + std::unordered_set itsBaseClassSet; + + //! Maps from addresses to pointer ids + std::unordered_map itsSharedPointerMap; + + //! Copy of shared pointers used in #itsSharedPointerMap to make sure they are kept alive + // during lifetime of itsSharedPointerMap to prevent CVE-2020-11105. + std::vector> itsSharedPointerStorage; + + //! The id to be given to the next pointer + std::uint32_t itsCurrentPointerId; + + //! Maps from polymorphic type name strings to ids + std::unordered_map itsPolymorphicTypeMap; + + //! The id to be given to the next polymorphic type name + std::uint32_t itsCurrentPolymorphicTypeId; + + //! Keeps track of classes that have versioning information associated with them + std::unordered_set itsVersionedTypes; +}; // class OutputArchive + +// ###################################################################### +//! The base input archive class +/*! This is the base input archive for all input archives. If you create + a custom archive class, it should derive from this, passing itself as + a template parameter for the ArchiveType. + + The base class provides all of the functionality necessary to + properly forward data to the correct serialization functions. + + Individual archives should use a combination of prologue and + epilogue functions together with specializations of serialize, save, + and load to alter the functionality of their serialization. + + @tparam ArchiveType The archive type that derives from InputArchive + @tparam Flags Flags to control advanced functionality. See the Flags + enum for more information. + @ingroup Internal */ +template class InputArchive : public detail::InputArchiveBase +{ +public: + //! Construct the output archive + /*! @param derived A pointer to the derived ArchiveType (pass this from the derived archive) */ + InputArchive(ArchiveType * const derived) + : self(derived), itsBaseClassSet(), itsSharedPointerMap(), itsPolymorphicTypeMap(), itsVersionedTypes() + { + } + + InputArchive & operator=(InputArchive const &) = delete; + + //! Serializes all passed in data + /*! This is the primary interface for serializing data with an archive */ + template inline ArchiveType & operator()(Types &&... args) + { + process(std::forward(args)...); + return *self; + } + + //! Serializes any data marked for deferment using defer + /*! This will cause any data wrapped in DeferredData to be immediately serialized */ + void serializeDeferments() + { + for (auto & deferment : itsDeferments) + deferment(); + } + + /*! @name Boost Transition Layer + Functionality that mirrors the syntax for Boost. This is useful if you are transitioning + a large project from Boost to cereal. The preferred interface for cereal is using operator(). */ + //! @{ + + //! Indicates this archive is intended for loading + /*! This ensures compatibility with boost archive types. If you are transitioning + from boost, you can check this value within a member or external serialize function + (i.e., Archive::is_loading::value) to enable behavior specific to loading, until + you can transition to split save/load or save_minimal/load_minimal functions */ + using is_loading = std::true_type; + + //! Indicates this archive is not intended for saving + /*! This ensures compatibility with boost archive types. If you are transitioning + from boost, you can check this value within a member or external serialize function + (i.e., Archive::is_saving::value) to disable behavior specific to loading, until + you can transition to split save/load or save_minimal/load_minimal functions */ + using is_saving = std::false_type; + + //! Serializes passed in data + /*! This is a boost compatability layer and is not the preferred way of using + cereal. If you are transitioning from boost, use this until you can + transition to the operator() overload */ + template inline ArchiveType & operator&(T && arg) + { + self->process(std::forward(arg)); + return *self; + } + + //! Serializes passed in data + /*! This is a boost compatability layer and is not the preferred way of using + cereal. If you are transitioning from boost, use this until you can + transition to the operator() overload */ + template inline ArchiveType & operator>>(T && arg) + { + self->process(std::forward(arg)); + return *self; + } + + //! @} + + //! Retrieves a shared pointer given a unique key for it + /*! This is used to retrieve a previously registered shared_ptr + which has already been loaded. + + @internal + @param id The unique id that was serialized for the pointer + @return A shared pointer to the data + @throw Exception if the id does not exist */ + inline std::shared_ptr getSharedPointer(std::uint32_t const id) + { + if (id == 0) + return std::shared_ptr(nullptr); + + auto iter = itsSharedPointerMap.find(id); + if (iter == itsSharedPointerMap.end()) + throw Exception( + "Error while trying to deserialize a smart pointer. Could not find id " + std::to_string(id)); + + return iter->second; + } + + //! Registers a shared pointer to its unique identifier + /*! After a shared pointer has been allocated for the first time, it should + be registered with its loaded id for future references to it. + + @internal + @param id The unique identifier for the shared pointer + @param ptr The actual shared pointer */ + inline void registerSharedPointer(std::uint32_t const id, std::shared_ptr ptr) + { + std::uint32_t const stripped_id = id & ~detail::msb_32bit; + itsSharedPointerMap[stripped_id] = ptr; + } + + //! Retrieves the string for a polymorphic type given a unique key for it + /*! This is used to retrieve a string previously registered during + a polymorphic load. + + @internal + @param id The unique id that was serialized for the polymorphic type + @return The string identifier for the tyep */ + inline std::string getPolymorphicName(std::uint32_t const id) + { + auto name = itsPolymorphicTypeMap.find(id); + if (name == itsPolymorphicTypeMap.end()) { + throw Exception("Error while trying to deserialize a polymorphic pointer. Could not find type id " + + std::to_string(id)); + } + return name->second; + } + + //! Registers a polymorphic name string to its unique identifier + /*! After a polymorphic type has been loaded for the first time, it should + be registered with its loaded id for future references to it. + + @internal + @param id The unique identifier for the polymorphic type + @param name The name associated with the tyep */ + inline void registerPolymorphicName(std::uint32_t const id, std::string const & name) + { + std::uint32_t const stripped_id = id & ~detail::msb_32bit; + itsPolymorphicTypeMap.insert({stripped_id, name}); + } + +private: + //! Serializes data after calling prologue, then calls epilogue + template inline void process(T && head) + { + prologue(*self, head); + self->processImpl(head); + epilogue(*self, head); + } + + //! Unwinds to process all data + template inline void process(T && head, Other &&... tail) + { + process(std::forward(head)); + process(std::forward(tail)...); + } + + //! Serialization of a virtual_base_class wrapper + /*! \sa virtual_base_class */ + template inline ArchiveType & processImpl(virtual_base_class & b) + { + traits::detail::base_class_id id(b.base_ptr); + if (itsBaseClassSet.count(id) == 0) { + itsBaseClassSet.insert(id); + self->processImpl(*b.base_ptr); + } + return *self; + } + + //! Serialization of a base_class wrapper + /*! \sa base_class */ + template inline ArchiveType & processImpl(base_class & b) + { + self->processImpl(*b.base_ptr); + return *self; + } + + std::vector> itsDeferments; + + template inline ArchiveType & processImpl(DeferredData const & d) + { + std::function deferment([this, d]() { + self->process(d.value); + }); + itsDeferments.emplace_back(std::move(deferment)); + + return *self; + } + +//! Helper macro that expands the requirements for activating an overload +/*! Requirements: + Has the requested serialization function + Does not have version and unversioned at the same time + Is input serializable AND + is specialized for this type of function OR + has no specialization at all */ +#define PROCESS_IF(name) \ +traits::EnableIf::value, \ + !traits::has_invalid_input_versioning::value, \ + (traits::is_input_serializable::value && \ + (traits::is_specialized_##name::value || \ + !traits::is_specialized::value))> = traits::sfinae + + //! Member serialization + template inline ArchiveType & processImpl(T & t) + { + access::member_serialize(*self, t); + return *self; + } + + //! Non member serialization + template inline ArchiveType & processImpl(T & t) + { + CEREAL_SERIALIZE_FUNCTION_NAME(*self, t); + return *self; + } + + //! Member split (load) + template inline ArchiveType & processImpl(T & t) + { + access::member_load(*self, t); + return *self; + } + + //! Non member split (load) + template inline ArchiveType & processImpl(T & t) + { + CEREAL_LOAD_FUNCTION_NAME(*self, t); + return *self; + } + + //! Member split (load_minimal) + template inline ArchiveType & processImpl(T & t) + { + using OutArchiveType = typename traits::detail::get_output_from_input::type; + typename traits::has_member_save_minimal::type value; + self->process(value); + access::member_load_minimal(*self, t, value); + return *self; + } + + //! Non member split (load_minimal) + template inline ArchiveType & processImpl(T & t) + { + using OutArchiveType = typename traits::detail::get_output_from_input::type; + typename traits::has_non_member_save_minimal::type value; + self->process(value); + CEREAL_LOAD_MINIMAL_FUNCTION_NAME(*self, t, value); + return *self; + } + + //! Empty class specialization + template ::value, + std::is_empty::value> = traits::sfinae> + inline ArchiveType & processImpl(T const &) + { + return *self; + } + + //! No matching serialization + /*! Invalid if we have invalid input versioning or + we are not input serializable, and either + don't allow empty class ellision or allow it but are not serializing an empty class */ + template ::value || + (!traits::is_input_serializable::value && + (!(Flags & AllowEmptyClassElision) || + ((Flags & AllowEmptyClassElision) && !std::is_empty::value)))> = traits::sfinae> + inline ArchiveType & processImpl(T const &) + { + static_assert(traits::detail::count_input_serializers::value != 0, + "cereal could not find any input serialization functions for the provided type and archive " + "combination. \n\n " + "Types must either have a serialize function, load/save pair, or load_minimal/save_minimal pair (you " + "may not mix these). \n " + "Serialize functions generally have the following signature: \n\n " + "template \n " + " void serialize(Archive & ar) \n " + " { \n " + " ar( member1, member2, member3 ); \n " + " } \n\n "); + + static_assert(traits::detail::count_input_serializers::value < 2, + "cereal found more than one compatible input serialization function for the provided type and " + "archive combination. \n\n " + "Types must either have a serialize function, load/save pair, or load_minimal/save_minimal pair (you " + "may not mix these). \n " + "Use specialization (see access.hpp) if you need to disambiguate between serialize vs load/save " + "functions. \n " + "Note that serialization functions can be inherited which may lead to the aforementioned " + "ambiguities. \n " + "In addition, you may not mix versioned with non-versioned serialization functions. \n\n "); + + return *self; + } + + //! Befriend for versioning in load_and_construct + template friend struct detail::Construct; + + //! Registers a class version with the archive and serializes it if necessary + /*! If this is the first time this class has been serialized, we will record its + version number and serialize that. + + @tparam T The type of the class being serialized */ + template inline std::uint32_t loadClassVersion() + { + static const auto hash = std::type_index(typeid(T)).hash_code(); + auto lookupResult = itsVersionedTypes.find(hash); + + if (lookupResult != itsVersionedTypes.end()) // already exists + return lookupResult->second; + else // need to load + { + std::uint32_t version; + + process(make_nvp("cereal_class_version", version)); + itsVersionedTypes.emplace_hint(lookupResult, hash, version); + + return version; + } + } + + //! Member serialization + /*! Versioning implementation */ + template inline ArchiveType & processImpl(T & t) + { + const auto version = loadClassVersion(); + access::member_serialize(*self, t, version); + return *self; + } + + //! Non member serialization + /*! Versioning implementation */ + template inline ArchiveType & processImpl(T & t) + { + const auto version = loadClassVersion(); + CEREAL_SERIALIZE_FUNCTION_NAME(*self, t, version); + return *self; + } + + //! Member split (load) + /*! Versioning implementation */ + template inline ArchiveType & processImpl(T & t) + { + const auto version = loadClassVersion(); + access::member_load(*self, t, version); + return *self; + } + + //! Non member split (load) + /*! Versioning implementation */ + template inline ArchiveType & processImpl(T & t) + { + const auto version = loadClassVersion(); + CEREAL_LOAD_FUNCTION_NAME(*self, t, version); + return *self; + } + + //! Member split (load_minimal) + /*! Versioning implementation */ + template inline ArchiveType & processImpl(T & t) + { + using OutArchiveType = typename traits::detail::get_output_from_input::type; + const auto version = loadClassVersion(); + typename traits::has_member_versioned_save_minimal::type value; + self->process(value); + access::member_load_minimal(*self, t, value, version); + return *self; + } + + //! Non member split (load_minimal) + /*! Versioning implementation */ + template inline ArchiveType & processImpl(T & t) + { + using OutArchiveType = typename traits::detail::get_output_from_input::type; + const auto version = loadClassVersion(); + typename traits::has_non_member_versioned_save_minimal::type value; + self->process(value); + CEREAL_LOAD_MINIMAL_FUNCTION_NAME(*self, t, value, version); + return *self; + } + +#undef PROCESS_IF + +private: + ArchiveType * const self; + + //! A set of all base classes that have been serialized + std::unordered_set itsBaseClassSet; + + //! Maps from pointer ids to metadata + std::unordered_map> itsSharedPointerMap; + + //! Maps from name ids to names + std::unordered_map itsPolymorphicTypeMap; + + //! Maps from type hash codes to version numbers + std::unordered_map itsVersionedTypes; +}; // class InputArchive +} // namespace cereal + +// This include needs to come after things such as binary_data, make_nvp, etc +#include "cereal/types/common.hpp" + +#endif // CEREAL_CEREAL_HPP_ diff --git a/minco_ws/src/navigation/minco_planner/include/cereal/details/helpers.hpp b/minco_ws/src/navigation/minco_planner/include/cereal/details/helpers.hpp new file mode 100644 index 0000000..2ffebf9 --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/include/cereal/details/helpers.hpp @@ -0,0 +1,412 @@ +/*! \file helpers.hpp + \brief Internal helper functionality + \ingroup Internal */ +/* + Copyright (c) 2014, Randolph Voorhies, Shane Grant + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef CEREAL_DETAILS_HELPERS_HPP_ +#define CEREAL_DETAILS_HELPERS_HPP_ + +#include +#include +#include +#include +#include +#include + +#include "cereal/details/static_object.hpp" +#include "cereal/macros.hpp" + +namespace cereal { +// ###################################################################### +//! An exception class thrown when things go wrong at runtime +/*! @ingroup Utility */ +struct Exception : public std::runtime_error +{ + explicit Exception(const std::string & what_) : std::runtime_error(what_) {} + explicit Exception(const char * what_) : std::runtime_error(what_) {} +}; + +// ###################################################################### +//! The size type used by cereal +/*! To ensure compatability between 32, 64, etc bit machines, we need to use + a fixed size type instead of size_t, which may vary from machine to + machine. + + The default value for CEREAL_SIZE_TYPE is specified in cereal/macros.hpp */ +using size_type = CEREAL_SIZE_TYPE; + +// forward decls +class BinaryOutputArchive; +class BinaryInputArchive; + +// ###################################################################### +namespace detail { +struct NameValuePairCore +{ +}; //!< Traits struct for NVPs +struct DeferredDataCore +{ +}; //!< Traits struct for DeferredData +} // namespace detail + +// ###################################################################### +//! For holding name value pairs +/*! This pairs a name (some string) with some value such that an archive + can potentially take advantage of the pairing. + + In serialization functions, NameValuePairs are usually created like so: + @code{.cpp} + struct MyStruct + { + int a, b, c, d, e; + + template + void serialize(Archive & archive) + { + archive( CEREAL_NVP(a), + CEREAL_NVP(b), + CEREAL_NVP(c), + CEREAL_NVP(d), + CEREAL_NVP(e) ); + } + }; + @endcode + + Alternatively, you can give you data members custom names like so: + @code{.cpp} + struct MyStruct + { + int a, b, my_embarrassing_variable_name, d, e; + + template + void serialize(Archive & archive) + { + archive( CEREAL_NVP(a), + CEREAL_NVP(b), + cereal::make_nvp("var", my_embarrassing_variable_name) ); + CEREAL_NVP(d), + CEREAL_NVP(e) ); + } + }; + @endcode + + There is a slight amount of overhead to creating NameValuePairs, so there + is a third method which will elide the names when they are not used by + the Archive: + + @code{.cpp} + struct MyStruct + { + int a, b; + + template + void serialize(Archive & archive) + { + archive( cereal::make_nvp(a), + cereal::make_nvp(b) ); + } + }; + @endcode + + This third method is generally only used when providing generic type + support. Users writing their own serialize functions will normally + explicitly control whether they want to use NVPs or not. + + @internal */ +template class NameValuePair : detail::NameValuePairCore +{ +private: + // If we get passed an array, keep the type as is, otherwise store + // a reference if we were passed an l value reference, else copy the value + using Type = typename std::conditional::type>::value, + typename std::remove_cv::type, + typename std::conditional::value, T, typename std::decay::type>::type>:: + type; + + // prevent nested nvps + static_assert( + !std::is_base_of::value, "Cannot pair a name to a NameValuePair"); + + NameValuePair & operator=(NameValuePair const &) = delete; + +public: + //! Constructs a new NameValuePair + /*! @param n The name of the pair + @param v The value to pair. Ideally this should be an l-value reference so that + the value can be both loaded and saved to. If you pass an r-value reference, + the NameValuePair will store a copy of it instead of a reference. Thus you should + only pass r-values in cases where this makes sense, such as the result of some + size() call. + @internal */ + NameValuePair(char const * n, T && v) : name(n), value(std::forward(v)) {} + + char const * name; + Type value; +}; + +//! A specialization of make_nvp<> that simply forwards the value for binary archives +/*! @relates NameValuePair + @internal */ +template +inline typename std::enable_if::value || + std::is_same::value, + T &&>::type +make_nvp(const char *, T && value) +{ + return std::forward(value); +} + +//! A specialization of make_nvp<> that actually creates an nvp for non-binary archives +/*! @relates NameValuePair + @internal */ +template +inline typename std::enable_if::value && + !std::is_same::value, + NameValuePair>::type +make_nvp(const char * name, T && value) +{ + return {name, std::forward(value)}; +} + +//! Convenience for creating a templated NVP +/*! For use in internal generic typing functions which have an + Archive type declared + @internal */ +#define CEREAL_NVP_(name, value) ::cereal::make_nvp(name, value) + +// ###################################################################### +//! A wrapper around data that can be serialized in a binary fashion +/*! This class is used to demarcate data that can safely be serialized + as a binary chunk of data. Individual archives can then choose how + best represent this during serialization. + + @internal */ +template struct BinaryData +{ + //! Internally store the pointer as a void *, keeping const if created with + //! a const pointer + using PT = typename std::conditional< + std::is_const::type>::type>::value, + const void *, + void *>::type; + + BinaryData(T && d, uint64_t s) : data(std::forward(d)), size(s) {} + + PT data; //!< pointer to beginning of data + uint64_t size; //!< size in bytes +}; + +// ###################################################################### +//! A wrapper around data that should be serialized after all non-deferred data +/*! This class is used to demarcate data that can only be safely serialized after + any data not wrapped in this class. + + @internal */ +template class DeferredData : detail::DeferredDataCore +{ +private: + // If we get passed an array, keep the type as is, otherwise store + // a reference if we were passed an l value reference, else copy the value + using Type = typename std::conditional::type>::value, + typename std::remove_cv::type, + typename std::conditional::value, T, typename std::decay::type>::type>:: + type; + + // prevent nested nvps + static_assert(!std::is_base_of::value, "Cannot defer DeferredData"); + + DeferredData & operator=(DeferredData const &) = delete; + +public: + //! Constructs a new NameValuePair + /*! @param v The value to defer. Ideally this should be an l-value reference so that + the value can be both loaded and saved to. If you pass an r-value reference, + the DeferredData will store a copy of it instead of a reference. Thus you should + only pass r-values in cases where this makes sense, such as the result of some + size() call. + @internal */ + DeferredData(T && v) : value(std::forward(v)) {} + + Type value; +}; + +// ###################################################################### +namespace detail { +// base classes for type checking +/* The rtti virtual function only exists to enable an archive to + be used in a polymorphic fashion, if necessary. See the + archive adapters for an example of this */ +class OutputArchiveBase +{ +public: + OutputArchiveBase() = default; + OutputArchiveBase(OutputArchiveBase &&) CEREAL_NOEXCEPT {} + OutputArchiveBase & operator=(OutputArchiveBase &&) CEREAL_NOEXCEPT { return *this; } + virtual ~OutputArchiveBase() CEREAL_NOEXCEPT = default; + +private: + virtual void rtti() {} +}; + +class InputArchiveBase +{ +public: + InputArchiveBase() = default; + InputArchiveBase(InputArchiveBase &&) CEREAL_NOEXCEPT {} + InputArchiveBase & operator=(InputArchiveBase &&) CEREAL_NOEXCEPT { return *this; } + virtual ~InputArchiveBase() CEREAL_NOEXCEPT = default; + +private: + virtual void rtti() {} +}; + +// forward decls for polymorphic support +template struct polymorphic_serialization_support; +struct adl_tag; + +// used during saving pointers +static const uint32_t msb_32bit = 0x80000000; +static const int32_t msb2_32bit = 0x40000000; +} // namespace detail + +// ###################################################################### +//! A wrapper around size metadata +/*! This class provides a way for archives to have more flexibility over how + they choose to serialize size metadata for containers. For some archive + types, the size may be implicitly encoded in the output (e.g. JSON) and + not need an explicit entry. Specializing serialize or load/save for + your archive and SizeTags allows you to choose what happens. + + @internal */ +template class SizeTag +{ +private: + // Store a reference if passed an lvalue reference, otherwise + // make a copy of the data + using Type = + typename std::conditional::value, T, typename std::decay::type>::type; + + SizeTag & operator=(SizeTag const &) = delete; + +public: + SizeTag(T && sz) : size(std::forward(sz)) {} + + Type size; +}; + +// ###################################################################### +//! A wrapper around a key and value for serializing data into maps. +/*! This class just provides a grouping of keys and values into a struct for + human readable archives. For example, XML archives will use this wrapper + to write maps like so: + + @code{.xml} + + + MyFirstKey + MyFirstValue + + + MySecondKey + MySecondValue + + + @endcode + + \sa make_map_item + @internal */ +template struct MapItem +{ + using KeyType = typename std:: + conditional::value, Key, typename std::decay::type>::type; + + using ValueType = typename std:: + conditional::value, Value, typename std::decay::type>::type; + + //! Construct a MapItem from a key and a value + /*! @internal */ + MapItem(Key && key_, Value && value_) : key(std::forward(key_)), value(std::forward(value_)) + { + } + + MapItem & operator=(MapItem const &) = delete; + + KeyType key; + ValueType value; + + //! Serialize the MapItem with the NVPs "key" and "value" + template inline void CEREAL_SERIALIZE_FUNCTION_NAME(Archive & archive) + { + archive(make_nvp("key", key), make_nvp("value", value)); + } +}; + +//! Create a MapItem so that human readable archives will group keys and values together +/*! @internal + @relates MapItem */ +template +inline MapItem make_map_item(KeyType && key, ValueType && value) +{ + return {std::forward(key), std::forward(value)}; +} + +namespace detail { +//! Tag for Version, which due to its anonymous namespace, becomes a different +//! type in each translation unit +/*! This allows CEREAL_CLASS_VERSION to be safely called in a header file */ +namespace { +struct version_binding_tag +{ +}; +} // namespace + +// ###################################################################### +//! Version information class +/*! This is the base case for classes that have not been explicitly + registered */ +template struct Version +{ + static const std::uint32_t version = 0; + // we don't need to explicitly register these types since they + // always get a version number of 0 +}; + +//! Holds all registered version information +struct Versions +{ + std::unordered_map mapping; + + std::uint32_t find(std::size_t hash, std::uint32_t version) + { + const auto result = mapping.emplace(hash, version); + return result.first->second; + } +}; // struct Versions +} // namespace detail +} // namespace cereal + +#endif // CEREAL_DETAILS_HELPERS_HPP_ diff --git a/minco_ws/src/navigation/minco_planner/include/cereal/details/polymorphic_impl.hpp b/minco_ws/src/navigation/minco_planner/include/cereal/details/polymorphic_impl.hpp new file mode 100644 index 0000000..e7aecf1 --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/include/cereal/details/polymorphic_impl.hpp @@ -0,0 +1,822 @@ +/*! \file polymorphic_impl.hpp + \brief Internal polymorphism support + \ingroup Internal */ +/* + Copyright (c) 2014, Randolph Voorhies, Shane Grant + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* This code is heavily inspired by the boost serialization implementation by the following authors + + (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . + Use, modification and distribution is subject to the Boost Software + License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt) + + See http://www.boost.org for updates, documentation, and revision history. + + (C) Copyright 2006 David Abrahams - http://www.boost.org. + + See /boost/serialization/export.hpp, /boost/archive/detail/register_archive.hpp, + and /boost/serialization/void_cast.hpp for their implementation. Additional details + found in other files split across serialization and archive. +*/ +#ifndef CEREAL_DETAILS_POLYMORPHIC_IMPL_HPP_ +#define CEREAL_DETAILS_POLYMORPHIC_IMPL_HPP_ + +#include "cereal/details/polymorphic_impl_fwd.hpp" +#include "cereal/details/static_object.hpp" +#include "cereal/types/memory.hpp" +#include "cereal/types/string.hpp" +#include +#include +#include +#include +#include +#include + +//! Helper macro to omit unused warning +#if defined(__GNUC__) +// GCC / clang don't want the function +#define CEREAL_BIND_TO_ARCHIVES_UNUSED_FUNCTION +#else +#define CEREAL_BIND_TO_ARCHIVES_UNUSED_FUNCTION \ +static void unused() \ +{ \ +(void)b; \ +} +#endif + +//! Binds a polymorhic type to all registered archives +/*! This binds a polymorphic type to all compatible registered archives that + have been registered with CEREAL_REGISTER_ARCHIVE. This must be called + after all archives are registered (usually after the archives themselves + have been included). */ +#ifdef CEREAL_HAS_CPP17 +#define CEREAL_BIND_TO_ARCHIVES(...) \ +namespace cereal { \ +namespace detail { \ +template <> struct init_binding<__VA_ARGS__> \ +{ \ +static inline bind_to_archives<__VA_ARGS__> const & b = \ + ::cereal::detail::StaticObject>::getInstance().bind(); \ +CEREAL_BIND_TO_ARCHIVES_UNUSED_FUNCTION \ +}; \ +} \ +} /* end namespaces */ +#else +#define CEREAL_BIND_TO_ARCHIVES(...) \ +namespace cereal { \ +namespace detail { \ +template <> struct init_binding<__VA_ARGS__> \ +{ \ +static bind_to_archives<__VA_ARGS__> const & b; \ +CEREAL_BIND_TO_ARCHIVES_UNUSED_FUNCTION \ +}; \ +bind_to_archives<__VA_ARGS__> const & init_binding<__VA_ARGS__>::b = \ + ::cereal::detail::StaticObject>::getInstance().bind(); \ +} \ +} /* end namespaces */ +#endif + +namespace cereal { +/* Polymorphic casting support */ +namespace detail { +//! Base type for polymorphic void casting +/*! Contains functions for casting between registered base and derived types. + + This is necessary so that cereal can properly cast between polymorphic types + even though void pointers are used, which normally have no type information. + Runtime type information is used instead to index a compile-time made mapping + that can perform the proper cast. In the case of multiple levels of inheritance, + cereal will attempt to find the shortest path by using registered relationships to + perform the cast. + + This class will be allocated as a StaticObject and only referenced by pointer, + allowing a templated derived version of it to define strongly typed functions + that cast between registered base and derived types. */ +struct PolymorphicCaster +{ + PolymorphicCaster() = default; + PolymorphicCaster(const PolymorphicCaster &) = default; + PolymorphicCaster & operator=(const PolymorphicCaster &) = default; + PolymorphicCaster(PolymorphicCaster &&) CEREAL_NOEXCEPT {} + PolymorphicCaster & operator=(PolymorphicCaster &&) CEREAL_NOEXCEPT { return *this; } + virtual ~PolymorphicCaster() CEREAL_NOEXCEPT = default; + + //! Downcasts to the proper derived type + virtual void const * downcast(void const * const ptr) const = 0; + //! Upcast to proper base type + virtual void * upcast(void * const ptr) const = 0; + //! Upcast to proper base type, shared_ptr version + virtual std::shared_ptr upcast(std::shared_ptr const & ptr) const = 0; +}; + +//! Holds registered mappings between base and derived types for casting +/*! This will be allocated as a StaticObject and holds a map containing + all registered mappings between base and derived types. */ +struct PolymorphicCasters +{ + //! Maps from a derived type index to a set of chainable casters + using DerivedCasterMap = std::unordered_map>; + //! Maps from base type index to a map from derived type index to caster + std::unordered_map map; + + std::multimap reverseMap; + +//! Error message used for unregistered polymorphic casts +#define UNREGISTERED_POLYMORPHIC_CAST_EXCEPTION(LoadSave) \ +throw cereal::Exception( \ + "Trying to " #LoadSave " a registered polymorphic type with an unregistered polymorphic cast.\n" \ + "Could not find a path to a base class (" + \ + util::demangle(baseInfo.name()) + ") for type: " + ::cereal::util::demangledName() + \ + "\n" \ + "Make sure you either serialize the base class at some point via cereal::base_class or " \ + "cereal::virtual_base_class.\n" \ + "Alternatively, manually register the association with CEREAL_REGISTER_POLYMORPHIC_RELATION."); + + //! Checks if the mapping object that can perform the upcast or downcast exists, and returns it if so + /*! Uses the type index from the base and derived class to find the matching + registered caster. If no matching caster exists, the bool in the pair will be false and the vector + reference should not be used. */ + static std::pair const &> lookup_if_exists( + std::type_index const & baseIndex, std::type_index const & derivedIndex) + { + // First phase of lookup - match base type index + auto const & baseMap = StaticObject::getInstance().map; + auto baseIter = baseMap.find(baseIndex); + if (baseIter == baseMap.end()) + return {false, {}}; + + // Second phase - find a match from base to derived + auto const & derivedMap = baseIter->second; + auto derivedIter = derivedMap.find(derivedIndex); + if (derivedIter == derivedMap.end()) + return {false, {}}; + + return {true, derivedIter->second}; + } + + //! Gets the mapping object that can perform the upcast or downcast + /*! Uses the type index from the base and derived class to find the matching + registered caster. If no matching caster exists, calls the exception function. + + The returned PolymorphicCaster is capable of upcasting or downcasting between the two types. */ + template + inline static std::vector const & lookup( + std::type_index const & baseIndex, std::type_index const & derivedIndex, F && exceptionFunc) + { + // First phase of lookup - match base type index + auto const & baseMap = StaticObject::getInstance().map; + auto baseIter = baseMap.find(baseIndex); + if (baseIter == baseMap.end()) + exceptionFunc(); + + // Second phase - find a match from base to derived + auto const & derivedMap = baseIter->second; + auto derivedIter = derivedMap.find(derivedIndex); + if (derivedIter == derivedMap.end()) + exceptionFunc(); + + return derivedIter->second; + } + + //! Performs a downcast to the derived type using a registered mapping + template + inline static const Derived * downcast(const void * dptr, std::type_info const & baseInfo) + { + auto const & mapping = lookup(baseInfo, typeid(Derived), [&]() { + UNREGISTERED_POLYMORPHIC_CAST_EXCEPTION(save) + }); + + for (auto const * dmap : mapping) + dptr = dmap->downcast(dptr); + + return static_cast(dptr); + } + + //! Performs an upcast to the registered base type using the given a derived type + /*! The return is untyped because the final casting to the base type must happen in the polymorphic + serialization function, where the type is known at compile time */ + template + inline static void * upcast(Derived * const dptr, std::type_info const & baseInfo) + { + auto const & mapping = lookup(baseInfo, typeid(Derived), [&]() { + UNREGISTERED_POLYMORPHIC_CAST_EXCEPTION(load) + }); + + void * uptr = dptr; + for (auto mIter = mapping.rbegin(), mEnd = mapping.rend(); mIter != mEnd; ++mIter) + uptr = (*mIter)->upcast(uptr); + + return uptr; + } + + //! Upcasts for shared pointers + template + inline static std::shared_ptr upcast( + std::shared_ptr const & dptr, std::type_info const & baseInfo) + { + auto const & mapping = lookup(baseInfo, typeid(Derived), [&]() { + UNREGISTERED_POLYMORPHIC_CAST_EXCEPTION(load) + }); + + std::shared_ptr uptr = dptr; + for (auto mIter = mapping.rbegin(), mEnd = mapping.rend(); mIter != mEnd; ++mIter) + uptr = (*mIter)->upcast(uptr); + + return uptr; + } + +#undef UNREGISTERED_POLYMORPHIC_CAST_EXCEPTION +}; + +#ifdef CEREAL_OLDER_GCC +#define CEREAL_EMPLACE_MAP(map, key, value) map.insert(std::make_pair(std::move(key), std::move(value))); +#else // NOT CEREAL_OLDER_GCC +#define CEREAL_EMPLACE_MAP(map, key, value) map.emplace(key, value); +#endif // NOT_CEREAL_OLDER_GCC + +//! Strongly typed derivation of PolymorphicCaster +template struct PolymorphicVirtualCaster : PolymorphicCaster +{ + //! Inserts an entry in the polymorphic casting map for this pairing + /*! Creates an explicit mapping between Base and Derived in both upwards and + downwards directions, allowing void pointers to either to be properly cast + assuming dynamic type information is available */ + PolymorphicVirtualCaster() + { + const auto baseKey = std::type_index(typeid(Base)); + const auto derivedKey = std::type_index(typeid(Derived)); + + // First insert the relation Base->Derived + const auto lock = StaticObject::lock(); + auto & baseMap = StaticObject::getInstance().map; + + { + auto & derivedMap = baseMap.insert({baseKey, PolymorphicCasters::DerivedCasterMap{}}).first->second; + auto & derivedVec = derivedMap.insert({derivedKey, {}}).first->second; + derivedVec.push_back(this); + } + + // Insert reverse relation Derived->Base + auto & reverseMap = StaticObject::getInstance().reverseMap; + CEREAL_EMPLACE_MAP(reverseMap, derivedKey, baseKey); + + // Find all chainable unregistered relations + /* The strategy here is to process only the nodes in the class hierarchy graph that have been + affected by the new insertion. The aglorithm iteratively processes a node an ensures that it + is updated with all new shortest length paths. It then rocesses the parents of the active node, + with the knowledge that all children have already been processed. + + Note that for the following, we'll use the nomenclature of parent and child to not confuse with + the inserted base derived relationship */ + { + // Checks whether there is a path from parent->child and returns a pair + // dist is set to MAX if the path does not exist + auto checkRelation = [](std::type_index const & parentInfo, std::type_index const & childInfo) + -> std::pair const &> { + auto result = PolymorphicCasters::lookup_if_exists(parentInfo, childInfo); + if (result.first) { + auto const & path = result.second; + return {path.size(), path}; + } else + return {(std::numeric_limits::max)(), {}}; + }; + + std::stack parentStack; // Holds the parent nodes to be processed + std::vector dirtySet; // Marks child nodes that have been changed + std::unordered_set processedParents; // Marks parent nodes that have been processed + + // Checks if a child has been marked dirty + auto isDirty = [&](std::type_index const & c) { + auto const dirtySetSize = dirtySet.size(); + for (size_t i = 0; i < dirtySetSize; ++i) + if (dirtySet[i] == c) + return true; + + return false; + }; + + // Begin processing the base key and mark derived as dirty + parentStack.push(baseKey); + dirtySet.emplace_back(derivedKey); + + while (!parentStack.empty()) { + using Relations = std::unordered_multimap>>; + Relations + unregisteredRelations; // Defer insertions until after main loop to prevent iterator invalidation + + const auto parent = parentStack.top(); + parentStack.pop(); + + // Update paths to all children marked dirty + for (auto const & childPair : baseMap[parent]) { + const auto child = childPair.first; + if (isDirty(child) && baseMap.count(child)) { + auto parentChildPath = checkRelation(parent, child); + + // Search all paths from the child to its own children (finalChild), + // looking for a shorter parth from parent to finalChild + for (auto const & finalChildPair : baseMap[child]) { + const auto finalChild = finalChildPair.first; + + auto parentFinalChildPath = checkRelation(parent, finalChild); + auto childFinalChildPath = checkRelation(child, finalChild); + + const size_t newLength = 1u + parentChildPath.first; + + if (newLength < parentFinalChildPath.first) { + std::vector path = parentChildPath.second; + path.insert( + path.end(), childFinalChildPath.second.begin(), childFinalChildPath.second.end()); + + // Check to see if we have a previous uncommitted path in unregisteredRelations + // that is shorter. If so, ignore this path + auto hintRange = unregisteredRelations.equal_range(parent); + auto hint = hintRange.first; + for (; hint != hintRange.second; ++hint) + if (hint->second.first == finalChild) + break; + + const bool uncommittedExists = hint != unregisteredRelations.end(); + if (uncommittedExists && (hint->second.second.size() <= newLength)) + continue; + + auto newPath = std::pair>{ + finalChild, std::move(path)}; + +// Insert the new path if it doesn't exist, otherwise this will just lookup where to do the +// replacement +#ifdef CEREAL_OLDER_GCC + auto old = unregisteredRelations.insert(hint, std::make_pair(parent, newPath)); +#else // NOT CEREAL_OLDER_GCC + auto old = unregisteredRelations.emplace_hint(hint, parent, newPath); +#endif // NOT CEREAL_OLDER_GCC + + // If there was an uncommitted path, we need to perform a replacement + if (uncommittedExists) + old->second = newPath; + } + } // end loop over child's children + } // end if dirty and child has children + } // end loop over children + + // Insert chained relations + for (auto const & it : unregisteredRelations) { + auto & derivedMap = baseMap.find(it.first)->second; + derivedMap[it.second.first] = it.second.second; + CEREAL_EMPLACE_MAP(reverseMap, it.second.first, it.first); + } + + // Mark current parent as modified + dirtySet.emplace_back(parent); + + // Insert all parents of the current parent node that haven't yet been processed + auto parentRange = reverseMap.equal_range(parent); + for (auto pIter = parentRange.first; pIter != parentRange.second; ++pIter) { + const auto pParent = pIter->second; + if (!processedParents.count(pParent)) { + parentStack.push(pParent); + processedParents.insert(pParent); + } + } + } // end loop over parent stack + } // end chainable relations + } // end PolymorphicVirtualCaster() + +#undef CEREAL_EMPLACE_MAP + + //! Performs the proper downcast with the templated types + void const * downcast(void const * const ptr) const override + { + return dynamic_cast(static_cast(ptr)); + } + + //! Performs the proper upcast with the templated types + void * upcast(void * const ptr) const override + { + return dynamic_cast(static_cast(ptr)); + } + + //! Performs the proper upcast with the templated types (shared_ptr version) + std::shared_ptr upcast(std::shared_ptr const & ptr) const override + { + return std::dynamic_pointer_cast(std::static_pointer_cast(ptr)); + } +}; + +//! Registers a polymorphic casting relation between a Base and Derived type +/*! Registering a relation allows cereal to properly cast between the two types + given runtime type information and void pointers. + + Registration happens automatically via cereal::base_class and cereal::virtual_base_class + instantiations. For cases where neither is called, see the CEREAL_REGISTER_POLYMORPHIC_RELATION + macro */ +template struct RegisterPolymorphicCaster +{ + static PolymorphicCaster const * bind(std::true_type /* is_polymorphic */) + { + return &StaticObject>::getInstance(); + } + + static PolymorphicCaster const * bind(std::false_type /* is_polymorphic */) { return nullptr; } + + //! Performs registration (binding) between Base and Derived + /*! If the type is not polymorphic, nothing will happen */ + static PolymorphicCaster const * bind() { return bind(typename std::is_polymorphic::type()); } +}; +} // namespace detail + +/* General polymorphism support */ +namespace detail { +//! Binds a compile time type with a user defined string +template struct binding_name +{ +}; + +//! A structure holding a map from type_indices to output serializer functions +/*! A static object of this map should be created for each registered archive + type, containing entries for every registered type that describe how to + properly cast the type to its real type in polymorphic scenarios for + shared_ptr, weak_ptr, and unique_ptr. */ +template struct OutputBindingMap +{ + //! A serializer function + /*! Serializer functions return nothing and take an archive as + their first parameter (will be cast properly inside the function, + a pointer to actual data (contents of smart_ptr's get() function) + as their second parameter, and the type info of the owning smart_ptr + as their final parameter */ + typedef std::function Serializer; + + //! Struct containing the serializer functions for all pointer types + struct Serializers + { + Serializer shared_ptr, //!< Serializer function for shared/weak pointers + unique_ptr; //!< Serializer function for unique pointers + }; + + //! A map of serializers for pointers of all registered types + std::map map; +}; + +//! An empty noop deleter +template struct EmptyDeleter +{ + void operator()(T *) const {} +}; + +//! A structure holding a map from type name strings to input serializer functions +/*! A static object of this map should be created for each registered archive + type, containing entries for every registered type that describe how to + properly cast the type to its real type in polymorphic scenarios for + shared_ptr, weak_ptr, and unique_ptr. */ +template struct InputBindingMap +{ + //! Shared ptr serializer function + /*! Serializer functions return nothing and take an archive as + their first parameter (will be cast properly inside the function, + a shared_ptr (or unique_ptr for the unique case) of any base + type, and the type id of said base type as the third parameter. + Internally it will properly be loaded and cast to the correct type. */ + typedef std::function &, std::type_info const &)> SharedSerializer; + //! Unique ptr serializer function + typedef std::function> &, std::type_info const &)> + UniqueSerializer; + + //! Struct containing the serializer functions for all pointer types + struct Serializers + { + SharedSerializer shared_ptr; //!< Serializer function for shared/weak pointers + UniqueSerializer unique_ptr; //!< Serializer function for unique pointers + }; + + //! A map of serializers for pointers of all registered types + std::map map; +}; + +// forward decls for archives from cereal.hpp +class InputArchiveBase; +class OutputArchiveBase; + +//! Creates a binding (map entry) between an input archive type and a polymorphic type +/*! Bindings are made when types are registered, assuming that at least one + archive has already been registered. When this struct is created, + it will insert (at run time) an entry into a map that properly handles + casting for serializing polymorphic objects */ +template struct InputBindingCreator +{ + //! Initialize the binding + InputBindingCreator() + { + auto & map = StaticObject>::getInstance().map; + auto lock = StaticObject>::lock(); + auto key = std::string(binding_name::name()); + auto lb = map.lower_bound(key); + + if (lb != map.end() && lb->first == key) + return; + + typename InputBindingMap::Serializers serializers; + + serializers.shared_ptr = + [](void * arptr, std::shared_ptr & dptr, std::type_info const & baseInfo) { + Archive & ar = *static_cast(arptr); + std::shared_ptr ptr; + + ar(CEREAL_NVP_("ptr_wrapper", ::cereal::memory_detail::make_ptr_wrapper(ptr))); + + dptr = PolymorphicCasters::template upcast(ptr, baseInfo); + }; + + serializers.unique_ptr = + [](void * arptr, std::unique_ptr> & dptr, std::type_info const & baseInfo) { + Archive & ar = *static_cast(arptr); + std::unique_ptr ptr; + + ar(CEREAL_NVP_("ptr_wrapper", ::cereal::memory_detail::make_ptr_wrapper(ptr))); + + dptr.reset(PolymorphicCasters::template upcast(ptr.release(), baseInfo)); + }; + + map.insert(lb, {std::move(key), std::move(serializers)}); + } +}; + +//! Creates a binding (map entry) between an output archive type and a polymorphic type +/*! Bindings are made when types are registered, assuming that at least one + archive has already been registered. When this struct is created, + it will insert (at run time) an entry into a map that properly handles + casting for serializing polymorphic objects */ +template struct OutputBindingCreator +{ + //! Writes appropriate metadata to the archive for this polymorphic type + static void writeMetadata(Archive & ar) + { + // Register the polymorphic type name with the archive, and get the id + char const * name = binding_name::name(); + std::uint32_t id = ar.registerPolymorphicType(name); + + // Serialize the id + ar(CEREAL_NVP_("polymorphic_id", id)); + + // If the msb of the id is 1, then the type name is new, and we should serialize it + if (id & detail::msb_32bit) { + std::string namestring(name); + ar(CEREAL_NVP_("polymorphic_name", namestring)); + } + } + + //! Holds a properly typed shared_ptr to the polymorphic type + class PolymorphicSharedPointerWrapper + { + public: + /*! Wrap a raw polymorphic pointer in a shared_ptr to its true type + + The wrapped pointer will not be responsible for ownership of the held pointer + so it will not attempt to destroy it; instead the refcount of the wrapped + pointer will be tied to a fake 'ownership pointer' that will do nothing + when it ultimately goes out of scope. + + The main reason for doing this, other than not to destroy the true object + with our wrapper pointer, is to avoid meddling with the internal reference + count in a polymorphic type that inherits from std::enable_shared_from_this. + + @param dptr A void pointer to the contents of the shared_ptr to serialize */ + PolymorphicSharedPointerWrapper(T const * dptr) : refCount(), wrappedPtr(refCount, dptr) {} + + //! Get the wrapped shared_ptr */ + inline std::shared_ptr const & operator()() const { return wrappedPtr; } + + private: + std::shared_ptr refCount; //!< The ownership pointer + std::shared_ptr wrappedPtr; //!< The wrapped pointer + }; + + //! Does the actual work of saving a polymorphic shared_ptr + /*! This function will properly create a shared_ptr from the void * that is passed in + before passing it to the archive for serialization. + + In addition, this will also preserve the state of any internal enable_shared_from_this mechanisms + + @param ar The archive to serialize to + @param dptr Pointer to the actual data held by the shared_ptr */ + static inline void savePolymorphicSharedPtr( + Archive & ar, T const * dptr, std::true_type /* has_shared_from_this */) + { + ::cereal::memory_detail::EnableSharedStateHelper state(const_cast(dptr)); + PolymorphicSharedPointerWrapper psptr(dptr); + ar(CEREAL_NVP_("ptr_wrapper", memory_detail::make_ptr_wrapper(psptr()))); + } + + //! Does the actual work of saving a polymorphic shared_ptr + /*! This function will properly create a shared_ptr from the void * that is passed in + before passing it to the archive for serialization. + + This version is for types that do not inherit from std::enable_shared_from_this. + + @param ar The archive to serialize to + @param dptr Pointer to the actual data held by the shared_ptr */ + static inline void savePolymorphicSharedPtr( + Archive & ar, T const * dptr, std::false_type /* has_shared_from_this */) + { + PolymorphicSharedPointerWrapper psptr(dptr); + ar(CEREAL_NVP_("ptr_wrapper", memory_detail::make_ptr_wrapper(psptr()))); + } + + //! Initialize the binding + OutputBindingCreator() + { + auto & map = StaticObject>::getInstance().map; + auto key = std::type_index(typeid(T)); + auto lb = map.lower_bound(key); + + if (lb != map.end() && lb->first == key) + return; + + typename OutputBindingMap::Serializers serializers; + + serializers.shared_ptr = [&](void * arptr, void const * dptr, std::type_info const & baseInfo) { + Archive & ar = *static_cast(arptr); + writeMetadata(ar); + + auto ptr = PolymorphicCasters::template downcast(dptr, baseInfo); + +#if defined(_MSC_VER) && _MSC_VER < 1916 && !defined(__clang__) + savePolymorphicSharedPtr( + ar, ptr, ::cereal::traits::has_shared_from_this::type()); // MSVC doesn't like typename here +#else // not _MSC_VER + savePolymorphicSharedPtr(ar, ptr, typename ::cereal::traits::has_shared_from_this::type()); +#endif // _MSC_VER + }; + + serializers.unique_ptr = [&](void * arptr, void const * dptr, std::type_info const & baseInfo) { + Archive & ar = *static_cast(arptr); + writeMetadata(ar); + + std::unique_ptr> const ptr( + PolymorphicCasters::template downcast(dptr, baseInfo)); + + ar(CEREAL_NVP_("ptr_wrapper", memory_detail::make_ptr_wrapper(ptr))); + }; + + map.insert({std::move(key), std::move(serializers)}); + } +}; + +//! Used to help out argument dependent lookup for finding potential overloads +//! of instantiate_polymorphic_binding +struct adl_tag +{ +}; + +//! Tag for init_binding, bind_to_archives and instantiate_polymorphic_binding. +//! For C++14 and below, we must instantiate a unique StaticObject per TU that is +//! otherwise identical -- otherwise we get multiple definition problems (ODR violations). +//! To achieve this, put a tag in an anonymous namespace and use it as a template argument. +//! +//! For C++17, we can use static inline global variables to unify these definitions across +//! all TUs in the same shared object (DLL). The tag is therefore not necessary. +//! For convenience, keep it to not complicate other code, but don't put it in +//! an anonymous namespace. Now the template instantiations will correspond +//! to the same type, and since they are marked inline with C++17, they will be merged +//! across all TUs. +#ifdef CEREAL_HAS_CPP17 +struct polymorphic_binding_tag +{ +}; +#else +namespace { +struct polymorphic_binding_tag +{ +}; +} // namespace +#endif + +//! Causes the static object bindings between an archive type and a serializable type T +template struct create_bindings +{ + static const InputBindingCreator & load(std::true_type) + { + return cereal::detail::StaticObject>::getInstance(); + } + + static const OutputBindingCreator & save(std::true_type) + { + return cereal::detail::StaticObject>::getInstance(); + } + + inline static void load(std::false_type) {} + inline static void save(std::false_type) {} +}; + +//! When specialized, causes the compiler to instantiate its parameter +template struct instantiate_function +{ +}; + +/*! This struct is used as the return type of instantiate_polymorphic_binding + for specific Archive types. When the compiler looks for overloads of + instantiate_polymorphic_binding, it will be forced to instantiate this + struct during overload resolution, even though it will not be part of a valid + overload */ +template struct polymorphic_serialization_support +{ +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) + //! Creates the appropriate bindings depending on whether the archive supports + //! saving or loading + virtual CEREAL_DLL_EXPORT void instantiate() CEREAL_USED; +#else // NOT _MSC_VER + //! Creates the appropriate bindings depending on whether the archive supports + //! saving or loading + static CEREAL_DLL_EXPORT void instantiate() CEREAL_USED; + //! This typedef causes the compiler to instantiate this static function + typedef instantiate_function unused; +#endif // _MSC_VER +}; + +// instantiate implementation +template +CEREAL_DLL_EXPORT void polymorphic_serialization_support::instantiate() +{ + create_bindings::save(std::integral_constant < bool, + std::is_base_of::value && + traits::is_output_serializable::value > {}); + + create_bindings::load(std::integral_constant < bool, + std::is_base_of::value && + traits::is_input_serializable::value > {}); +} + +//! Begins the binding process of a type to all registered archives +/*! Archives need to be registered prior to this struct being instantiated via + the CEREAL_REGISTER_ARCHIVE macro. Overload resolution will then force + several static objects to be made that allow us to bind together all + registered archive types with the parameter type T. */ +template struct bind_to_archives +{ + //! Binding for non abstract types + void bind(std::false_type) const + { + instantiate_polymorphic_binding(static_cast(nullptr), 0, Tag{}, adl_tag{}); + } + + //! Binding for abstract types + void bind(std::true_type) const {} + + //! Binds the type T to all registered archives + /*! If T is abstract, we will not serialize it and thus + do not need to make a binding */ + bind_to_archives const & bind() const + { + static_assert(std::is_polymorphic::value, "Attempting to register non polymorphic type"); + bind(std::is_abstract()); + return *this; + } +}; + +//! Used to hide the static object used to bind T to registered archives +template struct init_binding; + +//! Base case overload for instantiation +/*! This will end up always being the best overload due to the second + parameter always being passed as an int. All other overloads will + accept pointers to archive types and have lower precedence than int. + + Since the compiler needs to check all possible overloads, the + other overloads created via CEREAL_REGISTER_ARCHIVE, which will have + lower precedence due to requring a conversion from int to (Archive*), + will cause their return types to be instantiated through the static object + mechanisms even though they are never called. + + See the documentation for the other functions to try and understand this */ +template void instantiate_polymorphic_binding(T *, int, BindingTag, adl_tag) +{ +} +} // namespace detail +} // namespace cereal + +#endif // CEREAL_DETAILS_POLYMORPHIC_IMPL_HPP_ diff --git a/minco_ws/src/navigation/minco_planner/include/cereal/details/polymorphic_impl_fwd.hpp b/minco_ws/src/navigation/minco_planner/include/cereal/details/polymorphic_impl_fwd.hpp new file mode 100644 index 0000000..9020487 --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/include/cereal/details/polymorphic_impl_fwd.hpp @@ -0,0 +1,61 @@ +/*! \file polymorphic_impl_fwd.hpp + \brief Internal polymorphism support forward declarations + \ingroup Internal */ +/* + Copyright (c) 2014, Randolph Voorhies, Shane Grant + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* This code is heavily inspired by the boost serialization implementation by the following authors + + (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . + Use, modification and distribution is subject to the Boost Software + License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt) + + See http://www.boost.org for updates, documentation, and revision history. + + (C) Copyright 2006 David Abrahams - http://www.boost.org. + + See /boost/serialization/export.hpp and /boost/archive/detail/register_archive.hpp for their + implementation. +*/ + +#ifndef CEREAL_DETAILS_POLYMORPHIC_IMPL_FWD_HPP_ +#define CEREAL_DETAILS_POLYMORPHIC_IMPL_FWD_HPP_ + +namespace cereal { +namespace detail { +//! Forward declaration, see polymorphic_impl.hpp for more information +template struct RegisterPolymorphicCaster; + +//! Forward declaration, see polymorphic_impl.hpp for more information +struct PolymorphicCasters; + +//! Forward declaration, see polymorphic_impl.hpp for more information +template struct PolymorphicRelation; +} // namespace detail +} // namespace cereal + +#endif // CEREAL_DETAILS_POLYMORPHIC_IMPL_FWD_HPP_ diff --git a/minco_ws/src/navigation/minco_planner/include/cereal/details/static_object.hpp b/minco_ws/src/navigation/minco_planner/include/cereal/details/static_object.hpp new file mode 100644 index 0000000..8d63edb --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/include/cereal/details/static_object.hpp @@ -0,0 +1,126 @@ +/*! \file static_object.hpp + \brief Internal polymorphism static object support + \ingroup Internal */ +/* + Copyright (c) 2014, Randolph Voorhies, Shane Grant + All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef CEREAL_DETAILS_STATIC_OBJECT_HPP_ +#define CEREAL_DETAILS_STATIC_OBJECT_HPP_ + +#include "cereal/macros.hpp" + +#if CEREAL_THREAD_SAFE +#include +#endif + +//! Prevent link optimization from removing non-referenced static objects +/*! Especially for polymorphic support, we create static objects which + may not ever be explicitly referenced. Most linkers will detect this + and remove the code causing various unpleasant runtime errors. These + macros, adopted from Boost (see force_include.hpp) prevent this + (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . + Use, modification and distribution is subject to the Boost Software + License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) */ + +#if defined(_MSC_VER) && !defined(__clang__) +#define CEREAL_DLL_EXPORT __declspec(dllexport) +#define CEREAL_USED +#else // clang or gcc +#define CEREAL_DLL_EXPORT __attribute__((visibility("default"))) +#define CEREAL_USED __attribute__((__used__)) +#endif + +namespace cereal { +namespace detail { +//! A static, pre-execution object +/*! This class will create a single copy (singleton) of some + type and ensures that merely referencing this type will + cause it to be instantiated and initialized pre-execution. + For example, this is used heavily in the polymorphic pointer + serialization mechanisms to bind various archive types with + different polymorphic classes */ +template class CEREAL_DLL_EXPORT StaticObject +{ +private: + static T & create() + { + static T t; + //! Forces instantiation at pre-execution time + (void)instance; + return t; + } + + StaticObject(StaticObject const & /*other*/) {} + +public: + static T & getInstance() { return create(); } + + //! A class that acts like std::lock_guard + class LockGuard + { +#if CEREAL_THREAD_SAFE + public: + LockGuard(std::mutex & m) : lock(m) + { + } + + private: + std::unique_lock lock; +#else + public: + LockGuard() = default; + LockGuard(LockGuard const &) = default; // prevents implicit copy ctor warning + ~LockGuard() CEREAL_NOEXCEPT + { + } // prevents variable not used +#endif + }; + + //! Attempts to lock this static object for the current scope + /*! @note This function is a no-op if cereal is not compiled with + thread safety enabled (CEREAL_THREAD_SAFE = 1). + + This function returns an object that holds a lock for + this StaticObject that will release its lock upon destruction. This + call will block until the lock is available. */ + static LockGuard lock() + { +#if CEREAL_THREAD_SAFE + static std::mutex instanceMutex; + return LockGuard{instanceMutex}; +#else + return LockGuard{}; +#endif + } + +private: + static T & instance; +}; + +template T & StaticObject::instance = StaticObject::create(); +} // namespace detail +} // namespace cereal + +#endif // CEREAL_DETAILS_STATIC_OBJECT_HPP_ diff --git a/minco_ws/src/navigation/minco_planner/include/cereal/details/traits.hpp b/minco_ws/src/navigation/minco_planner/include/cereal/details/traits.hpp new file mode 100644 index 0000000..107b143 --- /dev/null +++ b/minco_ws/src/navigation/minco_planner/include/cereal/details/traits.hpp @@ -0,0 +1,1552 @@ +/*! \file traits.hpp + \brief Internal type trait support + \ingroup Internal */ +/* + Copyright (c) 2014, Randolph Voorhies, Shane Grant + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef CEREAL_DETAILS_TRAITS_HPP_ +#define CEREAL_DETAILS_TRAITS_HPP_ + +#ifndef __clang__ +#if (__GNUC__ == 4 && __GNUC_MINOR__ <= 7) +#define CEREAL_OLDER_GCC +#endif // gcc 4.7 or earlier +#endif // __clang__ + +#include +#include + +#include "cereal/access.hpp" +#include "cereal/macros.hpp" + +namespace cereal { +namespace traits { +using yes = std::true_type; +using no = std::false_type; + +namespace detail { +// ###################################################################### +//! Used to delay a static_assert until template instantiation +template struct delay_static_assert : std::false_type +{ +}; + +// ###################################################################### +// SFINAE Helpers +#ifdef CEREAL_OLDER_GCC // when VS supports better SFINAE, we can use this as the default +template struct Void +{ + typedef void type; +}; +#endif // CEREAL_OLDER_GCC + +//! Return type for SFINAE Enablers +enum class sfinae +{ +}; + +// ###################################################################### +// Helper functionality for boolean integral constants and Enable/DisableIf +template +struct meta_bool_and : std::integral_constant::value> +{ +}; +template struct meta_bool_and : std::integral_constant +{ +}; + +template +struct meta_bool_or : std::integral_constant::value> +{ +}; +template struct meta_bool_or : std::integral_constant +{ +}; + +// workaround needed due to bug in MSVC 2013, see +// http://connect.microsoft.com/VisualStudio/feedback/details/800231/c-11-alias-template-issue +template +struct EnableIfHelper : std::enable_if::value, sfinae> +{ +}; + +template +struct DisableIfHelper : std::enable_if::value, sfinae> +{ +}; +} // namespace detail + +//! Used as the default value for EnableIf and DisableIf template parameters +/*! @relates EnableIf + @relates DisableIf */ +static const detail::sfinae sfinae = {}; + +// ###################################################################### +//! Provides a way to enable a function if conditions are met +/*! This is intended to be used in a near identical fashion to std::enable_if + while being significantly easier to read at the cost of not allowing for as + complicated of a condition. + + This will compile (allow the function) if every condition evaluates to true. + at compile time. This should be used with SFINAE to ensure that at least + one other candidate function works when one fails due to an EnableIf. + + This should be used as the las template parameter to a function as + an unnamed parameter with a default value of cereal::traits::sfinae: + + @code{cpp} + // using by making the last template argument variadic + template ::value> = sfinae> + void func(T t ); + @endcode + + Note that this performs a logical AND of all conditions, so you will need + to construct more complicated requirements with this fact in mind. + + @relates DisableIf + @relates sfinae + @tparam Conditions The conditions which will be logically ANDed to enable the function. */ +template using EnableIf = typename detail::EnableIfHelper::type; + +// ###################################################################### +//! Provides a way to disable a function if conditions are met +/*! This is intended to be used in a near identical fashion to std::enable_if + while being significantly easier to read at the cost of not allowing for as + complicated of a condition. + + This will compile (allow the function) if every condition evaluates to false. + This should be used with SFINAE to ensure that at least one other candidate + function works when one fails due to a DisableIf. + + This should be used as the las template parameter to a function as + an unnamed parameter with a default value of cereal::traits::sfinae: + + @code{cpp} + // using by making the last template argument variadic + template ::value> = sfinae> + void func(T t ); + @endcode + + This is often used in conjunction with EnableIf to form an enable/disable pair of + overloads. + + Note that this performs a logical AND of all conditions, so you will need + to construct more complicated requirements with this fact in mind. If all conditions + hold, the function will be disabled. + + @relates EnableIf + @relates sfinae + @tparam Conditions The conditions which will be logically ANDed to disable the function. */ +template using DisableIf = typename detail::DisableIfHelper::type; + +// ###################################################################### +namespace detail { +template struct get_output_from_input : no +{ + static_assert(detail::delay_static_assert::value, + "Could not find an associated output archive for input archive."); +}; + +template struct get_input_from_output : no +{ + static_assert(detail::delay_static_assert::value, + "Could not find an associated input archive for output archive."); +}; +} // namespace detail + +//! Sets up traits that relate an input archive to an output archive +#define CEREAL_SETUP_ARCHIVE_TRAITS(InputArchive, OutputArchive) \ +namespace cereal { \ +namespace traits { \ +namespace detail { \ +template <> struct get_output_from_input \ +{ \ +using type = OutputArchive; \ +}; \ +template <> struct get_input_from_output \ +{ \ +using type = InputArchive; \ +}; \ +} \ +} \ +} /* end namespaces */ + +// ###################################################################### +//! Used to convert a MAKE_HAS_XXX macro into a versioned variant +#define CEREAL_MAKE_VERSIONED_TEST , 0 + +// ###################################################################### +//! Creates a test for whether a non const member function exists +/*! This creates a class derived from std::integral_constant that will be true if + the type has the proper member function for the given archive. + + @param name The name of the function to test for (e.g. serialize, load, save) + @param test_name The name to give the test for the function being tested for (e.g. serialize, + versioned_serialize) + @param versioned Either blank or the macro CEREAL_MAKE_VERSIONED_TEST */ +#ifdef CEREAL_OLDER_GCC +#define CEREAL_MAKE_HAS_MEMBER_TEST(name, test_name, versioned) \ +template struct has_member_##test_name : no \ +{ \ +}; \ +template \ +struct has_member_##test_name(), std::declval() versioned))>::type> : yes \ +{ \ +} +#else // NOT CEREAL_OLDER_GCC +#define CEREAL_MAKE_HAS_MEMBER_TEST(name, test_name, versioned) \ +namespace detail { \ +template struct has_member_##name##_##versioned##_impl \ +{ \ +template \ +static auto test(int) \ + -> decltype(cereal::access::member_##name(std::declval(), std::declval() versioned), yes()); \ +template static no test(...); \ +static const bool value = std::is_same(0)), yes>::value; \ +}; \ +} /* end namespace detail */ \ +template \ +struct has_member_##test_name \ +: std::integral_constant::value> \ +{ \ +} +#endif // NOT CEREAL_OLDER_GCC + +// ###################################################################### +//! Creates a test for whether a non const non-member function exists +/*! This creates a class derived from std::integral_constant that will be true if + the type has the proper non-member function for the given archive. */ +#define CEREAL_MAKE_HAS_NON_MEMBER_TEST(test_name, func, versioned) \ +namespace detail { \ +template struct has_non_member_##test_name##_impl \ +{ \ +template \ +static auto test(int) -> decltype(func(std::declval(), std::declval() versioned), yes()); \ +template static no test(...); \ +static const bool value = std::is_same(0)), yes>::value; \ +}; \ +} /* end namespace detail */ \ +template \ +struct has_non_member_##test_name \ +: std::integral_constant::value> \ +{ \ +} + +// ###################################################################### +// Member Serialize +CEREAL_MAKE_HAS_MEMBER_TEST(serialize, serialize, ); + +// ###################################################################### +// Member Serialize (versioned) +CEREAL_MAKE_HAS_MEMBER_TEST(serialize, versioned_serialize, CEREAL_MAKE_VERSIONED_TEST); + +// ###################################################################### +// Non Member Serialize +CEREAL_MAKE_HAS_NON_MEMBER_TEST(serialize, CEREAL_SERIALIZE_FUNCTION_NAME, ); + +// ###################################################################### +// Non Member Serialize (versioned) +CEREAL_MAKE_HAS_NON_MEMBER_TEST( + versioned_serialize, CEREAL_SERIALIZE_FUNCTION_NAME, CEREAL_MAKE_VERSIONED_TEST); + +// ###################################################################### +// Member Load +CEREAL_MAKE_HAS_MEMBER_TEST(load, load, ); + +// ###################################################################### +// Member Load (versioned) +CEREAL_MAKE_HAS_MEMBER_TEST(load, versioned_load, CEREAL_MAKE_VERSIONED_TEST); + +// ###################################################################### +// Non Member Load +CEREAL_MAKE_HAS_NON_MEMBER_TEST(load, CEREAL_LOAD_FUNCTION_NAME, ); + +// ###################################################################### +// Non Member Load (versioned) +CEREAL_MAKE_HAS_NON_MEMBER_TEST(versioned_load, CEREAL_LOAD_FUNCTION_NAME, CEREAL_MAKE_VERSIONED_TEST); + +// ###################################################################### +#undef CEREAL_MAKE_HAS_NON_MEMBER_TEST +#undef CEREAL_MAKE_HAS_MEMBER_TEST + +// ###################################################################### +//! Creates a test for whether a member save function exists +/*! This creates a class derived from std::integral_constant that will be true if + the type has the proper member function for the given archive. + + @param test_name The name to give the test (e.g. save or versioned_save) + @param versioned Either blank or the macro CEREAL_MAKE_VERSIONED_TEST */ +#ifdef CEREAL_OLDER_GCC +#define CEREAL_MAKE_HAS_MEMBER_SAVE_IMPL(test_name, versioned) \ +namespace detail { \ +template struct has_member_##test_name##_impl \ +{ \ +template struct test : no \ +{ \ +}; \ +template \ +struct test(), std::declval() versioned))>::type> : yes \ +{ \ +}; \ +static const bool value = test(); \ + \ +template struct test2 : no \ +{ \ +}; \ +template \ +struct test2(), std::declval::type &>() versioned))>::type> : yes \ +{ \ +}; \ +static const bool not_const_type = test2(); \ +}; \ +} /* end namespace detail */ +#else /* NOT CEREAL_OLDER_GCC =================================== */ +#define CEREAL_MAKE_HAS_MEMBER_SAVE_IMPL(test_name, versioned) \ +namespace detail { \ +template struct has_member_##test_name##_impl \ +{ \ +template \ +static auto test(int) \ + -> decltype(cereal::access::member_save(std::declval(), std::declval() versioned), \ + yes()); \ +template static no test(...); \ +static const bool value = std::is_same(0)), yes>::value; \ + \ +template \ +static auto test2(int) -> decltype(cereal::access::member_save_non_const(std::declval(), \ + std::declval::type &>() versioned), \ + yes()); \ +template static no test2(...); \ +static const bool not_const_type = std::is_same(0)), yes>::value; \ +}; \ +} /* end namespace detail */ +#endif /* NOT CEREAL_OLDER_GCC */ + +// ###################################################################### +// Member Save +CEREAL_MAKE_HAS_MEMBER_SAVE_IMPL(save, ) + +template +struct has_member_save : std::integral_constant::value> +{ + typedef typename detail::has_member_save_impl check; + static_assert(check::value || !check::not_const_type, + "cereal detected a non-const save. \n " + "save member functions must always be const"); +}; + +// ###################################################################### +// Member Save (versioned) +CEREAL_MAKE_HAS_MEMBER_SAVE_IMPL(versioned_save, CEREAL_MAKE_VERSIONED_TEST) + +template +struct has_member_versioned_save +: std::integral_constant::value> +{ + typedef typename detail::has_member_versioned_save_impl check; + static_assert(check::value || !check::not_const_type, + "cereal detected a versioned non-const save. \n " + "save member functions must always be const"); +}; + +// ###################################################################### +#undef CEREAL_MAKE_HAS_MEMBER_SAVE_IMPL + +// ###################################################################### +//! Creates a test for whether a non-member save function exists +/*! This creates a class derived from std::integral_constant that will be true if + the type has the proper non-member function for the given archive. + + @param test_name The name to give the test (e.g. save or versioned_save) + @param versioned Either blank or the macro CEREAL_MAKE_VERSIONED_TEST */ +#define CEREAL_MAKE_HAS_NON_MEMBER_SAVE_TEST(test_name, versioned) \ +namespace detail { \ +template struct has_non_member_##test_name##_impl \ +{ \ +template \ +static auto test(int) \ + -> decltype(CEREAL_SAVE_FUNCTION_NAME(std::declval(), std::declval() versioned), \ + yes()); \ +template static no test(...); \ +static const bool value = std::is_same(0)), yes>::value; \ + \ +template \ +static auto test2(int) -> decltype(CEREAL_SAVE_FUNCTION_NAME(std::declval(), \ + std::declval::type &>() versioned), \ + yes()); \ +template static no test2(...); \ +static const bool not_const_type = std::is_same(0)), yes>::value; \ +}; \ +} /* end namespace detail */ \ + \ +template \ +struct has_non_member_##test_name \ +: std::integral_constant::value> \ +{ \ +using check = typename detail::has_non_member_##test_name##_impl; \ +static_assert(check::value || !check::not_const_type, \ + "cereal detected a non-const type parameter in non-member " #test_name ". \n " #test_name \ + " non-member functions must always pass their types as const"); \ +}; + +// ###################################################################### +// Non Member Save +CEREAL_MAKE_HAS_NON_MEMBER_SAVE_TEST(save, ) + +// ###################################################################### +// Non Member Save (versioned) +CEREAL_MAKE_HAS_NON_MEMBER_SAVE_TEST(versioned_save, CEREAL_MAKE_VERSIONED_TEST) + +// ###################################################################### +#undef CEREAL_MAKE_HAS_NON_MEMBER_SAVE_TEST + +// ###################################################################### +// Minimal Utilities +namespace detail { +// Determines if the provided type is an std::string +template struct is_string : std::false_type +{ +}; + +template +struct is_string> : std::true_type +{ +}; +} // namespace detail + +// Determines if the type is valid for use with a minimal serialize function +template +struct is_minimal_type +: std::integral_constant::value || std::is_arithmetic::value> +{ +}; + +// ###################################################################### +//! Creates implementation details for whether a member save_minimal function exists +/*! This creates a class derived from std::integral_constant that will be true if + the type has the proper member function for the given archive. + + @param test_name The name to give the test (e.g. save_minimal or versioned_save_minimal) + @param versioned Either blank or the macro CEREAL_MAKE_VERSIONED_TEST */ +#ifdef CEREAL_OLDER_GCC +#define CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_IMPL(test_name, versioned) \ +namespace detail { \ +template struct has_member_##test_name##_impl \ +{ \ +template struct test : no \ +{ \ +}; \ +template \ +struct test(), std::declval() versioned))>::type> : yes \ +{ \ +}; \ + \ +static const bool value = test(); \ + \ +template struct test2 : no \ +{ \ +}; \ +template \ +struct test2(), \ + std::declval::type &>() versioned))>::type> : yes \ +{ \ +}; \ +static const bool not_const_type = test2(); \ + \ +static const bool valid = value || !not_const_type; \ +}; \ +} /* end namespace detail */ +#else /* NOT CEREAL_OLDER_GCC =================================== */ +#define CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_IMPL(test_name, versioned) \ +namespace detail { \ +template struct has_member_##test_name##_impl \ +{ \ +template \ +static auto test(int) -> decltype(cereal::access::member_save_minimal( \ + std::declval(), std::declval() versioned), \ + yes()); \ +template static no test(...); \ +static const bool value = std::is_same(0)), yes>::value; \ + \ +template \ +static auto test2(int) \ + -> decltype(cereal::access::member_save_minimal_non_const(std::declval(), \ + std::declval::type &>() versioned), \ + yes()); \ +template static no test2(...); \ +static const bool not_const_type = std::is_same(0)), yes>::value; \ + \ +static const bool valid = value || !not_const_type; \ +}; \ +} /* end namespace detail */ +#endif // NOT CEREAL_OLDER_GCC + +// ###################################################################### +//! Creates helpers for minimal save functions +/*! The get_member_*_type structs allow access to the return type of a save_minimal, + assuming that the function actually exists. If the function does not + exist, the type will be void. + + @param test_name The name to give the test (e.g. save_minimal or versioned_save_minimal) + @param versioned Either blank or the macro CEREAL_MAKE_VERSIONED_TEST */ +#define CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_HELPERS_IMPL(test_name, versioned) \ +namespace detail { \ +template struct get_member_##test_name##_type \ +{ \ +using type = void; \ +}; \ + \ +template struct get_member_##test_name##_type \ +{ \ +using type = decltype(cereal::access::member_save_minimal( \ + std::declval(), std::declval() versioned)); \ +}; \ +} /* end namespace detail */ + +// ###################################################################### +//! Creates a test for whether a member save_minimal function exists +/*! This creates a class derived from std::integral_constant that will be true if + the type has the proper member function for the given archive. + + @param test_name The name to give the test (e.g. save_minimal or versioned_save_minimal) */ +#define CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_TEST(test_name) \ +template \ +struct has_member_##test_name \ +: std::integral_constant::value> \ +{ \ +using check = typename detail::has_member_##test_name##_impl; \ +static_assert(check::valid, \ + "cereal detected a non-const member " #test_name ". \n " #test_name \ + " member functions must always be const"); \ + \ +using type = typename detail::get_member_##test_name##_type::type; \ +static_assert((check::value && is_minimal_type::value) || !check::value, \ + "cereal detected a member " #test_name " with an invalid return type. \n " \ + "return type must be arithmetic or string"); \ +}; + +// ###################################################################### +// Member Save Minimal +CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_IMPL(save_minimal, ) +CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_HELPERS_IMPL(save_minimal, ) +CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_TEST(save_minimal) + +// ###################################################################### +// Member Save Minimal (versioned) +CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_IMPL(versioned_save_minimal, CEREAL_MAKE_VERSIONED_TEST) +CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_HELPERS_IMPL(versioned_save_minimal, CEREAL_MAKE_VERSIONED_TEST) +CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_TEST(versioned_save_minimal) + +// ###################################################################### +#undef CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_IMPL +#undef CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_HELPERS_IMPL +#undef CEREAL_MAKE_HAS_MEMBER_SAVE_MINIMAL_TEST + +// ###################################################################### +//! Creates a test for whether a non-member save_minimal function exists +/*! This creates a class derived from std::integral_constant that will be true if + the type has the proper member function for the given archive. + + @param test_name The name to give the test (e.g. save_minimal or versioned_save_minimal) + @param versioned Either blank or the macro CEREAL_MAKE_VERSIONED_TEST */ +#define CEREAL_MAKE_HAS_NON_MEMBER_SAVE_MINIMAL_TEST(test_name, versioned) \ +namespace detail { \ +template struct has_non_member_##test_name##_impl \ +{ \ +template \ +static auto test(int) -> decltype(CEREAL_SAVE_MINIMAL_FUNCTION_NAME( \ + std::declval(), std::declval() versioned), \ + yes()); \ +template static no test(...); \ +static const bool value = std::is_same(0)), yes>::value; \ + \ +template \ +static auto test2(int) -> decltype(CEREAL_SAVE_MINIMAL_FUNCTION_NAME(std::declval(), \ + std::declval::type &>() versioned), \ + yes()); \ +template static no test2(...); \ +static const bool not_const_type = std::is_same(0)), yes>::value; \ + \ +static const bool valid = value || !not_const_type; \ +}; \ + \ +template struct get_non_member_##test_name##_type \ +{ \ +using type = void; \ +}; \ + \ +template struct get_non_member_##test_name##_type \ +{ \ +using type = decltype(CEREAL_SAVE_MINIMAL_FUNCTION_NAME( \ + std::declval(), std::declval() versioned)); \ +}; \ +} /* end namespace detail */ \ + \ +template \ +struct has_non_member_##test_name \ +: std::integral_constant::value> \ +{ \ +using check = typename detail::has_non_member_##test_name##_impl; \ +static_assert(check::valid, \ + "cereal detected a non-const type parameter in non-member " #test_name ". \n " #test_name \ + " non-member functions must always pass their types as const"); \ + \ +using type = typename detail::get_non_member_##test_name##_type::type; \ +static_assert((check::value && is_minimal_type::value) || !check::value, \ + "cereal detected a non-member " #test_name " with an invalid return type. \n " \ + "return type must be arithmetic or string"); \ +}; + +// ###################################################################### +// Non-Member Save Minimal +CEREAL_MAKE_HAS_NON_MEMBER_SAVE_MINIMAL_TEST(save_minimal, ) + +// ###################################################################### +// Non-Member Save Minimal (versioned) +CEREAL_MAKE_HAS_NON_MEMBER_SAVE_MINIMAL_TEST(versioned_save_minimal, CEREAL_MAKE_VERSIONED_TEST) + +// ###################################################################### +#undef CEREAL_MAKE_HAS_NON_MEMBER_SAVE_MINIMAL_TEST + +// ###################################################################### +// Load Minimal Utilities +namespace detail { +//! Used to help strip away conversion wrappers +/*! If someone writes a non-member load/save minimal function that accepts its + parameter as some generic template type and needs to perform trait checks + on that type, our NoConvert wrappers will interfere with this. Using + the struct strip_minmal, users can strip away our wrappers to get to + the underlying type, allowing traits to work properly */ +struct NoConvertBase +{ +}; + +//! A struct that prevents implicit conversion +/*! Any type instantiated with this struct will be unable to implicitly convert + to another type. Is designed to only allow conversion to Source const &. + + @tparam Source the type of the original source */ +template struct NoConvertConstRef : NoConvertBase +{ + using type = Source; //!< Used to get underlying type easily + + template ::value>::type> + operator Dest() = delete; + + //! only allow conversion if the types are the same and we are converting into a const reference + template ::value>::type> + operator Dest const &(); +}; + +//! A struct that prevents implicit conversion +/*! Any type instantiated with this struct will be unable to implicitly convert + to another type. Is designed to only allow conversion to Source &. + + @tparam Source the type of the original source */ +template struct NoConvertRef : NoConvertBase +{ + using type = Source; //!< Used to get underlying type easily + + template ::value>::type> + operator Dest() = delete; + +#ifdef __clang__ + template ::value>::type> + operator Dest const &() = delete; +#endif // __clang__ + + //! only allow conversion if the types are the same and we are converting into a const reference + template ::value>::type> + operator Dest &(); +}; + +//! A type that can implicitly convert to anything else +struct AnyConvert +{ + template operator Dest &(); + + template operator Dest const &() const; +}; +} // namespace detail + +// ###################################################################### +//! Creates a test for whether a member load_minimal function exists +/*! This creates a class derived from std::integral_constant that will be true if + the type has the proper member function for the given archive. + + Our strategy here is to first check if a function matching the signature more or less exists + (allow anything like load_minimal(xxx) using AnyConvert, and then secondly enforce + that it has the correct signature using NoConvertConstRef + + @param test_name The name to give the test (e.g. load_minimal or versioned_load_minimal) + @param versioned Either blank or the macro CEREAL_MAKE_VERSIONED_TEST */ +#ifdef CEREAL_OLDER_GCC +#define CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_IMPL(test_name, versioned) \ +namespace detail { \ +template struct has_member_##test_name##_impl : no \ +{ \ +}; \ +template \ +struct has_member_##test_name##_impl(), std::declval(), AnyConvert() versioned))>::type> : yes \ +{ \ +}; \ + \ +template struct has_member_##test_name##_type_impl : no \ +{ \ +}; \ +template \ +struct has_member_##test_name##_type_impl(), std::declval(), NoConvertConstRef() versioned))>::type> : yes \ +{ \ +}; \ +} /* end namespace detail */ +#else /* NOT CEREAL_OLDER_GCC =================================== */ +#define CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_IMPL(test_name, versioned) \ +namespace detail { \ +template struct has_member_##test_name##_impl \ +{ \ +template \ +static auto test(int) \ + -> decltype(cereal::access::member_load_minimal( \ + std::declval(), std::declval(), AnyConvert() versioned), \ + yes()); \ +template static no test(...); \ +static const bool value = std::is_same(0)), yes>::value; \ +}; \ +template struct has_member_##test_name##_type_impl \ +{ \ +template \ +static auto test(int) \ + -> decltype(cereal::access::member_load_minimal( \ + std::declval(), std::declval(), NoConvertConstRef() versioned), \ + yes()); \ +template static no test(...); \ +static const bool value = std::is_same(0)), yes>::value; \ +}; \ +} /* end namespace detail */ +#endif // NOT CEREAL_OLDER_GCC + +// ###################################################################### +//! Creates helpers for minimal load functions +/*! The has_member_*_wrapper structs ensure that the load and save types for the + requested function type match appropriately. + + @param load_test_name The name to give the test (e.g. load_minimal or versioned_load_minimal) + @param save_test_name The name to give the test (e.g. save_minimal or versioned_save_minimal, + should match the load name. + @param save_test_prefix The name to give the test (e.g. save_minimal or versioned_save_minimal, + should match the load name, without the trailing "_minimal" (e.g. + save or versioned_save). Needed because the preprocessor is an abomination. + @param versioned Either blank or the macro CEREAL_MAKE_VERSIONED_TEST */ +#define CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_HELPERS_IMPL( \ + load_test_name, save_test_name, save_test_prefix, versioned) \ +namespace detail { \ +template struct has_member_##load_test_name##_wrapper : std::false_type \ +{ \ +}; \ + \ +template struct has_member_##load_test_name##_wrapper \ +{ \ +using AOut = typename detail::get_output_from_input::type; \ + \ +static_assert(has_member_##save_test_prefix##_minimal::value, \ + "cereal detected member " #load_test_name " but no valid member " #save_test_name ". \n " \ + "cannot evaluate correctness of " #load_test_name " without valid " #save_test_name "."); \ + \ +using SaveType = typename detail::get_member_##save_test_prefix##_minimal_type::type; \ +const static bool value = has_member_##load_test_name##_impl::value; \ +const static bool valid = has_member_##load_test_name##_type_impl::value; \ + \ +static_assert(valid || !value, \ + "cereal detected different or invalid types in corresponding member " #load_test_name \ + " and " #save_test_name " functions. \n " \ + "the paramater to " #load_test_name " must be a constant reference to the type that " #save_test_name \ + " returns."); \ +}; \ +} /* end namespace detail */ + +// ###################################################################### +//! Creates a test for whether a member load_minimal function exists +/*! This creates a class derived from std::integral_constant that will be true if + the type has the proper member function for the given archive. + + @param load_test_name The name to give the test (e.g. load_minimal or versioned_load_minimal) + @param load_test_prefix The above parameter minus the trailing "_minimal" */ +#define CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_TEST(load_test_name, load_test_prefix) \ +template \ +struct has_member_##load_test_prefix##_minimal \ +: std::integral_constant::value>::value> \ +{ \ +}; + +// ###################################################################### +// Member Load Minimal +CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_IMPL(load_minimal, ) +CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_HELPERS_IMPL(load_minimal, save_minimal, save, ) +CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_TEST(load_minimal, load) + +// ###################################################################### +// Member Load Minimal (versioned) +CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_IMPL(versioned_load_minimal, CEREAL_MAKE_VERSIONED_TEST) +CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_HELPERS_IMPL( + versioned_load_minimal, versioned_save_minimal, versioned_save, CEREAL_MAKE_VERSIONED_TEST) +CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_TEST(versioned_load_minimal, versioned_load) + +// ###################################################################### +#undef CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_IMPL +#undef CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_HELPERS_IMPL +#undef CEREAL_MAKE_HAS_MEMBER_LOAD_MINIMAL_TEST + +// ###################################################################### +// Non-Member Load Minimal +namespace detail { +#ifdef CEREAL_OLDER_GCC +void CEREAL_LOAD_MINIMAL_FUNCTION_NAME(); // prevents nonsense complaining about not finding this +void CEREAL_SAVE_MINIMAL_FUNCTION_NAME(); +#endif // CEREAL_OLDER_GCC +} // namespace detail + +// ###################################################################### +//! Creates a test for whether a non-member load_minimal function exists +/*! This creates a class derived from std::integral_constant that will be true if + the type has the proper member function for the given archive. + + See notes from member load_minimal implementation. + + Note that there should be an additional const check on load_minimal after the valid check, + but this currently interferes with many valid uses of minimal serialization. It has been + removed (see #565 on github) and previously was: + + @code + static_assert( check::const_valid || !check::exists, + "cereal detected an invalid serialization type parameter in non-member " #test_name ". " + #test_name " non-member functions must accept their serialization type by non-const reference" ); + @endcode + + See #132, #436, #263, and #565 on https://github.com/USCiLab/cereal for more details. + + @param test_name The name to give the test (e.g. load_minimal or versioned_load_minimal) + @param save_name The corresponding name the save test would have (e.g. save_minimal or + versioned_save_minimal) + @param versioned Either blank or the macro CEREAL_MAKE_VERSIONED_TEST */ +#define CEREAL_MAKE_HAS_NON_MEMBER_LOAD_MINIMAL_TEST(test_name, save_name, versioned) \ +namespace detail { \ +template struct has_non_member_##test_name##_impl \ +{ \ +template \ +static auto test(int) \ + -> decltype(CEREAL_LOAD_MINIMAL_FUNCTION_NAME( \ + std::declval(), std::declval(), AnyConvert() versioned), \ + yes()); \ +template static no test(...); \ +static const bool exists = std::is_same(0)), yes>::value; \ + \ +template \ +static auto test2(int) \ + -> decltype(CEREAL_LOAD_MINIMAL_FUNCTION_NAME( \ + std::declval(), std::declval(), NoConvertConstRef() versioned), \ + yes()); \ +template static no test2(...); \ +static const bool valid = std::is_same(0)), yes>::value; \ + \ +template \ +static auto test3(int) \ + -> decltype(CEREAL_LOAD_MINIMAL_FUNCTION_NAME( \ + std::declval(), NoConvertRef(), AnyConvert() versioned), \ + yes()); \ +template static no test3(...); \ +static const bool const_valid = std::is_same(0)), yes>::value; \ +}; \ + \ +template struct has_non_member_##test_name##_wrapper : std::false_type \ +{ \ +}; \ + \ +template struct has_non_member_##test_name##_wrapper \ +{ \ +using AOut = typename detail::get_output_from_input::type; \ + \ +static_assert(detail::has_non_member_##save_name##_impl::valid, \ + "cereal detected non-member " #test_name " but no valid non-member " #save_name ". \n " \ + "cannot evaluate correctness of " #test_name " without valid " #save_name "."); \ + \ +using SaveType = typename detail::get_non_member_##save_name##_type::type; \ +using check = has_non_member_##test_name##_impl; \ +static const bool value = check::exists; \ + \ +static_assert(check::valid || !check::exists, \ + "cereal detected different types in corresponding non-member " #test_name " and " #save_name \ + " functions. \n " \ + "the paramater to " #test_name " must be a constant reference to the type that " #save_name \ + " returns."); \ +}; \ +} /* namespace detail */ \ + \ +template \ +struct has_non_member_##test_name \ +: std::integral_constant::exists>::value> \ +{ \ +}; + +// ###################################################################### +// Non-Member Load Minimal +CEREAL_MAKE_HAS_NON_MEMBER_LOAD_MINIMAL_TEST(load_minimal, save_minimal, ) + +// ###################################################################### +// Non-Member Load Minimal (versioned) +CEREAL_MAKE_HAS_NON_MEMBER_LOAD_MINIMAL_TEST( + versioned_load_minimal, versioned_save_minimal, CEREAL_MAKE_VERSIONED_TEST) + +// ###################################################################### +#undef CEREAL_MAKE_HAS_NON_MEMBER_LOAD_MINIMAL_TEST + +// ###################################################################### +namespace detail { +// const stripped away before reaching here, prevents errors on conversion from +// construct to construct +template +struct has_member_load_and_construct_impl +: std::integral_constant( + std::declval(), std::declval<::cereal::construct &>())), + void>::value> +{ +}; + +template +struct has_member_versioned_load_and_construct_impl +: std::integral_constant( + std::declval(), std::declval<::cereal::construct &>(), 0)), + void>::value> +{ +}; +} // namespace detail + +//! Member load and construct check +template +struct has_member_load_and_construct +: detail::has_member_load_and_construct_impl::type, A> +{ +}; + +//! Member load and construct check (versioned) +template +struct has_member_versioned_load_and_construct +: detail::has_member_versioned_load_and_construct_impl::type, A> +{ +}; + +// ###################################################################### +//! Creates a test for whether a non-member load_and_construct specialization exists +/*! This creates a class derived from std::integral_constant that will be true if + the type has the proper non-member function for the given archive. */ +#define CEREAL_MAKE_HAS_NON_MEMBER_LOAD_AND_CONSTRUCT_TEST(test_name, versioned) \ +namespace detail { \ +template struct has_non_member_##test_name##_impl \ +{ \ +template \ +static auto test(int) -> decltype(LoadAndConstruct::load_and_construct(std::declval(), \ + std::declval<::cereal::construct &>() versioned), \ + yes()); \ +template static no test(...); \ +static const bool value = std::is_same(0)), yes>::value; \ +}; \ +} /* end namespace detail */ \ +template \ +struct has_non_member_##test_name \ +: std::integral_constant::type, A>::value> \ +{ \ +}; + +// ###################################################################### +//! Non member load and construct check +CEREAL_MAKE_HAS_NON_MEMBER_LOAD_AND_CONSTRUCT_TEST(load_and_construct, ) + +// ###################################################################### +//! Non member load and construct check (versioned) +CEREAL_MAKE_HAS_NON_MEMBER_LOAD_AND_CONSTRUCT_TEST(versioned_load_and_construct, CEREAL_MAKE_VERSIONED_TEST) + +// ###################################################################### +//! Has either a member or non member load and construct +template +struct has_load_and_construct +: std::integral_constant::value || has_non_member_load_and_construct::value || + has_member_versioned_load_and_construct::value || + has_non_member_versioned_load_and_construct::value> +{ +}; + +// ###################################################################### +#undef CEREAL_MAKE_HAS_NON_MEMBER_LOAD_AND_CONSTRUCT_TEST + +// ###################################################################### +// End of serialization existence tests +#undef CEREAL_MAKE_VERSIONED_TEST + +// ###################################################################### +template +struct has_member_split +: std::integral_constant::value && has_member_save::value) || + (has_member_versioned_load::value && + has_member_versioned_save::value)> +{ +}; + +// ###################################################################### +template +struct has_non_member_split +: std::integral_constant::value && has_non_member_save::value) || + (has_non_member_versioned_load::value && + has_non_member_versioned_save::value)> +{ +}; + +// ###################################################################### +template +struct has_invalid_output_versioning +: std::integral_constant::value && has_member_save::value) || + (has_non_member_versioned_save::value && + has_non_member_save::value) || + (has_member_versioned_serialize::value && + has_member_serialize::value) || + (has_non_member_versioned_serialize::value && + has_non_member_serialize::value) || + (has_member_versioned_save_minimal::value && + has_member_save_minimal::value) || + (has_non_member_versioned_save_minimal::value && + has_non_member_save_minimal::value)> +{ +}; + +// ###################################################################### +template +struct has_invalid_input_versioning +: std::integral_constant::value && has_member_load::value) || + (has_non_member_versioned_load::value && + has_non_member_load::value) || + (has_member_versioned_serialize::value && + has_member_serialize::value) || + (has_non_member_versioned_serialize::value && + has_non_member_serialize::value) || + (has_member_versioned_load_minimal::value && + has_member_load_minimal::value) || + (has_non_member_versioned_load_minimal::value && + has_non_member_load_minimal::value)> +{ +}; + +// ###################################################################### +namespace detail { +//! Create a test for a cereal::specialization entry +#define CEREAL_MAKE_IS_SPECIALIZED_IMPL(name) \ +template \ +struct is_specialized_##name \ +: std::integral_constant>::value> \ +{ \ +} + +CEREAL_MAKE_IS_SPECIALIZED_IMPL(member_serialize); +CEREAL_MAKE_IS_SPECIALIZED_IMPL(member_load_save); +CEREAL_MAKE_IS_SPECIALIZED_IMPL(member_load_save_minimal); +CEREAL_MAKE_IS_SPECIALIZED_IMPL(non_member_serialize); +CEREAL_MAKE_IS_SPECIALIZED_IMPL(non_member_load_save); +CEREAL_MAKE_IS_SPECIALIZED_IMPL(non_member_load_save_minimal); + +#undef CEREAL_MAKE_IS_SPECIALIZED_IMPL + +//! Number of specializations detected +template +struct count_specializations +: std::integral_constant::value + is_specialized_member_load_save::value + + is_specialized_member_load_save_minimal::value + + is_specialized_non_member_serialize::value + is_specialized_non_member_load_save::value + + is_specialized_non_member_load_save_minimal::value> +{ +}; +} // namespace detail + +//! Check if any specialization exists for a type +template +struct is_specialized +: std::integral_constant::value || + detail::is_specialized_member_load_save::value || + detail::is_specialized_member_load_save_minimal::value || + detail::is_specialized_non_member_serialize::value || + detail::is_specialized_non_member_load_save::value || + detail::is_specialized_non_member_load_save_minimal::value> +{ + static_assert(detail::count_specializations::value <= 1, + "More than one explicit specialization detected for type."); +}; + +//! Create the static assertion for some specialization +/*! This assertion will fail if the type is indeed specialized and does not have the appropriate + type of serialization functions */ +#define CEREAL_MAKE_IS_SPECIALIZED_ASSERT(name, versioned_name, print_name, spec_name) \ +static_assert((is_specialized::value && detail::is_specialized_##spec_name::value && \ + (has_##name::value || has_##versioned_name::value)) || \ + !(is_specialized::value && detail::is_specialized_##spec_name::value), \ + "cereal detected " #print_name " specialization but no " #print_name " serialize function") + +//! Generates a test for specialization for versioned and unversioned functions +/*! This creates checks that can be queried to see if a given type of serialization function + has been specialized for this type */ +#define CEREAL_MAKE_IS_SPECIALIZED(name, versioned_name, spec_name) \ +template \ +struct is_specialized_##name \ +: std::integral_constant::value && detail::is_specialized_##spec_name::value> \ +{ \ +CEREAL_MAKE_IS_SPECIALIZED_ASSERT(name, versioned_name, name, spec_name); \ +}; \ +template \ +struct is_specialized_##versioned_name \ +: std::integral_constant::value && detail::is_specialized_##spec_name::value> \ +{ \ +CEREAL_MAKE_IS_SPECIALIZED_ASSERT(name, versioned_name, versioned_name, spec_name); \ +} + +CEREAL_MAKE_IS_SPECIALIZED(member_serialize, member_versioned_serialize, member_serialize); +CEREAL_MAKE_IS_SPECIALIZED(non_member_serialize, non_member_versioned_serialize, non_member_serialize); + +CEREAL_MAKE_IS_SPECIALIZED(member_save, member_versioned_save, member_load_save); +CEREAL_MAKE_IS_SPECIALIZED(non_member_save, non_member_versioned_save, non_member_load_save); +CEREAL_MAKE_IS_SPECIALIZED(member_load, member_versioned_load, member_load_save); +CEREAL_MAKE_IS_SPECIALIZED(non_member_load, non_member_versioned_load, non_member_load_save); + +CEREAL_MAKE_IS_SPECIALIZED(member_save_minimal, member_versioned_save_minimal, member_load_save_minimal); +CEREAL_MAKE_IS_SPECIALIZED( + non_member_save_minimal, non_member_versioned_save_minimal, non_member_load_save_minimal); +CEREAL_MAKE_IS_SPECIALIZED(member_load_minimal, member_versioned_load_minimal, member_load_save_minimal); +CEREAL_MAKE_IS_SPECIALIZED( + non_member_load_minimal, non_member_versioned_load_minimal, non_member_load_save_minimal); + +#undef CEREAL_MAKE_IS_SPECIALIZED_ASSERT +#undef CEREAL_MAKE_IS_SPECIALIZED + +// ###################################################################### +// detects if a type has any active minimal output serialization +template +struct has_minimal_output_serialization +: std::integral_constant::value || + ((has_member_save_minimal::value || + has_non_member_save_minimal::value || + has_member_versioned_save_minimal::value || + has_non_member_versioned_save_minimal::value) && + !(is_specialized_member_serialize::value || + is_specialized_member_save::value))> +{ +}; + +// ###################################################################### +// detects if a type has any active minimal input serialization +template +struct has_minimal_input_serialization +: std::integral_constant::value || + ((has_member_load_minimal::value || + has_non_member_load_minimal::value || + has_member_versioned_load_minimal::value || + has_non_member_versioned_load_minimal::value) && + !(is_specialized_member_serialize::value || + is_specialized_member_load::value))> +{ +}; + +// ###################################################################### +namespace detail { +//! The number of output serialization functions available +/*! If specialization is being used, we'll count only those; otherwise we'll count everything */ +template +struct count_output_serializers +: std::integral_constant::value + ? count_specializations::value + : has_member_save::value + has_non_member_save::value + + has_member_serialize::value + + has_non_member_serialize::value + + has_member_save_minimal::value + + has_non_member_save_minimal::value + + /*-versioned---------------------------------------------------------*/ + has_member_versioned_save::value + + has_non_member_versioned_save::value + + has_member_versioned_serialize::value + + has_non_member_versioned_serialize::value + + has_member_versioned_save_minimal::value + + has_non_member_versioned_save_minimal::value> +{ +}; +} // namespace detail + +template +struct is_output_serializable +: std::integral_constant::value == 1> +{ +}; + +// ###################################################################### +namespace detail { +//! The number of input serialization functions available +/*! If specialization is being used, we'll count only those; otherwise we'll count everything */ +template +struct count_input_serializers +: std::integral_constant::value + ? count_specializations::value + : has_member_load::value + has_non_member_load::value + + has_member_serialize::value + has_non_member_serialize::value + + has_member_load_minimal::value + + has_non_member_load_minimal::value + + /*-versioned---------------------------------------------------------*/ + has_member_versioned_load::value + + has_non_member_versioned_load::value + + has_member_versioned_serialize::value + + has_non_member_versioned_serialize::value + + has_member_versioned_load_minimal::value + + has_non_member_versioned_load_minimal::value> +{ +}; +} // namespace detail + +template +struct is_input_serializable +: std::integral_constant::value == 1> +{ +}; + +// ###################################################################### +// Base Class Support +namespace detail { +struct base_class_id +{ + template + base_class_id(T const * const t) + : type(typeid(T)), ptr(t), + hash(std::hash()(typeid(T)) ^ (std::hash()(t) << 1)) + { + } + + bool operator==(base_class_id const & other) const { return (type == other.type) && (ptr == other.ptr); } + + std::type_index type; + void const * ptr; + size_t hash; +}; +struct base_class_id_hash +{ + size_t operator()(base_class_id const & id) const { return id.hash; } +}; +} // namespace detail + +namespace detail { +//! Common base type for base class casting +struct BaseCastBase +{ +}; + +template struct get_base_class; + +template