Skip to content

Commit 4b4f0ab

Browse files
authored
Merge pull request #27 from kwrx/dev
Conforme alla teoria
2 parents 086846e + 15b848a commit 4b4f0ab

33 files changed

+382
-152
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ set(HAVE_CLASP 0)
1515

1616
## QASP
1717
set(HAVE_THREADS 1)
18-
set(HAVE_ITERATIONS 1)
1918

2019
## Wasp
2120
set(HAVE_WASP_ASSUMPTIONS 1)
2221
set(HAVE_WASP_RESET 1)
2322

2423
## Logger
2524
set(HAVE_PRETTY_LOGGER 1)
25+
set(HAVE_PERFORMANCE 1)
2626

2727
######################################
2828

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $ cmake -DCMAKE_BUILD_TYPE=Release -B build
1010
$ cmake --build build
1111
$ cmake --install build
1212
```
13-
**NOTE:** [CMake](https://cmake.org/) >= 3.11 and [Boost C++ Libraries](https://www.boost.org/) >= 1.72.0 are required.
13+
**NOTE:** [CMake](https://cmake.org/) >= 3.20 and [Boost C++ Libraries](https://www.boost.org/) >= 1.72.0 are required.
1414

1515
## Usage
1616
Open your terminal and type:
@@ -19,7 +19,7 @@ $ qasp [OPTIONS] SOURCES...
1919
```
2020
Or read from *stdin*
2121
```shell script
22-
$ cat SOURCES | qasp
22+
$ cat SOURCE | qasp
2323
```
2424
**NOTE:** type ```qasp --help``` for more information.
2525

@@ -34,7 +34,7 @@ d :- b.
3434
%@constraints
3535
:- c, not d.
3636
```
37-
Calculate if exists an *answer set* of **@exists fragment** such that for each *answer set* of **@forall fragmemt** is a *coherent* solution.
37+
Calculate if exists an *answer set* of **@exists program** such that for each *answer set* of **@forall program** is a *coherent* solution.
3838
```shell script
3939
$ qasp program.asp
4040
```

config.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
#cmakedefine HAVE_GRINGO @HAVE_GRINGO@
2828
#cmakedefine HAVE_CLASP @HAVE_CLASP@
2929
#cmakedefine HAVE_THREADS @HAVE_THREADS@
30-
#cmakedefine HAVE_ITERATIONS @HAVE_ITERATIONS@
3130
#cmakedefine HAVE_WASP_ASSUMPTIONS @HAVE_WASP_ASSUMPTIONS@
3231
#cmakedefine HAVE_WASP_RESET @HAVE_WASP_RESET@
3332
#cmakedefine HAVE_PRETTY_LOGGER @HAVE_PRETTY_LOGGER@
33+
#cmakedefine HAVE_PERFORMANCE @HAVE_PERFORMANCE@
3434

3535

3636
#define QASP_PROGRAM_NAME "@CMAKE_PROJECT_NAME@"

include/qasp/qasp.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,14 @@ namespace qasp {
4747

4848
uint16_t quiet;
4949
uint16_t cpus;
50-
qasp_iteration_t iterations;
5150

5251
Options(uint16_t quiet, uint16_t cpus, qasp_iteration_t iterations)
5352
: quiet(quiet)
54-
, cpus(cpus)
55-
, iterations(iterations) {}
53+
, cpus(cpus) {}
5654

5755
Options()
5856
: quiet(QASP_OPTIONS_DEFAULT_QUIET)
59-
, cpus(QASP_OPTIONS_DEFAULT_CPUS)
60-
, iterations(QASP_OPTIONS_DEFAULT_ITERATIONS) {}
57+
, cpus(QASP_OPTIONS_DEFAULT_CPUS) {}
6158

6259
};
6360

src/main.cc

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ static void show_usage(int argc, char** argv) {
3636
<< "Use: " << QASP_PROGRAM_NAME << " [OPTIONS] SOURCES...\n"
3737
<< "Process qasp SOURCES and blabla...\n\n"
3838
<< " -j N, --parallel=N allow N jobs at once.\n"
39-
<< " -n N, --iterations=N iterate solving N times (infinite: N <= 0).\n"
4039
<< " -q, --quiet hide log information.\n"
4140
<< " --help print this message and exit.\n"
4241
<< " --version print version info and exit.\n";
@@ -85,7 +84,7 @@ int main(int argc, char** argv) {
8584
qasp::Options options;
8685

8786
int c, idx;
88-
while((c = getopt_long(argc, argv, "qj:n:hv", long_options, &idx)) != -1) {
87+
while((c = getopt_long(argc, argv, "qj:hv", long_options, &idx)) != -1) {
8988

9089
switch(c) {
9190
case 'q':
@@ -94,9 +93,6 @@ int main(int argc, char** argv) {
9493
case 'j':
9594
options.cpus = atoi(optarg);
9695
break;
97-
case 'n':
98-
options.iterations = atoll(optarg);
99-
break;
10096
case 'v':
10197
show_version(argc, argv);
10298
break;
@@ -112,12 +108,7 @@ int main(int argc, char** argv) {
112108

113109

114110
if(unlikely(options.cpus < 1)) {
115-
std::cerr << QASP_PROGRAM_NAME << ": error: invalid parallel value" << std::endl;
116-
abort();
117-
}
118-
119-
if(unlikely(options.iterations <= 0)) {
120-
options.iterations = std::numeric_limits<decltype(options.iterations)>().max();
111+
options.cpus = std::numeric_limits<decltype(options.cpus)>().max();
121112
}
122113

123114

@@ -163,6 +154,7 @@ int main(int argc, char** argv) {
163154

164155
}
165156

157+
166158
return EXIT_SUCCESS;
167159

168160
}

src/qasp/AnswerSet.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#pragma once
2222

2323
#include "Atom.hpp"
24+
#include "utils/Performance.hpp"
2425

2526
#include <iostream>
2627
#include <vector>
@@ -34,7 +35,7 @@ namespace qasp {
3435
class AnswerSet : public std::vector<Atom> {
3536
public:
3637

37-
inline friend bool operator==(const AnswerSet& a, const AnswerSet& b) {
38+
inline friend bool operator==(const AnswerSet& a, const AnswerSet& b) { __PERF_TIMING(answerset_comparing);
3839

3940
if(a.size() != b.size())
4041
return false;

src/qasp/Program.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "AnswerSet.hpp"
2424
#include "grounder/Grounder.hpp"
2525
#include "solver/Solver.hpp"
26+
#include "utils/Performance.hpp"
2627

2728
#include <iostream>
2829
#include <sstream>
@@ -49,7 +50,7 @@ using namespace qasp::solver;
4950

5051

5152

52-
const Program& Program::groundize(Assumptions assumptions) {
53+
const Program& Program::groundize(Assumptions assumptions) { __PERF_TIMING(grounding);
5354

5455
LOG(__FILE__, INFO) << "Generating ground for program #" << id() << " with:"
5556
<< " assumptions(" << assumptions << ")" << std::endl;
@@ -115,7 +116,7 @@ const Program& Program::groundize(Assumptions assumptions) {
115116
}
116117

117118

118-
std::tuple<ProgramModel, std::vector<AnswerSet>> Program::solve(const AnswerSet& answer) const {
119+
std::tuple<ProgramModel, std::vector<AnswerSet>> Program::solve(const AnswerSet& answer) const { __PERF_TIMING(solving);
119120

120121
assert(!ground().empty());
121122

src/qasp/Program.hpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "Atom.hpp"
2424
#include "Assumptions.hpp"
2525
#include "AnswerSet.hpp"
26+
#include "utils/Performance.hpp"
2627

2728
#include <string>
2829
#include <vector>
@@ -94,6 +95,15 @@ namespace qasp {
9495
return this->__assumptions = std::move(assumptions), *this;
9596
}
9697

98+
99+
inline const auto& last() const {
100+
return this->__last;
101+
}
102+
103+
inline void last(bool last) {
104+
this->__last = std::move(last);
105+
}
106+
97107
const Program& groundize(Assumptions assumptions = {});
98108
std::tuple<ProgramModel, std::vector<AnswerSet>> solve(const AnswerSet& answer = {}) const;
99109

@@ -104,13 +114,15 @@ namespace qasp {
104114
ProgramType __type;
105115
std::string __source;
106116
std::string __ground;
107-
Assumptions __assumptions;
108117
std::vector<Program> __subprograms;
109-
std::unordered_map<std::string, Atom> __atoms;
110-
atom_index_t __atoms_index_offset;
118+
119+
std::unordered_map<std::string, Atom> __atoms {};
120+
atom_index_t __atoms_index_offset = 0;
121+
Assumptions __assumptions {};
122+
bool __last = false;
111123

112124

113-
inline const atom_index_t map_index(const Atom& atom) const {
125+
inline const atom_index_t map_index(const Atom& atom) const { __PERF_INC(mapping);
114126

115127
const auto& found = atoms().find(atom.predicate());
116128

src/qasp/Qasp.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,19 @@ std::string Qasp::run() {
4545

4646

4747
QaspSolver qasp(*this, program);
48-
49-
if(qasp.run()) {
48+
49+
bool result = qasp.run();
50+
51+
52+
53+
__PERF_PRINT_ALL();
54+
55+
if(result) {
5056

5157
std::ostringstream output;
5258

5359
for(const auto& answer : qasp.solution())
54-
output << answer.second << std::endl;
60+
output << answer << std::endl;
5561

5662
return output.str();
5763

0 commit comments

Comments
 (0)