{"id":18941994,"url":"https://github.com/lucidfrontier45/tree_traversal","last_synced_at":"2025-04-15T21:30:56.684Z","repository":{"id":58794758,"uuid":"532452038","full_name":"lucidfrontier45/tree_traversal","owner":"lucidfrontier45","description":"A Rust library for finding the optimal leaf node in a tree structure.","archived":false,"fork":false,"pushed_at":"2024-06-18T14:23:35.000Z","size":26,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2024-10-28T22:30:57.099Z","etag":null,"topics":["algorithms","combinatorial-optimization","integer-programming","optimization","optimization-algorithms","rust","tree","tree-search"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/tree_traversal","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucidfrontier45.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-04T05:57:32.000Z","updated_at":"2024-06-18T14:23:38.000Z","dependencies_parsed_at":"2024-06-18T16:15:14.513Z","dependency_job_id":"43157189-216e-4386-8192-811655d2c82a","html_url":"https://github.com/lucidfrontier45/tree_traversal","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"829c5fca7762eac9d92272d74d6bff21464e0569"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidfrontier45%2Ftree_traversal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidfrontier45%2Ftree_traversal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidfrontier45%2Ftree_traversal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidfrontier45%2Ftree_traversal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucidfrontier45","download_url":"https://codeload.github.com/lucidfrontier45/tree_traversal/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223684872,"owners_count":17185730,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","combinatorial-optimization","integer-programming","optimization","optimization-algorithms","rust","tree","tree-search"],"created_at":"2024-11-08T12:30:44.519Z","updated_at":"2024-11-08T12:31:37.121Z","avatar_url":"https://github.com/lucidfrontier45.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tree_traversal\nA Rust library for finding the optimal leaf node in a tree structure.\nThis crate implements several tree traversal algorithms to find the best (the lowest cost) leaf node in a tree.\n\n# Algorithms\n\n- Breadth First Search\n- Depth First Search\n- Beam Search\n- Branch and Bound Search\n- Greedy Search\n\n# Using this crate\n\n```bash\ncargo add tree_traversal\n```\n\n# Example\n\n```rust\nuse tree_traversal::bbs::bbs;\n\ntype Node = Vec\u003cbool\u003e;\nfn main() {\n    let weights = [4, 2, 6, 3, 4];\n    let profits = [100, 20, 2, 5, 10];\n    let capacity = 8 as u32;\n    let total_items = weights.len();\n\n    let successor_fn = |n: \u0026Node| {\n        if n.len() == total_items {\n            return vec![];\n        }\n\n        let total_weight: u32 = n\n            .iter()\n            .copied()\n            .enumerate()\n            .map(|(i, b)| {\n                if b {\n                    return weights[i];\n                } else {\n                    return 0;\n                }\n            })\n            .sum();\n\n        let mut childrean = vec![];\n\n        let next_idx = n.len();\n        if capacity \u003e= total_weight + weights[next_idx] {\n            let mut c1 = n.clone();\n            c1.push(true);\n            childrean.push(c1);\n        }\n\n        let mut c2 = n.clone();\n        c2.push(false);\n        childrean.push(c2);\n\n        childrean\n    };\n\n    let total_profit = |n: \u0026Node| {\n        let s: u32 = n\n            .iter()\n            .copied()\n            .enumerate()\n            .map(|(i, b)| {\n                if b {\n                    return profits[i];\n                } else {\n                    return 0;\n                }\n            })\n            .sum();\n        s\n    };\n\n    let lower_bound_fn = |n: \u0026Node| {\n        let current_profit = total_profit(n);\n        let max_remained_profit: u32 = profits[n.len()..].into_iter().sum();\n        Some(u32::MAX - (current_profit + max_remained_profit))\n    };\n\n    let cost_fn = |n: \u0026Node| Some(u32::MAX - total_profit(n));\n\n    let leaf_check_fn = |n: \u0026Node| n.len() == total_items;\n    let max_ops = usize::MAX;\n\n    let (cost, best_node) = bbs(\n        vec![],\n        successor_fn,\n        lower_bound_fn,\n        cost_fn,\n        leaf_check_fn,\n        max_ops,\n    )\n    .unwrap();\n    let cost = u32::MAX - cost;\n\n    dbg!((best_node, cost));\n}\n```\n\n# Note\n\nThe API is derived from the great [pathfinding](https://docs.rs/pathfinding/latest/pathfinding/index.html) crate.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidfrontier45%2Ftree_traversal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucidfrontier45%2Ftree_traversal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidfrontier45%2Ftree_traversal/lists"}