Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
rrs
viewer
log-segmentation
Commits
342fea6f
Unverified
Commit
342fea6f
authored
Nov 19, 2022
by
Juon Kawakami
🥗
Browse files
init
parent
54f6cedf
Changes
419
Show whitespace changes
Inline
Side-by-side
Too many changes to show.
To preserve performance only
20 of 419+
files are displayed.
Plain diff
Email patch
modules/gis2/src/gis2/scenario/PlaceAmbulanceCentreTool.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLBuilding
;
import
maps.gml.GMLShape
;
/**
* Tool for placing ambulance centres.
*/
public
class
PlaceAmbulanceCentreTool
extends
ShapeTool
{
/**
* Construct a PlaceAmbulanceCentreTool.
*
* @param editor The editor instance.
*/
public
PlaceAmbulanceCentreTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Place ambulance centre"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
shape
instanceof
GMLBuilding
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
addAmbulanceCentre
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
AddAmbulanceCentreEdit
(
shape
.
getID
()));
}
private
class
AddAmbulanceCentreEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
AddAmbulanceCentreEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
removeAmbulanceCentre
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
addAmbulanceCentre
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/PlaceAmbulanceTeamTool.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLShape
;
/**
* Tool for placing ambulance teams.
*/
public
class
PlaceAmbulanceTeamTool
extends
ShapeTool
{
/**
* Construct a PlaceAmbulanceTeamTool.
*
* @param editor The editor instance.
*/
public
PlaceAmbulanceTeamTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Place ambulance team"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
true
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
addAmbulanceTeam
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
AddAmbulanceTeamEdit
(
shape
.
getID
()));
}
private
class
AddAmbulanceTeamEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
AddAmbulanceTeamEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
removeAmbulanceTeam
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
addAmbulanceTeam
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/PlaceCivilianTool.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLShape
;
/**
* Tool for placing civilians.
*/
public
class
PlaceCivilianTool
extends
ShapeTool
{
/**
* Construct a PlaceCivilianTool.
*
* @param editor The editor instance.
*/
public
PlaceCivilianTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Place civilian"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
true
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
addCivilian
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
AddCivilianEdit
(
shape
.
getID
()));
}
private
class
AddCivilianEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
AddCivilianEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
removeCivilian
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
addCivilian
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/PlaceFireBrigadeTool.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLShape
;
/**
* Tool for placing fire brigades.
*/
public
class
PlaceFireBrigadeTool
extends
ShapeTool
{
/**
* Construct a PlaceFireBrigadeTool.
*
* @param editor The editor instance.
*/
public
PlaceFireBrigadeTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Place fire brigade"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
true
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
addFireBrigade
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
AddFireBrigadeEdit
(
shape
.
getID
()));
}
private
class
AddFireBrigadeEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
AddFireBrigadeEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
removeFireBrigade
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
addFireBrigade
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/PlaceFireStationTool.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLBuilding
;
import
maps.gml.GMLShape
;
/**
* Tool for placing fire stations.
*/
public
class
PlaceFireStationTool
extends
ShapeTool
{
/**
* Construct a PlaceFireStationTool.
*
* @param editor The editor instance.
*/
public
PlaceFireStationTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Place fire station"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
shape
instanceof
GMLBuilding
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
addFireStation
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
AddFireStationEdit
(
shape
.
getID
()));
}
private
class
AddFireStationEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
AddFireStationEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
removeFireStation
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
addFireStation
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/PlaceFireTool.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLBuilding
;
import
maps.gml.GMLShape
;
/**
* Tool for placing fires.
*/
public
class
PlaceFireTool
extends
ShapeTool
{
/**
* Construct a PlaceFireTool.
*
* @param editor The editor instance.
*/
public
PlaceFireTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Place fire"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
shape
instanceof
GMLBuilding
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
addFire
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
AddFireEdit
(
shape
.
getID
()));
}
private
class
AddFireEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
AddFireEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
removeFire
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
addFire
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/PlaceGasStationTool.java
0 → 100755
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLBuilding
;
import
maps.gml.GMLShape
;
/**
* Tool for placing gasStation.
*/
public
class
PlaceGasStationTool
extends
ShapeTool
{
/**
* Construct a PlaceGasStationTool.
*
* @param editor The editor instance.
*/
public
PlaceGasStationTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Place gas station"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
shape
instanceof
GMLBuilding
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
addGasStation
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
AddGasStationEdit
(
shape
.
getID
()));
}
private
class
AddGasStationEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
AddGasStationEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
removeGasStation
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
addGasStation
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/PlaceHydrantTool.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLRoad
;
import
maps.gml.GMLShape
;
/**
* Tool for placing refuges.
*/
public
class
PlaceHydrantTool
extends
ShapeTool
{
/**
* Construct a PlaceHydrantTool.
*
* @param editor The editor instance.
*/
public
PlaceHydrantTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Place hydrant"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
shape
instanceof
GMLRoad
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
addHydrant
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
AddHydrantEdit
(
shape
.
getID
()));
}
private
class
AddHydrantEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
AddHydrantEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
removeHydrant
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
addHydrant
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/PlacePoliceForceTool.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLShape
;
/**
* Tool for placing police forces.
*/
public
class
PlacePoliceForceTool
extends
ShapeTool
{
/**
* Construct a PlacePoliceForceTool.
*
* @param editor The editor instance.
*/
public
PlacePoliceForceTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Place police force"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
true
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
addPoliceForce
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
AddPoliceForceEdit
(
shape
.
getID
()));
}
private
class
AddPoliceForceEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
AddPoliceForceEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
removePoliceForce
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
addPoliceForce
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/PlacePoliceOfficeTool.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLBuilding
;
import
maps.gml.GMLShape
;
/**
* Tool for placing police offices.
*/
public
class
PlacePoliceOfficeTool
extends
ShapeTool
{
/**
* Construct a PlacePoliceOfficeTool.
*
* @param editor The editor instance.
*/
public
PlacePoliceOfficeTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Place police office"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
shape
instanceof
GMLBuilding
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
addPoliceOffice
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
AddPoliceOfficeEdit
(
shape
.
getID
()));
}
private
class
AddPoliceOfficeEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
AddPoliceOfficeEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
removePoliceOffice
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
addPoliceOffice
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/PlaceRefugeTool.java
0 → 100755
View file @
342fea6f
package
gis2.scenario
;
import
java.awt.GridLayout
;
import
javax.swing.JLabel
;
import
javax.swing.JOptionPane
;
import
javax.swing.JPanel
;
import
javax.swing.JTextField
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLBuilding
;
import
maps.gml.GMLShape
;
/**
* Tool for placing refuges.
*/
public
class
PlaceRefugeTool
extends
ShapeTool
{
/**
* Construct a PlaceRefugeTool.
*
* @param editor The editor instance.
*/
public
PlaceRefugeTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Place refuge"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
shape
instanceof
GMLBuilding
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
JPanel
panel
=
new
JPanel
(
new
GridLayout
(
3
,
2
));
JTextField
bedNumberField
=
new
JTextField
(
"100"
);
panel
.
add
(
new
JLabel
(
"Insert a bed capacity for the refuge"
));
panel
.
add
(
bedNumberField
);
if
(
JOptionPane
.
showConfirmDialog
(
null
,
panel
,
"Refuge Capacity"
,
JOptionPane
.
OK_CANCEL_OPTION
)
==
JOptionPane
.
OK_OPTION
)
{
int
bedCapacity
=
Integer
.
parseInt
(
bedNumberField
.
getText
());
int
refillCapacity
=
1000
;
// Integer.parseInt(refillNumberField.getText());
editor
.
getScenario
().
addRefuge
(
shape
.
getID
(),
bedCapacity
,
refillCapacity
);
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
AddRefugeEdit
(
shape
.
getID
()));
}
}
private
class
AddRefugeEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
AddRefugeEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
removeRefuge
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
addRefuge
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/RandomHydrantPlacementFunction.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
gis2.GisScenario
;
import
java.awt.GridLayout
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Random
;
import
javax.swing.JLabel
;
import
javax.swing.JOptionPane
;
import
javax.swing.JPanel
;
import
javax.swing.JTextField
;
import
maps.gml.GMLMap
;
import
maps.gml.GMLShape
;
/**
* Function for placing agents.
*/
public
class
RandomHydrantPlacementFunction
extends
AbstractFunction
{
private
Random
random
;
/**
* Construct a place agents function.
*
* @param editor The editor instance.
*/
public
RandomHydrantPlacementFunction
(
ScenarioEditor
editor
)
{
super
(
editor
);
random
=
new
Random
();
}
@Override
public
String
getName
()
{
return
"Random Hydrant Placement"
;
}
@Override
public
void
execute
()
{
JPanel
panel
=
new
JPanel
(
new
GridLayout
(
3
,
2
));
JTextField
numberField
=
new
JTextField
(
"1"
);
GMLMap
map
=
editor
.
getMap
();
double
height
=
(
map
.
getMaxX
()
-
map
.
getMinX
());
double
width
=
(
map
.
getMaxY
()
-
map
.
getMinY
());
int
suggestedCount
=
(
int
)
(
height
*
width
/
30000
);
panel
.
add
(
new
JLabel
(
"Number: suggested number:"
+
suggestedCount
));
panel
.
add
(
numberField
);
HashSet
<
Integer
>
selectedIds
=
new
HashSet
<>();
List
<
GMLShape
>
all
=
new
ArrayList
<
GMLShape
>(
editor
.
getMap
().
getRoads
());
if
(
JOptionPane
.
showConfirmDialog
(
null
,
panel
,
"Add agents"
,
JOptionPane
.
OK_CANCEL_OPTION
)
==
JOptionPane
.
OK_OPTION
)
{
GisScenario
s
=
editor
.
getScenario
();
try
{
int
number
=
Integer
.
parseInt
(
numberField
.
getText
());
for
(
int
i
=
0
;
i
<
number
;
++
i
)
{
int
id
=
all
.
get
(
random
.
nextInt
(
all
.
size
())).
getID
();
if
(
selectedIds
.
contains
(
id
))
i
--;
else
{
s
.
addHydrant
(
id
);
selectedIds
.
add
(
id
);
}
}
}
catch
(
NumberFormatException
e
)
{
e
.
printStackTrace
();
}
}
editor
.
setChanged
();
editor
.
updateOverlays
();
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/RandomScenarioGenerator.java
0 → 100755
View file @
342fea6f
package
gis2.scenario
;
import
gis2.GisScenario
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Random
;
import
maps.MapException
;
import
maps.MapReader
;
import
maps.gml.GMLBuilding
;
import
maps.gml.GMLMap
;
import
maps.gml.GMLShape
;
import
org.dom4j.Document
;
import
org.dom4j.DocumentHelper
;
import
org.dom4j.io.OutputFormat
;
import
org.dom4j.io.XMLWriter
;
/**
* A class for generating random scenarios.
*/
public
class
RandomScenarioGenerator
{
private
static
final
int
DEFAULT_MIN_CIVS
=
50
;
private
static
final
int
DEFAULT_MAX_CIVS
=
200
;
private
static
final
int
DEFAULT_MIN_PLATOONS
=
0
;
private
static
final
int
DEFAULT_MAX_PLATOONS
=
30
;
private
static
final
int
DEFAULT_MIN_CENTRES
=
0
;
private
static
final
int
DEFAULT_MAX_CENTRES
=
5
;
private
static
final
int
DEFAULT_MIN_REFUGES
=
0
;
private
static
final
int
DEFAULT_MAX_REFUGES
=
5
;
private
static
final
int
DEFAULT_MIN_FIRES
=
1
;
private
static
final
int
DEFAULT_MAX_FIRES
=
10
;
private
int
minCivs
;
private
int
maxCivs
;
private
int
minFBs
;
private
int
maxFBs
;
private
int
minFSs
;
private
int
maxFSs
;
private
int
minPOs
;
private
int
maxPOs
;
private
int
minPFs
;
private
int
maxPFs
;
private
int
minATs
;
private
int
maxATs
;
private
int
minACs
;
private
int
maxACs
;
private
int
minFires
;
private
int
maxFires
;
private
int
minRefuges
;
private
int
maxRefuges
;
/**
* Construct a RandomScenarioGenerator with default parameters.
*/
public
RandomScenarioGenerator
()
{
minCivs
=
DEFAULT_MIN_CIVS
;
maxCivs
=
DEFAULT_MAX_CIVS
;
minFBs
=
DEFAULT_MIN_PLATOONS
;
maxFBs
=
DEFAULT_MAX_PLATOONS
;
minPFs
=
DEFAULT_MIN_PLATOONS
;
maxPFs
=
DEFAULT_MAX_PLATOONS
;
minATs
=
DEFAULT_MIN_PLATOONS
;
maxATs
=
DEFAULT_MAX_PLATOONS
;
minFSs
=
DEFAULT_MIN_CENTRES
;
maxFSs
=
DEFAULT_MAX_CENTRES
;
minPOs
=
DEFAULT_MIN_CENTRES
;
maxPOs
=
DEFAULT_MAX_CENTRES
;
minACs
=
DEFAULT_MIN_CENTRES
;
maxACs
=
DEFAULT_MAX_CENTRES
;
minFires
=
DEFAULT_MIN_FIRES
;
maxFires
=
DEFAULT_MAX_FIRES
;
minRefuges
=
DEFAULT_MIN_REFUGES
;
maxRefuges
=
DEFAULT_MAX_REFUGES
;
}
/**
* Entry point.
*
* @param args Command line arguments: <map directory> [-civ min max] [-fb min
* max] [-fs min max] [-pf min max] [-po min max] [-at min max] [-ac
* min max] [-refuge min max] [-fire min max].
*/
public
static
void
main
(
String
[]
args
)
{
if
(
args
.
length
<
1
)
{
printUsage
();
return
;
}
String
dirName
=
args
[
0
];
RandomScenarioGenerator
generator
=
new
RandomScenarioGenerator
();
for
(
int
i
=
1
;
i
<
args
.
length
;
++
i
)
{
if
(
"-civ"
.
equals
(
args
[
i
]))
{
int
min
=
Integer
.
parseInt
(
args
[
i
+
1
]);
int
max
=
Integer
.
parseInt
(
args
[
i
+
2
]);
i
+=
2
;
generator
.
setCivilians
(
min
,
max
);
}
else
if
(
"-fb"
.
equals
(
args
[
i
]))
{
int
min
=
Integer
.
parseInt
(
args
[
i
+
1
]);
int
max
=
Integer
.
parseInt
(
args
[
i
+
2
]);
i
+=
2
;
generator
.
setFireBrigades
(
min
,
max
);
}
else
if
(
"-fs"
.
equals
(
args
[
i
]))
{
int
min
=
Integer
.
parseInt
(
args
[
i
+
1
]);
int
max
=
Integer
.
parseInt
(
args
[
i
+
2
]);
i
+=
2
;
generator
.
setFireStations
(
min
,
max
);
}
else
if
(
"-pf"
.
equals
(
args
[
i
]))
{
int
min
=
Integer
.
parseInt
(
args
[
i
+
1
]);
int
max
=
Integer
.
parseInt
(
args
[
i
+
2
]);
i
+=
2
;
generator
.
setPoliceForces
(
min
,
max
);
}
else
if
(
"-po"
.
equals
(
args
[
i
]))
{
int
min
=
Integer
.
parseInt
(
args
[
i
+
1
]);
int
max
=
Integer
.
parseInt
(
args
[
i
+
2
]);
i
+=
2
;
generator
.
setPoliceOffices
(
min
,
max
);
}
else
if
(
"-at"
.
equals
(
args
[
i
]))
{
int
min
=
Integer
.
parseInt
(
args
[
i
+
1
]);
int
max
=
Integer
.
parseInt
(
args
[
i
+
2
]);
i
+=
2
;
generator
.
setAmbulanceTeams
(
min
,
max
);
}
else
if
(
"-ac"
.
equals
(
args
[
i
]))
{
int
min
=
Integer
.
parseInt
(
args
[
i
+
1
]);
int
max
=
Integer
.
parseInt
(
args
[
i
+
2
]);
i
+=
2
;
generator
.
setAmbulanceCentres
(
min
,
max
);
}
else
if
(
"-refuge"
.
equals
(
args
[
i
]))
{
int
min
=
Integer
.
parseInt
(
args
[
i
+
1
]);
int
max
=
Integer
.
parseInt
(
args
[
i
+
2
]);
i
+=
2
;
generator
.
setRefuges
(
min
,
max
);
}
else
if
(
"-fire"
.
equals
(
args
[
i
]))
{
int
min
=
Integer
.
parseInt
(
args
[
i
+
1
]);
int
max
=
Integer
.
parseInt
(
args
[
i
+
2
]);
i
+=
2
;
generator
.
setFires
(
min
,
max
);
}
}
try
{
File
dir
=
new
File
(
dirName
);
GMLMap
map
=
(
GMLMap
)
MapReader
.
readMap
(
new
File
(
dir
,
"map.gml"
));
GisScenario
s
=
generator
.
makeRandomScenario
(
map
,
new
Random
());
Document
doc
=
DocumentHelper
.
createDocument
();
s
.
write
(
doc
);
XMLWriter
writer
=
new
XMLWriter
(
new
FileOutputStream
(
new
File
(
dir
,
"scenario.xml"
)),
OutputFormat
.
createPrettyPrint
());
writer
.
write
(
doc
);
writer
.
flush
();
writer
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
MapException
e
)
{
e
.
printStackTrace
();
}
}
private
static
void
printUsage
()
{
System
.
out
.
println
(
"Usage: Launch Random Scenario Generator [map] [options]"
);
System
.
out
.
println
();
System
.
out
.
println
(
"[map] Map directory to generate random scenario"
);
System
.
out
.
println
();
System
.
out
.
println
(
"[options]"
);
System
.
out
.
println
(
"-civ\tmin max\tSet the minimum and maximum number of civilians"
);
System
.
out
.
println
(
"-fb\tmin max\tSet the minimum and maximum number of fire brigades"
);
System
.
out
.
println
(
"-fs\tmin max\tSet the minimum and maximum number of fire stations"
);
System
.
out
.
println
(
"-pf\tmin max\tSet the minimum and maximum number of police forces"
);
System
.
out
.
println
(
"-po\tmin max\tSet the minimum and maximum number of police offices"
);
System
.
out
.
println
(
"-at\tmin max\tSet the minimum and maximum number of ambulance teams"
);
System
.
out
.
println
(
"-ac\tmin max\tSet the minimum and maximum number of ambulance centers"
);
System
.
out
.
println
(
"-refuge\tmin max\tSet the minimum and maximum number of refuges"
);
System
.
out
.
println
(
"-fire\tmin max\tSet the minimum and maximum number of fires"
);
}
/**
* Set the minimum and maximum number of civilians.
*
* @param min The new minimum.
* @param max The new maximum.
*/
public
void
setCivilians
(
int
min
,
int
max
)
{
minCivs
=
min
;
maxCivs
=
max
;
}
/**
* Set the minimum and maximum number of fire brigades.
*
* @param min The new minimum.
* @param max The new maximum.
*/
public
void
setFireBrigades
(
int
min
,
int
max
)
{
minFBs
=
min
;
maxFBs
=
max
;
}
/**
* Set the minimum and maximum number of fire stations.
*
* @param min The new minimum.
* @param max The new maximum.
*/
public
void
setFireStations
(
int
min
,
int
max
)
{
minFSs
=
min
;
maxFSs
=
max
;
}
/**
* Set the minimum and maximum number of police forces.
*
* @param min The new minimum.
* @param max The new maximum.
*/
public
void
setPoliceForces
(
int
min
,
int
max
)
{
minPFs
=
min
;
maxPFs
=
max
;
}
/**
* Set the minimum and maximum number of police offices.
*
* @param min The new minimum.
* @param max The new maximum.
*/
public
void
setPoliceOffices
(
int
min
,
int
max
)
{
minPOs
=
min
;
maxPOs
=
max
;
}
/**
* Set the minimum and maximum number of ambulance teams.
*
* @param min The new minimum.
* @param max The new maximum.
*/
public
void
setAmbulanceTeams
(
int
min
,
int
max
)
{
minATs
=
min
;
maxATs
=
max
;
}
/**
* Set the minimum and maximum number of ambulance centres.
*
* @param min The new minimum.
* @param max The new maximum.
*/
public
void
setAmbulanceCentres
(
int
min
,
int
max
)
{
minACs
=
min
;
maxACs
=
max
;
}
/**
* Set the minimum and maximum number of refuges.
*
* @param min The new minimum.
* @param max The new maximum.
*/
public
void
setRefuges
(
int
min
,
int
max
)
{
minRefuges
=
min
;
maxRefuges
=
max
;
}
/**
* Set the minimum and maximum number of fires.
*
* @param min The new minimum.
* @param max The new maximum.
*/
public
void
setFires
(
int
min
,
int
max
)
{
minFires
=
min
;
maxFires
=
max
;
}
/**
* Generate a random scenario.
*
* @param map The map to generate a scenario for.
* @param random A source of randomness.
* @return A new Scenario.
*/
public
GisScenario
makeRandomScenario
(
GMLMap
map
,
Random
random
)
{
GisScenario
result
=
new
GisScenario
();
int
civ
=
random
.
nextInt
(
maxCivs
-
minCivs
+
1
)
+
minCivs
;
int
fb
=
random
.
nextInt
(
maxFBs
-
minFBs
+
1
)
+
minFBs
;
int
fs
=
random
.
nextInt
(
maxFSs
-
minFSs
+
1
)
+
minFSs
;
int
pf
=
random
.
nextInt
(
maxPFs
-
minPFs
+
1
)
+
minPFs
;
int
po
=
random
.
nextInt
(
maxPOs
-
minPOs
+
1
)
+
minPOs
;
int
at
=
random
.
nextInt
(
maxATs
-
minATs
+
1
)
+
minATs
;
int
ac
=
random
.
nextInt
(
maxACs
-
minACs
+
1
)
+
minACs
;
int
fire
=
random
.
nextInt
(
maxFires
-
minFires
+
1
)
+
minFires
;
int
refuge
=
random
.
nextInt
(
maxRefuges
-
minRefuges
+
1
)
+
minRefuges
;
List
<
GMLBuilding
>
buildings
=
new
ArrayList
<
GMLBuilding
>(
map
.
getBuildings
());
Collections
.
shuffle
(
buildings
,
random
);
Iterator
<
GMLBuilding
>
it
=
buildings
.
iterator
();
placeRefuges
(
it
,
result
,
refuge
);
placeCentres
(
it
,
result
,
fs
,
po
,
ac
);
placeFires
(
it
,
result
,
fire
);
placeAgents
(
map
,
result
,
random
,
fb
,
pf
,
at
,
civ
);
return
result
;
}
private
void
placeRefuges
(
Iterator
<
GMLBuilding
>
it
,
GisScenario
result
,
int
num
)
{
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
result
.
addRefuge
(
it
.
next
().
getID
(),
1000
,
1000
);
}
}
private
void
placeCentres
(
Iterator
<
GMLBuilding
>
it
,
GisScenario
result
,
int
fire
,
int
police
,
int
ambulance
)
{
for
(
int
i
=
0
;
i
<
fire
;
++
i
)
{
result
.
addFireStation
(
it
.
next
().
getID
());
}
for
(
int
i
=
0
;
i
<
police
;
++
i
)
{
result
.
addPoliceOffice
(
it
.
next
().
getID
());
}
for
(
int
i
=
0
;
i
<
ambulance
;
++
i
)
{
result
.
addAmbulanceCentre
(
it
.
next
().
getID
());
}
}
private
void
placeFires
(
Iterator
<
GMLBuilding
>
it
,
GisScenario
result
,
int
num
)
{
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
result
.
addFire
(
it
.
next
().
getID
());
}
}
private
void
placeAgents
(
GMLMap
map
,
GisScenario
result
,
Random
random
,
int
fire
,
int
police
,
int
ambulance
,
int
civ
)
{
List
<
GMLShape
>
all
=
new
ArrayList
<
GMLShape
>(
map
.
getAllShapes
());
List
<
GMLBuilding
>
buildings
=
new
ArrayList
<
GMLBuilding
>(
map
.
getBuildings
());
for
(
int
i
=
0
;
i
<
fire
;
++
i
)
{
int
id
=
all
.
get
(
random
.
nextInt
(
all
.
size
())).
getID
();
result
.
addFireBrigade
(
id
);
}
for
(
int
i
=
0
;
i
<
police
;
++
i
)
{
int
id
=
all
.
get
(
random
.
nextInt
(
all
.
size
())).
getID
();
result
.
addPoliceForce
(
id
);
}
for
(
int
i
=
0
;
i
<
ambulance
;
++
i
)
{
int
id
=
all
.
get
(
random
.
nextInt
(
all
.
size
())).
getID
();
result
.
addAmbulanceTeam
(
id
);
}
for
(
int
i
=
0
;
i
<
civ
;
++
i
)
{
int
id
=
buildings
.
get
(
random
.
nextInt
(
buildings
.
size
())).
getID
();
result
.
addCivilian
(
id
);
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/RandomiseFunction.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
gis2.GisScenario
;
import
java.util.Random
;
/**
* Function for randomizing a scenario.
*/
public
class
RandomiseFunction
extends
AbstractFunction
{
private
Random
random
;
/**
* Construct a randomizer function.
*
* @param editor The editor instance.
*/
public
RandomiseFunction
(
ScenarioEditor
editor
)
{
super
(
editor
);
random
=
new
Random
();
}
@Override
public
String
getName
()
{
return
"Randomise"
;
}
@Override
public
void
execute
()
{
RandomScenarioGenerator
generator
=
new
RandomScenarioGenerator
();
GisScenario
s
=
generator
.
makeRandomScenario
(
editor
.
getMap
(),
random
);
try
{
editor
.
setScenario
(
editor
.
getMap
(),
s
);
editor
.
setChanged
();
editor
.
updateOverlays
();
}
catch
(
CancelledByUserException
e
)
{
// Ignore
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/RemoveAmbulanceCentreTool.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLBuilding
;
import
maps.gml.GMLShape
;
/**
* Tool for removing ambulance centres.
*/
public
class
RemoveAmbulanceCentreTool
extends
ShapeTool
{
/**
* Construct a RemoveAmbulanceCentreTool.
*
* @param editor The editor instance.
*/
public
RemoveAmbulanceCentreTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Remove ambulance centre"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
shape
instanceof
GMLBuilding
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
removeAmbulanceCentre
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
RemoveAmbulanceCentreEdit
(
shape
.
getID
()));
}
private
class
RemoveAmbulanceCentreEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
RemoveAmbulanceCentreEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
addAmbulanceCentre
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
removeAmbulanceCentre
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/RemoveAmbulanceTeamTool.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLShape
;
/**
* Tool for removing ambulance teams.
*/
public
class
RemoveAmbulanceTeamTool
extends
ShapeTool
{
/**
* Construct a RemoveAmbulanceTeamTool.
*
* @param editor The editor instance.
*/
public
RemoveAmbulanceTeamTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Remove ambulance team"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
true
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
removeAmbulanceTeam
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
RemoveAmbulanceTeamEdit
(
shape
.
getID
()));
}
private
class
RemoveAmbulanceTeamEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
RemoveAmbulanceTeamEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
addAmbulanceTeam
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
removeAmbulanceTeam
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/RemoveCivilianTool.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLShape
;
/**
* Tool for removing civilians.
*/
public
class
RemoveCivilianTool
extends
ShapeTool
{
/**
* Construct a RemoveCivilianTool.
*
* @param editor The editor instance.
*/
public
RemoveCivilianTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Remove civilian"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
true
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
removeCivilian
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
RemoveCivilianEdit
(
shape
.
getID
()));
}
private
class
RemoveCivilianEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
RemoveCivilianEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
addCivilian
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
removeCivilian
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/RemoveFireBrigadeTool.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLShape
;
/**
* Tool for removing fire brigades.
*/
public
class
RemoveFireBrigadeTool
extends
ShapeTool
{
/**
* Construct a RemoveFireBrigadeTool.
*
* @param editor The editor instance.
*/
public
RemoveFireBrigadeTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Remove fire brigade"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
true
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
removeFireBrigade
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
RemoveFireBrigadeEdit
(
shape
.
getID
()));
}
private
class
RemoveFireBrigadeEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
RemoveFireBrigadeEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
addFireBrigade
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
removeFireBrigade
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/RemoveFireStationTool.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLBuilding
;
import
maps.gml.GMLShape
;
/**
* Tool for removing fire stations.
*/
public
class
RemoveFireStationTool
extends
ShapeTool
{
/**
* Construct a RemoveFireStationTool.
*
* @param editor The editor instance.
*/
public
RemoveFireStationTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Remove fire station"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
shape
instanceof
GMLBuilding
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
removeFireStation
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
RemoveFireStationEdit
(
shape
.
getID
()));
}
private
class
RemoveFireStationEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
RemoveFireStationEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
addFireStation
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
removeFireStation
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
modules/gis2/src/gis2/scenario/RemoveFireTool.java
0 → 100644
View file @
342fea6f
package
gis2.scenario
;
import
javax.swing.undo.AbstractUndoableEdit
;
import
maps.gml.GMLBuilding
;
import
maps.gml.GMLShape
;
/**
* Tool for removing fires.
*/
public
class
RemoveFireTool
extends
ShapeTool
{
/**
* Construct a RemoveFireTool.
*
* @param editor The editor instance.
*/
public
RemoveFireTool
(
ScenarioEditor
editor
)
{
super
(
editor
);
}
@Override
public
String
getName
()
{
return
"Remove fire"
;
}
@Override
protected
boolean
shouldHighlight
(
GMLShape
shape
)
{
return
shape
instanceof
GMLBuilding
;
}
@Override
protected
void
processClick
(
GMLShape
shape
)
{
editor
.
getScenario
().
removeFire
(
shape
.
getID
());
editor
.
setChanged
();
editor
.
updateOverlays
();
editor
.
addEdit
(
new
RemoveFireEdit
(
shape
.
getID
()));
}
private
class
RemoveFireEdit
extends
AbstractUndoableEdit
{
private
int
id
;
public
RemoveFireEdit
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
void
undo
()
{
super
.
undo
();
editor
.
getScenario
().
addFire
(
id
);
editor
.
updateOverlays
();
}
@Override
public
void
redo
()
{
super
.
redo
();
editor
.
getScenario
().
removeFire
(
id
);
editor
.
updateOverlays
();
}
}
}
\ No newline at end of file
Prev
1
2
3
4
5
6
…
21
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment