Commit cb61cc74 authored by Tiago Peixoto's avatar Tiago Peixoto

Complete overhaul of command line parsing, and support for loading graph-tool...

Complete overhaul of command line parsing, and support for loading graph-tool as whole as a python module
    
The command line parsing was completely rewritten. It now supports
better parsing of sub-options, with type checking and grouping
support. Error reporting was also significantly improved, and it now
warns of invalid options and option values, before the option is
executed. Some syntax has changed, such as range filtering:
--[vertex|edge]-range-filter was replaced by
--exclude-[vertex|edge]-range and --keep-[vertex|edge]-range, which
should have a clearer meaning. Ranges can also be specified now by
comparison operators (>,<,>=,<=,=), such as ">=10", to indicate a
range of (10, inf). In addition, ranges can now be easily open or
closed at either end, by suffixing the specific end with '*', to
indicate it is closed, ex: "10 700*" means (10,700].
    
The graph-tool script can now be loaded as a python module (it must be
renamed first to 'something.py'). All the command line options (except
'for' and 'history' which become irrelevant) are available as
functions, with full description and optional parameter support. In
addition, pure function objects can be given as parameters where
expressions are asked, instead of strings and files, which enables
convenient extension of graph-tool.
parent 55028b02
......@@ -174,9 +174,9 @@ AC_DEFINE_UNQUOTED([COPYRIGHT],
"Copyright (C) 2007 Tiago de Paula Peixoto\nThis is free software; see the source for copying conditions. There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.",
[copyright info])
AC_DEFINE([GIT_COMMIT], "esyscmd(git show | head -n 1 | sed 's/commit //' | tr -d '\n')", [git commit hash])
AC_DEFINE([GIT_COMMIT], "esyscmd(git show | head -n 1 | sed 's/commit //' | grep -o -e '.\{8\}' | head -n 1 |tr -d '\n')", [git HEAD commit hash])
AC_DEFINE([GIT_COMMIT_DATE], "esyscmd(git log -1 | head -n 3 | grep 'Date:' | sed s/'Date: '// | tr -d '\n')", [git HEAD commit date])
dnl fi
AC_OUTPUT([
Makefile
src/Makefile
......
......@@ -6,4 +6,11 @@ SUBDIRS = graph .
bin_SCRIPTS = graph-tool
EXTRA_DIST = $(bin_SCRIPTS)
\ No newline at end of file
EXTRA_DIST = $(bin_SCRIPTS)
# Also install graph-tool as a python module (graph_tool.py)
install-exec-hook:
ln -s $(bindir)/graph-tool $(pythondir)/graph_tool.py
uninstall-hook:
rm -f $(pythondir)/graph_tool.py
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -184,6 +184,15 @@ bool GraphInterface::IsEdgeFilterActive() const {return _edge_filter_property !=
void GraphInterface::SetVertexFilterRange(std::pair<double,double> allowed_range, std::pair<bool,bool> include, bool invert)
{
#ifndef NO_RANGE_FILTERING
if (isinf(allowed_range.first) == 1)
allowed_range.first = numeric_limits<double>::max();
else if (isinf(allowed_range.first) == -1)
allowed_range.first = numeric_limits<double>::min();
if (isinf(allowed_range.second) == 1)
allowed_range.second = numeric_limits<double>::max();
else if (isinf(allowed_range.second) == -1)
allowed_range.second = numeric_limits<double>::min();
_vertex_range = allowed_range;
_vertex_range_include = include;
_vertex_range_invert = invert;
......@@ -195,6 +204,15 @@ void GraphInterface::SetVertexFilterRange(std::pair<double,double> allowed_range
void GraphInterface::SetEdgeFilterRange(std::pair<double,double> allowed_range, std::pair<bool,bool> include, bool invert)
{
#ifndef NO_RANGE_FILTERING
if (isinf(allowed_range.first) == 1)
allowed_range.first = numeric_limits<double>::max();
else if (isinf(allowed_range.first) == -1)
allowed_range.first = numeric_limits<double>::min();
if (isinf(allowed_range.second) == 1)
allowed_range.second = numeric_limits<double>::max();
else if (isinf(allowed_range.second) == -1)
allowed_range.second = numeric_limits<double>::min();
_edge_range = allowed_range;
_edge_range_include = include;
_edge_range_invert = invert;
......
......@@ -244,7 +244,7 @@ struct LibInfo
string GetName() const {return PACKAGE_NAME;}
string GetAuthor() const {return AUTHOR;}
string GetCopyright() const {return COPYRIGHT;}
string GetVersion() const {return VERSION " (commit " GIT_COMMIT ")";}
string GetVersion() const {return VERSION " (commit " GIT_COMMIT ", " GIT_COMMIT_DATE ")";}
string GetLicense() const {return "GPL version 3 or above";}
};
......@@ -334,6 +334,7 @@ BOOST_PYTHON_MODULE(libgraph_tool)
tuple_from_tuple<double,double,double>();
to_python_converter<pos_t, pos_t_to_tuple>();
pos_t_from_tuple();
pair_from_tuple<bool,bool>();
to_python_converter<GraphInterfaceWrap::hist_t, hist_to_dict<GraphInterfaceWrap::hist_t> >();
to_python_converter<GraphInterfaceWrap::hist2d_t, hist_to_dict<GraphInterfaceWrap::hist2d_t> >();
to_python_converter<GraphInterfaceWrap::hist3d_t, hist_to_dict<GraphInterfaceWrap::hist3d_t> >();
......
......@@ -179,16 +179,17 @@ private:
void operator()(MapType& filter_prop)
{
// ignore if outside allowed range
double val = double(get(filter_prop, _descriptor));
bool lower;
if (_include.first)
lower = double(get(filter_prop, _descriptor)) <= _range.first;
lower = val < _range.first;
else
lower = double(get(filter_prop, _descriptor)) < _range.first;
lower = val <= _range.first;
bool upper;
if (_include.second)
upper = double(get(filter_prop, _descriptor)) >= _range.second;
upper = val > _range.second;
else
upper = double(get(filter_prop, _descriptor)) > _range.second;
upper = val >= _range.second;
_retval = !(lower || upper);
if (_invert)
_retval = !_retval;
......
......@@ -167,7 +167,7 @@ struct compute_spring_block
cooling(linear_cooling<double>(iter)).
vertex_index_map(index_map).force_pairs(all_force_pairs()));
}
else if (type == "kk")
else if (type == "kw")
{
bool retval;
retval = compute_kamada_kawai(g, iter, n, pos, weight, typename is_convertible<typename graph_traits<Graph>::directed_category,undirected_tag>::type());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment