1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 3 /* 4 * Main authors: 5 * Jason Nguyen <jason.nguyen@monash.edu> 6 */ 7 8 /* This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 11 12 #pragma once 13 14 #include <minizinc/ast.hh> 15 #include <minizinc/solver_config.hh> 16 17 #include <iostream> 18 #include <string> 19 #include <unordered_map> 20 #include <unordered_set> 21 #include <vector> 22 23 namespace MiniZinc { 24 /// Configuration for solver parameters 25 class ParamConfig { 26 protected: 27 std::vector<std::string> _values; 28 std::unordered_set<std::string> _blacklist; 29 std::unordered_map<std::string, std::string> _boolSwitches; 30 void addValue(const ASTString& flag, Expression* e); 31 static std::string flagName(const ASTString& flag); 32 static std::string modelToString(Model& model); 33 34 public: ParamConfig()35 ParamConfig() {} 36 /// Load a configuration from a JSON file 37 void load(const std::string& filename); 38 /// Add given parameter to blacklist 39 void blacklist(const std::string& disallowed); 40 /// Add given parameters to blacklist 41 void blacklist(const std::vector<std::string>& disallowed); 42 /// Add boolean switch 43 /// When the key is found in the config, then if it's false the negated flag is used 44 void negatedFlag(const std::string& flag, const std::string& negated); 45 /// Return the arguments represented by this configuration 46 const std::vector<std::string>& argv(); 47 }; 48 49 class ParamException : public Exception { 50 public: 51 /// Construct with message \a msg ParamException(const std::string & msg)52 ParamException(const std::string& msg) : Exception(msg) {} 53 /// Destructor ~ParamException()54 ~ParamException() throw() override {} 55 /// Return description what() const56 const char* what() const throw() override { return "MiniZinc: solver parameter error"; } 57 }; 58 } // namespace MiniZinc 59