saved_rule_models, PageRuleInterface pageRuleInterface){
24 | this.context = context;
25 | this.saved_rule_models = saved_rule_models;
26 | System.out.println(saved_rule_models.size() + "fghjk");
27 | this.pageRuleInterface = pageRuleInterface;
28 | }
29 | @NonNull
30 | @Override
31 | public SavedRulesAdapter.Global_RulesHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
32 | // Раздувание макета и придание вида каждого элемента
33 | LayoutInflater inflater = LayoutInflater.from(context);
34 | View view = inflater.inflate(R.layout.recycler_view_row, parent, false);
35 |
36 | return new SavedRulesAdapter.Global_RulesHolder(view, pageRuleInterface);
37 | }
38 |
39 | @Override
40 | public void onBindViewHolder(@NonNull SavedRulesAdapter.Global_RulesHolder holder, int position) {
41 | // Присваивание значений для каждой из строк по мере их появления на экране
42 | holder.textView_name.setText(saved_rule_models.get(position).getName());
43 | System.out.println(position + " b");
44 | holder.imageView_img.setImageBitmap(saved_rule_models.get(position).getImgs().get(0));
45 | }
46 |
47 | @Override
48 | public int getItemCount() {
49 | // Сколько всего элементов
50 | return saved_rule_models.size();
51 | }
52 | public static class Global_RulesHolder extends RecyclerView.ViewHolder{
53 | // Извлекание вида из макета (onCreate)
54 | ImageView imageView_img;
55 | TextView textView_name;
56 | public Global_RulesHolder(@NonNull View itemView, PageRuleInterface pageRuleInterface) {
57 | super(itemView);
58 | imageView_img = itemView.findViewById(R.id.img);
59 | textView_name = itemView.findViewById(R.id.name);
60 |
61 | itemView.setOnClickListener(new View.OnClickListener() {
62 | @Override
63 | public void onClick(View v) {
64 | if (pageRuleInterface != null){
65 | int pos = getAdapterPosition();
66 | if (pos != RecyclerView.NO_POSITION){
67 | pageRuleInterface.onItemClick(pos);
68 | }
69 | }
70 | }
71 | });
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/Android/app/src/main/assets/fuzzy3.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
10 |
14 |
18 |
19 |
20 | Фаззификация. Функция принадлежности
21 | Фаззификацией называется процесс перевода входных данных в нечеткие, путем нахождения степени принадлежности измерения к нечеткому множеству. В качестве входных данных мы получаем положение модели (x) и скорость (v).
22 | Существует несколько видов функций принадлежности. Самыми часто используемыми стали Треугольная, Трапецеидальная и Гауссова.
23 | Треугольная функция принадлежности (Рисунок 3.1) задается тройкой чисел (a, b, c) и вычисляется согласно выражению (1):
24 |
25 |
26 | Рисунок 3.1 — Треугольная функция принадлежности
27 | Трапецеидальная функция принадлежности (Рисунок 3.2) задается четырьмя числами и вычисляется согласно выражению (2):
28 |
29 |
30 | Рисунок 3.2 — Трапецеидальная функция принадлежности
31 | Функция принадлежности гауссова типа (Рисунок 3.3) описывается формулой (3):
32 |
33 |
34 | Рисунок 3.3 — Гауссова функция принадлежности
35 | Для работы была выбрана Трапецеидальная функция принадлежности. Главная причина заключается в том, что при использовании Гауссовой функции принадлежности будет проблема в нахождении определенного интеграла, так как такая функция стремится к нулю, но никогда его не достигает. Треугольная функция принадлежности была не выбрана в связи с тем, что при большом желании из трапецеидального числа можно сделать треугольное, задав b=c.
36 |
37 |
--------------------------------------------------------------------------------
/Android/app/src/main/res/layout/fragment_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
13 |
18 |
19 |
25 |
37 |
49 |
59 |
60 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/Server/src/Main/BigDataSender.java:
--------------------------------------------------------------------------------
1 | package Main;
2 |
3 | import java.io.BufferedInputStream;
4 | import java.io.BufferedReader;
5 | import java.io.InputStreamReader;
6 | import java.io.PrintWriter;
7 | import java.net.Socket;
8 | import java.nio.CharBuffer;
9 | import java.nio.charset.StandardCharsets;
10 | import java.time.ZonedDateTime;
11 | import java.util.ArrayList;
12 | import java.util.logging.Logger;
13 |
14 | import org.json.JSONObject;
15 |
16 | public class BigDataSender{
17 | private Socket client;
18 | private String data;
19 | private String command;
20 | private BufferedReader input;
21 | private PrintWriter output;
22 | private int parts = 0;
23 | private ArrayList dataParts;
24 | private Logger logger = Main.logger;
25 | ArrayList dataSplitter(String d, int blockSize){
26 | parts = d.length() / blockSize + (((d.length() % blockSize) > 0)?1:0);
27 | ArrayList result = new ArrayList();
28 | for(int i = 0; i < parts; i++) {
29 | result.add(d.substring(i * blockSize, Math.min((i + 1) * blockSize, d.length())));
30 | }
31 | return result;
32 | }
33 | BigDataSender(Socket sock, BufferedReader in, PrintWriter out, String d, String c){
34 | client = sock;
35 | output = out;
36 | input = in;
37 | data = d;
38 | command = c;
39 | dataParts = dataSplitter(data, 4096);
40 | }
41 | public void send() {
42 | try {
43 | JSONObject header = new JSONObject();
44 | header.put("Command", "splitted_data");
45 | header.put("SplittedCommand", command);
46 | header.put("Parts", parts);
47 | BufferedReader input = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.UTF_8));
48 | PrintWriter output = new PrintWriter(client.getOutputStream());
49 | output.println(header.toString());
50 | System.out.println(header);
51 | System.out.println(header.length());
52 | output.flush();
53 | outer:
54 | for(int i = 0; i < parts; i++) {
55 | JSONObject body = new JSONObject();
56 | body.put("Command", "splitted_data");
57 | body.put("SplittedCommand", "continue");
58 | System.out.println(i);
59 | body.put("Part", i);
60 | body.put("SplittedData", dataParts.get(i));
61 | System.out.println(body);
62 | output.println(body.toString());
63 | output.flush();
64 | // output.print(body.toString());
65 | CharBuffer charb = CharBuffer.allocate(10000);
66 | String temp;
67 | JSONObject response = null;
68 | long begin = ZonedDateTime.now().toInstant().toEpochMilli();
69 | System.out.println(input);
70 | // while(!input.ready());
71 | // input.read(charb);
72 | // while((temp = input.readLine()) == null);
73 | // temp = input.readLine();
74 | // temp = new String(charb.array());
75 | // System.out.println(23212134);
76 | // System.out.println(temp);
77 | // response = new JSONObject(temp);
78 | // if(ZonedDateTime.now().toInstant().toEpochMilli() - begin > 10000) {
79 | // System.out.println("Timeouted");
80 | // output.println("{\"Status\": \"timeouted\"}");
81 | // output.flush();
82 | // break outer;
83 | // }
84 | //
85 | // if(!response.getString("Status").equals("OK")) {
86 | // i--;
87 | // System.out.println("i decreased");
88 | // }
89 |
90 | }
91 | logger.info("Big data sent successfully!");
92 | //return true;
93 | }catch(Exception e){
94 | logger.warning("Exception while sending big data:\n" + e.toString());
95 | e.printStackTrace();
96 | }
97 | }
98 |
99 | }
--------------------------------------------------------------------------------
/Android/app/src/main/res/layout/fragment_genetic_algorithm.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
22 |
33 |
34 |
44 |
54 |
64 |
65 |
77 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/Android/app/src/main/java/com/example/fuzzycontapp/Fragments/ChooseBluetooth.java:
--------------------------------------------------------------------------------
1 | package com.example.fuzzycontapp.Fragments;
2 |
3 | import androidx.core.app.ActivityCompat;
4 | import androidx.core.content.ContextCompat;
5 | import androidx.fragment.app.Fragment;
6 | import androidx.fragment.app.FragmentTransaction;
7 |
8 | import android.content.pm.PackageManager;
9 | import android.Manifest;
10 | import android.bluetooth.BluetoothAdapter;
11 | import android.bluetooth.BluetoothDevice;
12 | import android.content.Intent;
13 | import android.os.Bundle;
14 | import android.view.LayoutInflater;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.widget.AdapterView;
18 | import android.widget.ArrayAdapter;
19 | import android.widget.ListView;
20 | import android.widget.TextView;
21 | import android.widget.Toast;
22 |
23 | import com.example.fuzzycontapp.Activities.HomePageActivity;
24 | import com.example.fuzzycontapp.Activities.PhysicsModel;
25 | import com.example.fuzzycontapp.Indiv.Global;
26 | import com.example.fuzzycontapp.R;
27 | import com.example.fuzzycontapp.databinding.FragmentChooseBluetoothBinding;
28 | import com.example.fuzzycontapp.databinding.FragmentHomeBinding;
29 |
30 | import java.util.ArrayList;
31 | import java.util.ResourceBundle;
32 | import java.util.Set;
33 |
34 | public class ChooseBluetooth extends Fragment {
35 | FragmentChooseBluetoothBinding binding;
36 | private BluetoothAdapter BluetoothAdap = null;
37 | private ListView devicelist = null;
38 | private Set Devices;
39 |
40 | @Override
41 | public void onCreate(Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 |
44 | }
45 |
46 | @Override
47 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
48 | Bundle savedInstanceState) {
49 | binding = FragmentChooseBluetoothBinding.inflate(inflater, container, false);
50 | devicelist = binding.deviceList;
51 | BluetoothAdap = BluetoothAdapter.getDefaultAdapter();
52 | pairedDevices();
53 | return binding.getRoot();
54 | }
55 | private void pairedDevices() {
56 | if (ActivityCompat.checkSelfPermission(this.getContext(), Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
57 | return;
58 | }
59 | Devices = BluetoothAdap.getBondedDevices();
60 | ArrayList list = new ArrayList();
61 | if (Devices.size() > 0) {
62 | for (BluetoothDevice bt : Devices) {
63 | // Add all the available devices to the list
64 | list.add(bt.getName() + "\n" + bt.getAddress());
65 | }
66 | }
67 | else {
68 | // Toast.makeText(getView().getContext(), "No Paired Bluetooth Devices Found.", Toast.LENGTH_LONG).show();
69 | }
70 |
71 | // Adding the devices to the list with ArrayAdapter class
72 | final ArrayAdapter adapter = new ArrayAdapter(this.getContext(), android.R.layout.simple_list_item_1, list);
73 | devicelist.setAdapter(adapter);
74 |
75 | // Toast.makeText(getView().getContext(), "OK", Toast.LENGTH_LONG).show();
76 | devicelist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
77 | @Override
78 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
79 | String info = ((TextView)view).getText().toString();
80 | Global.ADDRESS = info.substring(info.length() - 17);
81 | FragmentTransaction fm = getActivity().getSupportFragmentManager().beginTransaction();
82 | fm.replace(R.id.frame_layout_phys, new PhysController());
83 | fm.commit();
84 | }
85 | });
86 | }
87 | }
--------------------------------------------------------------------------------
/Android/app/src/main/java/com/example/fuzzycontapp/Fragments/BasinHopping.java:
--------------------------------------------------------------------------------
1 | package com.example.fuzzycontapp.Fragments;
2 |
3 | import static com.example.fuzzycontapp.Activities.MainActivity.MyThread.input;
4 | import static com.example.fuzzycontapp.Activities.MainActivity.MyThread.output;
5 |
6 | import android.os.Bundle;
7 |
8 | import androidx.fragment.app.Fragment;
9 |
10 | import android.os.StrictMode;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.widget.Toast;
15 |
16 | import com.example.fuzzycontapp.R;
17 | import com.example.fuzzycontapp.databinding.FragmentBasinHoppingBinding;
18 | import com.example.fuzzycontapp.databinding.FragmentLoginBinding;
19 |
20 | import org.json.JSONException;
21 | import org.json.JSONObject;
22 |
23 | import java.io.IOException;
24 |
25 |
26 | public class BasinHopping extends Fragment {
27 | FragmentBasinHoppingBinding binding;
28 | public static String title, x_start, x_finish, iterations, step;
29 | @Override
30 | public void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 |
33 | }
34 |
35 | @Override
36 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
37 | Bundle savedInstanceState) {
38 | binding = FragmentBasinHoppingBinding.inflate(inflater, container, false);
39 |
40 | binding.optim.setOnClickListener(new View.OnClickListener() {
41 | @Override
42 | public void onClick(View v) {
43 | title = binding.title.getText().toString();
44 | x_start = binding.topBorder.getText().toString();
45 | x_finish = binding.bottomBorder.getText().toString();
46 | iterations = binding.indiv.getText().toString();
47 | step = binding.gener.getText().toString();
48 | SendData sendData = new SendData();
49 | sendData.start();
50 | binding.title.setText("");
51 | binding.topBorder.setText("");
52 | binding.bottomBorder.setText("");
53 | binding.indiv.setText("");
54 | binding.gener.setText("");
55 | Toast.makeText(getActivity(), R.string.saved,
56 | Toast.LENGTH_LONG).show();
57 |
58 | }
59 | });
60 |
61 |
62 | return binding.getRoot();
63 | }
64 | private void send_data(){
65 | String s = "";
66 | int SDK_INT = android.os.Build.VERSION.SDK_INT; // check
67 | if (SDK_INT > 8)
68 | {
69 | StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
70 | .permitAll().build();
71 | StrictMode.setThreadPolicy(policy);
72 | JSONObject request = new JSONObject();
73 | try {
74 | request.put("Command", "optimize");
75 | request.put("Title", title);
76 | request.put("x_start", x_start);
77 | request.put("x_finish", x_finish);
78 | request.put("iterations", iterations);
79 | request.put("step", step);
80 | request.put("type", "public");
81 | request.put("Type", "basin");
82 | } catch (JSONException e) {
83 | e.printStackTrace();
84 | }
85 |
86 | output.println(request);
87 | output.flush();
88 | try {
89 | while(!input.ready());
90 | s = input.readLine();
91 | } catch (IOException e) {
92 | e.printStackTrace();
93 | }
94 | }
95 | }
96 | class SendData extends Thread {
97 | @Override
98 | public void run() {
99 | send_data();
100 | }
101 | }
102 | }
--------------------------------------------------------------------------------
/Android/app/src/main/res/drawable/pic.xml:
--------------------------------------------------------------------------------
1 |
6 |
14 |
22 |
31 |
40 |
49 |
58 |
67 |
76 |
85 |
94 |
95 |
--------------------------------------------------------------------------------
/Android/app/src/main/java/com/example/fuzzycontapp/Fragments/PhysController.java:
--------------------------------------------------------------------------------
1 | package com.example.fuzzycontapp.Fragments;
2 |
3 | import android.Manifest;
4 | import android.bluetooth.BluetoothAdapter;
5 | import android.bluetooth.BluetoothDevice;
6 | import android.bluetooth.BluetoothSocket;
7 | import android.content.pm.PackageManager;
8 | import android.os.Bundle;
9 |
10 | import androidx.annotation.NonNull;
11 | import androidx.core.app.ActivityCompat;
12 | import androidx.fragment.app.Fragment;
13 |
14 | import android.view.LayoutInflater;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 |
18 | import com.example.fuzzycontapp.Indiv.Global;
19 | import com.example.fuzzycontapp.R;
20 | import com.example.fuzzycontapp.databinding.FragmentChooseBluetoothBinding;
21 | import com.example.fuzzycontapp.databinding.FragmentPhysControllerBinding;
22 |
23 | import java.io.IOException;
24 | import java.util.UUID;
25 |
26 | public class PhysController extends Fragment {
27 |
28 | FragmentPhysControllerBinding binding;
29 | BluetoothAdapter myBluetooth = null;
30 | boolean isBtConnected = false;
31 | public BluetoothSocket btSocket = null;
32 | // This UUID is unique and fix id for this device
33 | static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
34 |
35 | @Override
36 | public void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | }
39 |
40 | @Override
41 | public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
42 | Bundle savedInstanceState) {
43 | binding = FragmentPhysControllerBinding.inflate(inflater, container, false);
44 |
45 | binding.up.setOnClickListener(new View.OnClickListener() {
46 | @Override
47 | public void onClick(View v) {
48 | BTHandler handler = new BTHandler(new String("1"));
49 | handler.start();
50 |
51 | }
52 | });
53 | binding.down.setOnClickListener(new View.OnClickListener() {
54 | @Override
55 | public void onClick(View v) {
56 | BTHandler handler = new BTHandler(new String("0"));
57 | handler.start();
58 | }
59 | });
60 | binding.stop.setOnClickListener(new View.OnClickListener() {
61 | @Override
62 | public void onClick(View v) {
63 | BTHandler handler = new BTHandler(new String("2"));
64 | handler.start();
65 | }
66 | });
67 | return binding.getRoot();
68 | }
69 |
70 | class BTHandler extends Thread {
71 | String data;
72 |
73 | BTHandler(String s) {
74 | data = s;
75 | }
76 |
77 | void connect() {
78 | try {
79 | if (btSocket == null || !isBtConnected) {
80 | myBluetooth = BluetoothAdapter.getDefaultAdapter();
81 |
82 | // This will connect the device with address as passed
83 | BluetoothDevice hc = myBluetooth.getRemoteDevice(Global.ADDRESS);
84 | btSocket = hc.createInsecureRfcommSocketToServiceRecord(myUUID);
85 | // BluetoothAdapter.getDefaultAdapter().cancelDiscovery();
86 |
87 | btSocket.connect();
88 | isBtConnected = true;
89 | }
90 | } catch (IOException e) {
91 | e.printStackTrace();
92 | }
93 | }
94 | void send(){
95 | try {
96 | btSocket.getOutputStream().write(data.getBytes(), 0, data.getBytes().length);
97 | } catch (IOException e) {
98 | throw new RuntimeException(e);
99 | }
100 | }
101 | @Override
102 | public void run(){
103 | connect();
104 | send();
105 | }
106 | }
107 | }
--------------------------------------------------------------------------------
/Android/app/src/main/java/com/example/fuzzycontapp/Fragments/GeneticAlgorithm.java:
--------------------------------------------------------------------------------
1 | package com.example.fuzzycontapp.Fragments;
2 |
3 | import static com.example.fuzzycontapp.Activities.MainActivity.MyThread.input;
4 | import static com.example.fuzzycontapp.Activities.MainActivity.MyThread.output;
5 |
6 | import android.os.Bundle;
7 |
8 | import androidx.annotation.NonNull;
9 | import androidx.fragment.app.Fragment;
10 |
11 | import android.os.StrictMode;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.Toast;
16 |
17 | import com.example.fuzzycontapp.R;
18 | import com.example.fuzzycontapp.databinding.FragmentBasinHoppingBinding;
19 | import com.example.fuzzycontapp.databinding.FragmentGeneticAlgorithmBinding;
20 | import com.example.fuzzycontapp.databinding.FragmentLoginBinding;
21 |
22 | import org.json.JSONException;
23 | import org.json.JSONObject;
24 |
25 | import java.io.IOException;
26 |
27 |
28 | public class GeneticAlgorithm extends Fragment {
29 | FragmentGeneticAlgorithmBinding binding;
30 | public static String title, x_start, x_finish, iterations, step;
31 | @Override
32 | public void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 |
35 | }
36 |
37 | @Override
38 | public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
39 | Bundle savedInstanceState) {
40 | binding = FragmentGeneticAlgorithmBinding.inflate(inflater, container, false);
41 |
42 | binding.optim.setOnClickListener(new View.OnClickListener() {
43 | @Override
44 | public void onClick(View v) {
45 | title = binding.title.getText().toString();
46 | x_start = binding.topBorder.getText().toString();
47 | x_finish = binding.bottomBorder.getText().toString();
48 | iterations = binding.indiv.getText().toString();
49 | step = binding.gener.getText().toString();
50 | SendData sendData = new SendData();
51 | sendData.start();
52 | binding.title.setText("");
53 | binding.topBorder.setText("");
54 | binding.bottomBorder.setText("");
55 | binding.indiv.setText("");
56 | binding.gener.setText("");
57 | Toast.makeText(getActivity(), R.string.saved,
58 | Toast.LENGTH_LONG).show();
59 | }
60 | });
61 |
62 |
63 | return binding.getRoot();
64 | }
65 | private void send_data(){
66 | String s = "";
67 | int SDK_INT = android.os.Build.VERSION.SDK_INT; // check
68 | if (SDK_INT > 8)
69 | {
70 | StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
71 | .permitAll().build();
72 | StrictMode.setThreadPolicy(policy);
73 | JSONObject request = new JSONObject();
74 | try {
75 | request.put("Command", "optimize");
76 | request.put("Title", title);
77 | request.put("x_start", x_start);
78 | request.put("x_finish", x_finish);
79 | request.put("iterations", iterations);
80 | request.put("step", step);
81 | request.put("type", "public");
82 | request.put("Type", "genetic");
83 | } catch (JSONException e) {
84 | e.printStackTrace();
85 | }
86 |
87 | output.println(request);
88 | output.flush();
89 | try {
90 | while(!input.ready());
91 | s = input.readLine();
92 | } catch (IOException e) {
93 | e.printStackTrace();
94 | }
95 | }
96 | }
97 | class SendData extends Thread {
98 | @Override
99 | public void run() {
100 | send_data();
101 | }
102 | }
103 | }
--------------------------------------------------------------------------------
/Android/app/src/main/res/layout/fragment_signup.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
13 |
18 |
19 |
26 |
37 |
49 |
61 |
73 |
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------