我不知道如何解决excel范围的大小不是数组的大小

问题描述 投票:0回答:0

我正在连接到 excel 来解决我的问题,但范围的大小不是数组的大小我的代码是最小化端口操作的总等待时间。我该如何修复此代码的 excel。

in dat file
SheetConnectionReadData ("project2.xlsx");
num_docksfromSheetRead (ReadData, "Sheet1!A10:A12");
num_berthsfromSheetRead(ReadData, "Sheet1!B10:B12");
num_shipsfromSheetRead(ReadData, "Sheet1!C10:C12");
ratio_berthsfromSheetRead(ReadData, "Sheet1!D10:D12");
endb_timefromSheetRead(ReadData, "Sheet1!E10:E12");
ar_timefrom heetRead(ReadData, "Sheet1!F10:F12");
entrance_time from SheetRead(ReadData, "Sheet1!B17:D17");
waiting_time_at_dock from SheetRead(ReadData, "Sheet1!B18:D18");
totaltime_shipaccess from SheetRead(ReadData, "Sheet1!B19:D19");

请帮助我,我快到截止日期了 this is my excel file.

intnum_docks =3;
range Docks = 1..num_docks;
intnum_ships = 60;
range Ships = 1..num_ships;
int num_berths[Docks][Ships] = ...;
int entrance_time[Docks][Ships] = ...;
int ar_time[Docks][Ships] = ...;
int endb_time[Docks][Ships] = ...;
int waiting_time_at_dock[Docks][Ships] = ...;
int totaltime_shipaccess[Docks][Ships] = ...;
int total_berths=13;
int ratio_berths[Docks][Ships]=...;
float Max_Waiting_Time = 100.0;
dvar float+ total_waiting_time;

minimize sum(d in Docks, i in Ships) (entrance_time[d][i] - ar_time[d][i])
         + sum(d in Docks, i in Ships) (endb_time[d][i] - totaltime_shipaccess[d][i]);

subject to {
    // Constraint 1: Compute total number of berths
    total_berths == sum(d in Docks, i in Ships) num_berths[d][i];

    // Constraint 2: Ensure that arrival time is less than or equal to entrance time
    forall (d in Docks, i in Ships) {
        ar_time[d][i] <= entrance_time[d][i];
    }

    // Constraint 3: Compute waiting time at dock
    forall (d in Docks, i in Ships) {
        waiting_time_at_dock[d][i] == entrance_time[d][i] - ar_time[d][i];
    }

    // Constraint 4: Compute total waiting time
    forall (d in Docks, i in Ships) {
        ratio_berths[d][i] == num_berths[d][i] / total_berths;
        total_waiting_time == totaltime_shipaccess[d][i]*ratio_berths[d][i];
    }

    // Constraint 5: Limit waiting time at dock
    forall (d in Docks, i in Ships) {
       total_waiting_time <= Max_Waiting_Time;
    }

    // Constraint 6: Ensure that ships arrive at the right time
    forall (d in Docks: d < num_docks, i in Ships) {
        entrance_time[d][i] <= ar_time[d+1][i];
    }

    // Constraint 7: Limit the number of ships at each dock
    forall (d in Docks) {
        sum(i in Ships) (d - ar_time[d][i]) - sum(i in Ships) (d - entrance_time[d][i]) <= total_berths;
    }
}

execute {
    writeln("Optimal total_waiting_time: ", total_waiting_time.solutionValue, " mins");
    writeln("");

    for (var d in Docks) {
        for (var i in Ships) {
            writeln("Waiting time for ship ", i, " at dock ", d, ": ", waiting_time_at_dock[d][i].solutionValue, " mins");
        }
        writeln("Total waiting time at dock ", d, ": ");
    }
}

我不得不多次尝试替换列和行,但没有用。如果可以,您可以修复所有代码以供我检查或与我联系

arrays excel range size cplex
© www.soinside.com 2019 - 2024. All rights reserved.