Thu Sep 19, 2019 2:47 pm
Login Register Lost Password? Contact Us


Multi-Variable, Multi-Dimensional Searches

Share ideas, code, best practices and techniques with other community members

Fri Dec 21, 2018 9:53 am Change Time Zone

Hi,
Below is an example of the use of the GRAPH built-in. A very handy function when you want to search some multi-dimensional space (In the example below I've used holiday selection with 3 search criteria/dimensions) with a range of values (an OR of values).
Code: Select all
d := DATASET([{'A',1,100,0}
             ,{'B',2,200,0}
             ,{'C',2,200,2000}
             ,{'D',2,100,2000}
             ,{'E',2,100,0}
             ,{'F',3,200,0}
             ,{'G',3,200,2000}
             ,{'H',3,100,2000}
             ,{'I',3,100,0}
             ,{'J',3,300,0}
             ,{'K',3,300,3000}
             ,{'L',3,100,3000}
             ,{'M',3,100,0}
              ],{STRING1 Holiday;UNSIGNED TourOperator,UNSIGNED Price,UNSIGNED HolidayClass});

Select(SET OF UNSIGNED pTourOperator = [],SET OF UNSIGNED pPrice = [],SET OF UNSIGNED pHolidayClass = []) := FUNCTION

    DFilters:= [DATASET(pTourOperator,{UNSIGNED itm}),DATASET(pPrice,{UNSIGNED itm}),DATASET(pHolidayClass,{UNSIGNED itm})];
   
    RunFilter(SET OF DATASET(RECORDOF(d)) ds,UNSIGNED c) := FUNCTION

        j := JOIN(ds[c-1],DFilters[c],CASE(C, 1 => LEFT.TourOperator = RIGHT.itm
                                          ,   2 => LEFT.Price        = RIGHT.itm
                                          ,        LEFT.HolidayClass = RIGHT.itm),TRANSFORM(LEFT),ALL);
        RETURN IF(EXISTS(DFilters[c]),j,ds[c-1]);
    END;
    RETURN GRAPH(d,3,RunFilter(ROWSET(LEFT),COUNTER));
END;

Select(,,);
Select([3],,[3000,0]);
Select(,[100],[3000,0]);

Obviously easily extendable to as many dimensions as you like. Even with as low a number as 5 dimensions alternative approaches that don't use GRAPH start to look very messy.

YouTube Video explaining GRAPH: https://youtu.be/O8L83FxAa6s

Yours
Allan
Allan
 
Posts: 375
Joined: Sat Oct 01, 2011 7:26 pm

Return to Tips & Tricks

Who is online

Users browsing this forum: No registered users and 0 guests