Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication1;
- import java.util.Scanner;
- public class JavaApplication1 {
- static void printFuzzySet(double d[]) {
- for (int i = 0; i < d.length; i++) {
- double newKB = Math.round(d[i] * 100.0) / 100.0;
- System.out.print(newKB + "/" + (i + 1));
- if(i != d.length-1)
- System.out.print("+");
- }
- System.out.println("\n");
- }
- static double[] complement(double[] d) {
- for (int i = 0; i < d.length; i++) {
- d[i] = 1 - d[i];
- }
- return d;
- }
- static double[] union(double a[], double[] b) {
- double[] union = new double[a.length];
- for (int i = 0; i < union.length; i++) {
- if (a[i] < b[i]) {
- union[i] = b[i];
- } else {
- union[i] = a[i];
- }
- }
- return union;
- }
- static double[] inter(double a[], double[] b) {
- double[] inter = new double[a.length];
- for (int i = 0; i < inter.length; i++) {
- if (a[i] > b[i]) {
- inter[i] = b[i];
- } else {
- inter[i] = a[i];
- }
- }
- return inter;
- }
- static void difference(double[] a, double[] b) {
- double[] diff = new double[a.length];
- b = complement(b);
- diff = union(a, b);
- printFuzzySet(diff);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter the universal set limit: ");
- int limit = sc.nextInt();
- double arr1[] = new double[limit];
- double arr2[] = new double[limit];
- System.out.println("Enter the membership for each element in fuzzy set A");
- for (int i = 0; i < limit; i++) {
- System.out.println("For element " + (i + 1) + ":");
- arr1[i] = sc.nextDouble();
- }
- System.out.println("Enter the membership for each element in fuzzy set B");
- for (int i = 0; i < limit; i++) {
- System.out.println("For element " + (i + 1) + ":");
- arr2[i] = sc.nextDouble();
- }
- double union[] = union(arr1, arr2);
- System.out.println("A \u222A B : ");
- printFuzzySet(union);
- double inter[] = inter(arr1, arr2);
- System.out.println("A \u2229 B : ");
- printFuzzySet(inter);
- double[] arr1Comp = complement(arr1);
- System.out.println("Complement of A is: ");
- printFuzzySet(arr1Comp);
- System.out.println("Complement of B is: ");
- double[] arr2Comp = complement(arr2);
- printFuzzySet(arr2Comp);
- System.out.println("A - B: ");
- difference(arr1, arr2);
- System.out.println("B - A: ");
- difference(arr2, arr1);
- System.out.println("De Morgan's theorem: ");
- System.out.println(" Complement of A \u222A B is: ");
- double aub[] = complement(union(arr1,arr2));
- printFuzzySet(aub);
- System.out.println(" ~A \u2229 ~B is: ");
- aub = inter(complement(arr1),complement(arr2));
- printFuzzySet(aub);
- }
- }
- /*
- run:
- Enter the universal set limit:
- 3
- Enter the membership for each element in fuzzy set A
- For element 1:
- 0.5
- For element 2:
- 0.6
- For element 3:
- 0.7
- Enter the membership for each element in fuzzy set B
- For element 1:
- 0.9
- For element 2:
- 0.8
- For element 3:
- 0.3
- A ∪ B :
- 0.9/1+0.8/2+0.7/3
- A ∩ B :
- 0.5/1+0.6/2+0.3/3
- Complement of A is:
- 0.5/1+0.4/2+0.3/3
- Complement of B is:
- 0.1/1+0.2/2+0.7/3
- A - B:
- 0.9/1+0.8/2+0.3/3
- B - A:
- 0.9/1+0.8/2+0.7/3
- De Morgan's theorem:
- Complement of A ∪ B is:
- 0.1/1+0.2/2+0.3/3
- ~A ∩ ~B is:
- 0.1/1+0.2/2+0.3/3
- */
Add Comment
Please, Sign In to add comment