mirror of
https://github.com/ellmau/adf-obdd.git
synced 2025-12-20 09:39:38 +01:00
Start implementing endpoint to solve ADF on demand
This commit is contained in:
parent
88bc4a9100
commit
e7d0de79ea
1276
Cargo.lock
generated
1276
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -13,4 +13,8 @@ description = "Offer Solving ADFs as a service"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
adf_bdd = { version="0.3.1", path="../lib", features = ["frontend"] }
|
adf_bdd = { version="0.3.1", path="../lib", features = ["frontend"] }
|
||||||
|
actix-web = "4"
|
||||||
|
env_logger = "0.9"
|
||||||
|
log = "0.4"
|
||||||
|
serde = "1"
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,66 @@
|
|||||||
fn main() {
|
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
|
||||||
println!("Hello, world!");
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use adf_bdd::adf::Adf;
|
||||||
|
use adf_bdd::parser::AdfParser;
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
async fn root() -> impl Responder {
|
||||||
|
// TODO: this should serve the static files for the react frontend
|
||||||
|
HttpResponse::Ok().body("Hello world!")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
// This is a DTO for the graph output
|
||||||
|
struct DoubleLabeledGraph {
|
||||||
|
// number of nodes equals the number of node labels
|
||||||
|
// nodes implicitly have their index as their ID
|
||||||
|
node_labels: Vec<String>,
|
||||||
|
// every node gets this label containing multiple entries (it might be empty)
|
||||||
|
tree_root_labels: Vec<Vec<String>>,
|
||||||
|
edges: Vec<(usize, usize)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct SolveReqBody {
|
||||||
|
adf_input: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct SolveResBody {
|
||||||
|
graph: DoubleLabeledGraph,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[post("/solve")]
|
||||||
|
async fn solve(req_body: web::Json<SolveReqBody>) -> impl Responder {
|
||||||
|
let input = &req_body.adf_input;
|
||||||
|
|
||||||
|
let parser = AdfParser::default();
|
||||||
|
match parser.parse()(input) {
|
||||||
|
Ok(_) => log::info!("[Done] parsing"),
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Error during parsing:\n{} \n\n cannot continue, panic!", e);
|
||||||
|
panic!("Parsing failed, see log for further details")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log::info!("[Done] parsing");
|
||||||
|
|
||||||
|
let mut adf = Adf::from_parser(&parser);
|
||||||
|
|
||||||
|
log::debug!("{:?}", adf);
|
||||||
|
|
||||||
|
// TODO: as first test: turn full graph with initial ac into DoubleLabeledGraph DTO and return it
|
||||||
|
|
||||||
|
"Hello World"
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
|
env_logger::builder()
|
||||||
|
.filter_level(log::LevelFilter::Debug)
|
||||||
|
.init();
|
||||||
|
HttpServer::new(|| App::new().service(root).service(solve))
|
||||||
|
.bind(("127.0.0.1", 8080))?
|
||||||
|
.run()
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user