-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DC verifier python bindings and basic example
- Loading branch information
Showing
14 changed files
with
141 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import desbordante as db | ||
|
||
# # Given denial constraint tells us that if two persons | ||
# live in the same state, the one earning a lower | ||
# salary has a lower tax rate | ||
DC = "!(s.State == t.State and s.Salary < t.Salary and s.FedTaxRate > t.FedTaxRate)" | ||
|
||
TABLE = "test_input_data/TestDC1.csv" | ||
|
||
# Creating a verificator and loading data in algortihm | ||
verificator = db.dc_verification.algorithms.Default() | ||
verificator.load_data(table=(TABLE, ',', True)) | ||
|
||
# Algorithm execution | ||
verificator.execute(denial_constraint=DC) | ||
|
||
# Obtaining the result | ||
result: bool = verificator.dc_holds() | ||
|
||
print("DC " + DC + " holds: " + str(result)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import desbordante as db | ||
import networkx as nx | ||
import matplotlib.pyplot as plt | ||
import time | ||
|
||
def verify_dc(verificator, dc): | ||
total_start = time.time() | ||
print("Algo execution start") | ||
iterations = 1 | ||
|
||
algo_start = time.time() | ||
for _ in range(iterations): | ||
verificator.execute(denial_constraint=dc) | ||
algo_time = (time.time() - algo_start) / iterations | ||
|
||
print("Algo execution end") | ||
|
||
result = verificator.dc_holds() | ||
total_time = time.time() - total_start | ||
|
||
print("DC " + dc + " holds: " + str(result)) | ||
print("Algo average time elapsed: " + str(algo_time)) | ||
print("Total time elapsed: " + str(total_time)) | ||
|
||
|
||
def main(): | ||
table = 'TestDC1.csv' | ||
|
||
verificator = db.dc_verification.algorithms.Default() | ||
verificator.load_data(table=(table, ',', True)) | ||
|
||
dc = "!(t.0 == s.0 and t.1 > s.1 and t.2 < s.2)" | ||
|
||
verify_dc(verificator, dc) | ||
viols = verificator.get_violations() | ||
|
||
G = nx.Graph() | ||
for edge in viols: | ||
G.add_edge(*edge) | ||
print(G) | ||
nx.draw(G, with_labels=True) | ||
|
||
plt.show() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "bind_dc_verification.h" | ||
|
||
#include "algorithms/dc/verifier/dc_verifier.h" | ||
#include "py_util/bind_primitive.h" | ||
|
||
namespace python_bindings { | ||
|
||
namespace py = pybind11; | ||
|
||
void BindDCVerification(py::module_& main_module) { | ||
auto dc_verification_module = main_module.def_submodule("dc_verification"); | ||
|
||
BindPrimitiveNoBase<algos::DCVerifier>(dc_verification_module, "DCVerification") | ||
.def("dc_holds", &algos::DCVerifier::DCHolds); | ||
} | ||
|
||
} // namespace python_bindings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
namespace python_bindings { | ||
void BindDCVerification(pybind11::module_& main_module); | ||
} // namespace python_bindings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
State,Salary,FedTaxRate | ||
NewYork,3000,0.2 | ||
NewYork,4000,0.25 | ||
NewYork,5000,0.3 | ||
Wisconsin,5000,0.15 | ||
Wisconsin,6000,0.2 | ||
Wisconsin,4000,0.1 | ||
Wisconsin,4500,0.12 | ||
Texas,5000,0.05 | ||
Texas,1000,0.15 | ||
Texas,2000,0.25 | ||
Texas,3000,0.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
NewYork,3000,0.2 | ||
NewYork,4000,0.25 | ||
NewYork,5000,0.3 | ||
NewYork,10,10 | ||
Wisconsin,5000,0.15 | ||
Wisconsin,6000,0.2 | ||
Wisconsin,20,20 | ||
Wisconsin,4000,0.1 | ||
Texas,5000,0.05 | ||
Texas,1000,0.15 | ||
Texas,2000,0.25 | ||
Texas,3000,0.3 | ||
Texas,3000,0.31 | ||
Texas,30,30 |