0%

安装 Ipopt

1
2
3
4
5
6
7
8
9
10
$ wget https://www.coin-or.org/download/source/Ipopt/Ipopt-3.12.7.zip 
$ unzip Ipopt-3.12.7.zip
$ rm Ipopt-3.12.7.zip
$ cd Ipopt-3.12.7
$ ./configure
......
configure: Main configuration of Ipopt successful
$ make
$ make test
$ make install

参考:https://www.jianshu.com/p/4cdaa93d460b

参考:https://github.com/bapaden/ipopt-cmake-demo

下载 HSL MA21求解器 :

http://www.hsl.rl.ac.uk/ipopt/
https://github.com/casadi/casadi/wiki/Obtaining-HSL

没有学校邮箱的同学,可以选择下载个人版的。

为了避免后续问题,建议安装源码版本的。

1
2
3
4
5
6
7
8
9
10
#确保安装环境
$ sudo apt-get install libblas3 libblas-dev liblapack3 liblapack-dev gfortran
#方式2:源代码编译
$ tar -xf coinhsl-archive-2014.01.17.tar.gz
$ cd Ipopt-3.12.7/ThirdParty/HSL
$ ln -s ../../../coinhsl-archive-2014.01.17/ coinhsl
$ ./configure --enable-loadable-library
#出现
configure: Configuration of ThirdPartyHSL successful
$ make install

在$ make test 过程中出现问题:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 出现错误:
Exception of type: OPTION_INVALID in file "IpAlgBuilder.cpp" at line 271:
Exception message: Selected linear solver MA27 not available.
Tried to obtain MA27 from shared library "libhsl.so", but the following error occured:
libhsl.so: cannot open shared object file: No such file or directory

# 解决:
# 将lib copy到根目录下:
$ cd Ipopt-3.12.7/ThirdParty/HSL/lib
$ ln -s libcoinhsl.so.1.5.6 libhsl.so
$ sudo cp -rd * /usr/local/lib
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
#$ env | grep LD #确认设置好环境变量
$ cd Ipopt-3.12.7/lib
$ sudo cp * /usr/local/lib/

回到IPOPT环境下进行编译

1
2
$ make test
$ make install

编译成功后,可以看到目录下有这几个文件夹”bin”, “lib” and “include”

有时候需要安装CppAd,安装方法

1
2
sudo apt-get update -y
sudo apt-get install -y cppad

没有装CppAd可能会出现下面的问题:

1
example.cpp:1:33: fatal error: cppad/ipopt/solve.hpp: No such file or directory

出现问题:

1
/usr/include/cppad/ipopt/solve_callback.hpp:16:40: fatal error: coin/IpIpoptApplication.hpp: No such file or directory

解决办法:(参考:https://zhuanlan.zhihu.com/p/34650692)

1
$ sudo cp ~/Ipopt-3.12.7/include/* /usr/local/include

AMPL 的C++ API

方法:https://ampl.com/api/latest/cpp/getting-started.html

下载:https://ampl.com/products/api/

学习例子参考:

1)https://github.com/mez/model_predictive_controller_cpp

2)https://github.com/tianchenji/CarND-MPC-Project

在数学中,集合是最基本的概念之一。编程时,我们不可避免地会涉及到集合及其相关操作。在 C++ 中,标准模板库(STL)提供了 std::set/std::unordered_set 两种传统意义上的集合(除此之外,还有 std::multisetstd::unordered_multiset)。其中,std::set(和 std::multiset)定义在头文件 set 当中,从 C++98 起就有支持;而 std::unordered_set(和 std::unordered_multiset)则定义在头文件 unordered_set 当中,从 C++11 开始支持。

此篇我们讨论如何在 C++ 中集合如何进行交集和并集操作。

阅读全文 »

  1. 亚细亚大楼:折衷主义

    占地面积1739平方米,建筑面积11984平方米。总体为钢筋混凝土的框架结构,但外立面使用花岗岩和清水砖砌成。东、南两侧的外立面沿东南角呈对称结构,建筑风格属折衷主义。另外从横向和竖向而言均依据三段式结构进行设计建造,横向上,底部与顶部均吸收巴洛克风格,而中部又采用了现代主义的设计。竖向上,位于中央的底部与顶部均使用贯高两层的双爱奥尼柱式。在功能设置上,中央除底部外,中部和顶部均设置内凹阳台。

    另外,大楼为调和视觉感官,在东南角即延安东路)中山东一路路口也使用了凹面设计。1938年加建的第八层,其四角也采用了凹面式。平面上,建筑则为回字形,中间设计有天井。为确保建筑物的采光,整幢大楼共有大小窗户100余个。另外,在二层、五层和八层的窗、阳台廊柱均按半圆形设计。

    阅读全文 »

由于home文件夹较大,且其默认是在系统盘下的. 当系统盘空间不足时,我们可以将Home文件夹移至新磁盘下的新分区内.

Overview

This guide offers detailed instructions for migrating your home directory into its own dedicated partition. Setting up /home on a separate partition is beneficial because your settings, files, and desktop will be maintained if you upgrade, (re)install Ubuntu or another distro. This works because /home has a subdirectory for each user’s settings and files which contain all the data & settings of that user. Telling Ubuntu to use an existing home partition can be done by selecting “Manual Partitioning” during the installation of Ubuntu and specifying that you want your home partitions mount point to be /home, ensure you mark your /home partition not be formatted in the process. You should also make sure the usernames you enter for accounts during installation match usernames that existed in a previous installation.

This guide will follow these 8 basic steps:

  1. Set-up your new partition
  2. Find the uuid (=address) of the new partition
  3. Backup and edit your fstab to mount the new partition as /media/home (just for the time being) and reboot.
  4. Use rsync to migrate all data from /home into /media/home
  5. Check copying worked!
  6. Move /home to /old_home to avoid confusion later!
  7. Edit fstab again so the new partition mounts as /home instead of as /media/home
  8. Reboot or remount all. Check system seems to be working well
  9. Delete the /old_home after a while

The guide is written in such a way so that at any point in time if there is a system failure, power outage or random restart that it will not have a negative impact on the system and SHOULD safeguard against the possibility of the user accidentally deleting their home directory in the process.

阅读全文 »

Install

1
2
3
4
5
6
7
8
9
10
11
12
#pre-requirements
sudo apt install python3-dev
pip install pytest
#download source code
git clone https://github.com/pybind/pybind11.git
cd pybind11
mkdir build
cd build
#make
cmake ..
make check -j 8
sudo make install

Using

Attention: DO NOT use g++ or c++ to build (in case we haven’t install pybind11 in python environment(which is also no need to do)).

Instead, we use Cmake to compile our code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
cmake_minimum_required(VERSION 3.0)

set(PROJ_NAME "example")
project(${PROJ_NAME})

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3")

find_package(pybind11 REQUIRED)
pybind11_add_module(${PROJ_NAME} example.cpp)

target_link_libraries(${PROJ_NAME} PRIVATE pybind11::module)

find_package(Python)
find_path(PYTHON_SITE_PACKAGES site-packages ${PYTHON_INCLUDE_PATH}/..)

install(TARGETS ${PROJ_NAME} RUNTIME DESTINATION ${PYTHON_SITE_PACKAGES}
LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES}
ARCHIVE DESTINATION ${PYTHON_SITE_PACKAGES}
)

And folder is such like:

1
2
3
4
├── build
│ ├ ...
├── CMakeLists.txt
└── example.cpp

背景问题

C++ 的类有四类特殊成员函数,它们分别是:默认构造函数、析构函数、拷贝构造函数以及拷贝赋值运算符。这些类的特殊成员函数负责创建、初始化、销毁,或者拷贝类的对象。如果程序员没有显式地为一个类定义某个特殊成员函数,而又需要用到该特殊成员函数时,则编译器会隐式的为这个类生成一个默认的特殊成员函数。例如:

清单 1

1
2
3
4
5
6
class X{ 
private:
int a;
};

X x;

在清单 1 中,程序员并没有定义类 X 的默认构造函数,但是在创建类 X 的对象 x 的时候,又需要用到类 X 的默认构造函数,此时,编译器会隐式的为类 X 生成一个默认构造函数。该自动生成的默认构造函数没有参数,包含一个空的函数体,即 X::X(){ }。虽然自动生成的默认构造函数仅有一个空函数体,但是它仍可用来成功创建类 X 的对象 x,清单 1 也可以编译通过。

阅读全文 »

将系统原来的python3.5改为当前3.7后,gnome-terminal会打不开,解决方法如下:

1
2
3
4
cd /usr/lib/python3/dist-packages/gi/
# 下面的35 改成37 表示从py3.5 改到py3.7,如果安装的是3.6就改成36
sudo cp _gi_cairo.cpython-35m-x86_64-linux-gnu.so _gi_cairo.cpython-37m-x86_64-linux-gnu.so
sudo cp _gi.cpython-35m-x86_64-linux-gnu.so _gi.cpython-37m-x86_64-linux-gnu.so

Origin Article By Shaoshan Liu and Jean-Luc Gaudiot

许多年轻的都市人不想拥有汽车,与前几代人不同的是,他们不需要依赖公共交通。相反,他们将交通出行视为一种服务。当他们需要长途旅行时,比如说超过5英里(8公里),他们会用手机叫一辆Uber(或类似的共享单车公司的车)。如果他们的行程不到一英里左右,他们要么步行,要么使用各种 “微移动 “服务,比如越来越多的Lime和Bird踏板车,或者在一些城市,共享单车。

问题是,如今移动即服务生态系统往往不能很好地覆盖中间距离,比如说几英里的距离。雇佣Uber或Lyft来进行这种短途旅行,其费用令人沮丧,而且骑着踏板车或自行车超过一英里左右的路程对很多人来说可能会很费劲。因此,将自己送到1到5英里外的目的地可能是一个挑战。然而,这样的旅行占到了乘客总里程的一半左右。

阅读全文 »