Generated on for Gecode by doxygen 1.17.0
blackbox-backend.hh
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Jip J. Dekker <jip.dekker@monash.edu>
5 *
6 * Contributing authors:
7 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
8 *
9 * Copyright:
10 * Jip J. Dekker, 2026
11 *
12 * This file is part of Gecode, the generic constraint
13 * development environment:
14 * http://www.gecode.org
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining
17 * a copy of this software and associated documentation files (the
18 * "Software"), to deal in the Software without restriction, including
19 * without limitation the rights to use, copy, modify, merge, publish,
20 * distribute, sublicense, and/or sell copies of the Software, and to
21 * permit persons to whom the Software is furnished to do so, subject to
22 * the following conditions:
23 *
24 * The above copyright notice and this permission notice shall be
25 * included in all copies or substantial portions of the Software.
26 *
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 *
35 */
36
37#ifndef GECODE_FLATZINC_BLACKBOX_BACKEND_HH
38#define GECODE_FLATZINC_BLACKBOX_BACKEND_HH
39
40#include <cstddef>
41#include <cstdint>
42#include <string>
43#include <vector>
44
45#include <gecode/flatzinc.hh>
46#include <gecode/kernel.hh>
47#ifdef GECODE_HAS_THREADS
48#include <thread>
49#endif
50
51#ifdef _WIN32
52#define GECODE_BLACKBOX_CALL __stdcall
53#else
54#define GECODE_BLACKBOX_CALL
55#endif
56
57namespace Gecode {
58namespace FlatZinc {
59
60class BlackBoxProcessSession;
61
64 const std::vector<int64_t>& int_input;
65 const std::vector<double>& float_input;
66 std::vector<int64_t>& int_output;
67 std::vector<double>& float_output;
68};
69
72public:
73 virtual ~BlackBoxBackend(void) {}
74 virtual void run(BlackBoxCall& call) = 0;
75 void run(const std::vector<int64_t>& int_input,
76 const std::vector<double>& float_input,
77 std::vector<int64_t>& int_output,
78 std::vector<double>& float_output) {
79 BlackBoxCall call = {int_input, float_input, int_output, float_output};
80 run(call);
81 }
82};
83
86public:
88 BlackBoxLibrary(const std::string& name,
89 const std::vector<std::string>& args);
91 void run(BlackBoxCall& call) override;
92
93protected:
94 void* library;
95 void* (GECODE_BLACKBOX_CALL *library_fzn_init)(const char**, size_t);
97 void (GECODE_BLACKBOX_CALL *library_fzn_blackbox)(
98 void*, const int64_t*, size_t, const double*, size_t, int64_t*, size_t,
99 double*, size_t);
100 void (GECODE_BLACKBOX_CALL *library_fzn_free)(void*);
102
103#ifdef GECODE_HAS_THREADS
104 class Instance;
106 std::vector<Instance*> instances;
107 Instance* instance(void);
108#endif
109};
110
113public:
115 BlackBoxExec(const std::string& program,
116 const std::vector<std::string>& args);
118 void run(BlackBoxCall& call) override;
119
120protected:
121 std::string program;
122 std::vector<std::string> args;
124 std::vector<BlackBoxProcessSession*> sessions;
126};
127
130std::string encode_blackbox_request(const BlackBoxCall& call);
133void decode_blackbox_response(const std::string& response,
134 BlackBoxCall& call);
135
136} // namespace FlatZinc
137} // namespace Gecode
138
139#endif // GECODE_FLATZINC_BLACKBOX_BACKEND_HH
140
141// STATISTICS: flatzinc-other
#define GECODE_BLACKBOX_CALL
Backend for a deterministic FlatZinc blackbox function.
virtual void run(BlackBoxCall &call)=0
void run(const std::vector< int64_t > &int_input, const std::vector< double > &float_input, std::vector< int64_t > &int_output, std::vector< double > &float_output)
BlackBoxProcessSession & session(void)
std::vector< std::string > args
BlackBoxExec(const std::string &program, const std::vector< std::string > &args)
std::vector< BlackBoxProcessSession * > sessions
void run(BlackBoxCall &call) override
void *GECODE_BLACKBOX_CALL * library_fzn_clone(void *)
void *GECODE_BLACKBOX_CALL * library_fzn_init(const char **, size_t)
BlackBoxLibrary(const std::string &name, const std::vector< std::string > &args)
void run(BlackBoxCall &call) override
std::vector< Instance * > instances
void(GECODE_BLACKBOX_CALL *library_fzn_blackbox)(void *
void(GECODE_BLACKBOX_CALL *library_fzn_free)(void *)
Platform process session used by the executable blackbox backend.
A mutex for mutual exclausion among several threads.
Definition thread.hpp:78
#define GECODE_FLATZINC_EXPORT
Definition flatzinc.hh:75
GECODE_FLATZINC_EXPORT std::string encode_blackbox_request(const BlackBoxCall &call)
Encode one request for the executable backend's line protocol.
GECODE_FLATZINC_EXPORT void decode_blackbox_response(const std::string &response, BlackBoxCall &call)
Decode and validate one response from the executable backend.
Gecode toplevel namespace
Inputs and pre-sized output buffers for one backend call.
const std::vector< int64_t > & int_input
std::vector< int64_t > & int_output
const std::vector< double > & float_input
std::vector< double > & float_output