Main classes of FLMICMAC API and Java code example

INumericElement is a generic interface defining basic arithmetic operations required during MICMAC processing (or any variant of it). Any new datatype (such as integer or real values, TFNs, linguistic labels without a TFN, etcetera) that is to be used for representing the mutual relations of the MDI should implement all the operations of this interface.

TriangularFuzzyElement contains the representation of a triangular fuzzy number that has a linguistic label associated to it. This class implements the INumericElement interface. This means there are methods for fuzzy arithmetic (including distance and defuzzification) but also more specific methods for getting and setting the values defining the TFN and its label. The class itself also stores the set of input and output reference TFNs and their labels, which are to be taken as reference.

RealElement is our own implementation of the usual Double class. It implements the INumericElement interface and provides roughly the same arithmetical operations of TriangularFuzzyElement, except defuzzification and label-related methods.

MicmacVariable contains all the results (direct/indirect influence and dependence, and direct/indirect ranks of the variable) uncovered at the end of the processing about a specific variable of the problem. The datatype of such information depends on the variant of MICMAC that is being used, since a MicmacVariable object stores generic INumericElement references. If CrispMICMAC has been executed, the references will point to RealElement objects. If FLMICMAC has been run, they will point to TriangularFuzzyElement objects. This is an important point because, in case further operations are going to be done with the results, the user should cast the INumericElement objects returned by the getters of MicmacVariable to one of those specific classes according to the former criterion.

FLMICMAC is the most important class where the FLMICMAC algorithm is implemented. It has separate methods to run the algorithm, generate the Excel output file, and write heat-maps and influence/dependence plots to image files. Typically, the user will create a single object of this class with a parameter-free constructor, call a method to read the input parameters such as number of values, input and output labels to be used (sorted from smallest to greatest) and location of the Excel input file, and then run the processing with the data. After this, the methods for generating the plots can be invoked if necessary. If the results will be used for further processing in a larger program, all the output information of each variable can be retrieved with the getVariables() method, which returns an array of VariableMicmac objects (one per variable). Each of them contains the direct and indirect influence and dependence of that variable, stored as TriangularFuzzyElement objects.

CrispMICMAC implements the classic MICMAC method and provides roughly the same methods to generate the Excel output file and plot image files. Output influence and dependence computed by the algorithm are real numbers that are stored as RealElement objects inside the VariableMicmac object corresponding to each variable.

Java code example

The Excel file used as input can be downloaded here

public static void main(String[] args){ FLMICMAC mic = new FLMICMAC(); // Input labels present in the input file. // The No-influence label must be at index 0 // and the rest sorted from smallest to greatest String[] inputLabels = {"None","Weak","Moderate","Strong"}; // Output labels we want to use, sorted from smallest // to greatest String[] outputLabels = {"Very_weak","Weak","Moderate","Strong","Very_strong"}; String excelInputFilePath = "C:/Users/olbapjo/50variablesInputFile.xls"; String excelOutputFilePath = "C:/Users/olbapjo/FLMICMAC_outputFile.xls"; // Note no .GIF ending is given (the program will // create two GIF files by appending _direct.gif and // _indirect.gif to this path) String gifFilesPathRoot = "C:/Users/olbapjo/FLMICMAC_heatmap"; // Note no .PNG ending is given (the program will // create two PNG files appending _direct.png and // _indirect.png to this path) String chartsPath = "C:/Users/olbapjo/FLMICMAC_chart"; // A directory with write permission String temporaryDirectory = "C:/Users/olbapjo"; // The next two paths are used in the generation of // the bidimensional influence/dependence planes // Path to the Rscript program to run R scripts String RscriptExecutablePath = "C:/Program Files/R/R-2.15.1/bin/x64/Rscript.exe"; // Path to the R source file that we distribute // together with our API // Use myPlotGenerator.R for FLMICMAC and // myCrispPlotGenerator.R for CrispMICMAC String RsourceFile ="C:/Users/olbapjo/myPlotGenerator.R"; try{ // customized Triangular Fuzzy Numbers to represent // the input labels. // Weak=[1,1,3], Moderate=[1,3,5], Strong=[3,5,5] TriangularFuzzyElement[] TFNs = new TriangularFuzzyElement[3]; TFNs[0] = new TriangularFuzzyElement(1,1,3); // Weak TFNs[1] = new TriangularFuzzyElement(1,3,5); // Mod TFNs[2] = new TriangularFuzzyElement(3,5,5); // Str // If the TFNs argument is null, the default input TFNs are used mic.setParams(excelInputFilePath,inputLabels,outputLabels,50,TFNs); System.out.println("Micmac input data read successfully"); mic.runMICMAC(); mic.printResults(); // print results to screen (optional) mic.saveToExcel(excelOutputFilePath,true); // The following sentence will create two GIF files: // - FLMICMAC_heatmap_direct.gif // - FLMICMAC_heatmap_indirect.gif mic.createSaveHeatMapsToGIF(gifFilesPathRoot); // The following sentence will create two PNG files: // - FLMICMAC_chart_direct.png // - FLMICMAC_chart_indirect.png mic.createSaveFuzzyScatterPlots(RscriptExecutablePath, RsourceFile, chartsPath, temporaryDirectory); MicmacVariable[] results = mic.getVariables(); // Print (for example) only the dependence results to screen TriangularFuzzyElement temp1, temp2; for(int i=0; i<results.length; i++){ temp1 = (TriangularFuzzyElement)results[i].getDirectDependence(); temp2 = (TriangularFuzzyElement)results[i].getIndirectDependence(); System.out.println(temp1.toString()); System.out.println(temp2.toString()); } } catch(Exception e){ System.out.println("The following errors were found:"); e.printStackTrace(); } }