From a4460f6d9453bbd7e584937686449cef3e19f052 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Mon, 20 Aug 2018 20:34:57 -0400 Subject: Initial commit --- src/graphcoloring/levels/value.hpp | 80 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/graphcoloring/levels/value.hpp (limited to 'src/graphcoloring/levels/value.hpp') diff --git a/src/graphcoloring/levels/value.hpp b/src/graphcoloring/levels/value.hpp new file mode 100644 index 0000000..789540e --- /dev/null +++ b/src/graphcoloring/levels/value.hpp @@ -0,0 +1,80 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2018 Leo Tenenbaum +// This file is part of GraphColoring. +// +// GraphColoring is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// GraphColoring 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 General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with GraphColoring. If not, see . +//////////////////////////////////////////////////////////////////////////////// + +#ifndef GRAPHCOLORING_LEVELS_VALUE_H_ +#define GRAPHCOLORING_LEVELS_VALUE_H_ + + +#include "pugi/pugixml.hpp" +#include "../graphs/graph.hpp" + +namespace graphcoloring { + +class Value { +public: + typedef std::function operation_t; + Value(); + Value(std::vector list); + Value(int val); + Value(const std::string& string); + Value(pugi::xml_node node); + virtual ~Value() {} + int Eval(const Graph& graph, + std::function lookup_variable) const; + static void AddNodeToVariables(pugi::xml_node node); +private: + void FromString(const std::string& string); + void ReadOperation(std::string op); + static operation_t SimpleOperation(std::function op); // For operations which don't look at the graph. + // Bool operations return bools. + static operation_t SimpleBoolOperation(std::function op); + // Logical operations take bools and return bools. + static operation_t SimpleLogicOperation(std::function op); + static void InitializeOperationTable(); + std::vector EvalListOperation(const Graph& graph, // Handles anything that returns a list. + std::function lookup_variable) const; + operation_t operation; + static std::map operation_table; + std::shared_ptr fold_start; + std::shared_ptr val1; + std::shared_ptr val2; + std::string variable_name; + int val = 0; + std::vector list; + enum class Type + { + NULL_TYPE, + VALUE, // This value represents a constant number + LIST, + VARIABLE, + NUMBER_OF_VERTICES, + NUMBER_OF_EDGES, + VERTICES, + EDGES, + OPERATION, + LIST_OPERATION, + MAP, + ZIP, + FOLD + }; + Type type; +}; + +} // namespace graphcoloring + +#endif // GRAPHCOLORING_LEVELS_VALUE_H_ -- cgit v1.2.3