######################### EXAMPLE #1 ###############################
# create a truth table with 4 inputs A, B, C, D and 2 outputs X and Y
e.ex1 <- data.frame(
A = c(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1),
B = c(0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0),
C = c(0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1),
D = c(0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0),
X = c(1,1,1,1,0,1,1,1,"-",1,1,0,1,1,0,0),
Y = c("-",1,1,1,1,1,1,1,1,1,1,0,0,0,0,"-"))
# show the unoptimized equations
tt2eqn(e.ex1,4,2)
# optimize the truth table
tte <- logicopt(e.ex1,4,2)
# show the optimized equations
tt2eqn(tte[[1]],4,2)
# generate and print the prime implicants from optimized tte
ttp <- logicopt(tte[[1]],4,2,mode="primes")
print_primes_tt(ttp,TRUE,4,2)
######################### EXAMPLE #2 ###############################
# get path to an espresso format file
file <- system.file("extdata/espresso/small2.esp", package="LogicOpt")
# get the espresso truth table without optimization
small2 <- logicopt(esp_file=file,mode="echo")
# print the unoptimized equations
print_multi_tt(small2,TRUE,4,3)
# optimize with espresso algorithm
small2_opt <- logicopt(small2[[1]],4,3,mode="espresso")
# print the optimized equations
print_multi_tt(small2_opt,TRUE,4,3)
######################### EXAMPLE #3 ###############################
# load up truth table created from a QCA dataset
data(l.represent.1)
# read documentation on how truth table was created
?l.represent.1
# find the set of minimum solutions that cover QCA dataset (mode="multi-min")
# treat unspecified input conditions as don't cares (find_dc=TRUE)
# find a exact covering (exact_cover=TRUE)
lomm <- logicopt(l.represent.1,n_in=5,n_out=1,find_dc=TRUE,
exact_cover=1,mode="multi-min")
# print the solutions in equation format
print_multi_tt(lomm,TRUE,5,1,QCA=TRUE)
######################### EXAMPLE #4 ###############################
# optimize a truth table from Genetic Programming
inpath <- system.file("extdata/espresso/robot1_in.esp", package="LogicOpt")
robot1 <- logicopt(esp_file=inpath,mode="echo")
# unoptimized truth table has 273 rows (256 in ON set and 18 in OFF set)
robot1[2]
# optimize l.robot1
robot1_opt <- logicopt(robot1[[1]],8,3)
# optimized results have 13 rows that cover outputs zero, one, and minus
robot1_opt[2]
# print optimized equations (where each output is 1)
print_multi_tt(robot1_opt,TRUE,8,3)
######################### EXAMPLE #5 ###############################
# show how to use input_sizes
# get vector of number of unique values for each input
data(l.partybans.1)
pb_in_vals <- num_input_values(l.partybans.1,5)
pb_in_vals
# optimize with mode=espresso
epb <- logicopt(l.partybans.1,5,1,find_dc=TRUE,mode="espresso")
epb
pb_in_opt_vals <- num_input_values(epb[[1]],5)
# note how some input values have been optimized away and are no longer used!
pb_in_opt_vals
# we need original input sizes to process the optimized truth table
qmpb <- logicopt(epb[[1]],5,1,find_dc=FALSE, input_sizes=pb_in_vals,mode="qm")
print_multi_tt(epb,TRUE,5,1)
print_multi_tt(qmpb,TRUE,5,1)
Run the code above in your browser using DataLab