Hello,
I am making a code in R to calculate the various values of a Fuzzy code (using the "Sets" package).
I made the logic for it to calculate three Fuzzy variables from smallest to largest, but when I use logic to save these values, it just saves the last values.
I wanted to create a logic to save all possible values.
Follow the code below:
library(sets)
package:datasets
## set universe
sets_options("universe", seq(from = 0, to = 100, by = 0.1))
## set up fuzzy var
iables
variables <-
set( Ratio =
fuzzy_variable(low =
fuzzy_trapezoid(corners = c(0, 40, 50, 60)),
medium =
fuzzy_trapezoid(corners = c(40, 50, 80, 90)),
ok =
fuzzy_trapezoid(corners = c(80, 90, 95, 100))),
TamanhoFila =
fuzzy_variable(ok =
fuzzy_trapezoid(corners = c(0,10, 20, 30)),
alerta=
fuzzy_trapezoid(corners = c(20, 40, 70 , 80)),
ng =
fuzzy_trapezoid(corners = c(70, 80, 95, 100))),
TempoFila =
fuzzy_variable(ok =
fuzzy_trapezoid(corners = c(0, 10, 20, 30)),
alerta=
fuzzy_trapezoid(corners = c(20, 30, 60 , 70)),
ng =
fuzzy_trapezoid(corners = c(70, 80, 95, 110))),
recursos =
fuzzy_partition(varnames =
c(ok = 25, alerta = 50, metade = 75, total = 100),
FUN = fuzzy_cone, radius = 25)
)
## set up rules
rules <-
set(
fuzzy_rule(Ratio %is% low || TamanhoFila %is% NG || TempoFila %is% NG,
recursos %is% total),
fuzzy_rule(Ratio %is% low || TamanhoFila %is% alerta || TempoFila %is% alerta,
recursos %is% metade),
fuzzy_rule(Ratio %is% medium || TamanhoFila %is% alerta || TempoFila %is% alerta,
recursos %is% alerta),
fuzzy_rule(Ratio %is% medium || TamanhoFila %is% OK || TempoFila %is% OK,
recursos %is% ok),
fuzzy_rule(Ratio %is% ok ,
recursos %is% ok)
)
## combine to a system
system <- fuzzy_system(variables, rules)
print(system)
plot(system) ## plots variables
## do inference
for(x in 1:2){
for (y in 1:2){
for (z in 1:2){
print(x)
print(y)
print(z)
x1<- c(x*10)
x2<- c(y*10)
x3<- c(z*10)
fi <- (fuzzy_inference(system, list(Ratio = x*10, TempoFila = y*10, TamanhoFila = z*10)))
## plot resulting fuzzy set
#plot(fi)
## defuzzify
fuzzy <- ( gset_defuzzify(fi, "centroid"))
FuzzyT<- data.frame(fuzzy)
#print(x)
print(fuzzy)
Fuzzy_T <- c(x1, x2, x3, FuzzyT)
Fuzzy_T2 <- write.csv(Fuzzy_T, file="fuzzy.csv")
}
}
}
## reset universe
sets_options("universe", NULL)
Thank you very much