-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.R
97 lines (96 loc) · 2.96 KB
/
ui.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
library(shiny)
library(shinydashboard)
library(shinyjs)
# Shiny dashboard UI
dashboardPage(
# Application title
dashboardHeader(title = "Genetic Algorithm Example"),
# Sidebar options
dashboardSidebar(
sliderInput(
"pop_size",
label = "Population Size",
min = 2,
max = 200,
value = 50
),
sliderInput(
"mutation_prob",
label = "Mutation Probability",
min = 0,
max = 1,
value = 0.1
),
sliderInput(
"crossover_prob",
label = "Crossover Probability",
min = 0,
max = 1,
value = 0.8
),
sliderInput(
"elitism",
label = "Elitism",
min = 0,
max = 1,
value = 0.05
),
numericInput("iter_num",
"Iterations",
value = 100),
actionButton("run_opt",
"Run")
),
# Outputs
dashboardBody(
useShinyjs(),
fluidRow(
infoBox(
title = "Iteration",
value = uiOutput("iteration_count"),
icon = icon("redo"),
width = 3
),
infoBox(
title = "Best Fitness",
value = uiOutput("best_fitness"),
icon = icon("thumbs-up"),
width = 3
),
infoBox(
title = "Best X1",
value = uiOutput("best_x1"),
icon = icon("thumbs-up"),
width = 3
),
infoBox(
title = "Best X2",
value = uiOutput("best_x2"),
icon = icon("thumbs-up"),
width = 3
)
),
fluidRow(
box(title = "All Solutions in Population", plotOutput("population_plot")),
box(title = "Fitness", plotOutput("fitness_plot"))
),
fluidRow(
box(title = "What is this?",
"This is an interactive example of using a genetic algorithm to solve a simple problem.
Here we're attempting to find the optimum values for X1 and X2 to minimise the objective
function. We're using a Rastrigin function as the objective. You can see this plotted in
the population plot above. Note that there are many local minima (darker colors are lower).
The optimum value for both X1 and X2 is zero which also return zero from the objective function.",
br(), br(),
"Each red dot in the plot on the left represents an individual in the population. The plot on the
right shows the best, mean, and median fitness over all iterations of the algorithm.",
br(), br(),
"You can try different parameters for the genetic algorithm to explore how these affect the outcome."),
box(title = "More information",
"1. More about the ", tags$a(href="https://en.wikipedia.org/wiki/Rastrigin_function", "Rastrigin function"), ".", br(),
"2. Luca Scrucca's ", tags$a(href="https://luca-scr.github.io/GA/", "GA R Package"), ".", br(),
"3. This application's source code on ", tags$a(href="https://github.com/DavidASmith/shiny-ga-demo", "Github"), ".", br()
)
)
)
)