Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
wastedbro

Decision Tree Framework

Recommended Posts

Decision Tree Framework by wastedbro

 

Hello everyone,

While working on some very large scripts, I realized that the current accepted frameworks scale poorly with many tasks, and that I have to choose between cleanliness and efficiency. Due to this, I've been working on a new framework that I am writing about here.

Here is the Source, for Reference: https://gitlab.com/WBScripting/binary-decision-tree-framework

Summary

So the decision tree framework is based on, well, The Decision Tree.

My framework uses this concept and implements a Binary Tree of Decisions and Actions. Both decisions and actions are Nodes. Nodes can have 2 children. Actions will have null children, and Decisions will have 2 children of either Decisions, or Actions. I know it sounds a little confusing, so let's talk about why we even need this.

 

Why not use the popular Node Framework?

The Node Framework is a great way to split up a large amount of code. However, there is a problem. Even though each node is a different class, they really aren't flexible. If we assume each node is completely independent and isolated, we must ensure it's an invalid node when another node is valid, which is a huge waste of resources. If we do not do this, we must ensure our nodes are checked in a specific order (or prioritized).

While prioritized nodes prevent wasteful duplicate checks, it still does not prevent all wasteful checks. And it certainly cannot be in-depth. For example, if you want a "Pick up birds nest" node and a "chop node", you must ensure both of their validation methods include "is in chopping area". That's wasteful, so putting them in the same node is the only option.

These problems are not a big deal in small scripts, but as the complexity grows, so do these problems.

 

Gitlab Link: https://gitlab.com/WBScripting/binary-decision-tree-framework

Edited by wastedbro
  • Thanks 5

Share this post


Link to post
Share on other sites
37 minutes ago, HeyImJamie said:

May look to transferring to this. Is it limited to two process nodes per decision node or not? For example: a combat decision node could have a handleAntiban, shouldEat, attackNpc etc.

Would you just add another decision node like
inCombatArea - yes
isLowHP - no
shouldDoAntiban - no Attack or yes doAntiban
 

Share this post


Link to post
Share on other sites
4 hours ago, HeyImJamie said:

May look to transferring to this. Is it limited to two process nodes per decision node or not? For example: a combat decision node could have a handleAntiban, shouldEat, attackNpc etc.

A binary tree of decisions and actions is by definition only able choose between two different alternatives on each node.

Multiple decisions could be added in a hierarchical order. For example if you need to chose between 3 actions: "Chop down tree", "Perform anti-ban" and "Idle":

KcCfB1y.png

 

  • Like 2

Share this post


Link to post
Share on other sites
On 19.12.2017 at 1:37 AM, wastedbro said:

 

How do we run these nodes?

Here's an example:

DecisionNode hasToBankNode = new HasToBankNode();

ProcessNode bankNode = new BankNode();

hasToBankNode.addOnTrueNode(bankNode);
hasToBankNode.addOnFalseNode([insert some other node]);

DecisionTree executionTree = new DecisionTree(hasToBankNode); // Create a tree from the root node

while(true)
{
    INode node = executionTree.getValidNode();
    if(node != null)
        node.execute();
}

That's it! You'll want to shorten this code once you have a lot of nodes, though.

All of the background stuff is handled for you! The "getValidNode()" method is recursive. It will go through the entire tree and pick the correct process node for you.

 

 

Well thanks for your effort, but ... is this part of some main class or something?

it's a piece of code that should belong to somewhere, and I couldn't find it either on your github.

Share this post


Link to post
Share on other sites
1 hour ago, rstaiger said:

Well thanks for your effort, but ... is this part of some main class or something?

it's a piece of code that should belong to somewhere, and I couldn't find it either on your github.

It's an example that would go in your main class. It's hypothetical, and builds off the two classes also in the thread. They are non-functional examples, just to show you how the code works, so it's not actually IN anything. 

 

By the way, I have an update to this framework. It's now simpler. I will edit the main post and write a tutorial on it when I can.

 

Here is the link: https://github.com/WBScripts/DecisionTree-Framework

 

Basically, Process Node are now just classes that implement "Runnable". And DecisionNodes are a little simpler.

Edited by wastedbro
  • Like 1

Share this post


Link to post
Share on other sites
On 4.03.2018 at 4:58 PM, wastedbro said:

It's an example that would go in your main class. It's hypothetical, and builds off the two classes also in the thread. They are non-functional examples, just to show you how the code works, so it's not actually IN anything. 

 

By the way, I have an update to this framework. It's now simpler. I will edit the main post and write a tutorial on it when I can.

 

Here is the link: https://github.com/WBScripts/DecisionTree-Framework

 

Basically, Process Node are now just classes that implement "Runnable". And DecisionNodes are a little simpler.

can't really wrap my head around this, It would be nice to have some working examples I'll wait for some updates from you, I'll toy with the task framework till then.

Share this post


Link to post
Share on other sites

Completely rewrote this framework to be much, much simpler.

I also created a Builder class so that you can create decision trees using functional-ish programming, with a lot more flexibility on how you implement your code.

 

Here is a link: https://gitlab.com/WBScripting/binary-decision-tree-framework

 

Look in the "samples" directory to find out how to use this.

Edited by wastedbro

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Our picks

    • This update features:

      Fixed broken hooks from today's update


      Fix wilderness level with RuneLite (Thanks @Todd)


      Add support for Kotlin .class files in scripts (Thanks @wastedbro)


      Overhaul Inventory API (Thanks @wastedbro)


      Add List support for common methods


      Change method grouping to make more sense (by functionality)


      Refactor methods to utilize Java 8 streams instead of cumbersome loops




      Recognize chatbox minimization (Thanks @JoeDezzy1)


      Fix Screen#isInViewport when NPC chat is open (Thanks @JoeDezzy1)


      Fix login bot bugs (Thanks @erickho123)


      Fix hint arrow return values (Thanks @Encoded)


      Fix depositAllExcept functionality (Thanks @wastedbro)


      Change containing box interface bound and adjust for Y values (Thanks @erickho123)
        • Like
      • 151 replies
    • This release will:

      Fix prayers and world hopper API (Thanks @JoeDezzy1 and @erickho123)


      Improve banking API (Thanks @Encoded)


      Adds methods for returning and using Java Lists, rather than arrays


      Slightly randomizes some hardcoded behaviour


      Removes sleeps from waitConditions; the efficiency saving potential is negligible in these use-cases, therefore cleaner code is preferable


      Other back-end improvements





      Note: If you are using LG, please restart both the RS client and TRiBot.
        • Sad
        • Haha
        • Thanks
        • Like
      • 90 replies
    • This release will:

      Add new internal framework for capturing exceptions


      Fix issue with not selecting the last column in world hopper (Thanks @Todd)


      Add a message about pin usage in Banking#openBank (Thanks @Todd)


      Disable the firewall by default (Thanks @Todd)


      Fix handling of the welcome screen after login (Thanks @Encoded)


      Fix wrong amount bank withdrawal (Thanks @Encoded)


      Fix Screen#isInViewport


      Fix Game#isInViewport (Thanks @Encoded)


      Call onBreakEnd for ListenerManager Breaking Listeners (Thanks @Encoded)


      Fix Prayer#getPrayerPoints NumberFormatException (Thanks @JoeDezzy1)



      Note: If you are using LG, please restart both the RS client and TRiBot.
        • Thanks
        • Like
      • 28 replies
    • This release will:

      Fix LG for both OSBuddy and RuneLite


      Fix issue where the resizable client isn't able to be made smaller (Thanks @JoeDezzy1)


      Fix detection of the logout game tab when resizable mode and side panels are enabled (Thanks @JoeDezzy1)


      Add initial support for Sentry to allow us to identify and easily debug exceptions happening with all TRiBot users


      Add methods to determine if the bank is actually loaded, and not just the overarching interface (Thanks @wastedbro)



      Upcoming updates:

      Improved CLI support


      Full Sentry support


      Much more
        • Like
      • 64 replies
    • This release will:

      Fix NPE in Camera API (Thanks @wastedbro)


      Update deposit box interface ids (Thanks @Encoded)


      Add various bank methods (Thanks @wastedbro)


      Banking#getWithdrawXQuantity


      Banking#getDefaultWithdrawQuantity


      Banking#arePlaceholdersOn




      Fix resizeable minimap bug (Thanks @wastedbro)


      Remove Java 8 requirement


      Please note: TRiBot is not yet fully compatible with Java 10+




      Fix the break handler issues by ensuring the break handler thread never gets paused


      Fix broken settings hooks



      Upcoming updates:

      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Like
      • 68 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...