Skip to content
Daniel Cheng edited this page Mar 22, 2018 · 1 revision

GENERATOR.SERVICE

Description The generatePermutationsByRandom method is one of the two main paths of the program, chosen from the collision risk likelihood in solverDecisionTree. This path generates a list of randomly generated permutations possible solution sets the given equation.

Syntax

Parameters variables: Variable[] Array of Variable Objects entered by the user.

numberOfProblems: number Parameter set by user

equation: string String of the equation set by user. Returns [ ] An array of possible solution sets.

Parameters variables: Variable[ ] Array of Variable Objects entered by the user.
numberOfProblems: number Parameter set by user
equation: string String of the equation set by user.
Returns [ ] An array of possible solution sets.

See Also:

  • simplifyEquation
  • genRandomPermutation
  • solveForUnknownVariable
  • meetsUnknownVariableSpecification
  • isVariableInArray

Description The generatePermutationsFromList method is one of the two main paths of the program, chosen from the collision risk likelihood in solverDecisionTree. This path makes a list of all possible permutations for the given equation. Returns a valid solution set for the given equation.

Syntax

Parameters

  • Variables: Variable[ ]
  • Array of given variables (objects)

numberOfProblems: number Number of problems entered by user

Equation: string Equation entered by user Returns Result[ [] ] Valid solution set for given equation

Parameters variables: Variable [ ] Array of given variables (objects)
numberOfProblems: number Number of problems entered by user
equation: string Equation entered by user
Returns Result[ [ ] ] Valid solution set for given equation

See Also:

  • Generate permutations
  • Lodash _.last
  • simplifyEquation
  • pullRandomValue
  • solveForUnknownVariable
  • meetsUnknownVariableSpecification

Description The solverDecisionTree is the main method that returns results for the user. Using collision risk, it chooses from one of two paths: generatePermutationsFromList or generatePermutationsByRandom. Returns valid solution set for the given problem.

Syntax

Parameters Variables: Variable[ ] Array of given variables (objects)

numberOfProblems: number Number of problems entered by user

Equation: string Equation entered by user Returns Result Valid solution set for given equation

Parameters variables: Variable [ ] Array of given variables (objects)
numberOfProblems: number Number of problems entered by user
equation: string Equation entered by user
Returns Result[ [ ] ] Valid solution set for given equation

See Also:

  • generatePermutationsFromList
  • generatePermutationsByRandom

EQUATION COMPONENT

Description The onSubmit method is what is executed after the user submits the variables form. The method first updates the variables array with the data that was obtained from the form. Then it called the switchParameterToSolve method to move the variable that the user wants to solve for to the end of the variables array. Finally the solverDecisionTree method and assigned to the result constant. Result is the valid solution set for the given equation.

See Also:

Description The switchParameterToSolve method takes the variables array and moves the variable to solve for to the end of the array.

Syntax

Parameters Variables: Variable[ ] Array of given variables (objects)

GUPPY-INPUT COMPONENT

Description The output method retrieves the contents of the guppy box after the proceed button is clicked. It creates an instance of a variable object for each variable input and then pushes it into the guppyVariables array.

UTILITIES

Description The createKnownValuesObject method takes an array of numbers and Variable array and converts to a variable object.

Syntax

Parameters randomSet: number[ ] A random set from pullRandomValue

variables: Variable[ ]

Returns object An object of known variables

Description
Parameters randomSet: number[ ] A random set from pullRandomValue
variables: Variable[ ]
Returns object An object of known variables

Description The solveForVariable method solves the equation/expression using the nerdamer math library by taking array of numbers, the simplified algebric equation and the variable array. KnownVariables are plugged into the equation/expression

Syntax

Parameters randomSet: number[ ] A random set Generated by the splicePermutationSetRandomly method

simplifiedEquation: string The simplified equation returned by the simplifiedEquation method

variables: Variable[ ] The Array of all Variable objects Returns String [ ] An array with one element - the unknown variable as a string

Parameters randomSet: number[ ] A random set Generated by the splicePermutationSetRandomly method
simplifiedEquation: string The simplified equation returned by the simplifiedEquation method
variables: Variable[ ] The Array of all Variable objects
Returns String [ ] An array with one element - the unknown variable as a string

See Also:

  • createKnownValuesObject

Description The simplifyEquation method solves the equation entered by the user for the unknownVariable in terms of the knownVariables.

Syntax

DataType Description Parameters equation: string The equation entered by the user.

variableToSolve: string The variable to solve for( the unknownVariable ). Returns simplifiedEquation: string The equation represented as the unknownVariable in terms of the knownVariables.

DataType Description
Parameters equation: string The equation entered by the user.
variableToSolve: string The variable to solve for( the unknownVariable ).
Returns simplifiedEquation: string The equation represented as the unknownVariable in terms of the knownVariables.

Description The calculateDecimalPlaces method takes a number( or a string of a number) and returns the number of decimal places the input number contains. If the input number was an integer like 10, the method would return 0. If the input was a decimal string like “4.09087”, the returned value should be 5.

Role: helper method Syntax

Parameters Number or String ex. 4.9 or “4.9” A number or a string of a number
Returns number An integer representing the number of decimal places the input contains.

See Also:

  • meetsUnknownVariableSpecification - utilities.ts

Description The method getRangeValues is a helper method used by the generatePermutations that aids in the generation of the permutations table. The generatePermutations method relies upon getRangeValues to create an array of integer values that are between the min and max for the first knownVariable.

Syntax

Designation
Number Of Problems: 2 x 0 2 4 known
Solve for: y y 0 3 6 unknown
z 0 4 8 known

The array returned by the following parameters is: [ 2, 3, 4 ]

See Also:

Description The generatePermutations method takes the given parameters entered by the user and generates all the permutations of possible solution sets that are within the specified min and max for each variable.

The permutations that this method generates will be validated as actual solutions later later on against the equation. If this doesn’t make sense right now, thats ok. Look below for a grounded, concrete example. You can think of this method as returning a table of all combinations of integers you could possibly create with the parameters entered by the user.

Syntax

Parameters variables: Variable[ ] An Array of Variables objects Returns Array [ [ ] ] An Array arrays of known variables

Parameters variables: Variable[ ] An Array of Variables objects
Returns Array [ [ ] ] An Array arrays of known variables

Example

Equation: x + y = z

Designation
Number Of Problems: 2 x 0 2 4 known
Solve for: y y 0 3 6 unknown
z 0 4 8 known

Returns: [ [ 2, 4 ], [ 2, 5 ], [ 2, 6 ], [ 2, 7 ], [ 2, 8 ], [ 3, 4 ], [ 2, 5 ], [ 2, 6 ], [ 2, 7 ], [ 3, 8 ], [ 4, 4 ], [ 4, 5 ], [ 4, 6 ], [ 4, 7 ], [ 4, 8 ] ]

See Also:

  • getRangeValues

Description This function takes as argument the permutation array and the known variables. The logic tests if there is any Zero present in the answer array or not for the known variables. If the AllowZero box is unchecked for any of the known variables, then we reject the Zero for that particular variable in the permutation array. Thus the solution is without Zero.

Syntax Parameters permutation: number[] The current permutation values of the equation excluding the variable to solve for.

variables: Variable[] Use Input Variables with user requirements including allowZero Function

Returns True: if value meets unknown variable parameters of zero requirements False: if value does not meet unknown variable parameters of zero requirements

Parameters currentValue: number Current possible value for unknown variable
knownVariable: Variable Known variable object
Returns True: if value meets known variable zero conditions False: if value does not meet known variable zero conditions

See Also:

  • allowZero

Description This function takes as argument the answer array and the unknown variable. The logic tests if there is any Zero present in the answer array or not for the unknown variable. If the AllowZero box is un checked then we reject the Zero in the answer array. Thus the solution is without Zero.

Syntax Parameters permutation: number[] The current permutation values of the equation excluding variables: Variable[]

Returns True: if value meets unknown variable parameters of zero requirements False: if value does not meet unknown variable parameters of zero requirements

Parameters currentValue: number Current possible value for unknown variable
unknownVariable: Variable Unknown variable object
Returns True: if value meets unknown variable zero conditions False: if value does not meet unknown variable zero conditions

See Also:

  • allowZero

Description Takes a possible value for the unknown variable(variable to solve for) and returns a boolean if the value meet the parameters on the unknown variable.

Syntax

Parameters currentValue: number Current possible value for unknown variable

unknownVariable: Variable Unknown variable object

Returns True: if value meets unknown variable parameters False: if value does not meet unknown variable parameters

Parameters currentValue: number Current possible value for unknown variable
unknownVariable: Variable Unknown variable object
Returns True: if value meets unknown variable parameters False: if value does not meet unknown variable parameters

See Also:

Description Grabs a random value set from an array of value sets, removing it from the array

Syntax

Parameters Array: any[] A nested array of arrays of known variable value sets Returns Array: number [] Pulled known variable value set

Parameters Array: any[] A nested array of arrays of known variable value sets
Returns Array: number [ ] Pulled known variable value set
Example
Input : [ [1,2], [5,7], [8,2], [3,9] ]
Output: [5,7]
Array input: [ [1,2], [8,2], [3,9] ]

Description Takes the min, max, and decPoint of a variable object and returns the total number of values within min and max range includes decimal points

Syntax

Parameters Variable: variable object The min, max, and decPoint for variable object Returns number Total number of values within object’s range

Parameters Variable: variable object The min, max, and decPoint for variable object
Returns number Total number of values within object’s range

Description Takes the min, max, and decPoint of all variable objects and returns the total number of values within min and max range includes decimal points

Syntax

Parameters Variable: Variable[ ] Array of variable objects Returns number Total number of values within object’s range

Parameters Variable: Variable[ ] Array of variable objects
Returns number Total number of values within object’s range

See Also:

  • getValueTotal

getCollisionRisk

Description Returns a decimal value between 0 and 1 that represents the likelihood of repeating a solution set.

Syntax

Parameters Variable[ variable objects ], number of problems

Returns number Decimal value between 0 and 1

Parameters Variable[ variable objects ] number of problems
Returns number Decimal value between 0 and 1

Description The helper method genRandomPermutation generates a random possible solution set that is within the bounds of the parameters for each Variable.

Syntax

Parameters Variable: variable object
Returns number [ ] possible solution set ex. [ 2, 4, 5 ]

Description The getRandomValue method takes a variable object and returns number between the min and max value for that variable. This method is used to generate a valid random for each variable. These values are used to generate a possible permutation that will later be validated against the equation entered by the user.

Syntax

Parameters variable: Variable An object with many properties including: min, max, name and decPoint Returns number A number within the range variable.min to variable.max

Parameters variable: Variable An object with many properties including: min, max, name and decPoint
Returns number A number within the range variable.min to variable.max

See Also:

Description The isVariableInArray method is a helper method used in the generatePermutationsByRandom method( generator.service ) to checks if a permutation has already been generated. Imagine that the provided parameters and equation only have three perumutations,, but the user ask for 20 problems. Instead of returning duplicates, the three permutations are generated, that’s it.

Syntax

Parameters Number[ ]

A randomly generated permutation.

existingValues: any[ ] An array of previously generated permutations Returns boolean False indicates a novel permutation, True indicates permutation has been generated before

Parameters Number[ ] A randomly generated permutation.
existingValues: any[ ] An array of previously generated permutations
Returns boolean False indicates a novel permutation, True indicates permutation has been generated before

See Also:

  • generatePermutationsByRandom - generator.service