20 |
21 |
22 |
23 | /* This is a trivial JNI example where we use a native method
24 | * to return a new VM String.
25 | */
26 |
27 | //JavaVM *g_vm; // Can't have globals - SIGSEGV on server
28 |
29 | JNIEXPORT jstring JNICALL
30 | Java_eu_project_rapid_synthBenchmark_JniTest_stringFromJNI( JNIEnv* env,
31 | jobject thiz )
32 | {
33 | return (*env)->NewStringUTF(env, "Hello from JNI !");
34 | }
35 |
36 | jint JNI_OnLoad(JavaVM* vm, void* reserved)
37 | {
38 | //g_vm = vm;
39 | return JNI_VERSION_1_4;
40 | }
41 |
--------------------------------------------------------------------------------
/Rapid-DemoApp/libs/armeabi-v7a/libhello-jni.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/libs/armeabi-v7a/libhello-jni.so
--------------------------------------------------------------------------------
/Rapid-DemoApp/libs/armeabi/libhello-jni.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/libs/armeabi/libhello-jni.so
--------------------------------------------------------------------------------
/Rapid-DemoApp/libs/commons-compress-1.9.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/libs/commons-compress-1.9.jar
--------------------------------------------------------------------------------
/Rapid-DemoApp/libs/core-1.51.0.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/libs/core-1.51.0.0.jar
--------------------------------------------------------------------------------
/Rapid-DemoApp/libs/prov-1.51.0.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/libs/prov-1.51.0.0.jar
--------------------------------------------------------------------------------
/Rapid-DemoApp/libs/x86/libhello-jni.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/libs/x86/libhello-jni.so
--------------------------------------------------------------------------------
/Rapid-DemoApp/libs/x86_64/libhello-jni.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/libs/x86_64/libhello-jni.so
--------------------------------------------------------------------------------
/Rapid-DemoApp/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Rapid-DemoApp/project.properties:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Copyright (C) 2015, 2016 RAPID EU Project
3 | #
4 | # This library is free software; you can redistribute it and/or
5 | # modify it under the terms of the GNU Lesser General Public
6 | # License as published by the Free Software Foundation; either
7 | # version 2.1 of the License, or (at your option) any later version.
8 | #
9 | # This library is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | # Lesser General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU Lesser General Public
15 | # License along with this library; if not, write to the Free Software
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | ###############################################################################
18 | # This file is automatically generated by Android Tools.
19 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
20 | #
21 | # This file must be checked in Version Control Systems.
22 | #
23 | # To customize properties used by the Ant build system edit
24 | # "ant.properties", and override values to adapt the script to your
25 | # project structure.
26 | #
27 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
28 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
29 |
30 | # Project target.
31 | target=android-19
32 | android.library.reference.1=../AccelerationClient
33 |
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/drawable-hdpi/icon_dark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-hdpi/icon_dark.png
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/drawable-ldpi/icon_dark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-ldpi/icon_dark.png
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/drawable-mdpi/icon_dark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-mdpi/icon_dark.png
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/drawable-xhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-xhdpi/icon.png
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/drawable-xhdpi/icon_dark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable-xhdpi/icon_dark.png
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/drawable/icon.xcf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable/icon.xcf
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/drawable/prove.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable/prove.jpg
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/drawable/prove2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RapidProjectH2020/offloading-framework-android/6cf0c4bb0276039947a99fe2818d7cbf54f6a889/Rapid-DemoApp/res/drawable/prove2.jpg
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
25 |
26 |
32 |
33 |
34 |
35 |
43 |
44 |
49 |
50 |
56 |
57 |
62 |
63 |
64 |
65 |
66 |
74 |
75 |
81 |
82 |
89 |
90 |
96 |
97 |
104 |
105 |
106 |
107 |
108 |
116 |
117 |
122 |
123 |
129 |
130 |
135 |
136 |
141 |
142 |
143 |
151 |
152 |
153 |
154 |
155 |
180 |
181 |
182 |
194 |
195 |
201 |
202 |
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
24 | 128dp
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
21 |
22 |
23 | - 1 Clone
24 | - 2 Clones
25 | - 4 Clones
26 | - 8 Clones
27 |
28 |
29 |
30 | - 1
31 | - 2
32 | - 4
33 | - 8
34 |
35 |
36 |
37 | - 1
38 | - 2
39 | - 4
40 | - 8
41 |
42 |
43 |
44 | - 4 Queens
45 | - 5 Queens
46 | - 6 Queens
47 | - 7 Queens
48 | - 8 Queens
49 |
50 |
51 |
52 | - 4
53 | - 5
54 | - 6
55 | - 7
56 | - 8
57 |
58 |
59 |
60 | - 4
61 | - 5
62 | - 6
63 | - 7
64 | - 8
65 |
66 |
67 |
68 | - 1
69 | - 10
70 | - 100
71 | - 1000
72 |
73 |
74 |
75 | - -1
76 | - 0
77 | - 100
78 | - 256
79 | - 512
80 | - 768
81 | - 1000
82 | - 2000
83 | - 4000
84 | - 6000
85 | - 8000
86 | - 10000
87 |
88 |
89 |
90 | - "-1"
91 | - "0"
92 | - "1"
93 | - "2"
94 | - "3"
95 | - "4"
96 | - "5"
97 | - "6"
98 | - "7"
99 |
100 |
101 |
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 | 16dp
22 | 16dp
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
21 |
22 | ------------------------------------------
23 | RAPID Offloading Framework
24 | Test 1
25 | Test 2
26 | Test 3
27 | Scenario 1
28 | Scenario 2
29 | JNI test
30 | GVirtuS deviceQuery test
31 | Benchmark Bundle 1
32 | Benchmark Bundle 2
33 | All Bundles
34 | Puzzle Scenarios
35 | Testing code offloading
36 | Choose what to optimize by offloading
37 | Face Detection
38 | Virus Scanning
39 | Solve Sudoku
40 | Solve NQueens
41 | Always Local
42 | Always Remote
43 | Hybrid
44 | Energy
45 | Delay (Execution Time + Communication)
46 | Energy and Delay
47 | Local fraction [0, 1]
48 | Run All Experiments
49 | Number of VMs:
50 | Number of Queens:
51 | Number of Photos:
52 | MainActivity
53 | Settings
54 |
55 | Use Rapid Infrastructure or Direct connection with VM
56 | With Rapid infrastructure
57 | Direct connection to VM
58 |
59 | Choose the communication type
60 | Clear communication
61 | SSL communication
62 | Choose from methods annotations
63 |
64 | Insert VM\'s IP
65 | Remember settings
66 | Choose the remote device
67 | Start
68 | Connect to new VM
69 | Connect to previous VM
70 | If this device was connected previously to a VM, then the Registration Manager will try to connect to that VM again.
71 | Connect to nearby mobile devices
72 | Device not connected to Internet!\nYou can\'t connect to remote VMs on the cloud, only to nearby mobile devices for D2D offloading.
73 | Connected to VM in Clear
74 | Connected to VM in SSL
75 | Not Connected to VM
76 |
77 | Testing DSE and DFE implementation
78 | Test DSE performance
79 | Download file from Manager
80 | Upload file to Manager
81 | Test connection, UL, and DL
82 | Choose data rate:
83 | Test sending bytes 1000 times to clone
84 | Test receiving bytes 1000 times from clone
85 |
86 |
--------------------------------------------------------------------------------
/Rapid-DemoApp/res/values/style.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
21 |
26 |
--------------------------------------------------------------------------------
/Rapid-DemoApp/src/eu/project/rapid/demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (C) 2015, 2016 RAPID EU Project
3 | *
4 | * This library is free software; you can redistribute it and/or modify it under the terms of the
5 | * GNU Lesser General Public License as published by the Free Software Foundation; either version
6 | * 2.1 of the License, or (at your option) any later version.
7 | *
8 | * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 | * Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License along with this library;
13 | * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
14 | * 02110-1301 USA
15 | *******************************************************************************/
16 | package eu.project.rapid.demo;
17 |
18 | import java.security.Security;
19 |
20 | import android.app.Activity;
21 | import android.content.Context;
22 | import android.content.Intent;
23 | import android.content.SharedPreferences;
24 | import android.graphics.Color;
25 | import android.os.Bundle;
26 | import android.util.Log;
27 | import android.view.View;
28 | import android.widget.EditText;
29 | import android.widget.RadioGroup;
30 | import android.widget.RadioGroup.OnCheckedChangeListener;
31 | import eu.project.rapid.ac.DFE;
32 | import eu.project.rapid.common.RapidConstants.COMM_TYPE;
33 | import eu.project.rapid.common.RapidUtils;
34 |
35 | /**
36 | * The main activity for the Android program.
37 | *
38 | */
39 | public class MainActivity extends Activity {
40 |
41 | private static final String TAG = "MainActivity";
42 | public static final String KEY_VM_IP = "KEY_VM_IP";
43 | public static final String KEY_USE_RAPID_INFRASTRUCTURE = "KEY_USE_RAPID_INFRASTRUCTURE";
44 |
45 | private RadioGroup radioGroupStartAs;
46 | private RadioGroup radioGroupUseRapid;
47 | private EditText textVmIpAddress;
48 | private String vmIp;
49 |
50 | static {
51 | Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1);
52 | }
53 |
54 | /** Called when the activity is first created. */
55 | @Override
56 | public void onCreate(Bundle savedInstanceState) {
57 | super.onCreate(savedInstanceState);
58 | setContentView(R.layout.activity_main);
59 |
60 | radioGroupUseRapid = (RadioGroup) findViewById(R.id.radioGroupUseRapid);
61 | radioGroupUseRapid.setOnCheckedChangeListener(new OnUseRapidRadioChecked());
62 |
63 | radioGroupStartAs = (RadioGroup) findViewById(R.id.radioGroupStartAs);
64 | radioGroupStartAs.setOnCheckedChangeListener(new OnStartAsRadioChecked());
65 |
66 | textVmIpAddress = (EditText) findViewById(R.id.editTextIpAddress);
67 | SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
68 | vmIp = prefs.getString(KEY_VM_IP, null);
69 | textVmIpAddress.setText(vmIp);
70 | }
71 |
72 | public void onRadioCommunicationTypeChecked(View radioButton) {
73 |
74 | switch (radioButton.getId()) {
75 |
76 | case R.id.radio_clear_communication:
77 | DFE.commType = COMM_TYPE.CLEAR;
78 | Log.i(TAG, "The communication UE-VM should be performed in clear");
79 | break;
80 |
81 | case R.id.radio_ssl_communication:
82 | DFE.commType = COMM_TYPE.SSL;
83 | Log.i(TAG, "The communication UE-VM should be performed using SSL");
84 | break;
85 |
86 | case R.id.radio_choose_from_annotation_communication:
87 | Log.w(TAG, "TODO: The communication UE-VM will be decided based on methods' annotations");
88 | break;
89 | }
90 | }
91 |
92 | // Watch for button clicks
93 | public void onStartButton(View v) {
94 | Intent intent = new Intent(v.getContext(), StartExecution.class);
95 |
96 | // If the user is setting the IP of the VM automatically, we should check that the IP is
97 | // correctly formatted.
98 | if (radioGroupUseRapid.getCheckedRadioButtonId() == R.id.radioUseRapidNo) {
99 | vmIp = textVmIpAddress.getText().toString();
100 |
101 | if (!RapidUtils.validateIpAddress(vmIp)) {
102 | textVmIpAddress.setTextColor(Color.RED);
103 | } else {
104 | textVmIpAddress.setTextColor(Color.GREEN);
105 | Log.i(TAG, "Creating a connection with VM with IP: " + vmIp);
106 | intent.putExtra(KEY_VM_IP, vmIp);
107 | intent.putExtra(KEY_USE_RAPID_INFRASTRUCTURE, false);
108 | SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
109 | SharedPreferences.Editor editor = prefs.edit();
110 | editor.putString(KEY_VM_IP, vmIp);
111 | editor.commit();
112 | startActivity(intent);
113 | }
114 | } else {
115 | // Should use the Rapid infrastructure.
116 | intent.putExtra(KEY_USE_RAPID_INFRASTRUCTURE, true);
117 | startActivity(intent);
118 | }
119 | }
120 |
121 | private class OnStartAsRadioChecked implements OnCheckedChangeListener {
122 | public void onCheckedChanged(RadioGroup group, int checkedId) {
123 |
124 | switch (checkedId) {
125 | case R.id.radioStartAsNewVm:
126 | DFE.CONNECT_TO_PREVIOUS_VM = false;
127 | break;
128 |
129 | case R.id.radioStartAsOldVm:
130 | DFE.CONNECT_TO_PREVIOUS_VM = true;
131 | break;
132 |
133 | case R.id.radioStartAsD2D:
134 | break;
135 | }
136 | }
137 | }
138 |
139 | private class OnUseRapidRadioChecked implements OnCheckedChangeListener {
140 |
141 | public void onCheckedChanged(RadioGroup group, int checkedId) {
142 | switch (checkedId) {
143 | case R.id.radioUseRapidYes:
144 | textVmIpAddress.setVisibility(View.GONE);
145 | radioGroupStartAs.setVisibility(View.VISIBLE);
146 | break;
147 |
148 | case R.id.radioUseRapidNo:
149 | radioGroupStartAs.setVisibility(View.GONE);
150 | textVmIpAddress.setVisibility(View.VISIBLE);
151 | break;
152 | }
153 | }
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/Rapid-DemoApp/src/eu/project/rapid/sudoku/Sudoku.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (C) 2015, 2016 RAPID EU Project
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | *******************************************************************************/
18 | package eu.project.rapid.sudoku;
19 |
20 | import java.lang.reflect.Method;
21 |
22 | import eu.project.rapid.ac.DFE;
23 | import eu.project.rapid.ac.Remote;
24 | import eu.project.rapid.ac.Remoteable;
25 |
26 | /**
27 | * The Sudoku
class povides a static main
method allowing it to be called
28 | * from the command line to print the solution to a specified Sudoku problem.
29 | *
30 | *
31 | * The following is an example of a Sudoku problem:
32 | *
33 | *
34 | * -----------------------
35 | * | 8 | 4 2 | 6 |
36 | * | 3 4 | | 9 1 |
37 | * | 9 6 | | 8 4 |
38 | * -----------------------
39 | * | | 2 1 6 | |
40 | * | | | |
41 | * | | 3 5 7 | |
42 | * -----------------------
43 | * | 8 4 | | 7 5 |
44 | * | 2 6 | | 1 3 |
45 | * | 9 | 7 1 | 4 |
46 | * -----------------------
47 | *
48 | *
49 | * The goal is to fill in the missing numbers so that every row, column and box contains each of the
50 | * numbers 1-9
. Here is the solution to the problem above:
51 | *
52 | *
53 | * -----------------------
54 | * | 1 8 7 | 4 9 2 | 5 6 3 |
55 | * | 5 3 4 | 6 7 8 | 9 1 2 |
56 | * | 9 6 2 | 1 3 5 | 7 8 4 |
57 | * -----------------------
58 | * | 4 5 8 | 2 1 6 | 3 9 7 |
59 | * | 2 7 3 | 8 4 9 | 6 5 1 |
60 | * | 6 1 9 | 3 5 7 | 4 2 8 |
61 | * -----------------------
62 | * | 8 4 1 | 9 6 3 | 2 7 5 |
63 | * | 7 2 6 | 5 8 4 | 1 3 9 |
64 | * | 3 9 5 | 7 2 1 | 8 4 6 |
65 | * -----------------------
66 | *
67 | *
68 | * Note that the first row 187492563
contains each number exactly once, as does the
69 | * first column 159426873
, the upper-left box 187534962
, and every other
70 | * row, column and box.
71 | *
72 | *
73 | * The {@link #main(String[])} method encodes a problem as an array of strings, with one string
74 | * encoding each constraint in the problem in row-column-value format. Here is the problem again
75 | * with the indices indicated:
76 | *
77 | *
78 | * 0 1 2 3 4 5 6 7 8
79 | * -----------------------
80 | * 0 | 8 | 4 2 | 6 |
81 | * 1 | 3 4 | | 9 1 |
82 | * 2 | 9 6 | | 8 4 |
83 | * -----------------------
84 | * 3 | | 2 1 6 | |
85 | * 4 | | | |
86 | * 5 | | 3 5 7 | |
87 | * -----------------------
88 | * 6 | 8 4 | | 7 5 |
89 | * 7 | 2 6 | | 1 3 |
90 | * 8 | 9 | 7 1 | 4 |
91 | * -----------------------
92 | *
93 | *
94 | * The 8
in the upper left box of the puzzle is encoded as 018
(
95 | * 0
for the row, 1
for the column, and 8
for the value). The
96 | * 4
in the lower right box is encoded as 874
.
97 | *
98 | *
99 | * The full command-line invocation for the above puzzle is:
100 | *
101 | *
102 | * % java -cp . Sudoku 018 034 052 076 \
103 | *
104 | * 113 124 169 171 \
105 | *
106 | * 209 216 278 284 \
107 | *
108 | * 332 341 356 \
109 | *
110 | * 533 545 557 \
111 | *
112 | * 608 614 677 685 \
113 | *
114 | * 712 726 761 773 \
115 | *
116 | * 819 837 851 874 \
117 | *
118 | *
119 | *
120 | *
121 | * See Wikipedia: Sudoku for more information on
122 | * Sudoku.
123 | *
124 | *
125 | * The algorithm employed is similar to the standard backtracking
126 | * eight queens algorithm .
127 | *
128 | * @version 1.0
129 | * @author Bob Carpenter
130 | */
131 | public class Sudoku extends Remoteable {
132 |
133 | private static final long serialVersionUID = -3962977915411306215L;
134 |
135 | private transient DFE dfe;
136 |
137 | private int[][] matrix;
138 |
139 | private String[] input =
140 | {"006", "073", "102", "131", "149", "217", "235", "303", "345", "361", "378", "422", "465",
141 | "514", "521", "548", "582", "658", "679", "743", "752", "784", "818", "883"};
142 |
143 | public Sudoku(DFE dfe) {
144 | this.dfe = dfe;
145 | matrix = parseProblem(input);
146 | }
147 |
148 | @Remote
149 | public boolean localhasSolution() {
150 | return solve(0, 0, matrix);
151 | }
152 |
153 | public boolean solve(int i, int j, int[][] cells) {
154 | if (i == 9) {
155 | i = 0;
156 | if (++j == 9)
157 | return true;
158 | }
159 | if (cells[i][j] != 0)
160 | return solve(i + 1, j, cells);
161 | for (int val = 1; val <= 9; ++val) {
162 | if (legal(i, j, val, cells)) {
163 | cells[i][j] = val;
164 | if (solve(i + 1, j, cells))
165 | return true;
166 | }
167 | }
168 | cells[i][j] = 0;
169 | return false;
170 | }
171 |
172 | private boolean legal(int i, int j, int val, int[][] cells) {
173 | for (int k = 0; k < 9; ++k)
174 | if (val == cells[k][j])
175 | return false;
176 | for (int k = 0; k < 9; ++k)
177 | if (val == cells[i][k])
178 | return false;
179 | int boxRowOffset = (i / 3) * 3;
180 | int boxColOffset = (j / 3) * 3;
181 | for (int k = 0; k < 3; ++k)
182 | for (int m = 0; m < 3; ++m)
183 | if (val == cells[boxRowOffset + k][boxColOffset + m])
184 | return false;
185 | return true;
186 | }
187 |
188 | static int[][] parseProblem(String[] input) {
189 | int[][] problem = new int[9][9];
190 | for (int n = 0; n < input.length; ++n) {
191 | int i = Integer.parseInt(input[n].substring(0, 1));
192 | int j = Integer.parseInt(input[n].substring(1, 2));
193 | int val = Integer.parseInt(input[n].substring(2, 3));
194 | problem[i][j] = val;
195 | }
196 | return problem;
197 | }
198 |
199 | @Override
200 | public void copyState(Remoteable state) {}
201 |
202 | public boolean hasSolution() {
203 | Method toExecute;
204 | Class>[] paramTypes = null;
205 | Object[] paramValues = null;
206 | boolean result = false;
207 | try {
208 | toExecute = this.getClass().getDeclaredMethod("localhasSolution", paramTypes);
209 | result = (Boolean) dfe.execute(toExecute, paramValues, this);
210 | } catch (SecurityException e) {
211 | // Should never get here
212 | e.printStackTrace();
213 | throw e;
214 | } catch (NoSuchMethodException e) {
215 | // Should never get here
216 | e.printStackTrace();
217 | } catch (Throwable e) {
218 | // TODO Auto-generated catch block
219 | e.printStackTrace();
220 | }
221 | return result;
222 | }
223 | }
224 |
--------------------------------------------------------------------------------
/Rapid-DemoApp/src/eu/project/rapid/synthBenchmark/JniTest.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (C) 2015, 2016 RAPID EU Project
3 | *
4 | * This library is free software; you can redistribute it and/or modify it under the terms of the
5 | * GNU Lesser General Public License as published by the Free Software Foundation; either version
6 | * 2.1 of the License, or (at your option) any later version.
7 | *
8 | * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 | * Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License along with this library;
13 | * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
14 | * 02110-1301 USA
15 | *******************************************************************************/
16 | package eu.project.rapid.synthBenchmark;
17 |
18 | import java.lang.reflect.Method;
19 |
20 | import android.util.Log;
21 | import eu.project.rapid.ac.DFE;
22 | import eu.project.rapid.ac.Remoteable;
23 |
24 | public class JniTest extends Remoteable {
25 |
26 | /**
27 | *
28 | */
29 | private static final long serialVersionUID = 7407706990063388777L;
30 |
31 | private transient DFE dfe;
32 |
33 | public int temp = 0;
34 |
35 | public JniTest(DFE dfe) {
36 | this.dfe = dfe;
37 | }
38 |
39 | /*
40 | * A native method that is implemented by the 'hello-jni' native library, which is packaged with
41 | * this application.
42 | */
43 | public native String stringFromJNI();
44 |
45 | static {
46 | try {
47 | System.loadLibrary("hello-jni");
48 | } catch (UnsatisfiedLinkError e) {
49 | Log.i("JniTest", "Could not load native library, maybe this is running on the clone.");
50 | }
51 | }
52 |
53 | public String jniCaller() {
54 | Method toExecute;
55 | String result = null;
56 | try {
57 | toExecute = this.getClass().getDeclaredMethod("localjniCaller", (Class[]) null);
58 | result = (String) dfe.execute(toExecute, this);
59 | } catch (SecurityException e) {
60 | // Should never get here
61 | e.printStackTrace();
62 | throw e;
63 | } catch (NoSuchMethodException e) {
64 | // Should never get here
65 | e.printStackTrace();
66 | } catch (Throwable e) {
67 | // TODO Auto-generated catch block
68 | e.printStackTrace();
69 | }
70 | return result;
71 | }
72 |
73 | public String localjniCaller() {
74 | return stringFromJNI();
75 | }
76 |
77 | @Override
78 | public void copyState(Remoteable arg0) {
79 | // TODO Auto-generated method stub
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/Rapid-DemoApp/src/eu/project/rapid/synthBenchmark/TestRemoteable.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (C) 2015, 2016 RAPID EU Project
3 | *
4 | * This library is free software; you can redistribute it and/or modify it under the terms of the
5 | * GNU Lesser General Public License as published by the Free Software Foundation; either version
6 | * 2.1 of the License, or (at your option) any later version.
7 | *
8 | * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 | * Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License along with this library;
13 | * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
14 | * 02110-1301 USA
15 | *******************************************************************************/
16 | package eu.project.rapid.synthBenchmark;
17 |
18 | import java.lang.reflect.Method;
19 | import java.util.Random;
20 |
21 | import eu.project.rapid.ac.DFE;
22 | import eu.project.rapid.ac.Remoteable;
23 |
24 | /**
25 | * Simple class that tests offloading for trivial applications.
26 | */
27 | public class TestRemoteable extends Remoteable {
28 | private static final long serialVersionUID = 1L;
29 |
30 | public transient DFE dfe;
31 |
32 | public TestRemoteable(DFE dfe) {
33 | this.dfe = dfe;
34 | }
35 |
36 | public String cpuLoader1() {
37 | Method toExecute;
38 | String result = "";
39 | try {
40 | toExecute = this.getClass().getDeclaredMethod("localCpuLoader1", (Class[]) null);
41 | result = (String) dfe.execute(toExecute, this);
42 | } catch (SecurityException e) {
43 | e.printStackTrace();
44 | throw e;
45 | } catch (NoSuchMethodException e) {
46 | e.printStackTrace();
47 | } catch (Throwable e) {
48 | e.printStackTrace();
49 | }
50 | return result;
51 | }
52 |
53 | public String localCpuLoader1() {
54 | for (int i = 0; i < 10000; i++) {
55 | }
56 | return "cpuLoader1 finished";
57 | }
58 |
59 | public String cpuLoader2() {
60 | Method toExecute;
61 | String result = "";
62 | try {
63 | toExecute = this.getClass().getDeclaredMethod("localCpuLoader2", (Class[]) null);
64 | result = (String) dfe.execute(toExecute, this);
65 | } catch (SecurityException e) {
66 | // Should never get here
67 | e.printStackTrace();
68 | throw e;
69 | } catch (NoSuchMethodException e) {
70 | // Should never get here
71 | e.printStackTrace();
72 | } catch (Throwable e) {
73 | // TODO Auto-generated catch block
74 | e.printStackTrace();
75 | }
76 | return result;
77 | }
78 |
79 | public Long cpuLoader3(int seed) {
80 | Method toExecute;
81 | Class>[] paramTypes = {int.class};
82 | Object[] paramValues = {seed};
83 | Long result = null;
84 | try {
85 | toExecute = this.getClass().getDeclaredMethod("localCpuLoader3", paramTypes);
86 | result = (Long) dfe.execute(toExecute, paramValues, this);
87 | } catch (SecurityException e) {
88 | // Should never get here
89 | e.printStackTrace();
90 | throw e;
91 | } catch (NoSuchMethodException e) {
92 | // Should never get here
93 | e.printStackTrace();
94 | } catch (Throwable e) {
95 | // TODO Auto-generated catch block
96 | e.printStackTrace();
97 | }
98 | return result;
99 | }
100 |
101 | public String localCpuLoader2() {
102 | for (int i = 0; i < 500000; i++) {
103 | }
104 | return "cpuLoader2 finished";
105 | }
106 |
107 | public Long localCpuLoader3(int seed) {
108 | Random rand = new Random(seed);
109 | return rand.nextLong();
110 | }
111 |
112 | @Override
113 | public void copyState(Remoteable state) {
114 | // No fields to restore
115 | }
116 | }
117 |
--------------------------------------------------------------------------------