Friday, 17 August 2012

Strategy Simulation

Strategy Simulation is to solve:
(1) Predictable Congestion
(2) Unpredictable Incidents

=================
WHY Congestions?
(1) Drivers' decisions conflict with each other.
      Mode Choice, Departure Time, Route Choice.
(2) Capacity is limited.
      Speed - Density - Function => Low Speed & Low Flow
(3) What should be done.
       Gradually guide people outside.

Something:
(1) We know WHY Congestion Happen.
(2) Number of Vehicles - << Estimation Function -<< Simulation Prove;
(3) Balance between Level-of-Service and Diverge-Count;
(4) Both Sources (More) & Destinations

================
WHY Incidents?
(1) Something wrong happen?

Something:
================
(1) There are some delays, things already happen.
(2) Both Sources & Destinations (More)

Sunday, 12 August 2012

GIT

1. 三种状态

代码态: -> git add
索引态: -> git commit
仓库态:

2. 对比修改

1. git diff: 查看 代码态 和 索引态 的不同;
     回答:有什么修改的东西,还不在跟踪行列
2. git status: 获取整体改动的信息
    Changed but not updated
    已经修改了但还未 git add 的内容
    Changes to be committed
    已经 git add 但还未 git commit 的内容
    Untracked files
    增加了新文件或者在某个子目录下增加了新文件
  
3. 提交 git commit -a
git commit -a,这个命令可以直接提交所有修改,省去了你 git add 和 git diff 和 git
commit 的工序,可谓一条龙服务。
但是,此处有一点应该注意,那就是 git commit -a 无法把新增文件或文件夹加入进来,所以,如果你新增了文件或文件夹,那么就要老老实实的先 git add .,再 git commit 喽


4. 版本控制
git checkout experimental
复制当前branch,命名为experimental


5.合并
确保自己处于master branch
git merge XXX



6. 冲突
CONFLICT
注意:即时有冲突,实际的merge也已经结束;
需要做的是,修改master上的冲突;
然后,提交commit;

7. 删除分支
git branch -d experimental   Check 是否merge
git branch -D experimental   强制删除

8. 新建GIT
#cd myproject
#git init
#git add .
#git commit

9. 小结
按我的认识,更清楚且通俗的解释就是:git 维护的代码分成三部分,“当前工作目录”<->“index file”<->git 仓库。
git commit 会将 index file 中的改变写到 git 仓库;git add 会将“当前工作目录”的改变写到“index file”;“commit -a”则
会直接将“当前工作目录”的改动同时写到“index file”和“git 仓库”。
而 git diff 的使用稍微有些复杂,大家可以看看 Lee.MaRS 对于这个命令非常精彩的分析(蓝色字部分):(在此非常
感谢 Lee.MaRS)
将 Current working directory 记为 (1)
将 Index file 记为 (2)
将 Git repository 记为 (3)
他们之间的提交层次关系是 (1) -> (2) -> (3)
git add 完成的是(1) -> (2)
git commit 完成的是(2) -> (3)
git commit -a 两者的直接结合
从时间上看,可以认为(1)是最新的代码,(2)比较旧,(3)更旧
按时间排序就是 (1) <- (2) <- (3)
git diff 得到的是从(2)到(1)的变化
git diff –cached 得到的是从(3)到(2)的变化
git diff HEAD 得到的是从(3)到(1)的变化

Wednesday, 11 July 2012

要做的几件事

1. 让宏宇开心
2. 项目的报告和解释
3. DynaMIT-R 代码深解读
4. 去“张家界的信息”
5. PADS 2012 Report

Wednesday, 4 July 2012

Search VIM

1
Vim command Action
/pattern Search the file for pattern.
n Scan for next search match in the same direction.
N Scan for next search match but opposite direction.

2.

Replace
Vim command Action
:rs/foo/bar/a Substitute foo with bar. r determines the range and a determines the arguments.
The range (r) can be
nothing Work on current line only.
number Work on the line whose number you give.
% The whole file.
Arguments (a) can be
g Replace all occurrences in the line. Without this, Vim replaces only the first occurrences in each line.
i Ignore case for the search pattern.
I Don't ignore case.
c Confirm each substitution. You can type y to substitute this match, n to skip this match, a to substitute this and all the remaining matches ("Yes to all"), and q to quit substitution.
Examples
:452s/foo/bar/ Replace the first occurrence of the word foo with bar on line number 452.
:s/foo/bar/g Replace every occurrence of the word foo with bar on current line.
:%s/foo/bar/g Replace every occurrence of the word foo with bar in the whole file.
:%s/foo/bar/gi The same as above, but ignore the case of the pattern you want to substitute. This replaces foo, FOO, Foo, and so on.
:%s/foo/bar/gc Confirm every substitution.
:%s/foo/bar/c For each line on the file, replace the first occurrence of foo with bar and confirm every substitution.

3.
dd or :d Delete the current line. Again, you don't need to highlight it first.

4.

VIM

:w filename Save changes to a file. If you don't specify a file name, Vim saves as the file name you were editing. For saving the file under a different name, specify the file name.
:q Quit Vim. If you have unsaved changes, Vim refuses to exit.
:q! Exit Vim without saving changes.
:wq Write the file and exit.

Sunday, 1 July 2012

Tuesday, 26 June 2012

CMake

CMake is a sophisticated, cross-platform, open-source build system developed by Kitware in 2001. CMake is the name used to refer to the entire family of tools: CMake, CTest, CDash, and CPack. These tools are used to…
  • CMake – An intelligent build system used to build simple, to very elaborate projects.
  • CTest, CDash – These are used to test and debug your projects.
  • CPack – A packaging tool that finalizes your project for distribution.
 To:
http://mathnathan.com/2010/07/11/getting-started-with-cmake/

CMake simplifies the potentially monstrous build system into a few easy to write files. It is targeted towards C and C++ and is usable with various compiler/OS support. At the risk of over simplifying things, CMake looks at your project and sees a ‘file system’. You tell it where all your files are at, what you want it to do with them, and it does it. In a nut shell it’s really that easy. More elaborately however, CMake is wonderful for it’s design to support complex directory hierarchies. When you use CMake it will locate include files, libraries, executables, other optional build directives, then link everything for you. No more messy Makefiles.
CMake basically requires one thing, a CMakeLists.txt file. We’ll start with a simple example.
Here is a very simple program I wrote in C called fib.c which lists the Fibonacci Sequence up to a given value. That value is passed to the main function when it is called.
# include "stdio.h"
# include "stdlib.h"

int main( int argc, char** argv) {
 if ( argc > 2 || argc == 1 ) {
  printf("Fibonacci takes one postitive integer greater\
                         than two as it's argument\n");
  return EXIT_SUCCESS;
 }
 int a, b;
 a = 0;
 b = 1;
 printf( "%d", b );
 for( int i = 0; i + a <= atof( argv[1] ); b = i ) {
  i = a + b;
  a = b;
  printf( ", %d", i );
 }
 printf("\n");
 return EXIT_SUCCESS;
}
So let's say you'd like to compile this and give it a go. We could just compile it directly with one line...
        gcc -std=c99 fib.c
Notice we need a -std flag. We set it to c99 because loop initial declarations are only allowed in c99 mode. Alternatively you could just change that in your gcc compiler to use by default. Another option would be to use a Makefile..... Nah... Or we could use CMake. I declare the winner to be CMake.

Download

Let's make sure we have CMake on our systems, I'm using Ubuntu 10.04.
      sudo apt-get install cmake cmake-curses-gui
The cmake-curses-gui provides a somewhat-helpful-gui (a lot like the Windows version) if that's what you're into. There is pretty much no setup required here, we just need to make our CMakeLists.txt file in the main directory of our project, then run CMake from our build folder.

Setup Project

fib is the name of the folder/main directory, where the fib.c file is, as well as the soon to be disclosed CMakeLists.txt file. It's a good programming practice to do all of your builds in a build folder. Not doing so clutters your project folder with a bunch of confusing files. You'll see this after we run cmake. So let's set this up.
       mkdir /where/you/want/your/project/fib
        cd fib
        mkdir build
So this is what your project file system looks like.
        fib
       /
    build
Now use your favorite text editor (should be vim ;-) ) to create your own fib.c file, as well as a CMakeLists.txt file in your fib directory.

CMake Syntax

Here is the CMakeLists.txt file used to compile the fib.c program.
#Specify the version being used aswell as the language
cmake_minimum_required(VERSION 2.6 C)
#Name your project here
project(fibonacci)

#Sends the -std=c99 flag to the gcc compiler
add_definitions(-std=c99)
#This tells CMake to fib.c and name it fibonacci
add_executable(fibonacci fib.c)
The basic syntax of CMake consists of three things; comments, commands, and white spaces. A comment is made by beginning a line with the '#' character
       #Chocolate Curry is my favorite
And a command is constructed with the command name, opening parenthesis, whitespace separated arguments, and a closing parenthesis.
        command(arg1 agr2 agr3 ...)
The basic data type in CMake is a string. You can even create lists of strings using the set command.
        set(VAR a b c)
This creates variable VAR which is composed of three strings a, b, and c. Referencing a variable should look familiar to most of you. ${VAR} is the correct syntax to refer to the list of strings VAR at a later time. For instance these three command calls are the same.
        command(${VAR})
        command(a b c)
        command(a;b;c)
You can also separate strings with semicolons. Placing quotations around anything will allow it to be read as a string. For instance, the following command
        command("${VAR}")
will read in "${VAR}" not "a b c". CMake syntax also provides some useful flow control options. First is the if else logic structure.
        # some_command will be called if the variable's value is not:
        # empty, 0, N, NO, OFF, FALSE, NOTFOUND, or -NOTFOUND.
        if(var)
           some_command(...)
        endif(var) 
They also provide looping commands, foreach and while.
        set(VAR a b c)
        # loop over a, b,c with the variable f
        foreach(f ${VAR})
            message(${f})
        endforeach(f) 
Simple function and macro constructions are also supported.
        # define a macro hello
        macro(hello MESSAGE)
            message(${MESSAGE})
        endmacro(hello)
        # call the macro with the string "hello world"
        hello("hello world")
        # define a function hello
        function(hello MESSAGE)
            message(${MESSAGE})
        endfunction(hello)
Lastly CMake also supports all of your common Regular Expressions
  • ^ Matches at beginning of a line or string
  • $ Matches at end of a line or string
  • . Matches any single character other than a newline
  • [ ] Matches any character(s) inside the brackets
  • [^ ] Matches any character(s) not inside the brackets
  • [-] Matches any character in range on either side of a dash
  • * Matches preceding pattern zero or more times
  • + Matches preceding pattern one or more times
  • ? Matches preceding pattern zero or once only
  • () Saves a matched expression and uses it in a later replacement
For a more detailed description of CMake syntax go here.

Building The Project

So back to the CMakeLists.txt file to build our example
#Specify the version being used aswell as the language
cmake_minimum_required(VERSION 2.6 C)
#Name your project here
project(fibonacci)

#Sends the -std=c99 flag to the gcc compiler
add_definitions(-std=c99)
#This tells CMake to fib.c and name it fibonacci
add_executable(fibonacci fib.c)
CMake is case insensitive, thus it does not distinguish between command() and COMMAND(). I prefer all lowercase because it is faster to type. so here is the breakdown of the CMakeLists.txt
  • cmake_minimum_required(VERSION 2.6 C) - This signifies the version of CMake that you're using and allows you to pass the language into documentation.
  • project(fibonacci) - This allows you to name your project and you can later on refer to the project as a whole using this string.
  • add_definitions(-std=c99) - This command sends arguments to the compiler, which CMake will choose for you unless otherwise told so.
  • add_executable(fibonacci fib.c) - This does the magic. Here CMake takes fib.c, and using all of the libraries it was handed (none in this simple example) compiles it into the output file named fibonacci.
Beautiful, we're almost done. Now we want to compile things. Once run for the first time CMake will configure itself to your system, and place the binaries (your output files) into the directory you called it from. This is where we cd into the build folder, and run
        cmake ..
The ' .. ' argument is the same as the one used in BASH, it tells CMake to execute from the CMakeLists.txt in the previous directory. This call just produced your Makefile, so let's finish it off with the last command.
        make
Now if you ls into the build folder you'll see all kinds of stuff.
  • CMakeCache.txt - Think of this as a configuration file. It has many advanced settings to optimize the build process for large projects. (Such as building the Linux Kernel! ;-) )
  • CMakeFiles (directory) - This has a lot of the stuff CMake uses under the hood to build your project. I recommend you poke around through there and take a look at stuff...
  • cmake_install.cmake - Your install file. We didn't use one in this program.
  • fibonacci - Hooray it's our program!
  • Makefile - remember your last command 'make'? This is the Makefile produced by Cmake, this is really what it all came down to.