Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
Expand all | Collapse all

How to Initialize Tuples that Contain Other Tuples

  • 1.  How to Initialize Tuples that Contain Other Tuples

    Posted Fri October 01, 2010 06:51 PM

    Originally posted by: char507


    Hello,

    I am slowly building a complex data structure with tuples containing other tuples. For example, say I have defined the following tuples and sets of tuples:

    {code}
    tuple Asset{
    key string id;
    float cost;
    }

    tuple Customer{
    key string id;
    float budget;
    }

    tuple CustomerUsesAsset{
    Customer c;
    Asset a;
    }

    {Asset} listOfAssets = …;
    {Customer} listOfCustomers = …;
    {CustomerUsesAsset} CustomerAssetLinks = …;

    {/code}

    In the long run, I will be initializing the data set through external code but for now i'm trying to use a .dat file to test out the model.

    My problem is that I do not know how to initialize the "CustomerUsesAsset" tuple. These objects already exist in their respective sets but I don't know how to link them to the third tuple set. Is there a way to do this in the .dat file? In script maybe?

    The purpose of building these new data types is to cut down on memory usage so obviously I do not want to instantiate each tuple object more than once (plus they need to be unique). I just can't figure out how to make those links.

    Any help would be greatly appreciated! Complicated tasks such as this do not seem to be present in the documentation...
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to Initialize Tuples that Contain Other Tuples

    Posted Mon October 04, 2010 11:18 AM

    Originally posted by: SystemAdmin


    Not sure I fully understand your question.

    Here is how to fill a tupleSet with subTuple via comprehension, via direct data, via scripting.

    //X and X1 are just to make the sample work.
    {string} X = {"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10"}
    ;
    {string} X1 = {"f0", "f2", "f4", "f6", "f8", "f10"};
    tuple Asset{
    key string id;
    int cost;
    }
    tuple Customer{
    key string id;
    int budget;
    }
    tuple CustomerUsesAsset{
    key Customer c;
    key Asset a;
    }

    {Asset} listOfAssets = {<item(X,i),i+5> | i in 1..10};
    {Customer} listOfCustomers = {<item(X, i),i+10> | i in 1..10};;

    // fill with via iterators with some filtering.
    {CustomerUsesAsset} C2 = {<<id1, cost>, <id2, budget>> | <id1, cost> in listOfAs
    sets, <id2, budget> in listOfAssets : id1 not in X1 && id2 not in X1};

    //fill it with direct data (from .dat file, the separator must be removed in some places)
    {CustomerUsesAsset} C3 = {<<"f1", 6>, <", 12>>, <<"f2",7>, <",13>>};
    // another equivalent formula:
    {CustomerUsesAsset} C4 = {<t1, t2> | t1 in listOfAssets, t2 in listOfAssets : t1.id not in X1 && t2.id not in X1};

    //fill with via scripting: give all the components.
    execute{
    C2.add("f3",8,"f4",14);
    }
    execute{
    writeln(C2);
    writeln("\n");
    writeln(C3);
    writeln("\n");
    writeln(C4);
    writeln("\n");
    }

    // to find tuples in the tupleSet, you can use the keys:
    // in general, you can use the keys to find and iterate on tupleSets.
    execute{
    writeln(C2.find("f3", "f4"));
    }
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: How to Initialize Tuples that Contain Other Tuples

    Posted Fri October 08, 2010 12:30 PM

    Originally posted by: char507


    Okay, I have a few updates to try and help everyone better understand the problem:

    The objective here is to initialize a large set of data in this form with minimal memory consumption. I don't think I will be able to use generic initialization such as
    "{Asset} listOfAssets = {<item(X,i),i+5> | i in 1..10};"
    or
    "{CustomerUsesAsset} C4 = {<t1, t2> | t1 in listOfAssets, t2 in listOfAssets : t1.id not in X1 && t2.id not in X}"
    because these relationships are specifically defined by business logic. For example, each asset has a very specific cost associated with it that is pulled from another data source. In terms of the {CustomerUsesAsset} relationships, I would like to only define the relationships that exist in the real world in order to cut down on memory consumption.

    In regards to populating these relationships from a .dat file in the manner described:
    {CustomerUsesAsset} C3 = {<<"f1", 6>, <"f2",7>, <"f1" and some asset #, does this create another customer object in memory or does it refer to the "f1" customer object that already exists in the {Customer} Customers list? I.E. when I create relationships between customer "f1" and some number of assets, I only want to store Customer "f1" data one time.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer