📄 tsp.java
字号:
AbortButton.setEnabled(true);
ResetButton.setEnabled(false);
RandomCitiesComboBox.setEnabled(false);
SetRuntimeValue("00:00:00");
SetStepCountValue("0");
SecondsRunning=0;
MyTimer.start();
Algorithmen=(String)AlgorithmenComboBox.getSelectedItem();
if (Algorithmen=="Simulated Annealing")
{
MySimulatedAnnealingGui.HandleControls(false);
MySimulatedAnnealing = new simann(MyInstance);
MySimulatedAnnealing.SetBestSolutions(BestSolutions);
MySimulatedAnnealing.SetDelayTime(Delay);
MySimulatedAnnealing.SetNeighbourhoodType(MySimulatedAnnealingGui.Neighbourhood);
MySimulatedAnnealing.SetInitalTemperature(MySimulatedAnnealingGui.Temperature);
MySimulatedAnnealing.SetCoolingRate(MySimulatedAnnealingGui.CoolingRate);
MySimulatedAnnealing.SetInnerLoopBreak(MySimulatedAnnealingGui.InnerLoopBreak);
MySimulatedAnnealing.SetStartConfiguration(MyCities.GetStartConfiguration());
MySimulatedAnnealing.start();
}
else if (Algorithmen=="Ant Colony Optimization")
{
MyAntSystemGui.HandleControls(false);
MyAntSystem = new ant(MyInstance);
MyAntSystem.SetRandomConfiguration(MyCities.GetStartConfiguration());
MyAntSystem.SetBestSolutions(BestSolutions);
MyAntSystem.SetMaxCycles(MyAntSystemGui.MaxCycles);
MyAntSystem.SetDelayTime(Delay);
MyAntSystem.SetMyCities(MyCities.GetMyCities());
MyAntSystem.SetImpTrail(MyAntSystemGui.ImpTrail);
MyAntSystem.SetImpVisibility(MyAntSystemGui.ImpVisibility);
MyAntSystem.SetTrailPersistence(MyAntSystemGui.TrailPersistence);
MyAntSystem.SetTrailQuantity(MyAntSystemGui.TrailQuantity);
MyAntSystem.start();
}
}
});
AbortButton = new JButton();
AbortButton.setText("Stopp");
AbortButton.setBounds(90,440,70,25);
AbortButton.setFont(MyFont);
AbortButton.setEnabled(false);
AbortButton.addActionListener(new ActionListener ()
{
public void actionPerformed(ActionEvent e)
{
AbortButton.setEnabled(false);
ResetButton.setEnabled(false);
if (MySimulatedAnnealing!=null)
{
if (MySimulatedAnnealing.IsRunning())
{
MySimulatedAnnealing.SetStopFlag();
}
}
if (MyAntSystem!=null)
{
if (MyAntSystem.IsRunning())
{
MyAntSystem.SetStopFlag();
}
}
/*
HandleControls(true);
StartButton.setEnabled(true);
RandomCitiesComboBox.setEnabled(true);
MySimulatedAnnealingGui.HandleControls(true);
MyAntSystemGui.HandleControls(true);
SecondsRunning=0;
MyTimer.stop();
MyDraw.allowClick=true;
*/
}
});
ResetButton = new JButton();
ResetButton.setText("Reset");
ResetButton.setBounds(170,440,70,25);
ResetButton.setFont(MyFont);
ResetButton.setEnabled(true);
ResetButton.addActionListener(new ActionListener ()
{
public void actionPerformed(ActionEvent e)
{
if (MySimulatedAnnealing!=null)
{
if (MySimulatedAnnealing.IsRunning())
{
MySimulatedAnnealing.SetStopFlag();
}
}
if (MyAntSystem!=null)
{
if (MyAntSystem.IsRunning())
{
MyAntSystem.SetStopFlag();
}
}
MySimulatedAnnealingGui.HandleControls(true);
MyAntSystemGui.HandleControls(true);
if (MyAntSystem!=null)
{
try
{
MyAntSystem.join();
} catch(Exception ee) { }
};
if (MySimulatedAnnealing!=null)
{
try
{
MySimulatedAnnealing.join();
} catch(Exception ee) { }
}
HandleControls(true);
StartButton.setEnabled(false);
AbortButton.setEnabled(false);
Delay=0;
DelaySlider.setValue(0);
SetStepCountValue("0");
RandomCitiesComboBox.setEnabled(true);
RandomCitiesCheckBox.setSelected(false);
RandomCitiesComboBox.setSelectedIndex(0);
BestSolutionsCheckBox.setSelected(false);
BestSolutions=false;
MyCities.RemoveAllCities();
MyDraw.ClearAll();
MyCities.GenerateTucSymbol();
MyDraw.DrawAllCities();
MyDraw.allowClick=true;
SecondsRunning=0;
SetRuntimeValue("00:00:00");
MyTimer.stop();
MyCities.GenerateRandomStartSolution(true);
MyDraw.clicked = false;
}
});
OptionsPanel.add(AlgorithmenLabel);
OptionsPanel.add(AlgorithmenComboBox);
OptionsPanel.add(RandomCitiesCheckBox);
OptionsPanel.add(RandomCitiesComboBox);
OptionsPanel.add(BestSolutionsCheckBox);
OptionsPanel.add(DelayLabel);
OptionsPanel.add(DelaySlider);
OptionsPanel.add(StartButton);
OptionsPanel.add(AbortButton);
OptionsPanel.add(ResetButton);
MySimulatedAnnealingGui = new simanngui(OptionsPanel);
MySimulatedAnnealingGui.InitContent();
MyAntSystemGui = new antgui(OptionsPanel,MyInstance);
MyAntSystemGui.InitContent();
MySimulatedAnnealingGui.ShowControls(false);
MyAntSystemGui.ShowControls(true);
}
private void makeDisplayContent()
{
MyDraw = new draw(MyInstance);
DisplayPanel.add(MyDraw);
}
private void makeInformationContent()
{
Font MyFont = new Font("System",0,12);
Font MyFont2 = new Font("System",1,12);
StepCountLabel = new JLabel();
StepCountLabel.setText("Schritte/Runden: ");
StepCountLabel.setBounds(50,12,150,15);
StepCountLabel.setFont(MyFont);
StepCountLabel.setHorizontalAlignment(JLabel.RIGHT);
RuntimeLabel = new JLabel();
RuntimeLabel.setText("Laufzeit: ");
RuntimeLabel.setBounds(50,30,150,15);
RuntimeLabel.setFont(MyFont);
RuntimeLabel.setHorizontalAlignment(JLabel.RIGHT);
TemperatureLabel = new JLabel();
TemperatureLabel.setText("Temperatur: ");
TemperatureLabel.setBounds(50,48,150,15);
TemperatureLabel.setFont(MyFont);
TemperatureLabel.setHorizontalAlignment(JLabel.RIGHT);
OrgDistanceLabel = new JLabel();
OrgDistanceLabel.setText("Anfangsdistanz:");
OrgDistanceLabel.setBounds(250,12,130,15);
OrgDistanceLabel.setFont(MyFont);
OrgDistanceLabel.setHorizontalAlignment(JLabel.RIGHT);
NowDistanceLabel = new JLabel();
NowDistanceLabel.setText("Beste Distanz:");
NowDistanceLabel.setBounds(250,30,130,15);
NowDistanceLabel.setFont(MyFont);
NowDistanceLabel.setHorizontalAlignment(JLabel.RIGHT);
PerDistanceLabel = new JLabel();
PerDistanceLabel.setText("Verbesserung %:");
PerDistanceLabel.setBounds(250,48,130,15);
PerDistanceLabel.setFont(MyFont);
PerDistanceLabel.setHorizontalAlignment(JLabel.RIGHT);
StepCountValue = new JLabel();
StepCountValue.setBounds(203,12,130,15);
StepCountValue.setFont(MyFont2);
StepCountValue.setHorizontalAlignment(JLabel.LEFT);
SetStepCountValue("0");
RuntimeValue = new JLabel();
RuntimeValue.setBounds(203,30,130,15);
RuntimeValue.setFont(MyFont2);
RuntimeValue.setHorizontalAlignment(JLabel.LEFT);
SetRuntimeValue("00:00:00");
TemperatureValue = new JLabel();
TemperatureValue.setBounds(203,48,130,15);
TemperatureValue.setFont(MyFont2);
TemperatureValue.setHorizontalAlignment(JLabel.LEFT);
SetTemperatureValue("0,00");
OrgDistanceValue = new JLabel();
OrgDistanceValue.setBounds(383,12,130,15);
OrgDistanceValue.setFont(MyFont2);
OrgDistanceValue.setHorizontalAlignment(JLabel.LEFT);
SetOrgDistanceValue("0");
NowDistanceValue = new JLabel();
NowDistanceValue.setBounds(383,30,130,15);
NowDistanceValue.setFont(MyFont2);
NowDistanceValue.setHorizontalAlignment(JLabel.LEFT);
SetNowDistanceValue("0");
PerDistanceValue = new JLabel();
PerDistanceValue.setBounds(383,48,130,15);
PerDistanceValue.setFont(MyFont2);
PerDistanceValue.setHorizontalAlignment(JLabel.LEFT);
SetPerDistanceValue("0%");
InformationPanel.add(StepCountLabel);
InformationPanel.add(RuntimeLabel);
InformationPanel.add(TemperatureLabel);
InformationPanel.add(OrgDistanceLabel);
InformationPanel.add(NowDistanceLabel);
InformationPanel.add(PerDistanceLabel);
InformationPanel.add(StepCountValue);
InformationPanel.add(TemperatureValue);
InformationPanel.add(RuntimeValue);
InformationPanel.add(OrgDistanceValue);
InformationPanel.add(NowDistanceValue);
InformationPanel.add(PerDistanceValue);
}
public void SetStepCountValue (String act)
{
StepCountValue.setText(act);
}
public void SetRuntimeValue (String S)
{
RuntimeValue.setText(S);
}
public void SetTemperatureValue (String S)
{
TemperatureValue.setText(S);
}
public void SetOrgDistanceValue (String S)
{
OrgDistanceValue.setText(S);
}
public void SetNowDistanceValue (String S)
{
NowDistanceValue.setText(S);
}
public void SetPerDistanceValue (String S)
{
PerDistanceValue.setText(S);
}
private void HandleControls(boolean enabled)
{
if (enabled)
{
AlgorithmenComboBox.setEnabled(true);
RandomCitiesCheckBox.setEnabled(true);
}
else
{
AlgorithmenComboBox.setEnabled(false);
RandomCitiesCheckBox.setEnabled(false);
}
}
public void ChangeCityCount(int i)
{
ActCitiesCount=ActCitiesCount+i;
if (ActCitiesCount>2)
{
StartButton.setEnabled(true);
}
else
{
StartButton.setEnabled(false);
}
}
public void ResetCityCount()
{
ActCitiesCount=0;
StartButton.setEnabled(false);
}
public void MakeReady()
{
HandleControls(true);
StartButton.setEnabled(true);
ResetButton.setEnabled(true);
AbortButton.setEnabled(false);
MySimulatedAnnealingGui.HandleControls(true);
MyAntSystemGui.HandleControls(true);
SecondsRunning=0;
MyTimer.stop();
MyDraw.allowClick=true;
RandomCitiesComboBox.setEnabled(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -