├── .gitignore
├── .idea
├── misc.xml
├── modules.xml
├── uiDesigner.xml
├── vcs.xml
└── workspace.xml
├── Artificial-intelligence-fuzzy-logic.iml
├── README.md
├── docs
├── image
│ └── ss_main.png
├── report
│ └── report_3_fuzzy_logic.pdf
└── task
│ └── task_3_fuzzy_logic.pdf
└── src
└── com
└── frogobox
├── Main.java
├── base
└── BaseHelper.java
├── helper
├── FileCrudHelper.java
├── RawDataHelper.java
└── comparator
│ ├── FuzzyComp.java
│ └── SortComp.java
├── logic
├── Algorithm.java
└── AlgorithmView.java
├── model
├── Data.java
└── DataFuzzy.java
└── raw
└── influencers.csv
/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 |
3 | out
4 | result
5 |
6 | *.class
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
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 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
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 | 1574483164976
87 |
88 |
89 | 1574483164976
90 |
91 |
92 | 1574483326866
93 |
94 |
95 |
96 | 1574483326866
97 |
98 |
99 | 1574484075780
100 |
101 |
102 |
103 | 1574484075780
104 |
105 |
106 | 1574484094634
107 |
108 |
109 |
110 | 1574484094634
111 |
112 |
113 | 1574484114864
114 |
115 |
116 |
117 | 1574484114864
118 |
119 |
120 | 1574484137444
121 |
122 |
123 |
124 | 1574484137444
125 |
126 |
127 | 1574485719069
128 |
129 |
130 |
131 | 1574485719069
132 |
133 |
134 | 1575438362555
135 |
136 |
137 |
138 | 1575438362555
139 |
140 |
141 | 1575438377026
142 |
143 |
144 |
145 | 1575438377026
146 |
147 |
148 | 1575439864763
149 |
150 |
151 |
152 | 1575439864763
153 |
154 |
155 | 1575446981834
156 |
157 |
158 |
159 | 1575446981834
160 |
161 |
162 | 1575448156717
163 |
164 |
165 |
166 | 1575448156717
167 |
168 |
169 | 1575449131065
170 |
171 |
172 |
173 | 1575449131065
174 |
175 |
176 | 1575454758907
177 |
178 |
179 |
180 | 1575454758907
181 |
182 |
183 | 1575456782138
184 |
185 |
186 |
187 | 1575456782138
188 |
189 |
190 | 1575456818803
191 |
192 |
193 |
194 | 1575456818804
195 |
196 |
197 | 1575457214114
198 |
199 |
200 |
201 | 1575457214114
202 |
203 |
204 | 1575457258340
205 |
206 |
207 |
208 | 1575457258340
209 |
210 |
211 | 1575457639105
212 |
213 |
214 |
215 | 1575457639105
216 |
217 |
218 | 1575457696927
219 |
220 |
221 |
222 | 1575457696927
223 |
224 |
225 | 1575457735106
226 |
227 |
228 |
229 | 1575457735106
230 |
231 |
232 | 1575520513620
233 |
234 |
235 |
236 | 1575520513620
237 |
238 |
239 | 1575521283596
240 |
241 |
242 |
243 | 1575521283596
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 | 1.8.0_161
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
--------------------------------------------------------------------------------
/Artificial-intelligence-fuzzy-logic.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## ai-fuzzy-logic
2 | Task Artificial Intelligence
3 |
4 | ## Author
5 | Muhammad Faisal Amir (1301198497)
6 |
7 | ## University
8 | - Telkom University
9 | - Informatics Engineering 2019
10 | - IFX - 43 - 02
11 |
12 | ## About This Project
13 | Implement Fuzzy Logic
14 | - Read File
15 | - Fuzzyfication
16 | - Inferention
17 | - De-Fuzzyfication
18 |
19 | ## Result - Screen Shot App
20 | 
21 |
22 | ## Link Task
23 | https://github.com/amirisback/Artificial-intelligence-fuzzy-logic/blob/master/docs/task/task_3_fuzzy_logic.pdf
24 |
25 | ## Link Report
26 | https://github.com/amirisback/Artificial-intelligence-fuzzy-logic/blob/master/docs/report/report_3_fuzzy_logic.pdf
27 |
28 | ## Attention !!!
29 | Please enjoy and don't forget fork and give a star
30 |
--------------------------------------------------------------------------------
/docs/image/ss_main.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amirisback/ai-fuzzy-logic/2a8746bf1c048c0317b324602cdb606c855f3e7c/docs/image/ss_main.png
--------------------------------------------------------------------------------
/docs/report/report_3_fuzzy_logic.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amirisback/ai-fuzzy-logic/2a8746bf1c048c0317b324602cdb606c855f3e7c/docs/report/report_3_fuzzy_logic.pdf
--------------------------------------------------------------------------------
/docs/task/task_3_fuzzy_logic.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amirisback/ai-fuzzy-logic/2a8746bf1c048c0317b324602cdb606c855f3e7c/docs/task/task_3_fuzzy_logic.pdf
--------------------------------------------------------------------------------
/src/com/frogobox/Main.java:
--------------------------------------------------------------------------------
1 | package com.frogobox;
2 |
3 | import com.frogobox.helper.FileCrudHelper;
4 | import com.frogobox.helper.comparator.FuzzyComp;
5 | import com.frogobox.logic.AlgorithmView;
6 |
7 | import static com.frogobox.base.BaseHelper.*;
8 |
9 | public class Main {
10 |
11 | public static void main(String[] args) {
12 | // write your code here
13 | new Main().onCreate();
14 | }
15 |
16 | private void onCreate() {
17 | setupIntroView();
18 | setupProgramName();
19 | setupAlgorithm();
20 | setupCreateFileOutput();
21 | }
22 |
23 | private void setupIntroView() {
24 | System.out.println(LINE_VIEW);
25 | System.out.println("Muhammad Faisal Amir");
26 | System.out.println("1301198497");
27 | System.out.println("IFX-43-02");
28 | System.out.println(LINE_VIEW);
29 | System.out.println();
30 | }
31 |
32 | private void setupProgramName(){
33 | System.out.println("..:: Fuzzy Logic ::..");
34 | System.out.println(LINE_VIEW);
35 | System.out.println("Diketahui : ");
36 | System.out.println("Jumlah Influencer : 100");
37 | System.out.println(LINE_VIEW);
38 | System.out.println("Ditanya : ");
39 | System.out.println("20 Influencer Terbaik");
40 | System.out.println(LINE_VIEW);
41 | System.out.println("Solusi : ");
42 | System.out.println();
43 | }
44 |
45 | private void setupAlgorithm() {
46 | new AlgorithmView().showImportantData();
47 | new AlgorithmView().showResultFuzzy();
48 | }
49 |
50 | private void setupCreateFileOutput(){
51 | new FileCrudHelper().createFolderOutPut();
52 | new FileCrudHelper().createFileCsv(FILENAME, new FuzzyComp());
53 | }
54 |
55 | }
--------------------------------------------------------------------------------
/src/com/frogobox/base/BaseHelper.java:
--------------------------------------------------------------------------------
1 | package com.frogobox.base;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.Date;
5 | import java.util.Random;
6 |
7 | /**
8 | * Created by Faisal Amir
9 | * FrogoBox Inc License
10 | * =========================================
11 | * GeneticAlgorithm
12 | * Copyright (C) 28/09/2019.
13 | * All rights reserved
14 | * -----------------------------------------
15 | * Name : Muhammad Faisal Amir
16 | * E-mail : faisalamircs@gmail.com
17 | * Github : github.com/amirisback
18 | * LinkedIn : linkedin.com/in/faisalamircs
19 | * -----------------------------------------
20 | * FrogoBox Software Industries
21 | * com.frogobox.base
22 | */
23 | public class BaseHelper {
24 |
25 | public BaseHelper() {
26 | }
27 |
28 | // -----------------------------------------------------------------------------------------------------------------
29 | // Path Raw
30 | public static final String FILENAME = "chosen_influencer";
31 | public static final String EXTENSION_TXT = ".txt";
32 | public static final String EXTENSION_CSV = ".csv";
33 | public static final String PATH_OUTPUT_DATA = "result";
34 | public static final String PATH_ROOT_PROJECT = "Folder Output : [root_project]/";
35 | public String PATH_FILE_TIME_CSV = "#" + getDateNow() + EXTENSION_CSV;
36 | public String PATH_FILE_TIME_TXT = "#" + getDateNow() + EXTENSION_TXT;
37 | // -----------------------------------------------------------------------------------------------------------------
38 | // Path Raw Data
39 | public static final String BASE_PATH_RAW = "src/com/frogobox/raw";
40 | public static final String PATH_DATA_CSV = "/influencers" + EXTENSION_CSV;
41 | public static final String PATH_RAW_CSV_DATA = BASE_PATH_RAW + PATH_DATA_CSV;
42 | // -----------------------------------------------------------------------------------------------------------------
43 | public static final String LINE_VIEW = "--------------------------------------------";
44 | // -----------------------------------------------------------------------------------------------------------------
45 | public static final String FUZZY_ACCEPT = "ACCEPT";
46 | public static final String FUZZY_ACCEPTABLE = "ACCEPTABLE";
47 | public static final String FUZZY_REJECT = "REJECT";
48 |
49 | public static final String PARAM_FOLLOWER = "follower";
50 | public static final String PARAM_ENGAGEMENT = "engagement";
51 |
52 | public static final int SUM_CHOSEN_INFLUENCERS = 20;
53 |
54 | public String getPathOutputFolderCsv(String fileName) {
55 | return PATH_OUTPUT_DATA + "/" + fileName + PATH_FILE_TIME_CSV;
56 | }
57 |
58 | public String getPathOutputFolderTxt(String fileName) {
59 | return PATH_OUTPUT_DATA + "/" + fileName + PATH_FILE_TIME_TXT;
60 | }
61 |
62 | public static int randomNumber(int range) {
63 | return new Random().nextInt(range);
64 | }
65 |
66 | public static int randomNumber(int min, int max) {
67 | return min + (max - min) * new Random().nextInt();
68 | }
69 |
70 | public static double randomNumber(double min, double max) {
71 | return min + (max - min) * new Random().nextDouble();
72 | }
73 |
74 | public String getDateNow() {
75 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
76 | return simpleDateFormat.format(new Date());
77 | }
78 |
79 | public String getTimeNow() {
80 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
81 | return simpleDateFormat.format(new Date());
82 | }
83 |
84 | public int stringToInt(String string){
85 | return Integer.parseInt(string);
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/com/frogobox/helper/FileCrudHelper.java:
--------------------------------------------------------------------------------
1 | package com.frogobox.helper;
2 |
3 | import com.frogobox.base.BaseHelper;
4 | import com.frogobox.logic.AlgorithmView;
5 | import com.frogobox.model.DataFuzzy;
6 |
7 | import java.awt.*;
8 | import java.io.BufferedWriter;
9 | import java.io.File;
10 | import java.io.FileWriter;
11 | import java.io.IOException;
12 | import java.util.Comparator;
13 |
14 | import static com.frogobox.base.BaseHelper.*;
15 |
16 | /**
17 | * Created by Faisal Amir
18 | * FrogoBox Inc License
19 | * =========================================
20 | * GeneticAlgorithm
21 | * Copyright (C) 16/11/2019.
22 | * All rights reserved
23 | * -----------------------------------------
24 | * Name : Muhammad Faisal Amir
25 | * E-mail : faisalamircs@gmail.com
26 | * Github : github.com/amirisback
27 | * LinkedIn : linkedin.com/in/faisalamircs
28 | * -----------------------------------------
29 | * FrogoBox Software Industries
30 | * com.frogobox.helper
31 | */
32 | public class FileCrudHelper {
33 |
34 | public void createFolderOutPut(){
35 | try {
36 | File outputDir = new File(PATH_OUTPUT_DATA);
37 | if (!outputDir.exists()) {
38 | outputDir.mkdir();
39 | }
40 | } catch (Exception e) {
41 | System.out.println(e);
42 | }
43 | }
44 |
45 | public void createFileTxt(String fileName, Comparator comparator) {
46 | FileWriter fileWriter = null;
47 | BufferedWriter bufferedWriter = null;
48 | try {
49 |
50 | File file = new File(new BaseHelper().getPathOutputFolderTxt(fileName));
51 | // if file doesnt exists, then create it
52 | if (!file.exists()) {
53 | file.createNewFile();
54 | }
55 | fileWriter = new FileWriter(file);
56 | bufferedWriter = new BufferedWriter(fileWriter);
57 | bufferedWriter.write(PATH_ROOT_PROJECT + new BaseHelper().getPathOutputFolderTxt(fileName));
58 | bufferedWriter.newLine();
59 | new AlgorithmView().setupWriteFuzzySortTxt(comparator, bufferedWriter);
60 |
61 | } catch (IOException e) {
62 | } finally {
63 | try {
64 | if (bufferedWriter != null)
65 | bufferedWriter.close();
66 | if (fileWriter != null)
67 | fileWriter.close();
68 | Desktop.getDesktop().open(new File(new BaseHelper().getPathOutputFolderTxt(fileName)));
69 | } catch (IOException ex) {
70 | }
71 | }
72 |
73 | }
74 |
75 | public void createFileCsv(String fileName, Comparator comparator) {
76 | FileWriter fileWriter = null;
77 | BufferedWriter bufferedWriter = null;
78 | try {
79 |
80 | File file = new File(new BaseHelper().getPathOutputFolderCsv(fileName));
81 | // if file doesnt exists, then create it
82 | if (!file.exists()) {
83 | file.createNewFile();
84 | }
85 | fileWriter = new FileWriter(file);
86 | bufferedWriter = new BufferedWriter(fileWriter);
87 | new AlgorithmView().setupWriteFuzzySortCsv(comparator, bufferedWriter);
88 |
89 | } catch (IOException e) {
90 | } finally {
91 | try {
92 | if (bufferedWriter != null)
93 | bufferedWriter.close();
94 | if (fileWriter != null)
95 | fileWriter.close();
96 | Desktop.getDesktop().open(new File(new BaseHelper().getPathOutputFolderCsv(fileName)));
97 | } catch (IOException ex) {
98 | }
99 | }
100 |
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/src/com/frogobox/helper/RawDataHelper.java:
--------------------------------------------------------------------------------
1 | package com.frogobox.helper;
2 |
3 | import com.frogobox.model.Data;
4 |
5 | import java.io.BufferedReader;
6 | import java.io.FileReader;
7 | import java.util.ArrayList;
8 | import java.util.Collections;
9 |
10 | /**
11 | * Created by Faisal Amir
12 | * FrogoBox Inc License
13 | * =========================================
14 | * Artificial-intelligence-genetic-algorithm
15 | * Copyright (C) 16/11/2019.
16 | * All rights reserved
17 | * -----------------------------------------
18 | * Name : Muhammad Faisal Amir
19 | * E-mail : faisalamircs@gmail.com
20 | * Github : github.com/amirisback
21 | * LinkedIn : linkedin.com/in/faisalamircs
22 | * -----------------------------------------
23 | * FrogoBox Software Industries
24 | * com.frogobox.helper
25 | */
26 | public class RawDataHelper {
27 |
28 | public int getSumFetchDataInLine(String sourceRaw) {
29 | int sum = 0;
30 | BufferedReader reader;
31 | try {
32 | reader = new BufferedReader(new FileReader(sourceRaw));
33 | String column = reader.readLine();
34 | String[] splitString = column.split(",");
35 | sum = splitString.length;
36 | reader.close();
37 | } catch (Exception e) {
38 | e.printStackTrace();
39 | }
40 | return sum;
41 | }
42 |
43 | public ArrayList fetchData(String sourceRaw) {
44 | ArrayList dataArrayList = new ArrayList<>();
45 | BufferedReader reader;
46 | try {
47 | reader = new BufferedReader(new FileReader(sourceRaw));
48 | String column;
49 | while ((column = reader.readLine()) != null) {
50 | String[] splitString = column.split(",");
51 | ArrayList partTemp = new ArrayList<>();
52 | Collections.addAll(partTemp, splitString);
53 | Data mData = new Data(partTemp.get(0), Integer.parseInt(partTemp.get(1)), Double.parseDouble(partTemp.get(2)));
54 | dataArrayList.add(mData);
55 | }
56 | reader.close();
57 | } catch (Exception e) {
58 | e.printStackTrace();
59 | }
60 | return dataArrayList;
61 | }
62 |
63 | public ArrayList fetchTargetData(String sourceRaw) {
64 | ArrayList practiceString = new ArrayList<>();
65 | BufferedReader reader;
66 | try {
67 | reader = new BufferedReader(new FileReader(sourceRaw));
68 | String column;
69 | while ((column = reader.readLine()) != null) {
70 | practiceString.add(column);
71 | }
72 | reader.close();
73 | } catch (Exception e) {
74 | e.printStackTrace();
75 | }
76 | return practiceString;
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/com/frogobox/helper/comparator/FuzzyComp.java:
--------------------------------------------------------------------------------
1 | package com.frogobox.helper.comparator;
2 |
3 | import com.frogobox.model.Data;
4 | import com.frogobox.model.DataFuzzy;
5 |
6 | import java.util.Comparator;
7 |
8 | /**
9 | * Created by Faisal Amir
10 | * FrogoBox Inc License
11 | * =========================================
12 | * Artificial-intelligence-fuzzy-logic
13 | * Copyright (C) 04/12/2019.
14 | * All rights reserved
15 | * -----------------------------------------
16 | * Name : Muhammad Faisal Amir
17 | * E-mail : faisalamircs@gmail.com
18 | * Github : github.com/amirisback
19 | * LinkedIn : linkedin.com/in/faisalamircs
20 | * -----------------------------------------
21 | * FrogoBox Software Industries
22 | * com.frogobox.helper.comparator
23 | */
24 | public class FuzzyComp implements Comparator {
25 |
26 | @Override
27 | public int compare(DataFuzzy dataA, DataFuzzy dataB) {
28 | if ((dataA.getFuzzyOutput() == 2) && (dataB.getFuzzyOutput() == 2)) {
29 | return dataB.getFollowerCount() - dataA.getFollowerCount();
30 | } else if ((dataA.getFuzzyOutput() == 1) && (dataB.getFuzzyOutput() == 1)){
31 | return dataB.getFollowerCount() - dataA.getFollowerCount();
32 | } else {
33 | return dataB.getFuzzyOutput() - dataA.getFuzzyOutput();
34 | }
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/src/com/frogobox/helper/comparator/SortComp.java:
--------------------------------------------------------------------------------
1 | package com.frogobox.helper.comparator;
2 |
3 | import com.frogobox.model.Data;
4 |
5 | import java.util.Comparator;
6 |
7 | import static com.frogobox.base.BaseHelper.PARAM_FOLLOWER;
8 |
9 | /**
10 | * Created by Faisal Amir
11 | * FrogoBox Inc License
12 | * =========================================
13 | * Artificial-intelligence-fuzzy-logic
14 | * Copyright (C) 23/11/2019.
15 | * All rights reserved
16 | * -----------------------------------------
17 | * Name : Muhammad Faisal Amir
18 | * E-mail : faisalamircs@gmail.com
19 | * Github : github.com/amirisback
20 | * LinkedIn : linkedin.com/in/faisalamircs
21 | * -----------------------------------------
22 | * FrogoBox Software Industries
23 | * com.frogobox.helper
24 | */
25 | public class SortComp implements Comparator {
26 |
27 | private String param;
28 |
29 | public SortComp(String param) {
30 | this.param = param;
31 | }
32 |
33 | public String getParam() {
34 | return param;
35 | }
36 |
37 | public void setParam(String param) {
38 | this.param = param;
39 | }
40 |
41 | @Override
42 | public int compare(Data dataA, Data dataB) {
43 | if (param.equalsIgnoreCase(PARAM_FOLLOWER)) {
44 | return dataB.getFollowerCount() - dataA.getFollowerCount();
45 | } else {
46 | return (int) dataB.getEngagementRate() - (int) dataA.getEngagementRate();
47 | }
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/com/frogobox/logic/Algorithm.java:
--------------------------------------------------------------------------------
1 | package com.frogobox.logic;
2 |
3 | import com.frogobox.helper.RawDataHelper;
4 | import com.frogobox.helper.comparator.SortComp;
5 | import com.frogobox.model.Data;
6 | import com.frogobox.model.DataFuzzy;
7 |
8 | import java.util.ArrayList;
9 | import java.util.Comparator;
10 |
11 | import static com.frogobox.base.BaseHelper.*;
12 |
13 | /**
14 | * Created by Faisal Amir
15 | * FrogoBox Inc License
16 | * =========================================
17 | * Artificial-intelligence-fuzzy-logic
18 | * Copyright (C) 04/12/2019.
19 | * All rights reserved
20 | * -----------------------------------------
21 | * Name : Muhammad Faisal Amir
22 | * E-mail : faisalamircs@gmail.com
23 | * Github : github.com/amirisback
24 | * LinkedIn : linkedin.com/in/faisalamircs
25 | * -----------------------------------------
26 | * FrogoBox Software Industries
27 | * com.frogobox.logic
28 | */
29 | public class Algorithm {
30 |
31 | public ArrayList rawDataArray() {
32 | return new RawDataHelper().fetchData(PATH_RAW_CSV_DATA);
33 | }
34 |
35 | public ArrayList rawDataArraySort(Comparator comparator) {
36 | ArrayList sortRawData = rawDataArray();
37 | sortRawData.sort(comparator);
38 | return sortRawData;
39 | }
40 |
41 | public int indexLowest(Comparator comparator) {
42 | return rawDataArraySort(comparator).size() - 1;
43 | }
44 |
45 | public int indexHighest() {
46 | return 0;
47 | }
48 |
49 | public int indexMid(Comparator comparator) {
50 | return rawDataArraySort(comparator).size() / 2;
51 | }
52 |
53 | public int getHighestFollower() {
54 | return rawDataArraySort(new SortComp(PARAM_FOLLOWER)).get(indexHighest()).getFollowerCount();
55 | }
56 |
57 | public int getLowestFollower() {
58 | return rawDataArraySort(new SortComp(PARAM_FOLLOWER)).get(indexLowest(new SortComp(PARAM_FOLLOWER))).getFollowerCount();
59 | }
60 |
61 | public int getMidFollower() {
62 | return (getHighestFollower() - getLowestFollower()) / 2;
63 | }
64 |
65 | public int getAverageFollower(){
66 | int temp = 0;
67 | for (int i = 0; i < rawDataArray().size(); i++) {
68 | temp = temp + rawDataArray().get(i).getFollowerCount();
69 | }
70 | return temp / rawDataArray().size();
71 | }
72 |
73 | public double getHighestEngagement() {
74 | return rawDataArraySort(new SortComp(PARAM_ENGAGEMENT)).get(indexHighest()).getEngagementRate();
75 | }
76 |
77 | public double getLowestEngagement() {
78 | return rawDataArraySort(new SortComp(PARAM_ENGAGEMENT)).get(indexLowest(new SortComp(PARAM_ENGAGEMENT))).getEngagementRate();
79 | }
80 |
81 | public double getMidEngagement() {
82 | return (getHighestEngagement() - getLowestEngagement()) / 2;
83 | }
84 |
85 | public double getAverageEngagement(){
86 | double temp = 0.0;
87 | for (int i = 0; i < rawDataArray().size(); i++) {
88 | temp = temp + rawDataArray().get(i).getEngagementRate();
89 | }
90 | return temp / rawDataArray().size();
91 | }
92 |
93 | public boolean checkAcceptableFollower(int followerCount){
94 | return (followerCount >= getMidFollower()) && followerCount <= getHighestFollower();
95 | }
96 |
97 | public boolean checkAcceptableEngagementCount(double engagementRate){
98 | return (engagementRate >= getMidEngagement()) && engagementRate <= getHighestEngagement();
99 | }
100 |
101 | public boolean checkAcceptInfluencer(int followerCount, double engagementRate){
102 | return checkAcceptableFollower(followerCount) && checkAcceptableEngagementCount(engagementRate);
103 | }
104 |
105 | public boolean checkAcceptableInfluencer(int followerCount, double engagementRate){
106 | return checkAcceptableFollower(followerCount) || checkAcceptableEngagementCount(engagementRate);
107 | }
108 |
109 | public ArrayList arrayDataFuzzyLogic(Comparator comparator){
110 | ArrayList chosenArrayList = new ArrayList<>();
111 |
112 | int state = 0;
113 | for (Data data : rawDataArray()) {
114 | if (checkAcceptInfluencer(data.getFollowerCount(), data.getEngagementRate())) {
115 | state = 2;
116 | } else {
117 | if (checkAcceptableInfluencer(data.getFollowerCount(), data.getEngagementRate())) {
118 | state = 1;
119 | } else {
120 | state = 0;
121 | }
122 | }
123 | DataFuzzy dataFuzzy = new DataFuzzy(data.getId(), data.getFollowerCount(), data.getEngagementRate(), state);
124 | chosenArrayList.add(dataFuzzy);
125 | }
126 |
127 | chosenArrayList.sort(comparator);
128 |
129 | return chosenArrayList;
130 | }
131 |
132 | }
133 |
--------------------------------------------------------------------------------
/src/com/frogobox/logic/AlgorithmView.java:
--------------------------------------------------------------------------------
1 | package com.frogobox.logic;
2 |
3 | import com.frogobox.helper.comparator.SortComp;
4 | import com.frogobox.helper.comparator.FuzzyComp;
5 | import com.frogobox.model.Data;
6 | import com.frogobox.model.DataFuzzy;
7 |
8 | import java.io.BufferedWriter;
9 | import java.io.IOException;
10 | import java.util.ArrayList;
11 | import java.util.Comparator;
12 |
13 | import static com.frogobox.base.BaseHelper.*;
14 |
15 | /**
16 | * Created by Faisal Amir
17 | * FrogoBox Inc License
18 | * =========================================
19 | * Artificial-intelligence-fuzzy-logic
20 | * Copyright (C) 04/12/2019.
21 | * All rights reserved
22 | * -----------------------------------------
23 | * Name : Muhammad Faisal Amir
24 | * E-mail : faisalamircs@gmail.com
25 | * Github : github.com/amirisback
26 | * LinkedIn : linkedin.com/in/faisalamircs
27 | * -----------------------------------------
28 | * FrogoBox Software Industries
29 | * com.frogobox.logic
30 | */
31 | public class AlgorithmView {
32 |
33 | private Algorithm algorithm = new Algorithm();
34 |
35 | public void setupShowDataOri() {
36 | for (Data data : algorithm.rawDataArray()) {
37 | System.out.println(data.toString());
38 | }
39 | }
40 |
41 | public void setupSortByComparator(Comparator comparator) {
42 | for (Data data : algorithm.rawDataArraySort(comparator)) {
43 | System.out.println(data.toString());
44 | }
45 | }
46 |
47 | public void setupWriteFuzzySortCsv(Comparator comparator, BufferedWriter bufferedWriter) {
48 | ArrayList fuzzyArrayList = algorithm.arrayDataFuzzyLogic(comparator);
49 | for (int i = 0; i < 20; i++) {
50 | try {
51 | bufferedWriter.write(fuzzyArrayList.get(i).getId());
52 | bufferedWriter.newLine();
53 | } catch (IOException e) {
54 | e.printStackTrace();
55 | }
56 | }
57 | }
58 |
59 | public void setupWriteFuzzySortTxt(Comparator comparator, BufferedWriter bufferedWriter) {
60 | ArrayList fuzzyArrayList = algorithm.arrayDataFuzzyLogic(comparator);
61 | for (int i = 0; i < 20; i++) {
62 | try {
63 | bufferedWriter.write(fuzzyArrayList.get(i).toString());
64 | bufferedWriter.newLine();
65 | } catch (IOException e) {
66 | e.printStackTrace();
67 | }
68 | }
69 | }
70 |
71 | public void setupResultFuzzySort(Comparator comparator) {
72 | ArrayList fuzzyArrayList = algorithm.arrayDataFuzzyLogic(comparator);
73 | for (int i = 0; i < fuzzyArrayList.size(); i++) {
74 | if (i == 20) {
75 | System.out.println("\nWhich was not selected");
76 | System.out.println(LINE_VIEW);
77 | System.out.println(fuzzyArrayList.get(i).toString());
78 | } else {
79 | System.out.println(fuzzyArrayList.get(i).toString());
80 | }
81 |
82 | }
83 | }
84 |
85 | public void showImportantData() {
86 | // jumlah linguistik, bentuk fungsi keanggotaan, rule inferensi,
87 | System.out.println("Highest Follower Count : " + algorithm.getHighestFollower());
88 | System.out.println("Highest Engagement Rate : " + algorithm.getHighestEngagement());
89 |
90 | System.out.println("Mid Follower Count : " + algorithm.getMidFollower());
91 | System.out.println("Mid Engagement Rate : " + algorithm.getMidEngagement());
92 |
93 | System.out.println("Lowest Follower Count : " + algorithm.getLowestFollower());
94 | System.out.println("Lowest Engagement Rate : " + algorithm.getLowestEngagement());
95 |
96 | System.out.println(LINE_VIEW);
97 | System.out.println();
98 |
99 | }
100 |
101 | public void showSortByComparator() {
102 | System.out.println("Original Data");
103 | setupShowDataOri();
104 |
105 | System.out.println();
106 |
107 | System.out.println("Sort By Follower Count");
108 | setupSortByComparator(new SortComp(PARAM_FOLLOWER));
109 |
110 | System.out.println();
111 |
112 | System.out.println("Sort By Engagement Rate");
113 | setupSortByComparator(new SortComp(PARAM_ENGAGEMENT));
114 |
115 | System.out.println();
116 |
117 | }
118 |
119 | public void showResultFuzzy() {
120 | System.out.println("Fuzzy Output (Chosen Influencers)");
121 | System.out.println(LINE_VIEW);
122 | setupResultFuzzySort(new FuzzyComp());
123 | }
124 |
125 | }
--------------------------------------------------------------------------------
/src/com/frogobox/model/Data.java:
--------------------------------------------------------------------------------
1 | package com.frogobox.model;
2 |
3 | /**
4 | * Created by Faisal Amir
5 | * FrogoBox Inc License
6 | * =========================================
7 | * Artificial-intelligence-fuzzy-logic
8 | * Copyright (C) 23/11/2019.
9 | * All rights reserved
10 | * -----------------------------------------
11 | * Name : Muhammad Faisal Amir
12 | * E-mail : faisalamircs@gmail.com
13 | * Github : github.com/amirisback
14 | * LinkedIn : linkedin.com/in/faisalamircs
15 | * -----------------------------------------
16 | * FrogoBox Software Industries
17 | * com.frogobox.model
18 | */
19 | public class Data {
20 | private String id;
21 | private int followerCount;
22 | private double engagementRate;
23 |
24 | public Data(String id, int followerCount, double engagementRate) {
25 | this.id = id;
26 | this.followerCount = followerCount;
27 | this.engagementRate = engagementRate;
28 | }
29 |
30 | public String getId() {
31 | return id;
32 | }
33 |
34 | public void setId(String id) {
35 | this.id = id;
36 | }
37 |
38 | public int getFollowerCount() {
39 | return followerCount;
40 | }
41 |
42 | public void setFollowerCount(int followerCount) {
43 | this.followerCount = followerCount;
44 | }
45 |
46 | public double getEngagementRate() {
47 | return engagementRate;
48 | }
49 |
50 | public void setEngagementRate(double engagementRate) {
51 | this.engagementRate = engagementRate;
52 | }
53 |
54 | @Override
55 | public String toString() {
56 | return "Data{id = " + id + ",\t followerCount = " + followerCount + ",\t engagementRate = " + engagementRate + "}";
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/com/frogobox/model/DataFuzzy.java:
--------------------------------------------------------------------------------
1 | package com.frogobox.model;
2 |
3 | import static com.frogobox.base.BaseHelper.*;
4 |
5 | /**
6 | * Created by Faisal Amir
7 | * FrogoBox Inc License
8 | * =========================================
9 | * Artificial-intelligence-fuzzy-logic
10 | * Copyright (C) 04/12/2019.
11 | * All rights reserved
12 | * -----------------------------------------
13 | * Name : Muhammad Faisal Amir
14 | * E-mail : faisalamircs@gmail.com
15 | * Github : github.com/amirisback
16 | * LinkedIn : linkedin.com/in/faisalamircs
17 | * -----------------------------------------
18 | * FrogoBox Software Industries
19 | * com.frogobox.model
20 | */
21 | public class DataFuzzy {
22 | private String id;
23 | private int followerCount;
24 | private double engagementRate;
25 | private int fuzzyOutput;
26 |
27 | public DataFuzzy(String id, int followerCount, double engagementRate, int fuzzyOutput) {
28 | this.id = id;
29 | this.followerCount = followerCount;
30 | this.engagementRate = engagementRate;
31 | this.fuzzyOutput = fuzzyOutput;
32 | }
33 |
34 | public String getId() {
35 | return id;
36 | }
37 |
38 | public void setId(String id) {
39 | this.id = id;
40 | }
41 |
42 | public int getFollowerCount() {
43 | return followerCount;
44 | }
45 |
46 | public void setFollowerCount(int followerCount) {
47 | this.followerCount = followerCount;
48 | }
49 |
50 | public double getEngagementRate() {
51 | return engagementRate;
52 | }
53 |
54 | public void setEngagementRate(double engagementRate) {
55 | this.engagementRate = engagementRate;
56 | }
57 |
58 | public int getFuzzyOutput() {
59 | return fuzzyOutput;
60 | }
61 |
62 | public void setFuzzyOutput(int fuzzyOutput) {
63 | this.fuzzyOutput = fuzzyOutput;
64 | }
65 |
66 | @Override
67 | public String toString() {
68 |
69 | String state ="";
70 | if (fuzzyOutput == 2) {
71 | state = FUZZY_ACCEPT;
72 | } else if (fuzzyOutput ==1 ) {
73 | state = FUZZY_ACCEPTABLE;
74 | } else {
75 | state = FUZZY_REJECT;
76 | }
77 |
78 | return "Data{id = " + id + ",\t followerCount = " + followerCount + ",\t engagementRate = " + engagementRate + ",\t fuzzyOutput = " + state + "}";
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/com/frogobox/raw/influencers.csv:
--------------------------------------------------------------------------------
1 | 1,6207,1.0
2 | 2,38237,5.8
3 | 3,14840,0.6
4 | 4,43851,1.4
5 | 5,15530,3.5
6 | 6,24050,3.3
7 | 7,44837,1.3
8 | 8,10029,3.4
9 | 9,14531,0.2
10 | 10,7862,2.8
11 | 11,95117,6.6
12 | 12,28548,2.5
13 | 13,90773,6.7
14 | 14,34711,1.8
15 | 15,11546,2.4
16 | 16,38046,0.9
17 | 17,17006,0.9
18 | 18,22159,1.0
19 | 19,55217,4.9
20 | 20,1908,2.3
21 | 21,23555,0.8
22 | 22,6463,1.2
23 | 23,27915,2.1
24 | 24,3628,0.5
25 | 25,77585,2.7
26 | 26,30010,1.2
27 | 27,18404,3.1
28 | 28,9828,3.7
29 | 29,12108,0.5
30 | 30,7643,2.0
31 | 31,6517,1.1
32 | 32,17289,2.3
33 | 33,44833,0.6
34 | 34,10953,3.9
35 | 35,14910,3.0
36 | 36,30419,3.3
37 | 37,32406,1.2
38 | 38,30308,0.4
39 | 39,9890,9.4
40 | 40,18403,0.9
41 | 41,81909,3.6
42 | 42,29689,0.3
43 | 43,29843,0.7
44 | 44,13129,1.0
45 | 45,15165,1.2
46 | 46,42111,0.2
47 | 47,46847,0.9
48 | 48,19925,6.5
49 | 49,42391,0.3
50 | 50,43475,2.0
51 | 51,21126,3.1
52 | 52,39504,1.1
53 | 53,56257,3.2
54 | 54,18921,2.5
55 | 55,18570,1.5
56 | 56,30940,1.4
57 | 57,10645,0.7
58 | 58,5655,0.1
59 | 59,58987,6.7
60 | 60,58403,5.2
61 | 61,53701,4.5
62 | 62,33443,0.4
63 | 63,48553,1.4
64 | 64,8585,0.7
65 | 65,34471,0.4
66 | 66,46833,0.9
67 | 67,31642,3.4
68 | 68,28320,1.7
69 | 69,45718,0.3
70 | 70,11602,2.9
71 | 71,25160,2.8
72 | 72,61456,4.6
73 | 73,21216,2.5
74 | 74,22394,6.3
75 | 75,94551,3.0
76 | 76,39175,3.3
77 | 77,17408,1.9
78 | 78,20226,3.0
79 | 79,47405,0.4
80 | 80,20406,3.2
81 | 81,44116,1.2
82 | 82,12098,0.2
83 | 83,10614,0.1
84 | 84,25712,2.0
85 | 85,25346,2.3
86 | 86,26515,2.0
87 | 87,9043,2.9
88 | 88,19602,2.7
89 | 89,22801,2.3
90 | 90,1526,2.5
91 | 91,22100,3.2
92 | 92,3837,2.4
93 | 93,27657,5.5
94 | 94,49646,0.5
95 | 95,15523,3.1
96 | 96,13436,0.7
97 | 97,5741,0.9
98 | 98,27417,0.4
99 | 99,40869,0.1
100 | 100,15788,6.8
101 |
--------------------------------------------------------------------------------