Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Using perl in CBC conditional pricing

Hi all

I haven't had much experience in the CBC module, but I've got a study to set up and it's a doozy!

Here's the thing:

17 brands (they see the brand they choose outside the model)
5 pack sizes (the packs they see are based on the brand - some have 4, some have 2)
Prices (This equals Base price + a price determined by the level (3 levels) + a loading if they are a regional customer , also set outside the model).

The statistician has given me a design to import, and I plan on displaying it using freeformat.

SO!  I have determined that the brands can be bunched up into the same price structure and packs to be shown, so thinking I should create a separate model for each "bunch" to take some of the complication out of the mix.

That just leaves the price to be displayed.  Was thinking that I should set up conditional pricing.  Can I use perl for this? Was thinking of something like this:

[% Begin Unverified Perl
my $base = 4.10;
my $generic = HOW DO I DO THIS BIT?
my $region = 0.20;
my $level = -0.20;

if(VALUE("MetroRegional") == 1)
{
    $base = $base + $level;
}
else
{
    $base = $base + $level + $region;
}

return $base;
End Unverified %]


Would this work?  How do I access the Generic attribute?

I have these attributes and levels:
Size (pack 1, pack 2, pack 3, pack 4)
Price (Level 1, Level 2, Level 3)
Generic (Level 1, Level 2, Level 3)
asked Sep 17, 2021 by Marion Silver (5,220 points)
I've amended my code to this within the conditional relationship (forming a relationship between size, price and generic.  This is for the first cell.  Should I be doing anything different?

[% Begin Unverified Perl
my $region = 0.20;

my $pack = 4.10;
my $price = -0.20;
my $generic = 0;
my $show = 0;

if(VALUE("MetroRegional") == 1)
{
    $show = $show + $pack + $price + $generic;
}
else
{
    $show = $show + $pack + $price + $generic + $region;
}

return $show;

End Unverified %]
If anyone can let me know how I can work all the brands into the one model, that would be grand!
What value is meant to be stored in "$generic"?  The 1, 2, or 3 representing the level selected for that attribute?  If so, I'd think calling "CBCATTRIBUTEVALUE" would work.

I'm not sure I know what you have in mind with terms like "bunches" or "models."  Could you elaborate more on the intended result of this code?
Hi Zachary!!!  Yes, Generic represents a loading on the base price (either $0, $0.50 or $1.00).

By Bunches, I mean where brands have the exact same price profile.  There are 17 brands.  As a for instance, the first three of them have the same prices.

By Model I mean CBC.

Everyone goes through just one brand - one that is chosen in the general interviewing stuff.
This might be the easiest way to load the generic price into a "$genericPrice" variable:

my $genericLevel = CBCDESIGNLEVELVALUE('cbc_Random1', ___, ___);
my $genericPrice = 0;
if ($genericLevel == 2) {
    $genericPrice = .5;
}
elsif ($genericLevel == 3) {
    $genericPrice = 1;
}


On line 1, the exercise and question names should be updated, the first underscore should be the concept number you're interested in, and the second underscore should be the position of the generic attribute.

With your bunches, it sounds like it depends on what you want to do in the code.  You could just wrap up everything in a few conditionals like this:

my $brand = GETVALUE('BrandQ...');
if ($brand == 1 || $brand == 2 || $brand == 3) {
    ...
}
elsif ($brand == 4 || $brand == 5) {
    ...
}


Perhaps what you have in mind would be to store that conditional info in a single boolean that you can use later, like this:

my $brand = GETVALUE('BrandQ...');
my $isFirstThreeBrands = $brand == 1 || $brand == 2 || $brand == 3;

...

if ($isFirstThreeBrands) {
    ...
}
else {
    ...
}


Perhaps if you could post code that doesn't use bunches and I could look it over and see if there are changes I would make?

Your solution to the original question

Please only use this to answer the original question. Otherwise please use comments.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

To avoid this verification in future, please log in or register.
...