• No results found

The Necklace Illustrator Web Applet

N/A
N/A
Protected

Academic year: 2019

Share "The Necklace Illustrator Web Applet"

Copied!
94
0
0

Loading.... (view fulltext now)

Full text

(1)

Rochester Institute of Technology

RIT Scholar Works

Theses

Thesis/Dissertation Collections

2005

The Necklace Illustrator Web Applet

David W. Fraser

Follow this and additional works at:

http://scholarworks.rit.edu/theses

This Thesis is brought to you for free and open access by the Thesis/Dissertation Collections at RIT Scholar Works. It has been accepted for inclusion in Theses by an authorized administrator of RIT Scholar Works. For more information, please contactritscholarworks@rit.edu.

Recommended Citation

(2)

The Necklace Illustrator Web Applet

by

David W. Fraser

A Report Submitted

m

Partial Fu)fi]]ment of the

Requirements for the Degree of

Master of Science

m

Applied Mathematics

Approved by

Principal

Advisor:_..:...P=-au=I:....:W~ils::...;:o~n-'-

_ _ _ _ _ _ _ _ _ _ _ _ _

_

Dr.

Paul Wilson

Committee Member:

-~~~~~---

David Hart

Prof. David

Hart

Committee Member:---=D=:..a=r'-'-re=n'-'--'-N=ac.:....:ra:::..lyc..:::a:...:...;n~

_ _ _ _ _ _ _ _ _ _ _ _

_

Dr. Darren Naravan

Committee Member: Hossein Shahmahamad

Dr. Hossein Shahmohamad

Department of Mathematics and Statistics

Rochester Institute of Technology

(3)

RIT DML

Electronic Thesis

&

Dissertation (ETD)

Thesis/Capstone Project

Author Permission Statement

Title of thesis/Capstone project:

i 1'Jl..

!Jet.

Jt,~L<--l:

lilA

sift;

to

r LJ

e

Jo

,A

ppl

e

t-I, David Fraser , hereby grant the nonexclusive license to the Rochester Institute of Technology Digital Media Library (RIT DML) to archive and provide electronic access to my thesis/Capstone project in perpetuity.

I hereby certify that, if appropriate, I have obtained and attached written permission statements from the owners of each third party copyrighted matter to be included in my thesis/Capstone project. I certify that the version I submitted is the same as that approved by my advisor and/or committee.

I hereby grant to the Rochester Institute of Technology and its agents the non-exclusive license to archive and make accessible my thesis/Capstone project in whole or in part in all forms of media. I understand that my work, in addition to its bibliographic record and abstract, will be available to the world-wide community of scholars and researchers through the RIT DML.

I retain all other ownership rights to the copyright of my thesis/Capstone project. I also retain the right to use in future works (such as articles or books) all or part of my thesis/Capstone project. The Rochester Institute of Technology does not require registration of copyright for thesis/Capstone projects

Signature of author: --;D=-.::::ac....:.v..:...id:::...:..F-=-r.=a..::.s.=e..:....r _ _ _ _ --:-_ _ _ _ _ _ _ _ _ _ _ _ _

Date:

'-113,

1

0 )" Degree: ..4..tII---<4 _ _ _ _ _ _ _ _ _ _ _

College: ~c.. €VlLi...

(4)

Table ofContents

SectionI: Background 1

Introductionto Necklaces 1

TheDihedral Group 1

Burnside'sTheorem 2

The Cycle Index 3

The PatternInventory 4

Section II: TheApplet 6

IntroductiontoJava 6

Applet Overview 7

Input 8

The Cycle Index 8

The PatternInventory 8

NecklaceIllustrations 10

Section III: Problemsand Fixes 12

SectionIV: TheCode 16

CIDraw.java 17

Cyclelndexjava 19

CyclelndexList.java 36

CyclelndexObj.java 37

DrawObj.java 38

Necklace.java 47

NecklaceCompute.java 54

NecklaceObj.java 63

Patternlnventory.java 66

PatternlnventoryObj.java 84

(5)

SectionI: Background

IntroductiontoNecklaces

In terms ofCombinatorics and Graph Theory, a necklace is a cycle with each vertex (or

"bead")given a certain color. Theproblemisto countthenumber of necklaceshavingnbeadsif

k colors are available. The number of distinct necklaces can be determined by building the

patterninventory, apolynomial with variablesrepresentingdifferentcolors, theexponents ofthe

variables representing the number ofbeads ofthat color, and the coefficients representing the number ofdistinct necklaces with that coloring. For example, a necklace made offive beads

using the colors black and white has the pattern inventory

b5

+2b3w2+bw4+b4w+2b2w3 +W5.

Twonecklaces are consideredidentical ifthereexist symmetries suchthat thenecklaces look

the same after the symmetries are applied. For example, the figure below shows three necklaces, eachmade oftwo whitebeads and two gray beads. Necklace 1 andNecklace 2 are distinctsincethereisnosymmetrythat canbeappliedto makethemlookthe same. Necklace 2

andNecklace 3, however, are not considereddistinct since a clockwise rotation of90 applied toNecklace 2wouldhave itappearidenticaltoNecklace 3.

Necklace 1 Necklace 2 Necklace 3

The DihedralGroup

Before discussion of necklace counting can begin, one must first understand the dihedral group. Thisis theset ofrigidmotions on an -gon. Itconsistsofrotationsandreflections. The

followingparagraphs explaindihedralgroups intermsof necklaceswith an evenor odd number

ofbeads.

(6)

opposite beads, we can consider aline of reflectionrunning through these pairs. Finally, there

are n/2 pairs of opposite edges and we can consider a line of reflection running through these

pairs. Intotal, we seethatthere are atotalof2nsymmetries onanecklace ofeven beads. The

followingfigureshowsthelinesofreflectionforafour-beadnecklace.

In the case ofan odd number ofbeads, the number of rotations is similar to that ineven

necklaces. The lines ofreflection, however are not the same. There are no pairs of opposite

beads or opposite edges. Instead, a line of reflection is constructed from each bead to the

opposite edge. Again, thisgives n rotations and n reflectionsfor a totalof2 symmetries. The

followingfigureshowsthelinesof reflectionforafive-beadnecklace.

Burnside's Theorem

Therearetwo versions ofBurnside's Theorem (alsoknownasNot Burnside's Theoremsince

theresultswereknowntoCauchyandFrobenius decades before Burnside'sproof)when applied

to thenecklaceproblem. Theyare asfollows:

(1) N=-l-Z*7*

(2) N=-LZG*(*)

Inthese equations, N isthenumberofdistinctcoloringofa necklacewitha given number of

colors. \G\ isthenumberofpermutation ofthenecklace. Thisisthe size ofthedihedral group,

(7)

x is anyone coloring. 0(x) denotes the number of symmetries that leave the coloring x fixed.

Equation (2) uses G, jt, and ft. G isthe group of permutations or symmetries ofthe necklace

and ^isanyone permutation of symmetry. \j/(n)isthenumber of coloringsinTleftfixedbytt.

What Burnside's Theoremsays isthat thenumber ofdistinctnecklacesisequalto thenumber

ofcoloringsleft fixedbyall symmetriesdividedby2n.

The CycleIndex

The firststep infindingthepatterninventoryforagiven numberof colors andbeadsistofind

the cycle index for a given number ofbeads. To do so, we must find the cycle structure

representation ofeachsymmetry. Wecandothisfortherotationsin adirect manner. Foreach

rotation,wetrace thepathofthebeadsthroughthe rotatioa Considerthe following four-bead

necklace.

o

Consider

all rotations to be in a clockwise direction. For a rotation of0 (we can also

considerthis a rotationof360), eachbead remains fixed. Thus, we have a cycle structure of

(a)(b)(c)(d). Fora rotation of90,agoestob,b goesto c,cgoestod,anddgoestoa. Thisis

acycle structure of(abed). Forrotations of180 and 270, we get (ac)(bd) and (adeb). For

reflections about the lines through opposite edges, we get (ab)(cd) and (ad)(bc). Finally, for

reflectionsaboutthelinesfromato c andfrombto d,we get(a)(bd)(c)and(ac)(b)(d).

The next step is to convert these cycles into a notation in terms ofx. Eachx will have a

subscriptand asuperscript.

Xjwill appearforeach ofthe/timesa cycle oflength/occursinthe

cycle structure for each symmetry. For the rotations, we get x\, x\, x\, and x\. For the

reflections, we getx\, x\, x\x\, and x\x\. Groupingthe terms together givesx\ + 2x\ + 3>x\ +

2x\Xj.

Cycle Index Term Cycle Structure

x\ (a)(b)(c)(d)

2x\ (abcd),{adcb)

3xf (ac)(bd),(ab)(cd),(ad)(bc)

(8)

Nowconsider a necklace withfive beads. Again, there are fiveclockwise rotations, eacha

multiple of72. Forarotation of0(or360),we get acycle structureof(a)(b)(c)(d)(e). Fora

rotationof72, we haveacycle structure of(abode). In fact, for each rotation other than0,

wehavethecycle structureof(abcde). Thereflections aboutthelines from verticesto opposite

edges givethecycle structures(a)(be)(cd),(b)(ac)(de), (c)(bd)(ae), (d)(ce)(ab),and(e)(ad)(bc).

Converting these cycle structures into cycle index notation, we get xf for 0 andx\ for all

other rotations. Eachofthereflections gives xlx^. Thereforethecycleindex isxf +4x\ + 5x\xl.

CycleIndex Term Cycle Structure

x? (a)(b)(e)(d)(e)

4x\ (abcde),(acebd),(adbec),(aedcb)

Sx\4 (a)(be)(cd)Xb)(ac)(deUc)(bd)(ae),(d)(ce)(ab),(e)(ad)(bc)

We candrawsome generalizations about computingthe cycle indexwithouthaving to trace

the locations through all rotations and reflections. Whenconsidering therotations ofnecklace

with n beads, index them as 1 through n. The cycle index term for the fth rotation will be

x/gcd(/jj)- The cycle indexterms forthe reflections will depend on whether n is even or odd.

Foroddn,allthereflectiontermswillbe x}x2 ~

. Whenn iseven, therewillbe termsofthe fornix^2

and |termsoftheformx?x^"2)/2.

ThePatternInventory

Once we have computed the cycle index, we are readyto determine thepattern inventory.

Construct anexpression foreachterm inthe cycle indexasfollows: {cr +bc*

+... +

c^)e such

that a, b, ..., c are variables representing different colors, d is the subscript ofthe cycle index

term, and e is the superscript ofthe cycle index term. Expanding this polynomial willalmost

result in the pattern inventory for the chosen colors and number of beads. Each distinct

(9)

betoolargebyafactorof2n. Simplydividingthecoefficientsby2willgivethedesiredresult.

Suppose that we were to color a four-bead necklace with black and white beads. We start

withthecycleindex for four beads,x\ +2x\+ 3x\ +2x\x\. Next,we insert(bl + wV foreach xj. This gives us (b + w)4

+ 2(b4 + w4) + 3(b2+ w2)2

+ 2(b + w)2(b2

+ w2). Following

expansion and coefficientdivisionby 8,we are leftwithanexpression ofb4 + b3w + 2b2 vr +

Zw3 +

w4. Readingthe coefficients, this tells usthat thereis onlyone distinct necklace with all black beads, one with threeblack andone white bead, two withtwo blackand two white, one

(10)

SectionII: The Applet

The Necklace

Illustrator

Red Beads 4'

m W:

Blue Beads 2 ?

!-:;:'|aflri;t#^

Green Beads fm*

Yellow Beads o ;?

Cycle Index: x7 + 6xJ +

7x\x|

Necklaces 1 through 9

oo

oo

oo

oo

o

Pattern Inventory:r7+r^1 +i^g1+3^+ 3rsb1g1 + SrSg2 + Afiti3 +9r4b2g1 + grVg2 +

4,4g3 + 4r3b4 +1oWg1 +18r3b2g2 +1Dr^g3+ 4r3g4+3^13^+9r2b4g1+

1S^t^g2 +1S^l^g3 +

9r2b1g4+3r2g5 +r1b6+ Sr^g1 + 9r1b4g2 + 10r1b3g3 + 9r1b2g4 +3r1b1g5 +r1g6+ b7+ b6g1 +

3ifi^* 4b4g3+AtPgP+ 3b2g5 +b1ge+g7

Introduction to Java

Thissectioncontainsterms thatmaynotbeunderstoodbya readerthatdoesnotknowmuch

about the Java programming language. This is a brief introduction that explains some ofthe

moreimportanttermsused.

Java is an object-oriented language. This means that a program consists of interacting

objects,each with certaindataandfunctionspredefined. Thesedataandfunctiondefinitionsare

determined by the class to which an object belongs. When a new object is created in the

program,it isaninstanceofaclass.

(11)

passed or returndataas wellasperform operations.

AnAppletisatypeofJavaprogram. Itrequires aJavaenvironment, suchas aJava-enabled

webbrowser,to run.

Whenwe saythat Class Aextends Class B, it meansthat a newclass, ClassA, was created

that inheritsalltheproperties ofClassB inadditiontoanynew methods added.

Therewere somestandardJavaclassesthatwereusedin creatingthisApplet. One suchclass

istheVectorclass. This is essentiallyanarraythatcontains objects. Thedifferencebetweenthe

VectorandtheusualJava arrayisthatthearraymustbepasseditsmaximum sizeuponcreation

and aVectorisresizable.

Anotherclass repeatedlyused wastheCanvasclass. TheCanvasistypicallyusedfordrawing

tothescreen.

Applet Overview

The Applet is designed to display three different results based on the selection ofbeads

chosenbytheuser. Thefirstresultis thecycleindexofthe totalnumber ofbeadschosen. The

second result is the pattern inventory for the number and colors ofbeads chosen. Finally, all

distinctnecklacesbasedontheselectedbeadsaredisplayedingroups ofupto ten.

Uponloading, theAppletgivestheuserfour drop-downselectionboxes fromwhichtheycan

choosethe number ofbeads ofeach color. Thevalid colors are red, blue, green, and yellow.

Thevalidchoicesforeachcolorrangefromzerotofive.

When the usertriggers any ofthedrop-down boxesand selects anumber forthat color, the

Applet automaticallycomputes and displaysthenew cycleindex and patterninventory. The list

ofdistinctnecklaces are notautomatically drawn, however. Theuser must first click abutton

labelled "Drawfirst 10". Iftherearetenorfewernecklaces, theyarealldrawnonthescreen. If

therearemore than ten necklaces, the "Draw first 10"

buttonisre-labelled "Drawnext 10". A

newbuttonisalso createdlabelled "Newnecklace". This secondbutton is included incase the

user nolongerwishesto viewthecurrent necklace and make a new colorselection. Aftera new

selection of colors, clicking the "New necklace"

button will terminate illustrating the first

necklace and willbegin drawingthedistinct necklacesforthenewcolorselection. Whenall of

thenecklaces have been shown, the "Draw next 10" button is once again labelled "Drawfirst

10"

andthe"Newnecklace"

(12)

Input

The Necklace Applet itself is visually divided into four separate panels. Thefirst isused for

input. It contains four JComboBox objects, one for each color. A JComboBox is a "drop-down"

menufor selecting data. EachJComboBoxhasanActionListenerattachedto it so that when a new number is selected fromthat box, the routinesfor computing cycle indexand pattern inventory are automatically run. The input panel contains the "Draw first 10"/"Draw next 10" button and the "New necklace"

button. These buttons also have ActionListeners

attachedtoruntheappropriate routines.

Thepanels forthe cycle index, patterninventory, and necklaceillustrations contain objects thatextendtheCanvasclasscontainingmodifiedpaintmethods.

IntheeventofanActionListenerbeingtriggeredbycolor selectionor abuttonclick, thefirst

thingthat occursthat thevaluesinthefour JComboBoxesarestored as integervariablesforthe fourcolors. The Appletthendetermines whetherit was a colorselection or abuttonclick that

occurred

TheCycle Index

Whena newcolorselection ismade, a Cyclelndexobject iscreated forthe total number of

beads. This Cyclelndex object has the task ofcreating a Vector that stores CyclelndexList

objects. The CyclelndexList isan objectthatcontainsaninteger coefficientas wellasaVector

containingeitherone ortwo CyclelndexObj objects. TheseCyclelndexObj objects representthe

'x'

in the cycle index and store the superscript and subscript. The Cyclelndex object has

hardcodedroutinesfortotalbeadvaluesonethrough twenty.

Oncethe Cyclelndex object is created, theVectorthat stores the appropriatecycle index is

passedto aCIDrawobject. The CIDrawobjectisa canvas onwhichthecycleindex is drawnto

be displayedto theuser.

ThePatternInventory

Next, aPatternlnventoryobject iscreated andispassedtheVector containingthecycleindex

as well as the number ofred, blue, green, and yellow beads. This object first determines the

number ofbeadsused. Specificmethodsare calledforone ortwobeads. Foratotalbeadcount

(13)

the pattern inventory are stored in PatternlnventoryObj objects. These simply store integer

coefficientsas well as exponents forthe variablesr, b,g, and y. All PatternlnventoryObjterms

are storedinaVectorwithinthePatternlnventoryobject.

Ifthereisonebead,aPatternlnventoryObjiscreatedthat setstheexponent oftheappropriate

variableto 1 andisaddedtotheVector.

Ifthere are two beads, the Patternlnventorydetermines iftheyareboththe same color. If

theyare, aPatternlnventoryObjiscreatedthat setstheexponent oftheappropriate variableto 2

and is added to the Vector. When there are two beads of two different colors, a

PatternlnventoryObj is created that sets the exponents ofthe appropriate variables to 1 and is

addedto theVector.

When there are more than two beads, there are four different methods to determine the

patterninventory.

Inthe simplestcase whereonlyone colorisused, aPatternlnventoryObj object iscreated

that sets the exponent oftheappropriate variable to the number ofbeads and is added to the

Vector.

Whenthere are two colors, each CyclelndexList object is read except for the last one,

whichcontains two CyclelndexObj objects(or V values). For each ofthese, the superscript is

read and used to compute the terms of the polynomial in the following manner: Let

r=superscript ofthe cycle index term,y=exponent ofthe first color, fc=exponent ofthe second

color, and /w=subscript ofthe cycle indexterm, jrunsfrom 0to iand kruns from to 0 such

that y + k=

i ineachterm. Abinomialcoefficient isproduced for eachpairof jand kand all

exponents are multipliedbym. Whenthis is done forallbutthe lastCyclelndexList, the terms

are all grouped together. Forthe last CyclelndexList, a similar process occurs foreachofthe

two V terms and they are multiplied together by taking all pairs of terms, adding their

exponents, andmultiplying their coefficients. Alllike termsare groupedtogetherforthe entire

pattern inventory. Finally, all coefficients are divided by 2n for the final pattern inventory

expression. Each term is stored in a Vector as a PatternlnventoryObj object that stores the

coefficient aswellastheexponentsforeach color variable.

Whenthere arethree orfourcolors, theprocedures are similar. First, afour-dimensional

array is created using Vectors. This is done by creating three Vectors that contain Vector

objects. The fourthVectorcontains PatternlnventoryObjobjects that store thecoefficients and exponents for each color variables. When initially created, the indices ofthe four Vectors

representthe exponentsstored inthePatternlnventoryObj. Thecoefficients are allinitializedto

(14)

similartothetwo-colorcase. Allexponentsforthevariables are foundsuchthattheyaddupto

the superscriptofthe CyclelndexObj,a multinomial coefficient isgenerated, and the exponents

are multiplied by the

CyclelndexObj

subscript. The four-dimensional array is then accessed

based onthe variable exponents andthe current coefficient isadded to the coefficient stored in

thearray. Forthelast CyclelndexList, eachofthe'x' termsisexpandedina similarmanner. For

eachterm inthe second 'x1, theterms ofthe first 'x'

are multiplied byadding the exponentsand

multiplying the coefficients. The array is thenaccessed and the current coefficient is addedto

the coefficient stored inthe array. Finally, allPatternlnventoryObj objects stored inthe array

are examined and ifthe coefficient is not 0, it is written to a Vector that can quickly give all

termsofthepatterninventory.

Once the Patternlnventory object is created, the Vectorthat stores the appropriate pattern

inventory is passed to a PIDraw object along with the number ofbeads of each color. The

PIDraw object is a Canvas-extending object on which the pattern inventory is drawn to be

displayedto theuser. Whenthe exponents ofthecolors matchthecolor selection givenbythe

user, the termis displayed inabold font.

Necklace Illustrations

Whenthe userselectseitherofthe drawbuttons,theAppletcreates a newNecklaceCompute

object whichdoesthecalculations fordetermining distinctnecklaces. Duetorestrictionsonthe

largercases, ismust first be determined ifthecolorselectiongiven issmallenoughto compute.

Withthecutoffdeterminedto begreaterthan 14beadsusingallfourcolors,aflag isset. Ifthe

selectionis too large,amessageis displayedsaying so. Otherwisetheprocess continues. First,

the color selection is transformed into a string representation. For example, 'rrbbbg' would

represent twored beads,threebluebeads, and onegreenbead. Apartiallistof permutations of

thisstringisthengenerated. Thispartiallistcontains stringsthatrepresentalldistinctnecklaces.

Toreducethenumberofpermutations,onlythosethat beginwiththe letterofthe smallest color

chosen are generated. Whenallofthesearegenerated, theyare examinedto seeiftheyalso end

with the smallest color chosen. Ifso, they are discounted since they represent necklaces that

have undergone a rotation and are a duplicate of some necklace that does not end with the

smallest color chosen. Withthe list ofpermutations minimized inthis manner, eachremaining

string ispassed to anewNecklaceObjobjectthat storesthe string, thestring reversed, and two integers called the forNum and backNum that represent all consecutive pairs ofletters in the

(15)

forward string is traversed and consecutive letters are considered. Based on what these two

letters are, the forNum is multiplied by a certain prime number. Likewise, then backNum is

generatedbytraversing thebackward string, considering consecutive letters, andmultiplyingby

a certain prime number. Thisway, weknowwhat letters are adjacentforward andback, which

helps speed up determining duplicate necklaces. These NecklaceObj objects are stored in a

Vector.

WiththeNecklaceObjVectorgenerated, theAppletcan nowstarteliminating duplicates. To

speed up the process, only up to ten distinct necklaces are identified at a time. The

NecklaceCompute is passed the Vector ofNecklaceObj objects as well as the start and end

indices ofthe desired necklaces. For example, it can be passed 0 to 9, 10 to 19, or 20 to 29.

Theprocedure is donebystartingat thelower indexandcomparingtoeach priorNecklaceObj,

all ofwhichareassumedtobe distinct. TheforNumsarefirstcompared andiftheymatch, there

is the possibility that they are duplicate necklaces. The forward string is then rotated by

repeatedly moving the leading character to the end. Ifthe strings match at any point, the

process is terminated and the current NecklaceObj is marked as a duplicate. Ifthere is no

match, the backNum of the current NecklaceObj is compared to the forNum of the prior

NecklaceObj. Iftheyarethe same,a similarrotation process occurstolook foramatch. Ifit is

determinedthat the currentNecklaceObj isaduplicate, it is removed andthenextNecklaceObj

goes through the same process. If it is determined that the current NecklaceObj is not a

duplicate,it isgrouped withthepriordistinctnecklaces and thenextNecklaceObjgoes through

the same process. This repeats until either the upper index is reached or all necklaces are

compared.

Itisthen time todrawthecurrentset of necklaces. ADrawObjobjectiscreatedthatrenders

thecurrent setoftenorless necklaces. This isdone bypassing theDrawObj theNecklaceObj

Vector and selecting the forward strings for the current set of necklaces. When the first ten

necklaces are drawn, a "New necklace"

button is created in case the user wishes to view

necklaces of anewcolor selection. Once the entire set ofdistinctnecklacesisdrawn,the "New

necklace"

(16)

Section III: Problemsandfixes

During the writing ofthis Applet, anumber of problems arose. The followingparagraphs documenttheseproblems anddescribe howtheywere eitherfixedorworked around.

The firstproblem encountered washowto generate alist ofpermutations ofa string. Thisin itselfwouldhave beennoproblemifallthecharactersweredistinct, butthefactthat therecould

be repeated characters meant therewould bemany repeated permutations. Afterseveral hours

searching Java booksandtheInternet, littleprogress had beenmade. Thekeywasterminology. Whenthe searchwas changed from

'permutation'

to 'anagram', a solution was soonfound. An

anagram-generating algorithm was found in An Introduction to Object-OrientedProgramming

with Java by C. Thomas Wu. This algorithm also assumed non-repeated character, but it was

easily adapted to take repeated characters into account. This can be found in the NecklaceComputeclassinthe permutationGeneratorOmethod.

Oncethislist of permutations wasobtained, itwastime to startmakingitmore efficient. The list could grow quite largeand contain manyduplicate necklaces. The first taskwas to find a

wayto eliminate as manystrings as possible without the risk oflosing any distinct necklaces. This was done by considering only strings that start withthe letter correspondingto the color

withthe smallest number ofbeads. Anyother string couldbe considered aduplicate ofone of these (either forward or backward) after some rotation was applied. Therefore, any other

string'snecklace would be a duplicate of at leastone string'snecklace fromthe smaller set. A

second check was set upto eliminate furtherduplicates fromthissmaller set. The last character

ofthe string is checked and if it also is the letter corresponding to the color withthe smallest

number ofbeads, it is discounted. This is due to the factthat the necklace itrepresents would bearotationof some necklace whosestringdidnotendinthesameletter.

The firstproblemthatwaspure Java programmingand notalgorithm-orientedwasthat when

the distinct necklaces were drawn on the screen and another window was opened over these

necklaces, theywoulddisappearwhenreturningtotheApplet. Thisproblemexisted forseveral

weeks and any attempts to fix it failed. The vitalpiece ofinformation concernedthe Canvas

class that was usedindrawingthesenecklaces. When aCanvas-extendingobject iscovered on

the screen,itrecallsitspaint()methoduponbeingexposed again. Whennothing is inthepaintO

method, thedefaultisto clearthe screeninthat area. TheDrawObj classwaswrittenextending

(17)

Whentheuser selected a necklace composed ofjust onecolor,nonecklaces would be drawn. Thiswas a result ofthe method used forobtaining the necklace strings. When a stringbegan and ended withthe same character, it was discounted. With only one colorused, there is only

one stringand allcharacters, includingthe firstand last, arethe same. This stringwould never be considered and an empty Vector would be created. Special code was inserted in the

permutation generator ofthe NecklaceCompute object to handle the case where there wasjust

onebeadandthecasewheretherewere multiplebeadsofonlyone color.

Duringtesting,several combinationsofbeadswere showntohaveproblems withthenumber

ofnecklacesdisplay. Oneofthefirst to beproblematic was a3-3-2 combination whentheuser

selectedtwo red, three blue, andthree green. It displayedadifferent number of necklacesthan when the user selected three red, three blue, and two green, which gave the correct number.

The problem was traced back to the omission of an equal sign. When determining whether

necklaces weredistinct, theNecklaceCompute would goup, but notincluding, the upper index

sent bythe Applet. Thismeant that a few necklaces were not checked and were reported as

distinctwhentheywereduplicates.

Aproblem wasfound whentheAppletwas run on some, butnotall, Macintoshcomputers.

Problems loadingthe Appletwere foundusing boththe Safari andInternet Explorer browsers. Similar problems were later encountered when attempting to load theApplet onto a Windows computer withInternet Explorer. In thecase ofthe Windows computer, trip to www.sun.com resulted in downloading an up-to-date version of the Java Runtime Environment. After

installation,theAppletloadedand performed properly.

Aproblem was foundwhen trying to displaynecklaces with alarge number ofbeads. The

case that first found this problem was five red, three blue, five green, and four yellow. The

problem was tracked back to a Java memory problem. Even when the permutation list is minimized as described above, there are problems with large cases. Although the program

discounts many strings as being duplicates, the recursive nature ofthe permutation generator

meant that all permutations were generated, ifnot saved. A new method was added to the permutation generator that would onlybuild strings that started with the letter ofthe smallest color. Even withthis implemented, there were stillproblems withthe largercases. The only workaround was to impose a limit so that for these larger cases, the work would not be done

that resulted in the memory errors. After testing, the breaking point appeared to be whenthe user selected morethanfourteen beadsusingallfourcolors.

Displaying the cycle index and pattern inventory requires the use of subscripts and

(18)

to use a StyledDocument and add each piece individually. Each time the style of the text

changed, the StyledDocument style had to be changed. This worked for the cycle index, but

problems wouldlaterarise withthepatterninventory.

The next problem that presented itselfwas the question ofhow to expand the pattern

inventorypolynomial based onthe cycle index and colors chosen. The initial attempt mirrored

theway inwhichonewould expandpolynomialsbyhand. Thetermsinsidetheparenthesiswere determined by the colors chosen and the cycle index subscript (for example, r4

+ o1

+ g4).

They were then multiplied by itselfbytaking individual terms and adding the exponents. This

was repeatedaccordingto the superscript ofthecycleindex. Whenthisprocess wascompleted,

alltermswere addedto aVector. TheVectorwouldthenbe traversedand the termswouldbe

groupedtogether, resulting in a coefficient foreachterm. Whilethis workedforsmall cases, it

was highly inefficient and failed completely due to memory issues with even moderately large

cases. Asearchwas conductedto findifotherJavaclasses couldhandletakingthe expression

as a string, expanding the polynomial, and returning the expression as a string that could be

displayed. Some were found,buttheyall provedto bequite complexandlearning to use them would befairly difficult in a short amount oftime. Returning to writing a new procedure, the

result was the process described in the previous section that can be found in the

Patternlnventoryclass.

Oncethepatterninventorycouldbecomputed andstored inaVectorofPatternlnventoryObj

objects, a new problem arose concerning how to display them. When the number ofbeads

grows largeenough, the panel usedto displaythe terms hadproblems sincethe termswere all displayed horizontally by the StyledDocument. In addition, cases that were small enough to displaybut stillfairlylargewere slowto display. The solution was torenderthemas adrawing as donewiththenecklaces. Insteadof a StyledDocument, aCanvas-extending objectwas used that drew the terms on the screen in the panel The main problem was keeping track ofthe locationwhere itemsshouldbedrawn, sincethechangingstylesfromregulartext to superscript

textcauseddifferencesintextwidthmeasurements.

This approach towriting thepatterninventoryworked, but it was stilltoo slow. Eachtime

the screen was refreshed, it would have to write eachterm individually, whichwas a problem

when there were many terms. For each term, the coefficient was drawn in addition to any

variable with a non-zero exponent as well asthe exponent. To fix this, amethod was included

that created a Bufferedlmage. The terms were then drawn onto this image. Now when the

screenisrefreshed,itsimplyredraws oneimageinsteadof alltheindividualterms.

(19)

green. The pattern inventory says that there should be ten distinct necklaces with this color

selection. Inpractice,notonlywere eight display,buttheywere labelled "Necklaces 1 1 through 18". Reviewingthecodefordetermining distinctnecklaces foundconsecutive ifstatementsthat

had opposite conditions. Whilethe second condition was initiallyfalse, executing the code for

the first if statement caused it to be true. Changing this to an if-else statement resolved the

problem.

The final fewproblemfixesdealtwiththenecklacedrawingofmiscellaneous cases. One such

case was whenthe numberofnecklaces was a multiple often. In some instances, there were

additional stringsto check for duplicity, so the Applet did not knowthat alldistinct necklaces had already been displayed. Ifthere were onlyten, for instance, the final necklace illustration

wouldbe blankexceptforatitlethatread"Necklaces 11 to 10". Thiswasfixedbyaddingsome

code to theNecklaceand PIDrawclasses. Asthe PIDrawstepsthroughthe patterninventory

terms, itchecksto see ifthetermcorresponds to the color selection givenbytheuser. Ifso,it

is drawn inabold font. Inaddition, the coefficientisnoted asthemaximumnumber ofdistinct

necklaces. The Necklaceclassusesthiscoefficient as a cutofffordrawingnecklaces.

Iftheuser attemptedto drawnecklaces with no beads,the drawpanel wouldbe blank with

thetitle "Necklaces 1 to 0". CodewasinsertedintheDrawObjclassto insteaddisplaythe title

"Nothingselected".

The final problem encountered was one which was thought of earlier, but dismissed as

unlikelyto occur. Whentestingthepatterninventoryfortwenty beads,five of eachcolor, many ofthe largest coefficients came up as negativenumbers. In Java,the intdatatype has a range

up to 2147483647. All ofthe coefficients were withinthis range. The problem wasthat this

number must first be dividedby40. Priorto this division, thenumbers wereoutsidethe range. Whenthishappens, the integer "wraps around"

andbecomes anegative number. Thenumbers

were changed from the int data type to the long data type, which has a range up to

(20)

Section IV: The Code

The

following

pages contain the Java code for all classes used by the Necklace Illustrator
(21)

/*

*

CIDraw.java *

ForusewiththeNecklaceIllustrator Applet

*

byDavidFraser

*

RochesterInstituteofTechnology *

May2005 *

*/

packageNecklace;

importjava.awt.Canvas; importjava.awt.Graphics;

importjava.awt.Font;

importjava.lang.Integer;

importjava.util.Vector;

importNecklace.CyclelndexList;

importNecklace.CyclelndexObj; importjava.awt.FontMetrics;

public classCIDrawextendsCanvas{

VectorciVector;

Graphicsg;

//createa newCIDrawthatispassedtheCycle Index Vector

publicCIDraw(Vector vec) { ciVector=

vec;

g=getGraphicsO;

}

//paintmethod usedtorendertoscreen

public void paint(Graphics g){

Font boldFont=

newFont("boldFont",java.awt.Font.BOLD, 12);

g.setFont(boldFont);

g.drawString("CycleIndex: ", 10,20); intnewX=

10+tliis.getFontMetrics(bol(lFont).stringWidth("CycleIndex: ");

//ifthe Cycle Index Vector isnotempty if(ciVector. sizeO!=0) {

FontregFont=

newFont("regFont",java.awt.Font.PLATN, 12); FontsmallFont=

newFont("smallFont",java.awt.Font.PLATN, 10);

g.setFont(regFont);

(22)

CyclelndexListciList=

(CyclelndexList)ciVector.elementAt(i); VectortempVector=

ciList.getCyclelndexEntryO;

Integerconvlnt=

newInteger(0);

//ifthecoefficientisnotI, drawtoscreen

if(ciList.getCoeffO!=l){

StringtempStr=

convInt.toString(ciList.getCoeff()); g.drawString(tempStr,newX,20);

newX=

newX+diis.getFontMetrics(regFont).stringWidth(tempStr); }

//foreach "x"interm:

for (intj=0; j<tempVector.sizeO;j++){

CyclelndexObjciObj=(CyclelndexObj)tempVector.elementAt(j); g.setFont(regFont);

//draw "x"

g.drawStringC'x", newX,20);

newX=

l+newX+this.getFontMetrics(regFont).stringWidth("x");

g.setFont(smallFont);

//drawsuperscript andsubscript StringtempSup=

convInt.toString(ciObj.getSupO);

StringtempSub=

convInt.toString(ciObj.getSubO);

g.drawString(tempSup, newX, 16);

g.drawString(tempSub,newX,24);

newX=newX+java.lang.Mam.max(this.getFontMetrics(smalIFont)

.stringWidm(tempSup),this.getFontMetrics(boldFont) .stringWidth(tempSub));

}

//ifnotthelastterm if (i!=ciVector.

size()-1 ){ g.setFont(regFont); //draw "

+ " g.drawString("

+ ",newX,20);

newX=newX+this.getFontMetrics(regFont).stringWidth("

+"); }

} }

g.dispose();

(23)

/*

*Cyclelndex.java

*

Foruse withtheNecklaceIllustrator Applet *

byDavidFraser *

Rochester InstituteofTechnology *

May2005 *

*/

packageNecklace;

import java.util.Vector;

public classCyclelndex {

privateVectorcyclelndexVector;

//createa newCyclelndex

publicCyclelndexO {

}

//createa newCyclelndexthatispassedthenumberof beads

publicCyclelndex(intbeads) {

cyclelndexVector=

newVector();

//checkthenumberofbeads, call appropriate method

switch(beads) {

case 1: oneBeadO;

break;

case2: twoBeadO;

break;

case3: threeBeadO; break;

case4: fourBead(); break;

case5: fiveBeadO; break;

case6: sixBeadO;

break;

case7: sevenBeadO;

break;

case 8: eightBeadO;

break;

case9: nineBeadO;

break;

(24)

break;

case 11: elevenBead();

break;

case 12: twelveBead(); break;

case 13: thirteenBeadO;

break;

case 14: fourteenBeadO; break;

case 15: fifteenBeadO;

break;

case 16: sixteenBead(); break;

case 17: seventeenBeadO; break;

case 18: eighteenBeadO; break;

case 19: nineteenBeadO; break;

case20: twentyBead();

break;

}

private voidoneBead(){

//createx(sub(l), sup(l))

CyclelndexListtempList=

newCyclelndexListO;

CyclelndexObjtempObj=

newCycleIndexObj(l,l);

tempList.addCI(tempObj); tempList.setCoeff(l);

cycleIndexVector.add(tempList);

}

private voidtwoBead(){

//createx(sub(l), sup(2)) CyclelndexListtempListOne=

newCyclelndexListO;

CyclelndexObj tempObjOne=

newCycleIndexObj(2,l);

tempListOne.addCI(tempObjOne);

tempListOne.setCoeff( 1);

cyclelndexVector.add(tempListOne);

//createx(sub(2), sup(l)) CyclelndexListtempListTwo=

newCyclelndexListO;

CyclelndexObjtempObjTwo=

newCycleIndexObj(l,2);

(25)

tempListTwo.setCoeff(1);

cyclelndexVector.add(tempListTwo); }

private voidthreeBead(){ //createx(sub(l), sup(3))

CyclelndexListtempListOne=

newCyclelndexListO;

CyclelndexObj tempObjOne=

newCycleIndexObj(3,l);

tempListOne.addCI(tempObjOne);

tempListOne.setCoeff(1);

cyclelndexVector.add(tempListOne);

//create2*x(sub(3), sup(l))

CyclelndexListtempListTwo=

newCyclelndexListO;

CyclelndexObjtempObjTwo=

newCycleIndexObj(l,3);

tempListTwo.addCI(tempObjTwo);

tempListTwo.setCoeff(2);

cycleIndexVector.add(tempListTwo);

//create3*x(sub(l), sup(l))*x(sub(2), sup(l))

CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObjtempObjThreeA=

newCycleIndexObj(l,l);

CyclelndexObj tempObjThreeB=

newCycleIndexObj(l,2);

tempListThree.addCI(tempObjThreeA); ternpListThree.addCI(tempObjThreeB);

ternpListThree.setCoeff(3);

cycleIndexVector.add(tempListThree);

}

privatevoidfourBeadO{ //createx(sub(l), sup(4))

CyclelndexListtempListOne=

newCyclelndexListO;

CyclelndexObjtempObjOne=

newCycleIndexObj(4,l);

tempListOne.addCI(tempObjOne);

tempListOne.setCoefftT);

cyclelndexVector.add(tempListOne);

//create2*x(sub(4), sup(l))

CyclelndexListtempListTwo=

newCyclelndexListO;

CyclelndexObj tempObjTwo=

newCycleIndexObj(l,4); tempListTwo.addCI(tempObjTwo);

tempListTwo.setCoeff(2);

(26)

//create3*x(sub(2), sup(2)) CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObjtempObjThree=

newCycleIndexObj(2,2);

tempListThree.addCI(tempObjThree); tempListThree.setCoeff(3);

cyclelndexVector.add(tempListThree);

//create2*x(sub(l), sup(2))*x(sub(2), sup(l)) CyclelndexListtempListFour=

newCyclelndexListO;

CyclelndexObj tempObjFourA=

newCycleIndexObj(2,l);

CyclelndexObjtempObjFourB=

newCycleIndexObj(l,2);

tempListFour.addCI(tempObjFourA); tempListFour.addCI(tempObjFourB); tempListFour.setCoeff(2);

cycleIndexVector.add(tempListFour);

}

privatevoidfiveBeadOl

//createx(sub(l), sup(5))

CyclelndexListtempListOne=

newCyclelndexListO;

CyclelndexObjtempObjOne=

newCycleIndexObj(5,l);

tempListOne.addCI(tempObjOne);

tempListOne.setCoefl(1);

cyclelndexVector.add(tempListOne);

//create4*x(sub(5), sup(l))

CyclelndexListtempListTwo=

newCyclelndexListO;

CyclelndexObjtempObjTwo=

newCycleIndexObj(l,5);

tempListTwo.addCI(tempObjTwo); tempListTwo.setCoeff(4);

cycleIndexVector.add(tempListTwo);

//create5*x(sub(l), sup(l))*x(sub(2), sup(2)) CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObjtempObjThreeA=

newCycleIndexObj(l,l);

CyclelndexObjtempObjThreeB=

newCyclelndexObj(2,2);

tempListThree.addCI(tempObjThreeA);

tempListThree.addCI(tempObjThreeB); tempListThree.setCoeff(5);

cycleIndexVector.add(tempListThree); }

privatevoidsixBeadO{

//createx(sub(l), sup(6)) CyclelndexListtempListOne=

(27)

}

CyclelndexObjtempObjOne=

newCycleIndexObj(6,l); tempListOne.addCI(tempObjOne);

tempListOne.setCoeff(1);

cycleIndexVector.add(tempListOne);

//create2*x(sub(6), sup(l))

CyclelndexListtempListTwo=

newCyclelndexListO;

CyclelndexObjtempObjTwo=

newCycleIndexObj(l,6); tempListTwo.addCI(tempObjTwo);

tempListTwo.setCoeff(2);

cycleIndexVector.add(tempListTwo);

//create2*x(sub(3), sub(2)) CyclelndexListtempListThree=

newCyclelndexListO; CyclelndexObjtempObjThree=

newCycleIndexObj(2,3); tempListThree.addCI(tempObjThree);

tempListThree.setCoeff(2);

cycleIndexVector.add(tempListThree);

//create4*x(sub(2), sup(3)) CyclelndexListtempListFour=

newCyclelndexListO; CyclelndexObjtempObjFour=

newCycleIndexObj(3,2); tempListFour.addCI(tempObjFour);

tempListFour.setCoeff(4);

cyclelndexVector.add(tempListFour);

//create3*x(sub(l), sup(2))*x(sub(2), sup(2)) CyclelndexListtempListFive=

newCyclelndexListO;

CyclelndexObjtempObjFiveA=

newCycleIndexObj(2,l); CyclelndexObjtempObjFiveB=

newCycleIndexObj(2,2); tempListFive.addCI(tempObjFiveA);

tempListFive.addCI(tempObjFiveB);

tempListFive.setCoeff(3);

cycleIndexVector.add(tempListFive);

privatevoidsevenBeadO{ //createx(sub(l), sup(7)) CyclelndexListtempListOne=

newCyclelndexListO;

CyclelndexObjtempObjOne=

newCycleIndexObj(7,l);

tempListOne.addCI(tempObjOne);

tempListOne.setCoeff( 1);

(28)

//create6*x(sub(7), sup(l))

CyclelndexListtempListTwo=

newCyclelndexListO;

CyclelndexObjtempObjTwo=

newCycleIndexObj(l,7);

tempListTwo.addCI(tempObjTwo); tempListTwo.setCoeff(6);

cycleIndexVector.add(tempListTwo);

//create 7*x(sub(l), sup(l))*x(sub(2), sup(3)) CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObj tempObjThreeA=

newCycleIndexObj(l,l);

CyclelndexObj tempObjThreeB=

newCycleIndexObj(3,2);

tempListThree.addCI(tempObjThreeA); tempListThree.addCI(tempObjThreeB); tempListThree.setCoeff(7);

cycleIndexVector.add(tempListThree);

}

private voideightBeadO{

//createx(sub(l), sup(8)) CyclelndexListtempListOne=

newCyclelndexListO;

CyclelndexObjtempObjOne=

newCycleIndexObj(8,l);

tempListOne.addCI(tempObjOne); tempListOne.setCoeff(l);

cycleIndexVector.add(tempListOne);

//create4*x(sub(8),sup(l))

CyclelndexListtempListTwo=

newCyclelndexListO;

CyclelndexObj tempObjTwo=

newCycleIndexObj(l,8);

tempListTwo.addCI(tempObjTwo); tempListTwo.setCoeff(4);

cycleIndexVector.add(tempListTwo);

//create2*x(sub(4), sup(2))

CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObjtempObjThree=

newCycleIndexObj(2,4);

tempListThree.addCI(tempObjThree); tempListThree.setCoeff(2);

cycleIndexVector.add(tempListThree);

//create5*x(sub(2), sup(4))

CyclelndexListtempListFour=

newCyclelndexListO;

CyclelndexObjtempObjFour=

newCycleIndexObj(4,2);

tempLisfFour.addCI(tempObjFour);

tempListFour.setCoeff(5);

(29)

//create4*x(sub(l), sup(2))*x(sub(2), sup(3))

CyclelndexListtempListFive=

newCyclelndexListO;

CyclelndexObjtempObjFiveA=

newCycleIndexObj(2,l); CyclelndexObjtempObjFiveB=

newCycleIndexObj(3,2);

tempListFive.addCI(tempObjFiveA);

tempListFive.addCI(tempObjFiveB); tempListFive.setCoefl(4);

cycleIndexVector.add(tempListFive);

}

private voidnineBeadO{

//createx(sub(l), sup(9))

CyclelndexListtempListOne=

newCyclelndexListO;

CyclelndexObjtempObjOne=

newCycleIndexObj(9,l);

tempListOne.addCI(tempObjOne);

tempListOne.setCoefl(1);

cycleIndexVector.add(tempListOne);

//create6*x(sub(9), sup(l)) CyclelndexListtempListTwo=

newCyclelndexListO;

CyclelndexObjtempObjTwo=

newCycleIndexObj(l,9);

tempListTwo.addCI(tempObjTwo);

tempListTwo.setCoeff(6);

cycleIndexVector.add(tempListTwo);

//create2*x(sub(3), sup(3))

CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObjtempObjThree=

newCycleIndexObj(3,3);

tempListThree.addCI(tempObjThree);

tempListThree.setCoeff(2);

cycleIndexVector.add(tempListThree);

//create9*x(sub(l), sup(l))*x(sub(2), sup(4)) CyclelndexListtempListFour=

newCyclelndexListO;

CyclelndexObjtempObjFourA=

newCycleIndexObj(l,l);

CyclelndexObjtempObjFourB=

newCycleIndexObj(4,2);

tempListFour.addCI(tempObjFourA);

tempListFour.addCI(tempObjFourB);

tempListFour.setCoeff(9);

cyclelndexVector.add(tempListFour); }

private voidtenBeadO{

(30)

}

CyclelndexListtempListOne=

newCyclelndexListO; CyclelndexObjtempObjOne=

newCycleIndexObj(10,l);

tempListOne.addCI(tempObjOne); tempListOne.setCoeff(l);

cycleIndexVector.add(tempListOne);

//create 4*x(sub(10),sup(l)) CyclelndexListtempListTwo=

newCyclelndexListO;

CyclelndexObjtempObjTwo =

newCycleIndexObj(l,10);

tempListTwo.addCI(tempObjTwo); tempListTwo.setCoefl(4);

cycleIndexVector.add(tempListTwo);

//create4*x(sub(5), sup(2)) CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObjtempObjThree=

newCycleIndexObj(2,5);

tempListThree.addCI(tempObjThree);

tempListThree.setCoeff(4);

cycleIndexVector.add(tempListThree);

//create6*x(sub(2), sup(5))

CyclelndexListtempLisfFour=

newCyclelndexListO;

CyclelndexObjtempObjFour=

newCycleIndexObj(5,2);

tempListFour.addCI(tempObjFour);

tempListFour.setCoeff(6);

cycleIndexVector.add(tempListFour);

//create5*x(sub(l), sup(2))*x(sub(2), sup(4)) CyclelndexListtempListFive=

newCyclelndexListO;

CyclelndexObjtempObjFiveA=

newCycleIndexObj(2,l);

CyclelndexObjtempObjFiveB=

newCycleIndexObj(4,2);

tempListFive.addCI(tempObjFiveA);

tempListFive.addCI(tempObjFiveB);

tempListFive. setCoeff(5);

cycleIndexVector.add(tempListFive);

private voidelevenBeadO{

//createx(sub(l), sup(ll)) CyclelndexListtempListOne=

newCyclelndexListO;

CyclelndexObjtempObjOne=

newCycleIndexObj(l1,1);

tempListOne.addCI(tempObjOne);

tempListOne.setCoeff( 1);

(31)

//createIO*x(sub(lI), sup(l)) CyclelndexListtempListTwo=

newCyclelndexListO; CyclelndexObjtempObjTwo=

newCycleIndexObj(l,l1); tempListTwo.addCI(tempObjTwo);

tempListTwo.setCoefl(l0);

cycleIndexVector.add(tempListTwo);

//create ll*x(sub(l), sup(l))*x(sub(2), sup(5))

CyclelndexListtempListThree=

newCyclelndexListO; CyclelndexObjtempObjThreeA=

newCycleIndexObj(l,l);

CyclelndexObjtempObjThreeB=

newCycleIndexObj(5,2);

tempListThree.addCI(ternpObjThreeA);

tempListThree.addCI(tempObjThreeB); tempListThree.setCoeff(l1);

cyclelndexVector.add(tempListThree);

}

private voidtwelveBeadO{

//createx(sub(l), sup(12))

CyclelndexListtempListOne=

newCyclelndexListO; CyclelndexObjtempObjOne=

newCycleIndexObj(12,l);

tempListOne.addCI(tempObjOne);

tempListOne.setCoeff(1);

cyclelndexVector.add(tempListOne);

//create4*x(sub(12), sup(l))

CyclelndexListtempListTwo=

newCyclelndexListO;

CyclelndexObjtempObjTwo=

newCycleIndexObj(l,12);

tempListTwo.addCI(tempObjTwo);

tempLisfTwo.setCoeff(4);

cycleIndexVector.add(tempListTwo);

//create2*x(sub(6), sup(2)) CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObjtempObjThree=

newCycleIndexObj(2,6);

tempListThree.addCI(ternpObjThree); tempListThree.setCoeff(2);

cyclelndexVector.add(tempListThree);

//create2*x(sub(4), sup(3)) CyclelndexListtempListFour=

newCyclelndexListO;

CyclelndexObjtempObjFour=

newCycleIndexObj(3,4); tempListFour.addCI(tempObjFour);

tempListFour.setCoeff(2);

(32)

//create2*x(sub(3), sup(4))

CyclelndexListtempListFive=

newCyclelndexListO; CyclelndexObjtempObjFive=

newCycleIndexObj(4,3);

tempListFive.addCI(tempObjFive); tempListFive.setCoeff(2);

cycleIndexVector.add(tempListFive);

//create 7*x(sub(2), sup(6)) CyclelndexListtempListSix=

newCyclelndexListO;

CyclelndexObjtempObjSix=

newCycleIndexObj(6,2);

tempListSix.addCI(tempObjSix);

tempListSix.setCoeff(7);

cycleIndexVector.add(tempListSix);

//create 6*x(sub(l), sup(2))*x(sub(2), sup(5))

CyclelndexListtempListSeven=

newCyclelndexListO;

CyclelndexObjtempObjSevenA=

newCycleIndexObj(2,l);

CyclelndexObjtempObjSevenB=

newCycleIndexObj(5,2);

tempListSeven.addCI(tempObjSevenA);

tempListSeven.addCI(tempObjSevenB);

tempListSeven.setCoeff(6);

cycleIndexVector.add(tempListSeven);

}

private voidthirteenBeadO{ //createx(sub(l), sup(13))

CyclelndexListtempListOne=

newCyclelndexListO;

CyclelndexObj tempObjOne=

newCycleIndexObj(13,l);

tempListOne.addCI(tempObjOne);

tempListOne.setCoeff(1);

cyclelndexVector.add(tempListOne);

//create 12*x(sub(13), sup(l)) CyclelndexListtempListTwo=

newCyclelndexListO; CyclelndexObjtempObjTwo=

newCycleIndexObj(l,13);

tempListTwo.addCI(tempObjTwo);

tempListTwo.setCoeff(l2);

cycleIndexVector.add(tempListTwo);

//create 13*x(sub(l), sup(l))*x(sub(2), sup(6)) CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObj tempObjThreeA=

newCycleIndexObj(l,l);

CyclelndexObjtempObjThreeB=

newCycleIndexObj(6,2);

(33)

tempListThree.addCI(tempObjThreeB);

tempListThree.setCoeff(13);

cycleIndexVector.add(tempListThree); }

private voidfourteenBead(){ //createx(sub(l), sup(14))

CyclelndexListtempListOne=

newCyclelndexListO;

CyclelndexObjtempObjOne=

newCycleIndexObj(14,l);

tempListOne.addCI(tempObjOne);

tempListOne.setCoeff( 1);

cycleIndexVector.add(tempListOne);

//create 6*x(sub(14), sup(l))

CyclelndexListtempListTwo =

newCyclelndexListO;

CyclelndexObjtempObjTwo=

newCycleIndexObj(l,14);

tempListTwo.addCI(tempObjTwo);

tempListTwo.setCoeff(6);

cycleIndexVector.add(tempListTwo);

//create6*x(sub(7), sup(2))

CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObjtempObjThree=

newCycleIndexObj(2,7);

tempListThree.addCI(tempObjThree); tempListThree.setCoeff(6);

cycleIndexVector.add(tempListThree);

//create8*x(sub(2), sup(7))

CyclelndexListtempListFour=

newCyclelndexListO;

CyclelndexObjtempObjFour=

newCycleIndexObj(7,2);

ternpListFour.addCI(tempObjFour);

tempListFour.setCoeff(8);

cyclelndexVector.add(tempListFour);

//create 7*x(sub(l), sup(2))*x(sub(2),sup(6))

CyclelndexListtempListFive=

newCyclelndexListO;

CyclelndexObjtempObjFiveA=

newCycleIndexObj(2,l);

CyclelndexObjtempObjFiveB=

newCycleIndexObj(6,2);

tempListFive.addCI(tempObjFiveA);

tempListFive.addCI(tempObjFiveB);

tempListFive.setCoeff(7);

cycleIndexVector.add(tempListFive);

}

(34)

}

//createx(sub(l), sup(15))

CyclelndexListtempListOne=

newCyclelndexListO; CyclelndexObjtempObjOne=

newCycleIndexObj(15,l);

tempListOne.addCI(tempObjOne);

tempListOne.setCoefl(1);

cycleIndexVector.add(tempListOne);

//create8*x(sub(15), sup(l))

CyclelndexListtempListTwo=

newCyclelndexListO; CyclelndexObjtempObjTwo=

newCycleIndexObj(l,15); tempListTwo.addCI(tempObjTwo);

tempListTwo.setCoeff(8);

cycleIndexVector.add(tempListTwo);

//create4*x(sub(5), sup(3))

CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObjtempObjThree=

newCycleIndexObj(3,5); tempListThree.addCI(tempObjThree);

tempListThree.setCoeff(4);

cycleIndexVector.add(tempListThree);

//create2*x(sub(3), sup(5))

CyclelndexListtempLisfFour=

newCyclelndexListO;

CyclelndexObjtempObjFour=

newCycleIndexObj(5,3); tempListFour.addCI(tempObjFour);

tempListFour.setCoefi(2);

cycleIndexVector.add(tempListFour);

//create 15*x(sub(l), sup(l))*x(sub(2), sup(7)) CyclelndexListtempListFive=

newCyclelndexListO;

CyclelndexObjtempObjFiveA=

newCycleIndexObj(l,l);

CyclelndexObjtempObjFiveB=

newCycleIndexObj(7,2); tempListFive.addCI(tempObjFiveA);

tempListFive.addCI(tempObjFiveB);

tempListFive.setCoeff(15);

cycleIndexVector.add(tempListFive);

privatevoidsixteenBeadO{

//createx(sub(l), sup(16)) CyclelndexListtempListOne=

newCyclelndexListO;

CyclelndexObjtempObjOne=

newCycleIndexObj(16,l); tempListOne.addCI(tempObjOne);

tempListOne.setCoeff(l);

(35)

//create8*x(sub(16), sup(I))

CyclelndexListtempListTwo=

newCyclelndexListO;

CyclelndexObjtempObjTwo=

newCycleIndexObj(l,16); tempListTwo.addCI(tempObjTwo);

tempListTwo.setCoeff(8);

cycleIndexVector.add(tempListTwo);

//create4*x(sub(8), sup(2)) CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObjtempObjThree=

newCycleIndexObj(2,8);

tempListThree.addCI(tempObjThree); tempListThree.setCoeff(4);

cycleIndexVector.add(tempListThree);

//create2*x(sub(4), sup(4))

CyclelndexListtempListFour=

newCyclelndexListO;

CyclelndexObjtempObjFour=

newCycleIndexObj(4,4); tempListFour.addCI(tempObjFour);

tempListFour.setCoeff(2);

cycleIndexVector.add(tempListFour);

//create9*x(sub(2), sup(8))

CyclelndexListtempListFive=

newCyclelndexListO;

CyclelndexObjtempObjFive=

newCycleIndexObj(8,2);

tempListFive.addCI(tempObjFive); tempListFive.setCoeff(9);

cycleIndexVector.add(tempListFive);

//create8*x(sub(l), sup(2))*x(sub(2), sup(7)) CyclelndexListtempListSix=

newCyclelndexListO;

CyclelndexObjtempObjSixA=

newCycleIndexObj(2,l);

CyclelndexObjtempObjSixB=

newCycleIndexObj(7,2);

tempListSix.addCI(tempObjSixA);

tempListSix.addCI(tempObjSixB);

tempListSix.setCoeff(8);

cycleIndexVector.add(tempListSix); }

private voidseventeenBeadO{

//createx(sub(l), sup(l7))

CyclelndexListtempListOne=

newCyclelndexListO;

CyclelndexObj tempObjOne=

newCycleIndexObj(17,l);

tempListOne.addCI(tempObjOne);

(36)

cyclelndexVector.add(tempListOne);

//create I6*x(sub(I7), sup(l)) CyclelndexListtempListTwo=

newCyclelndexListO;

CyclelndexObjtempObjTwo =

newCycleIndexObj(l,17);

tempListTwo.addCI(tempObjTwo); tempListTwo.setCoeff(16);

cycleIndexVector.add(tempListTwo);

//create 17*x(sub(l), sup(l))*x(sub(2), sup(8))

CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObj tempObjThreeA=

newCycleIndexObj(l,l);

CyclelndexObj tempObjThreeB=

newCycleIndexObj(8,2);

tempListThree.addCI(ternpObjThreeA); tempListThree.addCI(tempObjThreeB); tempListThree.setCoeff(17);

cycleIndexVector.add(tempListThree);

}

privatevoideighteenBeadO{

//createx(sub(l), sup(18)) CyclelndexListtempListOne=

newCyclelndexListO;

CyclelndexObjtempObjOne=

newCycleIndexObj(18,l);

tempListOne.addCI(tempObjOne); tempListOne.setCoeff(l);

cycleIndexVector.add(tempListOne);

//create6*x(sub(18), sup(l)) CyclelndexListtempListTwo=

newCyclelndexListO;

CyclelndexObjtempObjTwo=

newCycleIndexObj(l,18);

tempListTwo.addCI(tempObjTwo); tempListTwo.setCoeff(6);

cycleIndexVector.add(tempListTwo);

//create 6*x(sub(9), sup(2))

CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObjtempObjThree=

newCycleIndexObj(2,9);

tempListThree.addCI(tempObjThree); tempListThree.setCoeff(6);

cyclelndexVector.add(tempListThree);

//create2*x(sub(6), sup(3))

CyclelndexListtempLisfFour=

newCyclelndexListO;

CyclelndexObjtempObjFour=

newCycleIndexObj(3,6);

(37)

tempListFour.setCoeff(2);

cyclelndexVector.add(tempListFour);

//create2*x(sub(3), sup(6)) CyclelndexListtempListFive=

newCyclelndexListO;

CyclelndexObjtempObjFive=

newCycleIndexObj(6,3); tempListFive.addCI(tempObjFive);

tempListFive.setCoeff(2);

cyclelndexVector.add(tempListFive);

//create10*x(sub(2), sup(9)) CyclelndexListtempListSix=

newCyclelndexListO;

CyclelndexObjtempObjSix=

newCycleIndexObj(9,2);

tempListSix.addCI(tempObjSix); tempListSix.setCoeff(10);

cyclelndexVector.add(tempListSix);

//create9*x(sub(l), sup(2))*x(sub(2), sup(8))

CyclelndexListtempListSeven=

newCyclelndexListO;

CyclelndexObjtempObjSevenA=

newCycleIndexObj(2,l);

CyclelndexObjtempObjSevenB=

newCycleIndexObj(8,2);

tempListSeven.addCI(tempObjSevenA); tempListSeven. addCI(tempObjSevenB); tempListSeven.setCoeff(9);

cyclelndexVector.add(tempListSeven);

}

privatevoidnineteenBeadO{

//createx(sub(l), sup(19)) CyclelndexListtempListOne=

newCyclelndexListO;

CyclelndexObjtempObjOne=

newCycleIndexObj(19,l);

tempListOne.addCI(tempObjOne);

tempListOne.setCoeff(1);

cycleIndexVector.add(tempListOne);

//create18*x(sub(19), sup(l)) CyclelndexListtempListTwo=

newCyclelndexListO;

CyclelndexObjtempObjTwo =

newCycleIndexObj(l,19);

tempListTwo.addCI(tempObjTwo);

tempListTwo.setCoeff(18);

cycleIndexVector.add(tempListTwo);

//create19*x(sub(l), sup(l))*x(sub(2), sup(9))

CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObjtempObjThreeA=

(38)

}

CyclelndexObjtempObjThreeB=

newCycleIndexObj(9,2);

tempListThree.addCI(tempObjThreeA); ternpListThree.addCI(tempObjThreeB);

tempListThree.setCoeff(19);

cyclelndexVector.add(tempListThree);

private voidtwentyBeadO{

//createx(sub(I),sup(20))

CyclelndexListtempListOne=

newCyclelndexListO;

CyclelndexObjtempObjOne=

newCycleIndexObj(20,l);

tempListOne.addCI(tempObjOne);

tempListOne.setCoeff( 1);

cyclelndexVector.add(tempListOne);

//create8*x(sub(20), sup(l)) CyclelndexListtempListTwo=

newCyclelndexListO;

CyclelndexObjtempObjTwo=

newCycleIndexObj(l,20);

tempListTwo.addCI(tempObjTwo); tempListTwo.setCoeff(8);

cycleIndexVector.add(tempListTwo);

//create 4*x(sub(10), sup(2))

CyclelndexListtempListThree=

newCyclelndexListO;

CyclelndexObjtempObjThree=

newCycleIndexObj(2,10);

tempListTnree.addCI(tempObjThree);

tempListThree.setCoeff(4);

cyclelndexVector.add(tempListThree);

//create4*x(sub(5), sup(4)) CyclelndexListtempListFour=

newCyclelndexListO;

CyclelndexObjtempObjFour=

newCycleIndexObj(4,5);

tempListFour.addCI(tempObjFour);

tempListFour.setCoeff(4);

cycleIndexVector.add(tempListFour);

//create2*x(sub(4), sup(5)) CyclelndexListtempListFive=

newCyclelndexListO;

CyclelndexObjtempObjFive=

newCycleIndexObj(5,4);

tempListFive.addCI(tempObjFive);

tempListFive.setCoeff(2);

cycleIndexVector.add(tempListFive);

//createll*x(sub(2), sup(10)) CyclelndexListtempListSix=

(39)

CyclelndexObj tempObjSix=

newCycleIndexObj(10,2);

tempListSix.addCI(tempObjSix);

tempListSbc.setCoeff(l1);

cycleIndexVector.add(tempListSix);

//create 10*x(sub(l), sup(2))*x(sub(2), sup(9)) CyclelndexListtempListSeven=

newCyclelndexListO;

CyclelndexObjtempObjSevenA=

newCycleIndexObj(2,l);

CyclelndexObjtempObjSevenB=

newCycleIndexObj(9,2);

tempListSeveiLaddCI(tempObjSevenA);

tempListSeven.addCI(tempObjSevenB);

tempListSeven.setCoeff( 10);

cycleIndexVector.add(tempListSeven);

}

publicVector getCIVectorO{

//returntheCycleIndex Vector

(40)

/*

*

CyclelndexList.java *

ForusewiththeNecklaceIllustrator Applet *

byDavid Fraser *Rochester

InstituteofTechnology *

May2005 *

*/

packageNecklace;

import java.util.Vector;

public classCyclelndexList {

privateVector cyclelndexEntry;

privateintcoeff;

//createa newCyclelndexList

publicCyclelndexListO {

//createa new VectortostoreCycle Index "x"terms

cyclelndexEntry=

newVectorO;

}

<

References

Related documents

Computer simulations: Red = individuals preferring behavior 1 Yellow = individuals adjusting to behavior 1 Blue = individuals preferring behavior 2 Green = individuals

any color.. 1) Primary Colors of Light – BLUE , RED, GREEN – The three colors of light that when combined can make any color.. RED GREEN BLUE YELLOW YELLOW MAGENTA CYAN

Colors : Aqua Blue, Black, Brownish Yellow, Burgundy, Brickish Red, Dark Blue, Darker Green, Light Blue, Lighter Green, Orange, Purple, Purply Red, Yep Red. ITEM

This is called the ‘Additive color system’ Its primary colors are Red, Green and Blue No colors added together is black.. Red + Green = Yellow Green + Blue = Cyan Blue + Red

Normal view: blue-green and yellow-green line Red-green deficiency: only red-green and violet line.

Black Black Green Green Yellow Yellow Red Red White/Orange White/Blue Orange Blue White/Brown Brown White/Green Green Pairs 1 &amp; 2 Pairs 3 &amp; 4 Dual Jack Telephone Wallplate

Available in Black, Navy, Royal Blue, Dark Green, Tan, Red, and White (lid colors: Black, White, Green, Red, Orange, Teal, Yellow, Violet, and Royal Blue).. Available in

black white green yellow light blue