Search code examples
ilogjrules

how to invoke ilrmain function in ilog jrules


how do I invoke ilrmain function in ilog jrules , is it invoked implcitly or do we have to explcitly invoke , in the latter case , how do I do it. IBM documentation is very obscure regarding ilrmain function.


Solution

  • IlrMain provides an easy way to test your rules without too much overhead. You define your input variables, create your testcase and invoke the rule execution with context.execute. After execution, you can display the result.

    Here's a small example: Imagine you've created a ruleset to decide whether to grant a loan or not. Your input is called application of type LoanApplication and you expect a decision in your output. Your IlrMain would look something like this:

    LoanApplication app = new LoanApplication();
    app.loanAmount = 5000
    Applicant applicant = new Applicant();
    app.applicant = applicant;
    applicant.dateOfBirth = new ilog.rules.xml.types.IlrDate("1980-01-01");
    applicant.income = 2000;
    applicant.fixedExpenses = 600;
    
    input = app;
    context.execute();
    
    System.out.println("Loan Decision: "+output.decision);
    

    To start the IlrMain, click on Run > Run Configurations... > Rule Project and create a new run configuration for your rule project. Select the project with your IlrMain-Function and make shure Launch project with function ilrmain is selected. Under Parameters & Arguments you should select Clear All Values so that the parameter from your IlrMain are being used for execution. Apply and Run

    In your command line, your loan decision should appear. Something like:

    Loan Decision: green