Skip to content

Commit e562c83

Browse files
authored
Merge pull request #55 from MortenSchou/weight-for-trace
Query weight notation for trace and rules
2 parents cb26d00 + d81e7cb commit e562c83

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ if (AALWINES_GetDependencies)
5151
)
5252
ExternalProject_add(pdaaal-ext
5353
GIT_REPOSITORY [email protected]:DEIS-Tools/PDAAAL.git
54-
GIT_TAG 99d9622646c9c6122548277f9c944380fe775de5
54+
GIT_TAG e205e51be36cd32312739be61c552aa46fb31761
5555
#URL https://github.com/DEIS-Tools/PDAAAL/archive/v0.2.1.zip
5656
#URL_HASH SHA512=f6f49a6d4cbb5fda1ac173fa77fe1eb1436ffe4112cc6f8fabdd8c879fad1aa90aa6be20804d5777bbfff902dd800f9f66dd1afb808d014653e21722dcb91b87
5757
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} -DPDAAAL_BuildTests=OFF -DCMAKE_BUILD_TYPE=Release -DPTRIE_INSTALL_DIR=${EXTERNAL_INSTALL_LOCATION}/include

src/aalwines/model/NetworkPDAFactory.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,6 @@ namespace aalwines {
387387
auto eid = ((&entry) - s._inf->table().entries().data());
388388
auto rid = ((&forward) - entry._rules.data());
389389
res = add_state(n, s._inf, appmode, eid, rid, 0);
390-
if constexpr (is_weighted) {
391-
ar._weight = _weight_f(forward, false);
392-
}
393390
}
394391
ar._dest = res.second;
395392

@@ -481,17 +478,14 @@ namespace aalwines {
481478
} else {
482479
auto res = add_state(s._nfastate, s._inf, s._appmode, s._eid, s._rid, s._opid + 1);
483480
nr._dest = res.second;
484-
if constexpr (is_weighted) {
485-
nr._weight = _weight_f(r, false);
486-
}
487481
}
488482
//or/andHere
489483
}
490484
return result;
491485
}
492486

493487
template<typename W_FN, typename W>
494-
void NetworkPDAFactory<W_FN, W>::print_trace_rule(std::ostream &stream, const Interface* inf,
488+
void NetworkPDAFactory<W_FN, W>::print_trace_rule(std::ostream &stream, const Interface* inf,
495489
const RoutingTable::entry_t &entry,
496490
const RoutingTable::forward_t &rule) const {
497491
stream << "{";
@@ -509,6 +503,16 @@ namespace aalwines {
509503
}
510504
stream << ",\"rule\":";
511505
rule.print_json(stream, false);
506+
507+
if constexpr (is_weighted) {
508+
stream << ", \"priority-weight\": [";
509+
auto weights = _weight_f(rule, true);
510+
for (size_t v = 0; v < weights.size(); v++){
511+
if (v != 0) stream << ", ";
512+
stream << "\"" << std::to_string(weights[v]) << "\"";
513+
}
514+
stream << "]";
515+
}
512516
stream << "}";
513517
}
514518

src/main.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,12 @@ bool do_verification(stopwatch& compilation_time, stopwatch& reduction_time, sto
5454
Query& q, Query::mode_t m, Network& network, bool no_ip_swap, std::pair<size_t,size_t>& reduction, size_t tos,
5555
bool need_trace, size_t engine, Moped& moped, SolverAdapter& solver, utils::outcome_t& result,
5656
std::vector<pdaaal::TypedPDA<Query::label_t>::tracestate_t >& trace, std::stringstream& proof,
57-
const W_FN& weight_fn) {
57+
std::vector<unsigned int>& trace_weight, const W_FN& weight_fn) {
5858
compilation_time.start();
5959
q.set_approximation(m);
6060
NetworkPDAFactory factory(q, network, no_ip_swap, weight_fn);
6161
auto pda = factory.compile();
6262
compilation_time.stop();
63-
6463
reduction_time.start();
6564
reduction = Reducer::reduce(pda, tos, pda.initial(), pda.terminal());
6665
reduction_time.stop();
@@ -88,7 +87,11 @@ bool do_verification(stopwatch& compilation_time, stopwatch& reduction_time, sto
8887
engine_outcome = solver_result.first;
8988
verification_time.stop();
9089
if (need_trace && engine_outcome) {
91-
trace = solver.get_trace(pda, std::move(solver_result.second));
90+
if constexpr (pdaaal::is_weighted<typename W_FN::result_type>) {
91+
std::tie(trace, trace_weight) = solver.get_trace<pdaaal::Trace_Type::Shortest>(pda, std::move(solver_result.second));
92+
} else {
93+
trace = solver.get_trace<pdaaal::Trace_Type::Any>(pda, std::move(solver_result.second));
94+
}
9295
if (factory.write_json_trace(proof, trace))
9396
result = utils::YES;
9497
}
@@ -374,18 +377,19 @@ int main(int argc, const char** argv)
374377
stopwatch reduction_time(false);
375378
stopwatch verification_time(false);
376379
std::vector<pdaaal::TypedPDA<Query::label_t>::tracestate_t > trace;
380+
std::vector<unsigned int> trace_weight;
377381
std::stringstream proof;
378382
bool need_trace = was_dual || get_trace;
379383
for(auto m : modes) {
380384
bool engine_outcome;
381385
if (weight_fn) {
382386
engine_outcome = do_verification(compilation_time, reduction_time,
383387
verification_time,q, m, network, no_ip_swap, reduction, tos, need_trace, engine,
384-
moped, solver,result, trace, proof, weight_fn.value());
388+
moped, solver,result, trace, proof, trace_weight, weight_fn.value());
385389
} else {
386390
engine_outcome = do_verification<std::function<void(void)>>(compilation_time, reduction_time,
387391
verification_time,q, m,network, no_ip_swap, reduction, tos, need_trace, engine,
388-
moped, solver,result, trace, proof, [](){});
392+
moped, solver,result, trace, proof, trace_weight, [](){});
389393
}
390394
if(q.number_of_failures() == 0)
391395
result = engine_outcome ? utils::YES : utils::NO;
@@ -416,11 +420,19 @@ int main(int argc, const char** argv)
416420
break;
417421
}
418422
std::cout << ",\n";
419-
std::cout << "\t\t\"engine\":" << engineTypes[engine] << ", " << std::endl;
420-
std::cout << "\t\t\"mode\":" << modeTypes[mode] << ", " << std::endl;
423+
std::cout << "\t\t\"engine\": \"" << engineTypes[engine] << "\", " << std::endl;
424+
std::cout << "\t\t\"mode\": \"" << modeTypes[mode] << "\", " << std::endl;
421425
std::cout << "\t\t\"reduction\":[" << reduction.first << ", " << reduction.second << "]";
422426
if(get_trace && result == utils::YES)
423427
{
428+
if(weight_fn) {
429+
std::cout << ",\n\t\t\"trace-weight\": [";
430+
for(size_t i = 0; i < trace_weight.size(); i++){
431+
if(i != 0) std::cout << ", ";
432+
std::cout << trace_weight[i];
433+
}
434+
std::cout << "]";
435+
}
424436
std::cout << ",\n\t\t\"trace\":[\n";
425437
std::cout << proof.str();
426438
std::cout << "\n\t\t]";

0 commit comments

Comments
 (0)