51 lines
1.8 KiB
Rust
51 lines
1.8 KiB
Rust
use eframe::{run_native, App, CreationContext, NativeOptions, Frame};
|
|
use egui::{CentralPanel, SidePanel, Context};
|
|
use egui_graphs::{GraphView, Graph, SettingsStyle, LayoutRandom, LayoutStateRandom};
|
|
|
|
use random_generator::MaxflowProblem;
|
|
use algorithms::{ford_fulk
|
|
//use petgraph::stable_graph::StableGraph;
|
|
|
|
mod random_generator;
|
|
mod algorithms;
|
|
|
|
pub struct MaxflowApp {
|
|
g: Graph<(), u64>,
|
|
p: MaxflowProblem,
|
|
node_count: u64,
|
|
max_capacity: u64,
|
|
}
|
|
|
|
impl MaxflowApp {
|
|
fn new(_: &CreationContext<'_>) -> Self {
|
|
let problem = MaxflowProblem::new(10, 10);
|
|
Self { g: problem.g.clone(), p: problem, node_count: 10, max_capacity: 5 }
|
|
}
|
|
}
|
|
|
|
impl App for MaxflowApp {
|
|
fn update(&mut self, ctx: &Context, _: &mut Frame) {
|
|
CentralPanel::default().show(ctx, |ui| {
|
|
ui.add(&mut GraphView::<_, _, _, _, _, _, LayoutStateRandom, LayoutRandom>::new(&mut self.g).with_styles(&SettingsStyle::default().with_labels_always(true)));
|
|
});
|
|
SidePanel::right("right_panel")
|
|
.min_width(200.)
|
|
.show(ctx, |ui| {
|
|
ui.label("node count");
|
|
ui.add(egui::DragValue::new(&mut self.node_count).range(1..=1000));
|
|
ui.label("maximum capacity");
|
|
ui.add(egui::DragValue::new(&mut self.max_capacity).range(1..=10));
|
|
if ui.button("generate graph").clicked() {
|
|
let problem = random_generator::MaxflowProblem::new(self.node_count, self.max_capacity);
|
|
self.g = problem.g;
|
|
}
|
|
if ui.button("run algorithm").clicked() {
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
run_native("Maxflow.rs", NativeOptions::default(), Box::new(|cc| Ok(Box::new(MaxflowApp::new(cc)))),).unwrap();
|
|
}
|