1
0
This repository has been archived on 2025-03-06. You can view files and clone it, but cannot push or open issues or pull requests.
Jip J. Dekker 6719176975 Squashed 'software/gecode/' changes from 313e87646d..70a1cfa856
70a1cfa856 Add reasoning about why a restart happens
5db96c6afc Add initial version of the 'complete' propagator
3410436fc5 Fix include problems on Linux and Windows
0218f3e7be Remove deprecated restart_count from the variables set on restart
7f4a528ced Fix makefile mistake for LastVal constraint
8a39aee00d Initialise LastVal stored as the minimal in the domain
86707c674e Update STATUS to match the new enum
44d672100f Add support for LastVal from FlatZinc
bd8af2e8f6 Subsume after propagation
2f07e027ab Add LastVal propagator
f05cf9daba Output number of copies
707e30c0f0 Update generated parser files
179ee693cc Add restart_number() builtin (to work around the problem that otherwise we can't implement round robin style search)
04a492da17 Fix restart numbers (didn't count incomplete neighbourhoods)
fbaa3529ec Initial implementation of on_restart
6dd39a73dd Update LICENSE
8f5ea30eba Update LICENSE
4236a2e5ec Use std::vector instead of std::array
c53655d685 Dynamically adjust test batch sizes
37248557b6 Require C++11
cc60ea7cde Minor, remove exraneous newline in changelog
74c5f54b9f Make Region pool thread local
6f04ac3514 Use atomic for propagator identifier
2e0c275b07 Add support for parallel testing
3ada422b76 Refactor, extracted run_test function
787c41b8c4 Refactor, move data and logic into Options
120fc512a7 Refactor, extract run_tests function
85dd87a4af Refactoring: Thread rand through calls in test
cece9da4ef Refactor Assignments operator() to has_more
564410e4ee Refactor Assignment operator++ to next()
e1c84af894 Separate test filtering from running
8558856298 Remove empty statement warnings
a9d8cb64fa Fix compilation errors for CPProfiler support
9ec81a69b2 Add RestartStop
REVERT: 313e87646d Fix include problems on Linux and Windows
REVERT: 358b8ca63b Remove deprecated restart_count from the variables set on restart
REVERT: 83508d5de2 Fix makefile mistake for LastVal constraint
REVERT: 530bbaf107 Initialise LastVal stored as the minimal in the domain
REVERT: 96ba0d3d7e Update STATUS to match the new enum
REVERT: 7d772297f9 Add support for LastVal from FlatZinc
REVERT: 98b0162d75 Subsume after propagation
REVERT: 5cd4552144 Add LastVal propagator
REVERT: 9b80e644b7 Output number of copies
REVERT: aaa5301366 Update generated parser files
REVERT: 6ff4efe6a4 Add restart_number() builtin (to work around the problem that otherwise we can't implement round robin style search)
REVERT: 8bcbec5d6e Fix restart numbers (didn't count incomplete neighbourhoods)
REVERT: 3f63e743b2 Initial implementation of on_restart
REVERT: b6ffa462d1 Update LICENSE
REVERT: ad0621c26c Update LICENSE
REVERT: 93caa97684 Use std::vector instead of std::array
REVERT: 32d6399b35 Dynamically adjust test batch sizes
REVERT: e7f00e9977 Require C++11
REVERT: a5ba8e4282 Minor, remove exraneous newline in changelog
REVERT: b24831354d Make Region pool thread local
REVERT: b1a109ac2e Use atomic for propagator identifier
REVERT: 3d77aaad71 Add support for parallel testing
REVERT: b1b9526049 Refactor, extracted run_test function
REVERT: 85b8a57f65 Refactor, move data and logic into Options
REVERT: d2c1961437 Refactor, extract run_tests function
REVERT: 0236327c75 Refactoring: Thread rand through calls in test
REVERT: ba81289b02 Refactor Assignments operator() to has_more
REVERT: 038a554bd8 Refactor Assignment operator++ to next()
REVERT: f34f125131 Separate test filtering from running
REVERT: cec6336ede Remove empty statement warnings
REVERT: d63e1fc042 Fix compilation errors for CPProfiler support

git-subtree-dir: software/gecode
git-subtree-split: 70a1cfa856d138b0845d2681c46ca16f8507aebf
2021-07-11 16:26:15 +10:00

265 lines
7.8 KiB
C++

/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Guido Tack, 2007
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef FLATZINC_PARSER_HH
#define FLATZINC_PARSER_HH
#include <gecode/flatzinc.hh>
// This is a workaround for a bug in flex that only shows up
// with the Microsoft C++ compiler
#if defined(_MSC_VER)
#define YY_NO_UNISTD_H
#ifdef __cplusplus
extern "C" int isatty(int);
#endif
#endif
// The Microsoft C++ compiler marks certain functions as deprecated,
// so let's take the alternative definitions
#if defined(_MSC_VER)
#define strdup _strdup
#define fileno _fileno
#endif
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <gecode/flatzinc/option.hh>
#include <gecode/flatzinc/varspec.hh>
#include <gecode/flatzinc/conexpr.hh>
#include <gecode/flatzinc/ast.hh>
#include <gecode/flatzinc/parser.tab.hpp>
#include <gecode/flatzinc/symboltable.hh>
namespace Gecode { namespace FlatZinc {
typedef std::pair<std::string,Option<std::vector<int>* > > intvartype;
class VarSpec;
typedef std::pair<std::string, VarSpec*> varspec;
/// Strict weak ordering for output items
class OutputOrder {
public:
/// Return if \a x is less than \a y, based on first component
bool operator ()(const std::pair<std::string,AST::Node*>& x,
const std::pair<std::string,AST::Node*>& y) {
return x.first < y.first;
}
};
/// Types of symbols
enum SymbolType {
ST_INTVAR, //< Integer variable
ST_BOOLVAR, //< Boolean variable
ST_FLOATVAR, //< Float variable
ST_SETVAR, //< Set variable
ST_INTVARARRAY, //< Integer variable array
ST_BOOLVARARRAY, //< Boolean variable array
ST_SETVARARRAY, //< Set variable array
ST_FLOATVARARRAY, //< Float variable array
ST_INTVALARRAY, //< Integer array
ST_BOOLVALARRAY, //< Boolean array
ST_SETVALARRAY, //< Set array
ST_FLOATVALARRAY, //< Float array
ST_INT, //< Integer
ST_BOOL, //< Boolean
ST_SET, //< Set
ST_FLOAT //< Float
};
/// Entries in the symbol table
class SymbolEntry {
public:
SymbolType t; //< Type of entry
int i; //< Value of entry or array start index
/// Default constructor
SymbolEntry(void) {}
/// Constructor
SymbolEntry(SymbolType t0, int i0) : t(t0), i(i0) {}
};
/// Construct integer variable entry
forceinline SymbolEntry se_iv(int i) {
return SymbolEntry(ST_INTVAR, i);
}
/// Construct Boolean variable entry
forceinline SymbolEntry se_bv(int i) {
return SymbolEntry(ST_BOOLVAR, i);
}
/// Construct float variable entry
forceinline SymbolEntry se_fv(int i) {
return SymbolEntry(ST_FLOATVAR, i);
}
/// Construct set variable entry
forceinline SymbolEntry se_sv(int i) {
return SymbolEntry(ST_SETVAR, i);
}
/// Construct integer variable array entry
forceinline SymbolEntry se_iva(int i) {
return SymbolEntry(ST_INTVARARRAY, i);
}
/// Construct Boolean variable array entry
forceinline SymbolEntry se_bva(int i) {
return SymbolEntry(ST_BOOLVARARRAY, i);
}
/// Construct float variable array entry
forceinline SymbolEntry se_fva(int i) {
return SymbolEntry(ST_FLOATVARARRAY, i);
}
/// Construct set variable array entry
forceinline SymbolEntry se_sva(int i) {
return SymbolEntry(ST_SETVARARRAY, i);
}
/// Construct integer entry
forceinline SymbolEntry se_i(int i) {
return SymbolEntry(ST_INT, i);
}
/// Construct Boolean entry
forceinline SymbolEntry se_b(bool b) {
return SymbolEntry(ST_BOOL, b);
}
/// Construct set entry
forceinline SymbolEntry se_s(int i) {
return SymbolEntry(ST_SET, i);
}
/// Construct float entry
forceinline SymbolEntry se_f(int i) {
return SymbolEntry(ST_FLOAT, i);
}
/// Construct integer array entry
forceinline SymbolEntry se_ia(int i) {
return SymbolEntry(ST_INTVALARRAY, i);
}
/// Construct Boolean array entry
forceinline SymbolEntry se_ba(int i) {
return SymbolEntry(ST_BOOLVALARRAY, i);
}
/// Construct set array entry
forceinline SymbolEntry se_sa(int i) {
return SymbolEntry(ST_SETVALARRAY, i);
}
/// Construct float array entry
forceinline SymbolEntry se_fa(int i) {
return SymbolEntry(ST_FLOATVALARRAY, i);
}
/// %State of the %FlatZinc parser
class ParserState {
public:
ParserState(const std::string& b, std::ostream& err0,
Gecode::FlatZinc::FlatZincSpace* fg0)
: buf(b.c_str()), pos(0), length(b.size()), fg(fg0),
hadError(false), err(err0) {}
ParserState(char* buf0, int length0, std::ostream& err0,
Gecode::FlatZinc::FlatZincSpace* fg0)
: buf(buf0), pos(0), length(length0), fg(fg0),
hadError(false), err(err0) {}
void* yyscanner;
const char* buf;
unsigned int pos, length;
Gecode::FlatZinc::FlatZincSpace* fg;
std::vector<std::pair<std::string,AST::Node*> > _output;
SymbolTable<SymbolEntry> symbols;
std::vector<varspec> intvars;
std::vector<varspec> boolvars;
std::vector<varspec> setvars;
std::vector<varspec> floatvars;
std::vector<int> arrays;
std::vector<AST::SetLit> setvals;
std::vector<double> floatvals;
std::vector<ConExpr*> constraints;
std::vector<ConExpr*> domainConstraints;
int status_idx = -1;
int complete_idx = -1;
std::vector<std::array<int, 3>> int_uniform;
std::vector<std::array<int, 2>> int_sol;
std::vector<std::array<int, 2>> int_lastval;
bool hadError;
std::ostream& err;
int fillBuffer(char* lexBuf, unsigned int lexBufSize) {
if (pos >= length)
return 0;
int num = std::min(length - pos, lexBufSize);
memcpy(lexBuf,buf+pos,num);
pos += num;
return num;
}
void output(std::string x, AST::Node* n) {
_output.push_back(std::pair<std::string,AST::Node*>(x,n));
}
AST::Array* getOutput(void) {
OutputOrder oo;
std::sort(_output.begin(),_output.end(),oo);
AST::Array* a = new AST::Array();
for (unsigned int i=0; i<_output.size(); i++) {
a->a.push_back(new AST::String(_output[i].first+" = "));
if (_output[i].second->isArray()) {
AST::Array* oa = _output[i].second->getArray();
for (unsigned int j=0; j<oa->a.size(); j++) {
a->a.push_back(oa->a[j]);
oa->a[j] = nullptr;
}
delete _output[i].second;
} else {
a->a.push_back(_output[i].second);
}
a->a.push_back(new AST::String(";\n"));
}
return a;
}
};
}}
#endif
// STATISTICS: flatzinc-any