How to Compile
Create a new folder named
obj when compile the program for first time.
clang++to compile our program, however, you can change it in the
Makefileas you wish. Since our program utilized some features of c++11, the compiler must support c++11 to compile the program.
To run this program, execute the command below in root folder of the project.
./smart_grid inputs/equipments.data inputs/nodes.pos inputs/grids.wrapper
Structure of Program
This picture demostrates the structure of our program. Detailed explanation of the picture is in the blockquote below.
The filled arrow represents the ownership between classes, from owner to the class owned by the owner. Owning a class means that it's responsible for managing the life cycles of its objects. The hollow arrow represents the inheritance between classes, from child to parent.
The idea of this design is to seperate the fixed information from the data that we may need to change. All equipments in the smart grid is like a database storing all the static informations, and we query it only when we need to.
To achieve this, we abstract the vertices and edges from what it really is by defining a pointer pointing to its corresponding equipment instead of storing all the equipment's informations in it, causing unnecessary copys. For example, a vertex which is actually a resident will contain a pointer pointing to its corresponding resident object instead of making its own copy of the equipment's informations.
The beauty of this design is that when we have mutiple instances of a equipment, we can construct different vertices/edges referecing exactly the same equipment without the need to copy all the repetitive informations.
Some Useful Tools
Drawing the Graph
outputs/graph.jsonis generated by the function
Graph::OutputJSON()using a third party library.
Easier Code Navigation
To make navigating codes more efficiently, we use
ctags to generate the tag
file. Use Vim or some other editors supporting
ctags to utilize the power of