├── .github └── workflows │ └── nodejs.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── img ├── demo.gif ├── handoff.PNG └── simulation structure.PNG ├── package-lock.json ├── package.json ├── public ├── bs.png ├── index.html └── robots.txt └── src ├── App.js ├── App.test.js ├── HandoffVisualizer ├── Components │ ├── BootstrapDrop.jsx │ ├── BootstrapNav.css │ ├── BootstrapNav.jsx │ ├── Data.css │ ├── Data.jsx │ ├── Entrance.css │ ├── Entrance.jsx │ ├── Icons.css │ ├── Icons.jsx │ ├── Line.jsx │ ├── Node.css │ ├── Node.jsx │ ├── Plots.jsx │ └── Simulation.jsx ├── Handoff.css ├── Handoff.jsx └── img │ ├── arrow0.svg │ ├── arrow1.svg │ ├── arrow2.svg │ ├── arrow3.svg │ ├── bs.png │ ├── bs.svg │ ├── handoff.svg │ ├── handoff2(1).svg │ ├── handoff2.svg │ ├── handoff3.svg │ └── logo.svg ├── index.css ├── index.js ├── serviceWorker.js ├── setupTests.js └── utils.mjs /.github/workflows/nodejs.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | strategy: 18 | matrix: 19 | node-version: [10.x, 12.x] 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Use Node.js ${{ matrix.node-version }} 24 | uses: actions/setup-node@v1 25 | with: 26 | node-version: ${{ matrix.node-version }} 27 | - run: npm ci 28 | - run: npm run build --if-present 29 | - run: npm test 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "stable" 4 | cache: 5 | directories: 6 | - node_modules 7 | script: 8 | - npm run build 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Tony Chou 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 |

6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

14 | 15 | > 📶 Visualizing the transmission between users and base stations! 16 | 17 | Play with it! https://chonyy.github.io/handoff-visualizer/ 18 | 19 | Handoff is the **transition** for any given user of signal transmission from one base station to a geographically adjacent base station as the user moves around. In this project, we **visualize** the process of handoff by generating cars moving around the blocks and connecting them to different base stations based on different policies. 20 | 21 | This project is to **visualize** handoff and make the concept of handoff in wireless network easy to understand. **Different policies** are implemented to perform the handoff in different situations. The goal is to make the users try out all the different policies, understand the differences, and find out the most efficient policy. 22 | 23 | If your are interested in this visualiztion, please also check out the [handoff-simulator](https://github.com/chonyy/handoff-simulator). We want people to understand handoff in this visualizer project, and we **value the data** in that [handoff-simulator](https://github.com/chonyy/handoff-simulator). 24 | 25 | ## Simulation Structure 26 | 27 |

28 | 29 |

30 | Each node is a 20 * 20 (m^2) square. A block is composed of 24 nodes, whick makes the block size 120 * 80 (m^2). Cars are assummed to be moving on an extremely thin line path between blocks, the path doesn't take up any space. The velocity of the car is 20m/s. In our simulation, we iterate once in a second. The cars move one node, and all the data are calculated and updated every second. 31 | 32 | - **Velocity** = 72km/hr = 20m/s 33 | - **Probability of cars entrance** follows [Poisson distribution](https://en.wikipedia.org/wiki/Poisson_distribution) 34 | - **⋋** = 1 cars/ min [ P(t) = ⋋"e" ^(−"⋋" ) (t is in sec) ] 35 | - **Probability of cars turning** based on predefined value listed below 36 | - **Received Power Calculation** explained below 37 | 38 | ### Car Entrance Distribution 39 | 40 | The probability of the entrance follows [Poisson distribution](https://en.wikipedia.org/wiki/Poisson_distribution) and 41 | 42 | In our simultation 43 | 44 | - **⋋** = 0.0167 cars/ sec 45 | - **k** = 1 46 | 47 | ### Received Power 48 | 49 | The received power is calculated by the formula below. Read [ScienceDirect](https://www.sciencedirect.com/topics/engineering/received-signal-power) to dig deeper. 50 | 51 | - Base station transmission Pt(mW) = -50 dBm 52 | - Base = 1mW 53 | - 10log(Pt / Base) = dBm 54 | - First-meter path loss = 10 dBm 55 | - **P0 = -50 dBm** 56 | - **Pd = -50 - 10 - 20log(d(m) / 1m)** 57 | 58 | ## Policies Pseudocode 59 | 60 | Received Power referred to **P**, base station referered to **B**. 61 | 62 | Threshold referred to **T**, entrophy referred to **E**. 63 | 64 | ### Best Policy 65 | 66 | ```javascript 67 | if (Pnew > Pold) { 68 | car.bs = Bnew; 69 | car.power = Pnew; 70 | } 71 | ``` 72 | 73 | ### Threshold Policy 74 | 75 | ```javascript 76 | if (Pnew > Pold && Pold < T) { 77 | car.bs = Bnew; 78 | car.power = Pnew; 79 | } 80 | ``` 81 | 82 | ### Entrophy Policy 83 | 84 | ```javascript 85 | if (Pnew > Pold + E) { 86 | car.bs = Bnew; 87 | car.power = Pnew; 88 | } 89 | ``` 90 | 91 | ### Minimum Policy 92 | 93 | ```javascript 94 | if (Pnew < Pmin) { 95 | car.bs = Bnew; 96 | car.power = Pnew; 97 | } 98 | ``` 99 | 100 | ## Demo Video 101 | 102 |

103 | demo video 106 |

107 | 108 | ## What is handoff? 109 | 110 |

111 | 112 |

113 | 114 | [Handoff](https://searchmobilecomputing.techtarget.com/definition/handoff) is the **transition** for any given user of signal transmission from one base station to a geographically adjacent base station as the user **moves around**. 115 | 116 | Each time a mobile or portable cellular subscriber passes from one cellinto another, the network automatically **switches** coverage responsibility from one basestation to another. Each base-station transition, as well as the switching processor sequence itself, is called handoff. 117 | 118 | ## Policies parameter value 119 | 120 | The different parameters for each policy are listed below. 121 | 122 | | Parameters | Value | 123 | | ---------- | :------: | 124 | | Threshold | -108 dBm | 125 | | Entrophy | 5 dBm | 126 | | Minimum | -112 dBm | 127 | 128 | ## Posssibility of turning 129 | 130 | The possibility of changing direction when encountering intersection is listed below. 131 | 132 | ### Intersection with four roads 133 | 134 | | Direction | Possibility | 135 | | ----------- | :---------: | 136 | | Go straight | 1/2 | 137 | | Turn right | 1/3 | 138 | | Turn left | 1/6 | 139 | 140 | ### Intersection with three roads 141 | 142 | | Direction | Possibility | 143 | | ---------- | :---------: | 144 | | Turn right | 1/2 | 145 | | Turn left | 1/2 | 146 | 147 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 148 | 149 | ## Available Scripts 150 | 151 | In the project directory, you can run: 152 | 153 | ### `npm start` 154 | 155 | Runs the app in the development mode.
156 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 157 | 158 | The page will reload if you make edits.
159 | You will also see any lint errors in the console. 160 | 161 | ### `npm test` 162 | 163 | Launches the test runner in the interactive watch mode.
164 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 165 | 166 | ### `npm run build` 167 | 168 | Builds the app for production to the `build` folder.
169 | It correctly bundles React in production mode and optimizes the build for the best performance. 170 | 171 | The build is minified and the filenames include the hashes.
172 | Your app is ready to be deployed! 173 | 174 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 175 | 176 | ### `npm run eject` 177 | 178 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 179 | 180 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 181 | 182 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 183 | 184 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 185 | 186 | ## Learn More 187 | 188 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 189 | 190 | To learn React, check out the [React documentation](https://reactjs.org/). 191 | 192 | ### Code Splitting 193 | 194 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 195 | 196 | ### Analyzing the Bundle Size 197 | 198 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 199 | 200 | ### Making a Progressive Web App 201 | 202 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 203 | 204 | ### Advanced Configuration 205 | 206 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 207 | 208 | ### Deployment 209 | 210 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 211 | 212 | ### `npm run build` fails to minify 213 | 214 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 215 | -------------------------------------------------------------------------------- /img/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chonyy/handoff-visualizer/e7f10a04cc8b74c033e536a7842d63c315c000d7/img/demo.gif -------------------------------------------------------------------------------- /img/handoff.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chonyy/handoff-visualizer/e7f10a04cc8b74c033e536a7842d63c315c000d7/img/handoff.PNG -------------------------------------------------------------------------------- /img/simulation structure.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chonyy/handoff-visualizer/e7f10a04cc8b74c033e536a7842d63c315c000d7/img/simulation structure.PNG -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "newhandoff", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^4.2.4", 7 | "@testing-library/react": "^9.4.0", 8 | "@testing-library/user-event": "^7.2.1", 9 | "bootstrap": "^4.4.1", 10 | "plotly.js": "^1.52.2", 11 | "react": "^16.12.0", 12 | "react-bootstrap": "^1.0.0-beta.16", 13 | "react-dom": "^16.12.0", 14 | "react-plotly.js": "^2.4.0", 15 | "react-scripts": "3.4.0" 16 | }, 17 | "homepage": "http://chonyy.github.io/handoff-visualizer", 18 | "scripts": { 19 | "start": "react-scripts start", 20 | "build": "react-scripts build", 21 | "test": "react-scripts test", 22 | "eject": "react-scripts eject", 23 | "predeploy": "npm run build", 24 | "deploy": "gh-pages -d build" 25 | }, 26 | "eslintConfig": { 27 | "extends": "react-app" 28 | }, 29 | "browserslist": { 30 | "production": [ 31 | ">0.2%", 32 | "not dead", 33 | "not op_mini all" 34 | ], 35 | "development": [ 36 | "last 1 chrome version", 37 | "last 1 firefox version", 38 | "last 1 safari version" 39 | ] 40 | }, 41 | "devDependencies": { 42 | "gh-pages": "^2.2.0" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /public/bs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chonyy/handoff-visualizer/e7f10a04cc8b74c033e536a7842d63c315c000d7/public/bs.png -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 12 | Wireless Handoff Visualizer 13 | 14 | 15 | 16 |
17 | 18 | 19 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Handoff from './HandoffVisualizer/Handoff' 3 | 4 | function App() { 5 | return ( 6 | 7 | ); 8 | } 9 | 10 | export default App; 11 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | import ReactDOM from 'react-dom'; 4 | import App from './App'; 5 | 6 | it('renders without crashing', () => { 7 | const div = document.createElement('div'); 8 | ReactDOM.render(, div); 9 | }); 10 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/Components/BootstrapDrop.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import Dropdown from "react-bootstrap/Dropdown"; 3 | 4 | export default class BootstrapDrop extends Component { 5 | handledrop(clicked) { 6 | let policyobj = this.props.policyobj; 7 | if (clicked === 0) { 8 | document.getElementById("dropdown-basic").innerHTML = "Best Policy"; 9 | policyobj.policy = 0; 10 | } else if (clicked === 1) { 11 | document.getElementById("dropdown-basic").innerHTML = 12 | "Threshsold Policy"; 13 | policyobj.policy = 1; 14 | } else if (clicked === 2) { 15 | document.getElementById("dropdown-basic").innerHTML = 16 | "Entrophy Policy"; 17 | policyobj.policy = 2; 18 | } else if (clicked === 3) { 19 | document.getElementById("dropdown-basic").innerHTML = 20 | "Minimum Policy"; 21 | policyobj.policy = 3; 22 | } 23 | } 24 | 25 | render() { 26 | return ( 27 | 28 | 33 | Best Policy 34 | 35 | 36 | 37 | this.handledrop(0)}> 38 | Best Policy 39 | 40 | this.handledrop(1)}> 41 | Threshold Policy 42 | 43 | this.handledrop(2)}> 44 | Entrophy Policy 45 | 46 | this.handledrop(3)}> 47 | Minimum Policy 48 | 49 | 50 | 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/Components/BootstrapNav.css: -------------------------------------------------------------------------------- 1 | .navbarlinks { 2 | margin-left: 30px; 3 | margin-right: 30px; 4 | font-weight: 400; 5 | } 6 | 7 | .navbrand { 8 | font-weight: 600; 9 | } -------------------------------------------------------------------------------- /src/HandoffVisualizer/Components/BootstrapNav.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { Navbar, Nav } from "react-bootstrap"; 3 | import "./BootstrapNav.css"; 4 | 5 | export default class BootstrapNav extends Component { 6 | render() { 7 | return ( 8 |
9 | 16 | 17 | {" "} 25 | Wireless Network Handoff Visualizer 26 | 27 | 28 | 29 | 55 | 56 | 57 |
58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/Components/Data.css: -------------------------------------------------------------------------------- 1 | .data { 2 | padding: 5px 20px; 3 | font-size: 2.4vw; 4 | border-radius: 25%; 5 | text-align: center; 6 | } 7 | 8 | .word { 9 | color: #274455; 10 | font-size: 1vw; 11 | } 12 | 13 | .cars { 14 | color: #ffc400; 15 | font-weight: bold; 16 | } 17 | 18 | .handoffs { 19 | color: #fc913a; 20 | font-weight: bold; 21 | } 22 | 23 | .power { 24 | color: #ff4e50; 25 | font-weight: bold; 26 | } 27 | 28 | .plotlycontainer { 29 | width: 18vw; 30 | height: 8vw; 31 | margin: 5px 0; 32 | } -------------------------------------------------------------------------------- /src/HandoffVisualizer/Components/Data.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import createPlotlyComponent from "react-plotly.js/factory"; 3 | import Plotly from "plotly.js/dist/plotly-cartesian"; 4 | import "./Data.css"; 5 | 6 | const Plot = createPlotlyComponent(Plotly); 7 | let carslist = []; 8 | let handoffslist = []; 9 | let powerlist = []; 10 | let carcntlist = []; 11 | let handcntlist = []; 12 | let powercntlist = []; 13 | let carcnt = 0; 14 | let handcnt = 0; 15 | let powercnt = 0; 16 | let init = 0; 17 | 18 | export default class Data extends Component { 19 | constructor(props) { 20 | super(props); 21 | 22 | this.state = {}; 23 | } 24 | 25 | render() { 26 | let type = this.props.type; 27 | let data = this.props.data; 28 | let typename = ""; 29 | let extra = ""; 30 | let xlist = []; 31 | let list = []; 32 | if (type === "cars") { 33 | typename = "Cars"; 34 | carslist.push(data); 35 | carcntlist.push(carcnt); 36 | carcnt++; 37 | xlist = carcntlist; 38 | list = carslist; 39 | init = 4; 40 | } else if (type === "handoffs") { 41 | typename = "Handoffs"; 42 | handoffslist.push(data); 43 | handcntlist.push(handcnt); 44 | handcnt++; 45 | xlist = handcntlist; 46 | list = handoffslist; 47 | init = 0; 48 | } else if (type === "power") { 49 | typename = "Average Power"; 50 | extra = "dBm"; 51 | data = data.toFixed(2); 52 | powerlist.push(data); 53 | powercntlist.push(powercnt); 54 | powercnt++; 55 | xlist = powercntlist; 56 | list = powerlist; 57 | init = -103; 58 | } 59 | // console.log(xlist, list); 60 | return ( 61 |
62 |
63 |
{typename}
64 |
{`${data} ${extra}`}
65 |
66 |
67 | 93 |
94 |
95 | ); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/Components/Entrance.css: -------------------------------------------------------------------------------- 1 | .arrow0 { 2 | background-image: url("../img/arrow0.svg"); 3 | background-size: cover; 4 | } 5 | 6 | .arrow1 { 7 | background-image: url("../img/arrow1.svg"); 8 | background-size: cover; 9 | } 10 | 11 | .arrow2 { 12 | background-image: url("../img/arrow2.svg"); 13 | background-size: cover; 14 | } 15 | 16 | .arrow3 { 17 | background-image: url("../img/arrow3.svg"); 18 | background-size: cover; 19 | } 20 | 21 | .arrowsize { 22 | width: 4.2vw; 23 | height: 4.2vw; 24 | } 25 | 26 | .entering { 27 | animation-name: enterAnimation; 28 | animation-duration: 0.6s; 29 | animation-timing-function: ease-out; 30 | animation-delay: 0; 31 | animation-direction: alternate; 32 | animation-iteration-count: 1; 33 | animation-fill-mode: forwards; 34 | animation-play-state: running; 35 | } 36 | 37 | @keyframes enterAnimation { 38 | 0% { 39 | transform: scale(1); 40 | border-radius: 0px; 41 | } 42 | 43 | 25% { 44 | transform: scale(1.5); 45 | filter: invert(23%) sepia(11%) saturate(4889%) hue-rotate(115deg) brightness(95%) contrast(104%); 46 | } 47 | 48 | 50% { 49 | transform: scale(2); 50 | border-radius: 100%; 51 | filter: invert(44%) sepia(91%) saturate(3801%) hue-rotate(135deg) brightness(92%) contrast(102%); 52 | } 53 | 54 | 75% { 55 | transform: scale(1.5); 56 | filter: invert(23%) sepia(11%) saturate(4889%) hue-rotate(115deg) brightness(95%) contrast(104%); 57 | } 58 | 59 | 100% { 60 | transform: scale(1); 61 | border-radius: 0px; 62 | } 63 | } 64 | 65 | .entering { 66 | animation-name: enterAnimation; 67 | animation-duration: 0.6s; 68 | animation-timing-function: ease-out; 69 | animation-delay: 0; 70 | animation-direction: alternate; 71 | animation-iteration-count: 1; 72 | animation-fill-mode: forwards; 73 | animation-play-state: running; 74 | } 75 | 76 | @keyframes enterAnimation { 77 | 0% { 78 | transform: scale(1); 79 | border-radius: 0px; 80 | } 81 | 82 | 25% { 83 | transform: scale(1.5); 84 | filter: invert(23%) sepia(11%) saturate(4889%) hue-rotate(115deg) brightness(95%) contrast(104%); 85 | } 86 | 87 | 50% { 88 | transform: scale(2); 89 | border-radius: 100%; 90 | filter: invert(44%) sepia(91%) saturate(3801%) hue-rotate(135deg) brightness(92%) contrast(102%); 91 | } 92 | 93 | 75% { 94 | transform: scale(1.5); 95 | filter: invert(23%) sepia(11%) saturate(4889%) hue-rotate(115deg) brightness(95%) contrast(104%); 96 | } 97 | 98 | 100% { 99 | transform: scale(1); 100 | border-radius: 0px; 101 | } 102 | } 103 | 104 | .leaving { 105 | animation-name: leaveAnimation; 106 | animation-duration: 0.6s; 107 | animation-timing-function: ease-out; 108 | animation-delay: 0; 109 | animation-direction: alternate; 110 | animation-iteration-count: 1; 111 | animation-fill-mode: forwards; 112 | animation-play-state: running; 113 | } 114 | 115 | @keyframes leaveAnimation { 116 | 0% { 117 | transform: scale(1) rotate(180deg); 118 | border-radius: 0px; 119 | } 120 | 121 | 25% { 122 | transform: scale(1.5) rotate(180deg); 123 | filter: invert(12%) sepia(58%) saturate(4933%) hue-rotate(350deg) brightness(80%) contrast(87%); 124 | } 125 | 126 | 50% { 127 | transform: scale(2) rotate(180deg); 128 | border-radius: 100%; 129 | filter: invert(18%) sepia(75%) saturate(1692%) hue-rotate(335deg) brightness(120%) contrast(98%); 130 | } 131 | 132 | 75% { 133 | transform: scale(1.5) rotate(180deg); 134 | filter: invert(12%) sepia(58%) saturate(4933%) hue-rotate(350deg) brightness(80%) contrast(87%); 135 | } 136 | 137 | 100% { 138 | transform: scale(1) rotate(180deg); 139 | border-radius: 0px; 140 | } 141 | } -------------------------------------------------------------------------------- /src/HandoffVisualizer/Components/Entrance.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import "./Entrance.css"; 3 | 4 | export default class Entrance extends Component { 5 | constructor(props) { 6 | super(props); 7 | 8 | this.state = { 9 | row: this.props.row, 10 | col: this.props.col, 11 | dir: this.props.dir, 12 | enter: this.props.enter 13 | }; 14 | } 15 | 16 | componentDidMount() { 17 | let row = this.state.row; 18 | let col = this.state.col; 19 | let dir = this.state.dir; 20 | let enter = this.state.enter; 21 | let entrancenode = document.getElementById(`r${row}c${col}`); 22 | if (entrancenode !== null) { 23 | let result = getstyle(entrancenode, dir, enter); 24 | this.setState({ style: result.style, arrowimg: result.arrowimg }); 25 | } 26 | } 27 | 28 | render() { 29 | let entrancestyle = this.state.style; 30 | let arrowimg = this.state.arrowimg; 31 | let entering = 32 | this.state.enter === 0 33 | ? "entering" 34 | : this.state.enter === 1 35 | ? "leaving" 36 | : ""; 37 | return ( 38 |
42 | ); 43 | } 44 | } 45 | 46 | function getstyle(node, dir, enter) { 47 | let offset = getOffset(node); 48 | var x = 0; 49 | var y = 0; 50 | var bg = ""; 51 | 52 | if (dir === 1) { 53 | x = offset.left - 85; 54 | y = offset.top - 25; 55 | bg = `arrow${dir}`; 56 | } else if (dir === 0) { 57 | x = offset.left - 25; 58 | y = offset.top + 35; 59 | bg = `arrow${dir}`; 60 | } else if (dir === 2) { 61 | x = offset.left - 25; 62 | y = offset.top - 85; 63 | bg = `arrow${dir}`; 64 | } else if (dir === 3) { 65 | x = offset.left + 35; 66 | y = offset.top - 25; 67 | bg = `arrow${dir}`; 68 | } 69 | 70 | let style = { 71 | padding: "0px", 72 | margin: "0px", 73 | position: "absolute", 74 | top: y + "px", 75 | left: x + "px" 76 | }; 77 | 78 | return { 79 | style: style, 80 | arrowimg: bg 81 | }; 82 | } 83 | 84 | function getOffset(el) { 85 | var rect = el.getBoundingClientRect(); 86 | return { 87 | left: rect.left + window.pageXOffset, 88 | top: rect.top + window.pageYOffset, 89 | width: rect.width || el.offsetWidth, 90 | height: rect.height || el.offsetHeight 91 | }; 92 | } 93 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/Components/Icons.css: -------------------------------------------------------------------------------- 1 | .icons-description { 2 | display: flex; 3 | flex-direction: column; 4 | justify-content: center; 5 | align-items: center; 6 | margin-top: 1.2vw; 7 | } 8 | 9 | .icon-row { 10 | display: flex; 11 | flex-direction: row; 12 | margin: 5px; 13 | width: 100%; 14 | } 15 | 16 | .ms { 17 | background-color: rgb(235, 95, 118); 18 | color: white; 19 | font-weight: bold; 20 | text-align: center; 21 | display: flex; 22 | align-items: center; 23 | justify-content: center; 24 | font-size: 15px; 25 | } 26 | 27 | .legend { 28 | font-size: 1.05vw; 29 | } 30 | 31 | .bs { 32 | background-image: url(../img/bs.svg); 33 | background-color: #ffc952; 34 | background-size: cover; 35 | } 36 | 37 | .first { 38 | width: 1.85vw; 39 | height: 1.85vw; 40 | } 41 | 42 | .second { 43 | margin-left: 1.5vw; 44 | } 45 | 46 | .third { 47 | font-weight: bold; 48 | font-size: 0.8vw; 49 | text-align: center; 50 | } 51 | 52 | .path { 53 | background-color: #34314c; 54 | } 55 | 56 | .block { 57 | background-color: #47b8e0; 58 | } 59 | 60 | .transmission { 61 | margin-top: 0.8vw; 62 | height: 5px; 63 | width: 1.85vw; 64 | background-color: #ffc952; 65 | } 66 | 67 | .entrancee { 68 | background-size: cover; 69 | background-image: url(../img/arrow1.svg); 70 | } 71 | 72 | .enteringg { 73 | background-size: cover; 74 | background-image: url(../img/arrow1.svg); 75 | filter: invert(44%) sepia(91%) saturate(3801%) hue-rotate(135deg) brightness(92%) contrast(102%); 76 | } 77 | 78 | .leavingg { 79 | background-size: cover; 80 | background-image: url(../img/arrow3.svg); 81 | filter: invert(18%) sepia(75%) saturate(1692%) hue-rotate(335deg) brightness(120%) contrast(98%); 82 | } -------------------------------------------------------------------------------- /src/HandoffVisualizer/Components/Icons.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import "./Icons.css"; 3 | 4 | export default class Icons extends Component { 5 | constructor(props) { 6 | super(props); 7 | 8 | this.state = {}; 9 | } 10 | 11 | render() { 12 | return ( 13 |
14 |
15 |
-103
16 |
MS, Car (Power)
17 |
18 |
19 |
20 |
BS, Base station
21 |
22 |
23 |
24 |
Servicing
25 |
26 |
27 |
28 |
MS Path
29 |
30 |
31 |
32 |
Block
33 |
34 |
35 |
36 |
Handoff Made
37 |
38 |
39 |
40 |
41 |
MS Entrance
42 |
43 |
44 |
(Cars can only enter or leave here)
45 |
46 |
47 |
Car Entering
48 |
49 |
50 |
51 |
Car leaving
52 |
53 |
54 | ); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/Components/Line.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | 3 | export default class Line extends Component { 4 | constructor(props) { 5 | super(props); 6 | this.state = { 7 | row: this.props.row, 8 | col: this.props.col, 9 | basestaion: this.props.bs 10 | }; 11 | } 12 | 13 | componentDidMount() { 14 | let row = this.state.row; 15 | let col = this.state.col; 16 | let basestaion = this.state.basestaion; 17 | let movingnode = document.getElementById(`r${row}c${col}`); 18 | let bs = document.getElementById(`bs${basestaion}`); 19 | let linestyle = {}; 20 | if (movingnode !== null && bs !== null) { 21 | linestyle = connect(bs, movingnode, "#ffc952", 5); 22 | this.setState({ linestyle: linestyle }); 23 | } 24 | } 25 | 26 | render() { 27 | let row = this.props.row; 28 | let col = this.props.col; 29 | let basestaion = this.props.bs; 30 | let handoff = this.props.handoff; 31 | let linestyle = this.state.linestyle; 32 | let handoffstyle = {}; 33 | let movingnode = document.getElementById(`r${row}c${col}`); 34 | let bs = document.getElementById(`bs${basestaion}`); 35 | if (movingnode !== null && bs !== null) { 36 | linestyle = connect(bs, movingnode, "#ffc952", 5); 37 | } 38 | if (handoff && movingnode !== null) { 39 | handoffstyle = drawhandoff(movingnode); 40 | } else { 41 | handoffstyle = { display: "none" }; 42 | } 43 | 44 | return ( 45 | <> 46 |
47 |
48 | 49 | ); 50 | } 51 | } 52 | 53 | function drawhandoff(node) { 54 | var nodeOff = getOffset(node); 55 | var x = nodeOff.left - 0.7 * nodeOff.width; 56 | var y = nodeOff.top - 90; 57 | let handoffstyle = { 58 | padding: "0px", 59 | margin: "0px", 60 | width: "80px", 61 | height: "80px", 62 | position: "absolute", 63 | top: y + "px", 64 | left: x + "px" 65 | }; 66 | return handoffstyle; 67 | } 68 | 69 | function connect(div1, div2, color, thickness) { 70 | var off1 = getOffset(div1); 71 | var off2 = getOffset(div2); 72 | // bottom right 73 | var x1 = off1.left + 0.5 * off1.width; 74 | var y1 = off1.top + 0.5 * off1.height; 75 | // top right 76 | var x2 = off2.left + 0.5 * off2.width; 77 | var y2 = off2.top + 0.5 * off2.height; 78 | // distance 79 | var length = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); 80 | // center 81 | var cx = (x1 + x2) / 2 - length / 2; 82 | var cy = (y1 + y2) / 2 - thickness / 2; 83 | // angle 84 | var angle = Math.atan2(y1 - y2, x1 - x2) * (180 / Math.PI); 85 | // make hr 86 | 87 | let linestyle = { 88 | padding: "0px", 89 | margin: "0px", 90 | height: thickness + "px", 91 | backgroundColor: color, 92 | lineHeight: "1px", 93 | position: "absolute", 94 | left: cx + "px", 95 | top: cy + "px", 96 | width: length + "px", 97 | transform: "rotate(" + angle + "deg)", 98 | opacity: 0.5 99 | }; 100 | 101 | return linestyle; 102 | } 103 | 104 | function getOffset(el) { 105 | var rect = el.getBoundingClientRect(); 106 | return { 107 | left: rect.left + window.pageXOffset, 108 | top: rect.top + window.pageYOffset, 109 | width: rect.width || el.offsetWidth, 110 | height: rect.height || el.offsetHeight 111 | }; 112 | } 113 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/Components/Node.css: -------------------------------------------------------------------------------- 1 | .node { 2 | width: 1.68vw; 3 | height: 1.68vw; 4 | background-color: #47b8e0; 5 | color: white; 6 | font-weight: bold; 7 | text-align: center; 8 | display: flex; 9 | align-items: center; 10 | justify-content: center; 11 | } 12 | 13 | .visiting { 14 | background-color: #ff7473; 15 | font-size: 0.85vw; 16 | } 17 | 18 | .path { 19 | background-color: #34314c; 20 | box-shadow: inset 0 0 0 1px #aaa; 21 | } 22 | 23 | .bs { 24 | background-image: url(../img/bs.svg); 25 | background-color: #ffc952; 26 | box-shadow: inset 0 0 0 2px #333; 27 | } 28 | 29 | .node-visited { 30 | animation-name: visitedAnimation; 31 | animation-duration: 0.6s; 32 | animation-timing-function: ease-out; 33 | animation-delay: 0; 34 | animation-direction: alternate; 35 | animation-iteration-count: 1; 36 | animation-fill-mode: forwards; 37 | animation-play-state: running; 38 | } 39 | 40 | @keyframes visitedAnimation { 41 | 0% { 42 | transform: scale(1); 43 | background-color: rgba(255, 146, 145, 0.8); 44 | border-radius: 0px; 45 | } 46 | 47 | 25% { 48 | transform: scale(1.25); 49 | background-color: rgba(255, 131, 130, 0.8); 50 | } 51 | 52 | 50% { 53 | transform: scale(1.5); 54 | background-color: rgba(255, 116, 115, 0.8); 55 | border-radius: 100%; 56 | } 57 | 58 | 75% { 59 | transform: scale(1.25); 60 | background-color: rgba(255, 131, 130, 0.8); 61 | } 62 | 63 | 100% { 64 | transform: scale(1); 65 | background-color: rgba(255, 146, 145, 0.8); 66 | border-radius: 0px; 67 | } 68 | } 69 | 70 | .handoff { 71 | background-image: url(../img/handoff3.svg); 72 | background-size: cover; 73 | filter: invert(50%) sepia(98%) saturate(2300%) hue-rotate(4deg) brightness(96%) contrast(101%); 74 | 75 | animation-name: handoffAnimation; 76 | animation-duration: 0.6s; 77 | animation-timing-function: ease-out; 78 | animation-delay: 0; 79 | animation-direction: alternate; 80 | animation-iteration-count: 1; 81 | animation-fill-mode: forwards; 82 | animation-play-state: running; 83 | } 84 | 85 | @keyframes handoffAnimation { 86 | 0% { 87 | transform: scale(1); 88 | border-radius: 0px; 89 | } 90 | 91 | 25% { 92 | transform: scale(1.25); 93 | } 94 | 95 | 50% { 96 | transform: scale(1.5); 97 | border-radius: 100%; 98 | } 99 | 100 | 75% { 101 | transform: scale(1.25); 102 | } 103 | 104 | 100% { 105 | transform: scale(1); 106 | border-radius: 0px; 107 | } 108 | } -------------------------------------------------------------------------------- /src/HandoffVisualizer/Components/Node.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import "./Node.css"; 3 | 4 | export default class Node extends Component { 5 | render() { 6 | let id = 7 | this.props.bs >= 0 8 | ? "bs" + this.props.bs 9 | : "r" + this.props.row + "c" + this.props.col; 10 | 11 | let visitingclass = this.props.visiting 12 | ? "visiting node-visited" 13 | : this.props.bs >= 0 14 | ? "bs" 15 | : this.props.path 16 | ? "path" 17 | : ""; 18 | let value = this.props.visiting 19 | ? `${Math.sign(this.props.power) * 20 | Math.round(Math.abs(this.props.power))}` 21 | : ""; 22 | 23 | return ( 24 |
25 | {value} 26 |
27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/Components/Plots.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import Data from "./Data"; 3 | 4 | export default class Plots extends Component { 5 | render() { 6 | let cars = this.props.cars; 7 | let handoffs = this.props.handoffs; 8 | let power = this.props.power; 9 | 10 | return ( 11 |
12 |
13 | 14 | 15 | 16 |
17 |
18 | ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/Components/Simulation.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import uuidv4 from "uuid/v4"; 3 | import Node from "./Node"; 4 | import Line from "./Line"; 5 | import Entrance from "./Entrance"; 6 | 7 | export default class Simulation extends Component { 8 | render() { 9 | let grid = this.props.grid; 10 | let cars = this.props.cars; 11 | let entrances = this.props.entrances; 12 | 13 | return ( 14 |
15 |
16 |
17 | {grid.map(row => { 18 | return ( 19 |
20 | {row.map(node => { 21 | return ( 22 | 32 | ); 33 | })} 34 |
35 | ); 36 | })} 37 |
38 |
39 | {cars.map(car => { 40 | return ( 41 | 48 | ); 49 | })} 50 |
51 |
52 | {entrances.map(e => { 53 | let entering = -1; 54 | if (e.carenter === 0) entering = 0; 55 | else if (e.carenter === 1) entering = 1; 56 | e.carenter = -1; 57 | return ( 58 | 65 | ); 66 | })} 67 |
68 |
69 |
70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/Handoff.css: -------------------------------------------------------------------------------- 1 | .board { 2 | margin-top: 100px; 3 | display: flex; 4 | flex-direction: column; 5 | background-color: #34314c; 6 | } 7 | 8 | .roww { 9 | display: flex; 10 | flex-direction: row; 11 | } 12 | 13 | .datas { 14 | border: 2px solid darkolivegreen; 15 | display: flex; 16 | flex-direction: column; 17 | align-items: center; 18 | justify-content: space-around; 19 | border-radius: 10px; 20 | margin: 30px; 21 | } 22 | 23 | .firstRow { 24 | display: flex; 25 | flex-direction: row; 26 | margin: 0; 27 | } 28 | 29 | body { 30 | background-color: #edf5e1; 31 | } 32 | 33 | img { 34 | width: 80px; 35 | height: 80px; 36 | } 37 | 38 | .plot-container { 39 | margin-top: 150px; 40 | display: flex; 41 | flex-direction: column; 42 | justify-content: center; 43 | align-items: center; 44 | right: 10px; 45 | top: 100px; 46 | } 47 | 48 | .plot-container>div { 49 | margin: 10px; 50 | } 51 | 52 | #logo { 53 | width: 35px; 54 | height: 35px; 55 | } 56 | 57 | #dropdown { 58 | position: absolute; 59 | margin-top: 40px; 60 | left: 85px; 61 | } 62 | 63 | .maincontent { 64 | display: flex; 65 | flex-direction: row; 66 | margin-top: 62px; 67 | width: 100%; 68 | } 69 | 70 | .footer { 71 | height: 50px; 72 | } 73 | 74 | .description { 75 | display: flex; 76 | flex-direction: column; 77 | align-items: center; 78 | margin-left: 2vw; 79 | } 80 | 81 | .simulation { 82 | margin: 0px 6vw 0px 6vw; 83 | } 84 | 85 | .button { 86 | background-color: #e3504d; 87 | border: none; 88 | color: white; 89 | display: flex; 90 | flex-direction: column; 91 | justify-content: center; 92 | align-content: center; 93 | height: 10.5vw; 94 | width: 10.5vw; 95 | text-align: center; 96 | text-decoration: none; 97 | margin: 1vw 2vw 0 2vw; 98 | border-radius: 100%; 99 | font-size: 2vw; 100 | font-weight: bold; 101 | cursor: pointer; 102 | animation: shadow-pulse 1.5s infinite; 103 | } 104 | 105 | .button:hover { 106 | background-color: #e22825; 107 | transform: scale(1.1); 108 | text-shadow: 0px 0px 6px rgba(255, 255, 255, 1); 109 | -webkit-box-shadow: 0px 5px 40px -10px rgba(0, 0, 0, 0.57); 110 | -moz-box-shadow: 0px 5px 40px -10px rgba(0, 0, 0, 0.57); 111 | transition: all 0.4s ease 0s; 112 | } 113 | 114 | @keyframes shadow-pulse { 115 | 0% { 116 | box-shadow: 0 0 0 0px rgba(0, 0, 0, 0.2); 117 | } 118 | 119 | 100% { 120 | box-shadow: 0 0 0 1.5vw rgba(0, 0, 0, 0); 121 | } 122 | } 123 | 124 | .dropdown .btn { 125 | margin-top: 0.8vw; 126 | border-width: 0; 127 | background: #274455; 128 | color: #fff; 129 | } 130 | 131 | .dropdown .btn:hover { 132 | background: #3d6379; 133 | color: #fff; 134 | border-width: 0; 135 | transform: scale(1.05); 136 | } 137 | 138 | .dropdown .btn:focus { 139 | border-width: 0; 140 | background: #3d6379; 141 | } 142 | 143 | .dropdown .btn:active { 144 | border-width: 0px; 145 | background: #3d6379; 146 | } 147 | 148 | .nav-link { 149 | color: #ddd !important; 150 | font-size: 18px !important; 151 | } 152 | 153 | .nav-item { 154 | padding-left: 20px; 155 | padding-right: 20px; 156 | } 157 | 158 | .intro { 159 | color: darkolivegreen; 160 | font-family: Verdana, Geneva, sans-serif; 161 | font-size: 1vw; 162 | font-weight: 700; 163 | padding: 1px 25px; 164 | } 165 | 166 | .goal { 167 | font-size: 1.6vw; 168 | font-weight: bold; 169 | letter-spacing: 1px; 170 | } 171 | 172 | .goalcontainer { 173 | margin-top: 0.5vw; 174 | border: 2px solid darkolivegreen; 175 | border-radius: 10px; 176 | } 177 | 178 | .intropower { 179 | color: #fc913a; 180 | } 181 | 182 | .introhandoffs { 183 | color: #ff4e50; 184 | } 185 | 186 | .descontainer { 187 | width: 16.4%; 188 | } 189 | 190 | #dropdown-basic { 191 | width: 13vw; 192 | height: 3vw; 193 | letter-spacing: 0.15vw; 194 | font-size: 1vw; 195 | font-weight: 500; 196 | } 197 | 198 | #dropdownitem { 199 | width: 20vw !important; 200 | } 201 | 202 | 203 | .navbar-nav>li { 204 | font-size: 1.1vw; 205 | } 206 | 207 | .dropdown-menu { 208 | font-size: 1.1vw; 209 | } -------------------------------------------------------------------------------- /src/HandoffVisualizer/Handoff.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import BootstrapNav from "./Components/BootstrapNav"; 3 | import "./Handoff.css"; 4 | import BootstrapDrop from "./Components/BootstrapDrop"; 5 | import Icons from "./Components/Icons"; 6 | import Simulation from "./Components/Simulation"; 7 | import Plots from "./Components/Plots"; 8 | import { initgrid, move, carmoving, power, updateenter } from "../utils.mjs"; 9 | 10 | let policyobj = { policy: 0 }; 11 | let plotdata = { handoffs: 0, averagepower: -103 }; 12 | let running = 0; 13 | 14 | const bstation = [ 15 | { 16 | row: 5, 17 | col: 7 18 | }, 19 | { 20 | row: 5, 21 | col: 21 22 | }, 23 | { 24 | row: 15, 25 | col: 7 26 | }, 27 | { 28 | row: 15, 29 | col: 21 30 | } 31 | ]; 32 | 33 | export default class Handoff extends Component { 34 | constructor() { 35 | super(); 36 | 37 | this.state = { 38 | grid: [], 39 | cars: [ 40 | //0:top, 1:right, 2:down, 3:left 41 | { 42 | row: 5, 43 | col: 0, 44 | dir: 1, 45 | bs: 0, 46 | power: power(5, 0, bstation[0]), 47 | handoff: false 48 | }, 49 | { 50 | row: 5, 51 | col: 28, 52 | dir: 3, 53 | bs: 1, 54 | power: power(5, 28, bstation[1]), 55 | handoff: false 56 | }, 57 | { 58 | row: 15, 59 | col: 0, 60 | dir: 1, 61 | bs: 2, 62 | power: power(15, 0, bstation[2]), 63 | handoff: false 64 | }, 65 | { 66 | row: 15, 67 | col: 28, 68 | dir: 3, 69 | bs: 3, 70 | power: power(15, 28, bstation[3]), 71 | handoff: false 72 | } 73 | ], 74 | entrances: [ 75 | { 76 | row: 0, 77 | col: 7, 78 | arrowdir: 2, 79 | carenter: -1 80 | }, 81 | { 82 | row: 0, 83 | col: 21, 84 | arrowdir: 2, 85 | carenter: -1 86 | }, 87 | { 88 | row: 20, 89 | col: 7, 90 | arrowdir: 0, 91 | carenter: -1 92 | }, 93 | { 94 | row: 20, 95 | col: 21, 96 | arrowdir: 0, 97 | carenter: -1 98 | }, 99 | { 100 | row: 5, 101 | col: 28, 102 | arrowdir: 3, 103 | carenter: -1 104 | }, 105 | { 106 | row: 15, 107 | col: 28, 108 | arrowdir: 3, 109 | carenter: -1 110 | }, 111 | { 112 | row: 5, 113 | col: 0, 114 | arrowdir: 1, 115 | carenter: -1 116 | }, 117 | { 118 | row: 15, 119 | col: 0, 120 | arrowdir: 1, 121 | carenter: -1 122 | } 123 | ] 124 | }; 125 | } 126 | 127 | componentDidMount() { 128 | let newgrid = initgrid(this.state.cars); 129 | 130 | this.setState({ grid: newgrid }); 131 | let grid = this.state.grid; 132 | let cars = this.state.cars; 133 | let entrances = this.state.entrances; 134 | return ( 135 |
136 | 137 |
138 |
139 |
140 |
141 |
Goal
142 |
143 | Least Handoffs 144 |
145 |
146 | Highest Power 147 |
148 |
149 | 152 |
this.handleClick()} 155 | > 156 |
Visualize
157 |
158 | 159 |
160 |
161 | 166 |
167 |
168 |
169 | ); 170 | } 171 | 172 | handleClick() { 173 | if (running === 1) { 174 | running = 0; 175 | clearInterval(window.intervalid); 176 | } else { 177 | running = 1; 178 | window.intervalid = setInterval(() => { 179 | let newentrances = updateenter( 180 | this.state.entrances, 181 | this.state.cars 182 | ); 183 | let newcars = carmoving( 184 | this.state.entrances, 185 | this.state.cars, 186 | policyobj.policy, 187 | plotdata 188 | ); 189 | let newgrid = move(this.state.cars); 190 | this.setState({ 191 | grid: newgrid, 192 | cars: newcars, 193 | entrances: newentrances 194 | }); 195 | }, 600); 196 | } 197 | } 198 | 199 | render() { 200 | let grid = this.state.grid; 201 | let cars = this.state.cars; 202 | let entrances = this.state.entrances; 203 | return ( 204 |
205 | 206 |
207 |
208 |
209 |
210 |
Goal
211 |
212 | Least Handoffs 213 |
214 |
215 | Highest Power 216 |
217 |
218 | 221 |
this.handleClick()} 224 | > 225 |
Visualize
226 |
227 | 228 |
229 |
230 | 235 | 240 |
241 |
242 |
243 | ); 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/img/arrow0.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/img/arrow1.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/img/arrow2.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/img/arrow3.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/img/bs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chonyy/handoff-visualizer/e7f10a04cc8b74c033e536a7842d63c315c000d7/src/HandoffVisualizer/img/bs.png -------------------------------------------------------------------------------- /src/HandoffVisualizer/img/bs.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/img/handoff.svg: -------------------------------------------------------------------------------- 1 | getting-started-icon-hand-outline-orange -------------------------------------------------------------------------------- /src/HandoffVisualizer/img/handoff2(1).svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 10 | 16 | 32 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/img/handoff2.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | Created by potrace 1.15, written by Peter Selinger 2001-2017 9 | 10 | 12 | 18 | 36 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/img/handoff3.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/HandoffVisualizer/img/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | 9 | serviceWorker.unregister(); 10 | -------------------------------------------------------------------------------- /src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.0/8 are considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl, { 104 | headers: { 'Service-Worker': 'script' } 105 | }) 106 | .then(response => { 107 | // Ensure service worker exists, and that we really are getting a JS file. 108 | const contentType = response.headers.get('content-type'); 109 | if ( 110 | response.status === 404 || 111 | (contentType != null && contentType.indexOf('javascript') === -1) 112 | ) { 113 | // No service worker found. Probably a different app. Reload the page. 114 | navigator.serviceWorker.ready.then(registration => { 115 | registration.unregister().then(() => { 116 | window.location.reload(); 117 | }); 118 | }); 119 | } else { 120 | // Service worker found. Proceed as normal. 121 | registerValidSW(swUrl, config); 122 | } 123 | }) 124 | .catch(() => { 125 | console.log( 126 | 'No internet connection found. App is running in offline mode.' 127 | ); 128 | }); 129 | } 130 | 131 | export function unregister() { 132 | if ('serviceWorker' in navigator) { 133 | navigator.serviceWorker.ready 134 | .then(registration => { 135 | registration.unregister(); 136 | }) 137 | .catch(error => { 138 | console.error(error.message); 139 | }); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom/extend-expect'; 6 | -------------------------------------------------------------------------------- /src/utils.mjs: -------------------------------------------------------------------------------- 1 | const p = 0.0163911909; 2 | const e = 5; 3 | const t = -108; 4 | const pMin = -112; 5 | 6 | const bstation = [ 7 | { 8 | row: 5, 9 | col: 7 10 | }, 11 | { 12 | row: 5, 13 | col: 21 14 | }, 15 | { 16 | row: 15, 17 | col: 7 18 | }, 19 | { 20 | row: 15, 21 | col: 21 22 | } 23 | ]; 24 | 25 | export function initgrid(cars) { 26 | let newgrid = []; 27 | for (let i = 0; i < 21; i++) { 28 | let row = []; 29 | for (let j = 0; j < 29; j++) { 30 | let current = false; 31 | let power = 0; 32 | let handoff = false; 33 | for (let k = 0; k < cars.length; k++) { 34 | if (i === cars[k].row && j === cars[k].col) { 35 | current = true; 36 | power = cars[k].power; 37 | handoff = cars[k].handoff; 38 | break; 39 | } 40 | } 41 | let bs = -1; 42 | let pathroad = i % 5 === 0 || j % 7 === 0 ? true : false; 43 | if (i === 5 && j === 7) bs = 0; 44 | else if (i === 5 && j === 21) bs = 1; 45 | else if (i === 15 && j === 7) bs = 2; 46 | else if (i === 15 && j === 21) bs = 3; 47 | row.push({ 48 | row: i, 49 | col: j, 50 | visiting: current, 51 | path: pathroad, 52 | bs: bs, 53 | power: power, 54 | handoff: handoff 55 | }); 56 | } 57 | newgrid.push(row); 58 | } 59 | return newgrid; 60 | } 61 | 62 | export function move(cars) { 63 | let newgrid = []; 64 | for (let i = 0; i < 21; i++) { 65 | let row = []; 66 | for (let j = 0; j < 29; j++) { 67 | let current = false; 68 | let power = 0; 69 | let handoff = false; 70 | for (let k = 0; k < cars.length; k++) { 71 | if (i === cars[k].row && j === cars[k].col) { 72 | current = true; 73 | power = cars[k].power; 74 | handoff = cars[k].handoff; 75 | break; 76 | } 77 | } 78 | let bs = -1; 79 | let pathroad = i % 5 === 0 || j % 7 === 0 ? true : false; 80 | if (i === 5 && j === 7) bs = 0; 81 | else if (i === 5 && j === 21) bs = 1; 82 | else if (i === 15 && j === 7) bs = 2; 83 | else if (i === 15 && j === 21) bs = 3; 84 | row.push({ 85 | row: i, 86 | col: j, 87 | visiting: current, 88 | path: pathroad, 89 | bs: bs, 90 | power: power, 91 | handoff: handoff 92 | }); 93 | } 94 | newgrid.push(row); 95 | } 96 | return newgrid; 97 | } 98 | 99 | export function carmoving(entrances, oldcars, policy, plotdata) { 100 | let cars = [...oldcars]; 101 | let cartoremove = []; 102 | let carsingrid = 0; 103 | let totalpower = 0; 104 | for (let i = 0; i < cars.length; i++) { 105 | let car = cars[i]; 106 | if (car.row < 0 || car.row > 20 || car.col < 0 || car.col > 28) 107 | cartoremove.push(car); 108 | else { 109 | if (car.row % 5 === 0 && car.col % 7 === 0) changedirection(car); 110 | carmovealongdir(car); 111 | checkBS(car, policy, plotdata); 112 | carsingrid++; 113 | totalpower += car.power; 114 | } 115 | } 116 | plotdata.averagepower = totalpower / carsingrid; 117 | removecars(cars, cartoremove, entrances); 118 | return cars; 119 | } 120 | 121 | export function changedirection(car) { 122 | let orig = car.dir; 123 | let randnum = getRandomInt(0, 5); 124 | // at corner 125 | if (car.row % 20 === 0 && car.col % 28 === 0) { 126 | if (car.row === 0 && car.col === 0) { 127 | if (orig === 0) orig = 1; 128 | else if (orig === 3) orig = 2; 129 | } else if (car.row === 20 && car.col === 0) { 130 | if (orig === 3) orig = 0; 131 | else if (orig === 2) orig = 1; 132 | } else if (car.row === 0 && car.col === 28) { 133 | if (orig === 1) orig = 2; 134 | else if (orig === 0) orig = 3; 135 | } else if (car.row === 20 && car.col === 28) { 136 | if (orig === 2) orig = 3; 137 | else if (orig === 1) orig = 0; 138 | } 139 | } 140 | // crossroad with two choices 141 | else if ( 142 | (car.row === 0 && car.col === 14) || 143 | (car.row === 10 && car.col === 0) || 144 | (car.row === 10 && car.col === 28) || 145 | (car.row === 20 && car.col === 14) 146 | ) { 147 | let dirs = dirTwochoices(car.dir, car.row, car.col); 148 | if (randnum <= 2) { 149 | orig = dirs[0]; 150 | } else { 151 | orig = dirs[1]; 152 | } 153 | } else { 154 | // turn left 155 | if (randnum === 0) orig--; 156 | // turn right 157 | else if (randnum === 1 || randnum === 2) orig++; 158 | } 159 | 160 | if (orig === -1) orig = 3; 161 | orig %= 4; 162 | car.dir = orig; 163 | } 164 | 165 | export function getRandomInt(min, max) { 166 | min = Math.ceil(min); 167 | max = Math.floor(max); 168 | return Math.floor(Math.random() * (max - min + 1)) + min; 169 | } 170 | 171 | export function removecars(cars, cartoremove, entrances) { 172 | for (let i = 0; i < cartoremove.length; i++) { 173 | let row = cartoremove[i].row; 174 | let col = cartoremove[i].col; 175 | // console.log(row, col); 176 | if (row === -1 && col === 7) entrances[0].carenter = 1; 177 | else if (row === -1 && col === 21) entrances[1].carenter = 1; 178 | else if (row === 21 && col === 7) entrances[2].carenter = 1; 179 | else if (row === 21 && col === 21) entrances[3].carenter = 1; 180 | else if (row === 5 && col === 29) entrances[4].carenter = 1; 181 | else if (row === 15 && col === 29) entrances[5].carenter = 1; 182 | else if (row === 5 && col === -1) entrances[6].carenter = 1; 183 | else if (row === 15 && col === -1) entrances[7].carenter = 1; 184 | 185 | cars.splice(cars.indexOf(cartoremove[i]), 1); 186 | } 187 | } 188 | 189 | export function carmovealongdir(car) { 190 | if (car.dir === 2) { 191 | car.row++; 192 | } else if (car.dir === 0) { 193 | car.row--; 194 | } else if (car.dir === 1) { 195 | car.col++; 196 | } else if (car.dir === 3) { 197 | car.col--; 198 | } 199 | } 200 | 201 | export function checkBS(car, policy, plotdata) { 202 | let handoff = false; 203 | let pOld = power(car.row, car.col, bstation[car.bs]); 204 | let powerReceived = []; 205 | powerReceived.push(power(car.row, car.col, bstation[0])); 206 | powerReceived.push(power(car.row, car.col, bstation[1])); 207 | powerReceived.push(power(car.row, car.col, bstation[2])); 208 | powerReceived.push(power(car.row, car.col, bstation[3])); 209 | 210 | let pNew = Math.max(...powerReceived); 211 | let newBS = powerReceived.indexOf(pNew); 212 | 213 | if (policy === 0) { 214 | if (pNew > pOld) { 215 | car.bs = newBS; 216 | car.power = pNew; 217 | handoff = true; 218 | console.log("best"); 219 | } 220 | } else if (policy === 1) { 221 | if (pNew > pOld && pOld < t) { 222 | car.bs = newBS; 223 | car.power = pNew; 224 | handoff = true; 225 | console.log("threshold"); 226 | } 227 | } else if (policy === 2) { 228 | if (pNew > pOld + e) { 229 | car.bs = newBS; 230 | car.power = pNew; 231 | handoff = true; 232 | console.log("entrophy"); 233 | } 234 | } else if (policy === 3) { 235 | if (pOld < pMin) { 236 | car.bs = newBS; 237 | car.power = pNew; 238 | handoff = true; 239 | console.log("minimum"); 240 | } 241 | } 242 | 243 | if (handoff) { 244 | plotdata.handoffs++; 245 | car.handoff = true; 246 | } 247 | //update power with original bs if no handoff 248 | else { 249 | car.power = pOld; 250 | car.handoff = false; 251 | } 252 | } 253 | 254 | export function power(carRow, carCol, bs) { 255 | let powerVal = 0; 256 | let xdiff = Math.abs(carCol - bs.col) * 20; 257 | let ydiff = Math.abs(carRow - bs.row) * 20; 258 | let dist = (xdiff ** 2 + ydiff ** 2) ** (1 / 2); 259 | if (dist === 0) { 260 | powerVal = -50; 261 | } else { 262 | powerVal = -60 - 20 * log10(dist); 263 | } 264 | return powerVal; 265 | } 266 | 267 | export function log10(val) { 268 | return Math.log(val) / Math.log(10); 269 | } 270 | 271 | export function dirTwochoices(dir, row, col) { 272 | let dirs = [0, 1, 2, 3]; 273 | let dirtodelete = (dir + 2) % 4; 274 | 275 | dirs.splice(dirs.indexOf(dirtodelete), 1); 276 | if (row === 0 && col === 14) { 277 | dirs.splice(dirs.indexOf(0), 1); 278 | } else if (row === 10 && col === 0) { 279 | dirs.splice(dirs.indexOf(3), 1); 280 | } else if (row === 10 && col === 28) { 281 | dirs.splice(dirs.indexOf(1), 1); 282 | } else if (row === 20 && col === 14) { 283 | dirs.splice(dirs.indexOf(2), 1); 284 | } 285 | 286 | return dirs; 287 | } 288 | 289 | export function updateenter(entrances, cars) { 290 | let newE = [...entrances]; 291 | 292 | for (let i = 0; i < 8; i++) { 293 | let randnum = Math.random(); 294 | let enter = randnum < p; 295 | if (enter) { 296 | //top 2 297 | if (i === 0) { 298 | cars.push({ 299 | row: 0, 300 | col: 7, 301 | dir: 2, 302 | bs: 0, 303 | power: power(0, 7, bstation[0]) 304 | }); 305 | } else if (i === 1) { 306 | cars.push({ 307 | row: 0, 308 | col: 21, 309 | dir: 2, 310 | bs: 1, 311 | power: power(0, 21, bstation[1]) 312 | }); 313 | } 314 | //bottom 2 315 | else if (i === 2) { 316 | cars.push({ 317 | row: 20, 318 | col: 7, 319 | dir: 0, 320 | bs: 2, 321 | power: power(20, 7, bstation[2]) 322 | }); 323 | } else if (i === 3) { 324 | cars.push({ 325 | row: 20, 326 | col: 21, 327 | dir: 0, 328 | bs: 3, 329 | power: power(20, 21, bstation[3]) 330 | }); 331 | } 332 | //right 2 333 | else if (i === 4) { 334 | cars.push({ 335 | row: 5, 336 | col: 28, 337 | dir: 3, 338 | bs: 1, 339 | power: power(5, 28, bstation[1]) 340 | }); 341 | } else if (i === 5) { 342 | cars.push({ 343 | row: 15, 344 | col: 28, 345 | dir: 3, 346 | bs: 3, 347 | power: power(15, 28, bstation[3]) 348 | }); 349 | } 350 | //left 2 351 | else if (i === 6) { 352 | cars.push({ 353 | row: 5, 354 | col: 0, 355 | dir: 2, 356 | bs: 0, 357 | power: power(5, 0, bstation[0]) 358 | }); 359 | } else if (i === 7) { 360 | cars.push({ 361 | row: 15, 362 | col: 0, 363 | dir: 2, 364 | bs: 2, 365 | power: power(15, 0, bstation[2]) 366 | }); 367 | } 368 | newE[i].carenter = 0; 369 | } 370 | } 371 | 372 | return newE; 373 | } 374 | --------------------------------------------------------------------------------