Have an idea?

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

Showing attributes to ACBC using single constructed list

I have 15 attributes.

Attribute 1
Attribute 2
Attribute 3
.....
.....
Attribute 14
Price Attribute 15


I want to force first 2 attributes and price attribute to ACBC section without any condition.

Begin Unverified Perl
ADD("AttributeList",1);
ADD("AttributeList",2);
End Unverified


Then, I want to randomly show maximum of 2 attributes based on the selection in Q2

Begin Unverified Perl
if ((VALUE("Q2_1")==1))
{ADD("AttributeList",3);}
if ((VALUE("Q2_2")==1))
{ADD("AttributeList",4);}
if ((VALUE("Q2_3")==1))
{ADD("AttributeList",5);}
if ((VALUE("Q2_4")==1))
{ADD("AttributeList",6);}
if ((VALUE("Q2_5")==1))
{ADD("AttributeList",7);}
if ((VALUE("Q2_6")==1))
{ADD("AttributeList",8);}
if ((VALUE("Q2_7")==1))
{ADD("AttributeList",9);}
if ((VALUE("Q2_8")==1))
{ADD("AttributeList",10);}
if ((VALUE("Q2_9")==1))
{ADD("AttributeList",11);}
if ((VALUE("Q2_10")==1))
{ADD("AttributeList",12);}
if ((VALUE("Q2_11")==1))
{ADD("AttributeList",13);}
if ((VALUE("Q2_12")==1))
{ADD("AttributeList",14);}
RANDOMIZE();
LISTMAX(2);
End Unverified


My problem is, I want to add both the above perl scripts in a single constructed list as below. I have added 2 perl scripts, but it randomly selects max of 2 attributes from attributes 1 to 14 rather than from attributes 3 to 14. I couldn't force first 2 attributes due to randomization and listmax in the second script. Please help me to make the logic to work.


Begin Unverified Perl
ADD("AttributeList",1);
ADD("AttributeList",2);
End Unverified

Begin Unverified Perl
if ((VALUE("Q2_1")==1))
{ADD("AttributeList",3);}
if ((VALUE("Q2_2")==1))
{ADD("AttributeList",4);}
if ((VALUE("Q2_3")==1))
{ADD("AttributeList",5);}
if ((VALUE("Q2_4")==1))
{ADD("AttributeList",6);}
if ((VALUE("Q2_5")==1))
{ADD("AttributeList",7);}
if ((VALUE("Q2_6")==1))
{ADD("AttributeList",8);}
if ((VALUE("Q2_7")==1))
{ADD("AttributeList",9);}
if ((VALUE("Q2_8")==1))
{ADD("AttributeList",10);}
if ((VALUE("Q2_9")==1))
{ADD("AttributeList",11);}
if ((VALUE("Q2_10")==1))
{ADD("AttributeList",12);}
if ((VALUE("Q2_11")==1))
{ADD("AttributeList",13);}
if ((VALUE("Q2_12")==1))
{ADD("AttributeList",14);}
RANDOMIZE();
LISTMAX(2);
End Unverified

Begin Unverified Perl

if(LISTHASPARENTMEMBER('FinalAttributes',3)==1)
{ INSERT(3, "AttributeList", 3);}
if(LISTHASPARENTMEMBER('FinalAttributes',4)==1)
{ INSERT(4, "AttributeList", 4);}
if(LISTHASPARENTMEMBER('FinalAttributes',5)==1)
{ INSERT(5, "AttributeList", 5);}
if(LISTHASPARENTMEMBER('FinalAttributes',6)==1)
{ INSERT(6, "AttributeList", 6);}
if(LISTHASPARENTMEMBER('FinalAttributes',7)==1)
{ INSERT(7, "AttributeList", 7);}
if(LISTHASPARENTMEMBER('FinalAttributes',8)==1)
{ INSERT(8, "AttributeList", 8);}
if(LISTHASPARENTMEMBER('FinalAttributes',9)==1)
{ INSERT(9, "AttributeList", 9);}
if(LISTHASPARENTMEMBER('FinalAttributes',10)==1)
{ INSERT(10, "AttributeList", 10);}
if(LISTHASPARENTMEMBER('FinalAttributes',11)==1)
{ INSERT(11, "AttributeList", 11);}
if(LISTHASPARENTMEMBER('FinalAttributes',12)==1)
{ INSERT(12, "AttributeList", 12);}
if(LISTHASPARENTMEMBER('FinalAttributes',13)==1)
{ INSERT(13, "AttributeList", 13);}
if(LISTHASPARENTMEMBER('FinalAttributes',14)==1)
{ INSERT(14, "AttributeList", 14);}
ADD('AttributeList',15);
End Unverified



FYI - My boss wants to do this in a single constructed list rather 2 or more constructed list. If it won't work, please let me know any other method to achieve this.

Please let me know in case of any questions.
asked Aug 10, 2018 by Abdul Bronze (2,630 points)

1 Answer

0 votes
If I understand correctly, you have constructed list 1 (gets attributes 1+2 and 15-the price attribute) and constructed list 2 (gets a maximum of 2 attributes from attributes 3-14 with Q2 conditions applied) and when you blend them together in one constructed list, the outcome is incorrect.

Example:
Call constructed list 1: Att1ConList
Call constructed list 2: Att2ConList

Try creating a 3rd constructed list that simply adds the 2 constructed lists together as such (No Perl Script required, just SSI Script) ...
ADD(Att1ConList)
ADD(Att2ConList)

Use this constructed list 3 in your future questions. It should contain 3-5 items depending on Q2 responses.

Notes ...

*I am not much of a conjoint programmer but can assist with Perl to some degree.
*I didn't see your constructed list 1 adding in item 15. You can setup this constructed list without Perl Script and use SSI Script instead. That's a good habit to get into.
ADD(AttributeList,1)
ADD(AttributeList,2)
ADD(AttributeList,15)
Randomize()

*Do you want to randomise constructed list 1? Simple add in a Randomize() statement. See above example.
*If you want to randomise all the items in constructed list 3, again add in a Randomize() statement.

Let me know how you go.
answered Aug 10, 2018 by Paul Moon Platinum (82,475 points)
edited Aug 10, 2018 by Paul Moon
I just noticed your last comment about the one constructed list. Apologies.

Try this ...
Begin Unverified Perl
if ((VALUE("Q2_1")==1))
{ADD("AttributeList",3);}
if ((VALUE("Q2_2")==1))
{ADD("AttributeList",4);}
if ((VALUE("Q2_3")==1))
{ADD("AttributeList",5);}
if ((VALUE("Q2_4")==1))
{ADD("AttributeList",6);}
if ((VALUE("Q2_5")==1))
{ADD("AttributeList",7);}
if ((VALUE("Q2_6")==1))
{ADD("AttributeList",8);}
if ((VALUE("Q2_7")==1))
{ADD("AttributeList",9);}
if ((VALUE("Q2_8")==1))
{ADD("AttributeList",10);}
if ((VALUE("Q2_9")==1))
{ADD("AttributeList",11);}
if ((VALUE("Q2_10")==1))
{ADD("AttributeList",12);}
if ((VALUE("Q2_11")==1))
{ADD("AttributeList",13);}
if ((VALUE("Q2_12")==1))
{ADD("AttributeList",14);}
RANDOMIZE();
LISTMAX(2);

ADD("AttributeList",1);
ADD("AttributeList",2);
ADD("AttributeList",15);
End Unverified

The above example will get a maximum of 2 attributes from attributes 3-14 depending on the Q2 conditions.
It will then grab attributes 1+2+15 and add them after attributes 3-14.
At this point, you can randomise all of the attributes in this list if you need to. If you need to insert attributes 1+2+15 above attributes 3-14, you can do that with some INSERT statements instead of the ADD statements.

Hope that helps too.
...