Generated on for Gecode by doxygen 1.17.0
instance.hh
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
5 *
6 * Copyright:
7 * Mikael Zayenz Lagerkvist, 2026
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#ifndef GECODE_INSTANCE_HH
35#define GECODE_INSTANCE_HH
36
37#include <gecode/kernel.hh>
38#include <gecode/int.hh>
39
40#include <iosfwd>
41#include <memory>
42#include <string>
43
44/*
45 * Configure linking
46 *
47 */
48#if !defined(GECODE_STATIC_LIBS) && \
49 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
50
51#ifdef GECODE_BUILD_INSTANCE
52#define GECODE_INSTANCE_EXPORT __declspec( dllexport )
53#else
54#define GECODE_INSTANCE_EXPORT __declspec( dllimport )
55#endif
56
57#else
58
59#ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
60#define GECODE_INSTANCE_EXPORT __attribute__ ((visibility("default")))
61#else
62#define GECODE_INSTANCE_EXPORT
63#endif
64
65#endif
66
67// Configure auto-linking
68#ifndef GECODE_BUILD_INSTANCE
69#define GECODE_LIBRARY_NAME "Instance"
71#endif
72
89
90namespace Gecode { namespace Instance {
91
104
324
338 protected:
340 std::string msg;
341 public:
343 explicit Error(const std::string& m);
345 virtual const char* what(void) const noexcept override;
346 };
347
349 enum class ValueType {
353 };
354
355 class DataImpl;
356 class SpecImpl;
357 class ParamsImpl;
358
365 private:
367 std::shared_ptr<ParamsImpl> impl;
368 public:
370 Params(void);
372 void set(const std::string& name, const std::string& value);
380 void set(const std::string& assignments);
382 bool get(const std::string& name, std::string& value) const;
384 int size(void) const;
386 std::string name(int i) const;
387 };
388
407 friend class SpecImpl;
408 private:
410 std::shared_ptr<const DataImpl> impl;
411 public:
413 Data(void);
414
416
417
418 int entries(void) const;
420 std::string name(int i) const;
422 bool has(const std::string& n) const;
424 ValueType type(const std::string& n) const;
426 int depth(const std::string& n) const;
428
430
431
432 int size(const std::string& n, const IntArgs& path = IntArgs()) const;
434 long long int integer(const std::string& n, const IntArgs& path = IntArgs()) const;
436 double number(const std::string& n, const IntArgs& path = IntArgs()) const;
438 std::string text(const std::string& n, const IntArgs& path = IntArgs()) const;
440 IntArgs ints(const std::string& n, const IntArgs& path = IntArgs()) const;
442 ArgArray<double> numbers(const std::string& n, const IntArgs& path = IntArgs()) const;
444
446
447
461 void dzn(std::ostream& os) const;
463 };
464
471 private:
473 std::shared_ptr<const SpecImpl> impl;
474 public:
476 Spec(void);
477
479
480
481 static Spec parse(const std::string& text, const std::string& origin = "<spec>");
483 static Spec load(const std::string& path);
485
487
488
489 std::string name(void) const;
491
493
494
500 Data read(const std::string& path, const Params& p = Params()) const;
502 Data read_text(const std::string& text, const std::string& origin = "<input>", const Params& p = Params()) const;
513 Data catalog(const std::string& path, const Params& p = Params()) const;
515 Data catalog_text(const std::string& text, const std::string& origin = "<input>", const Params& p = Params()) const;
517 };
518
519}}
520
521#endif
522
523// STATISTICS: instance-any
Argument array for non-primitive types.
Definition array.hpp:695
Exception(const char *l, const char *i) noexcept
Initialize with location l and information i.
Definition exception.cpp:42
Named values read from an instance.
Definition instance.hh:406
IntArgs ints(const std::string &n, const IntArgs &path=IntArgs()) const
Return all integers in the array or row n at path.
Definition data.cpp:405
int size(const std::string &n, const IntArgs &path=IntArgs()) const
Return the length of the array or row n at path.
Definition data.cpp:385
void dzn(std::ostream &os) const
Print all entries as MiniZinc data.
Definition data.cpp:537
double number(const std::string &n, const IntArgs &path=IntArgs()) const
Return the number n at path (integers are converted).
Definition data.cpp:395
ValueType type(const std::string &n) const
Return the value type of entry n.
Definition data.cpp:375
std::string text(const std::string &n, const IntArgs &path=IntArgs()) const
Return the string n at path.
Definition data.cpp:400
int depth(const std::string &n) const
Return the depth of entry n (0 for scalars).
Definition data.cpp:380
Data(void)
Empty data.
Definition data.cpp:354
bool has(const std::string &n) const
Test whether there is an entry n.
Definition data.cpp:370
friend class SpecImpl
Definition instance.hh:407
std::string name(int i) const
Return name of entry i, in the order they were defined.
Definition data.cpp:363
long long int integer(const std::string &n, const IntArgs &path=IntArgs()) const
Return the integer n at path.
Definition data.cpp:390
ArgArray< double > numbers(const std::string &n, const IntArgs &path=IntArgs()) const
Return all numbers in the array or row n at path.
Definition data.cpp:410
int entries(void) const
Return number of entries.
Definition data.cpp:358
Error(const std::string &m)
Initialize with message m.
Definition data.cpp:52
std::string msg
The full message.
Definition instance.hh:340
virtual const char * what(void) const noexcept override
Return the full message.
Definition data.cpp:56
Values for the param statements of a spec.
Definition instance.hh:364
Params(void)
No parameters.
Definition data.cpp:60
std::string name(int i) const
Return the name of parameter i.
Definition data.cpp:110
bool get(const std::string &name, std::string &value) const
Return whether name is set, and if so store its value in value.
Definition data.cpp:95
int size(void) const
Return number of parameters.
Definition data.cpp:105
void set(const std::string &name, const std::string &value)
Set parameter name to value.
Definition data.cpp:64
static Spec load(const std::string &path)
Load the spec in file path.
Definition spec.cpp:1275
static Spec parse(const std::string &text, const std::string &origin="<spec>")
Parse spec text, using origin in error messages.
Definition spec.cpp:1268
Data read_text(const std::string &text, const std::string &origin="<input>", const Params &p=Params()) const
Read instance text, using origin in error messages.
Definition spec.cpp:1290
Data read(const std::string &path, const Params &p=Params()) const
Read instance file path.
Definition spec.cpp:1285
std::string name(void) const
Return the format name declared by the spec (may be empty).
Definition spec.cpp:1280
Data catalog(const std::string &path, const Params &p=Params()) const
List the instances in file path.
Definition spec.cpp:1295
Spec(void)
The empty spec (reads only empty input).
Definition spec.cpp:1264
Data catalog_text(const std::string &text, const std::string &origin="<input>", const Params &p=Params()) const
List the instances in text, using origin in error messages.
Definition spec.cpp:1300
Passing integer arguments.
Definition int.hh:653
#define GECODE_INSTANCE_EXPORT
Definition instance.hh:62
Reading instance files described by reader specs.
ValueType
Type of the values in a data entry.
Definition instance.hh:349
@ FLOAT
Floating point numbers.
Definition instance.hh:351
Gecode toplevel namespace
void path(Home home, const IntVarArgs &x, IntVar s, IntVar e, IntPropLevel ipl=IPL_DEF)
Post propagator such that x forms a Hamiltonian path.
Definition circuit.cpp:169