我的Java程序任务存在问题。任务是找到其脉冲宽度和电压降延迟的电压骤降。要考虑的参数是电压,脉冲宽度和脉冲延迟。
该程序是为线性搜索中的三维实现的。但总编译时间大约需要21小时才能完成一轮。有人可以帮我提出一个有效的三维搜索算法,编译时间更长吗?
以下是代码的一部分:
//...snip
if (exu.isDryRun()) {
return;
}
// singleRun();
// exu.pause(50);
// if( wasThereAnError() == true)
{
PulseWidthLoop();
for (V = 6.4; V <= 9.0; V += .1) {
Fixed_constant();
}
for (V = 6.3; V >= 6.0; V -= .1) {
Fixed_constant();
}
}
private void Fixed_constant() {
for (D = 604; D <= 1000; D += 4) {
PulseWidthLoop();
}
for (D = 600; D >= 4; D -= 4) {
boolean res = PulseWidthLoop();
}
}
private boolean PulseWidthLoop() {
final boolean result[] = new boolean[1];
result[0] = true;
exu.exec(new ATaskTS() {
@RunContextDirect
public void task() {
int correctCount = 0;
for (W = 200; correctCount <= 1 && W <= 1000; W += 4) {
singleRun();
exu.pause(50);
if (wasThereAnError()) {
result[0] = false;
correctCount = 0;
System.out.printf(" error Value of W = %f", W);
} else {
// correct
correctCount++;
System.out.printf("Value of W no error= %f", W);
}
System.out.printf("number oif loops %d\n", correctCount);
}
// Fixed_constant();
correctCount = 0;
for (W = 196; correctCount <= 2 && W >= 4; W -= 4) {
singleRun();
exu.pause(50);
if (wasThereAnError()) {
result[0] = false;
correctCount = 0;
} else {
correctCount++;
}
System.out.printf("number of negative loops %d\n", correctCount);
}
}
});
return result[0];
}
private void singleRun() {
exu.exec(new ATaskTS() {
@RunContextHil
public void task() {
exu.commentLevelEnter("voltage = %f , Delay_Start_Time = %f , PulseWidth_Start_duration = %f", V, D, W);
{
exu.modTS().objKlemme30().afcOff();
exu.pause(100);
exu.modTS().objKlemme30().afcOn();
exu.pause(100);
lib.Ignition_Off();
exu.modTS().objKlemme15().afcOff();
exu.pause(100);
lib.Ignition_On();
exu.modTS().objKlemme15().afcOn();
exu.pause(D);
setOutputVoltage(V);
exu.pause(W);
setOutputVoltage(12);
exu.pause(20);
{
isInStandby = false;
//String contextMsg = String.format(Locale.US,"ErrorCase: Voltage/Pulse_Delay/Pulse_width\t%f\t%f\t%f", V, D, W);
String contextMsg = String.format(Locale.US, "ErrorCase: %f\t%f\t%f", V, D, W);
testForErrorsStandby(contextMsg);
System.out.printf(contextMsg);
}
}
exu.commentLevelLeave();
}
}
);
}
int lastErrorCounter = 0;
private boolean wasThereAnError() {
// Assert.isTrue(exu.isRunContextDirect() || exu.isDryRun(), "should only be called from RunContextDirect"); // This will encounter the problem if it is in HIL mode or Direct mode
int errorcounter = exu.getUserValueAsInt(CteSetup.KEY_ERRORCOUNTER, 0);
boolean result = errorcounter != lastErrorCounter;
lastErrorCounter = errorcounter;
return result;
}
private void testForErrorsStandby(String contextMsg) {
exu.commentLevelEnter("Testing Error isInStandby=%s", isInStandby);
{
exu.pause(2000);
lib.DiagSendAndTest("Open Extended Session", "10 03", 6, "50 03");
exu.pause(100);
lib.DiagSendAndTest("Read LED Status", "22 02 01", 11, "62 02 01");
exu.pause(100);
exu.modTS().objDiag().msgID_Data().comment(10, true, contextMsg);
lib.DiagTestByteSequence(3,
// isInStandby ? "FF FF FF FF 01 01 01 01" : "23 26 30 35 3F 3F 1F 1F");
isInStandby ? "FF FF FF FF 01 01 01 01" : "23 26 30 35 3F 3F 1F 1F");
exu.pause(100);
}
exu.commentLevelLeave();
}