9#include <lala/logic/ast.hpp>
20template<
class Allocator>
22 using bstring = battery::string<Allocator>;
23 template<
class T>
using bvector = battery::vector<T, Allocator>;
24 using array_dim_t = bvector<battery::tuple<size_t,size_t>>;
25 using F = TFormula<Allocator>;
27 bvector<bstring> output_vars;
29 bvector<battery::tuple<bstring, array_dim_t, bvector<bstring>>> output_arrays;
32 std::string join_str(
const bvector<bstring>& vec,
const std::string& separator, std::function<std::string(
const bstring&)> toString)
const {
34 for (
size_t i = 0; i < vec.size(); ++i) {
35 result += toString(vec[i]);
36 if (i < vec.size() - 1) {
45 template <
class Alloc2>
55 , output_arrays(alloc),type(outputType)
61 template <
class Alloc>
63 output_vars = other.output_vars;
64 output_arrays = other.output_arrays;
69 template<
class Alloc2>
71 : output_vars(other.output_vars, allocator)
72 , output_arrays(other.output_arrays, allocator),type(other.type)
75 void add_array_var(
const std::string& name,
const bstring& var_name,
const peg::SemanticValues& sv) {
77 auto array_name = bstring(name.data());
78 for(
int i = 0; i < output_arrays.size(); ++i) {
79 if(battery::get<0>(output_arrays[i]) == array_name) {
85 output_arrays.push_back(battery::make_tuple<bstring, array_dim_t, bvector<bstring>>(bstring(array_name), {}, {}));
86 idx =
static_cast<int>(output_arrays.size()) - 1;
88 for(
int i = 0; i < sv.size(); ++i) {
89 auto range = std::any_cast<F>(sv[i]);
90 for(
int j = 0; j < range.s().size(); ++j) {
91 const auto& itv = range.s()[j];
92 battery::get<1>(output_arrays[idx]).push_back(battery::make_tuple(battery::get<0>(itv).z(), battery::get<1>(itv).z()));
96 battery::get<2>(output_arrays[idx]).push_back(var_name);
100 output_vars.push_back(var_name);
106 template <
class Alloc,
class B,
class Env>
107 CUDA
void print_variable(
const LVar<Alloc>& vname,
const Env& benv,
const B& b)
const {
108 const auto& x = *(benv.variable_of(vname));
109 x.sort.print_value(b.project(x.avars[0]));
113 template <
class Env,
class A,
class S>
115 for(
int i = 0; i < output_vars.size(); ++i) {
116 printf(
"%s=", output_vars[i].data());
117 simplifier.print_variable(output_vars[i], env, sol);
120 for(
int i = 0; i < output_arrays.size(); ++i) {
121 const auto& dims = battery::get<1>(output_arrays[i]);
122 const auto& array_vars = battery::get<2>(output_arrays[i]);
123 printf(
"%s=array%" PRIu64
"d(", battery::get<0>(output_arrays[i]).data(), dims.size());
124 for(
int j = 0; j < dims.size(); ++j) {
125 printf(
"%" PRIu64
"..%" PRIu64
",", battery::get<0>(dims[j]), battery::get<1>(dims[j]));
128 for(
int j = 0; j < array_vars.size(); ++j) {
129 simplifier.print_variable(array_vars[j], env, sol);
130 if(j+1 != array_vars.size()) {
138 template<
class Env,
class A,
class S>
140 auto vars = join_str(output_vars,
" ", [](
const bstring& s) -> std::string {
return s.data(); });
141 printf(
"v <instantiation> <list>%s</list> <values>", vars.c_str());
142 for (
int i = 0; i < output_vars.size(); ++i) {
143 simplifier.print_variable(output_vars[i], env, sol);
144 if(i+1 != output_vars.size()) {
148 printf(
"</values> </instantiation>\n");
153 template <
class Env,
class A,
class S>
Definition solver_output.hpp:105
Definition solver_output.hpp:21
CUDA SolverOutput(const SolverOutput< Alloc2 > &other, const Allocator &allocator=Allocator{})
Definition solver_output.hpp:70
CUDA SolverOutput(const Allocator &alloc, OutputType outputType)
Definition solver_output.hpp:53
void add_var(const bstring &var_name)
Definition solver_output.hpp:99
CUDA SolverOutput(const Allocator &alloc)
Definition solver_output.hpp:48
CUDA void print_solution(const Env &env, const A &sol, const S &simplifier=SimplifierIdentity{}) const
Definition solver_output.hpp:154
SolverOutput(SolverOutput &&)=default
CUDA SolverOutput< Allocator > & operator=(const SolverOutput< Alloc > &other)
Definition solver_output.hpp:62
CUDA void print_solution_xml(const Env &env, const A &sol, const S &simplifier=SimplifierIdentity{}) const
Definition solver_output.hpp:139
void add_array_var(const std::string &name, const bstring &var_name, const peg::SemanticValues &sv)
Definition solver_output.hpp:75
CUDA void print_solution_flat_zinc(const Env &env, const A &sol, const S &simplifier=SimplifierIdentity{}) const
Definition solver_output.hpp:114
bvector< bstring > getOutputVars()
Definition solver_output.hpp:102
SolverOutput< Allocator > & operator=(const SolverOutput< Allocator > &)=default
Definition flatzinc_parser.hpp:21
OutputType
Definition solver_output.hpp:14