LINGO
LINGO 起始畫面
示範例題 Max = 160*X1 + 100*X2 + 250*X3 s.t. X1 + X3 <= 4 X1, X2, X3 為整數 (integer)
答案求解 開始求解
模式建立 每一條式子都需要以分號 ; 作結尾 目標函數 - Max or Min 限制式 變數定義 - @BIN、@GIN 答案輸出 the general integer variable domain function A binary integer variable - also called a 0/1 variable 每一條式子都需要以分號 ; 作結尾
模式建立 目標函數 限制式 變數定義
結果輸出 最佳解之 目標函數值 最佳解之 變數值
SETS LINGO allows you to group many instances of the same variable into sets. For example, if a model involved 27 delivery trucks, then these 27 trucks could be described more simply as a single set. Sets may also include attributes for each member, such as the hauling capacity for each delivery truck.
Example SETS: Trucks/TR1..TR27/:Capacity; ENDSETS The attributes for each member are called “Capacity.”
set looping functions @FOR – generates constraints over members of a set. @SUM – sums an expression over all members of the set. @MIN – computes the minimum of an expression over all members of the set. @MAX – computes the maximum of an expression over all members of the set.
Example @FOR(Trucks(T): Capacity(T)<=3000); TOTAL_HAUL=@SUM(Trucks(J): Capacity(J)); MIN_HAUL = @MIN(Trucks(J): Capacity(J)); MAX_HAUL = @MAX(Trucks(J): Capacity(J));
The LINGO Data Section SETS: SET1 /A, B, C/: X, Y; ENDSETS DATA: ENDDATA
Example SETS: ITEMS / ANT_REPEL, BEER, BLANKET, BRATWURST, BROWNIES, FRISBEE, SALAD, WATERMELON/ : INCLUDE, WEIGHT, RATING; ENDSETS DATA: WEIGHT RATING = 1 2 3 9 4 3 3 8 3 10 1 6 5 4 10 10; KNAPSACK_CAPACITY = 15; ENDDATA MAX = @SUM( ITEMS: RATING * INCLUDE); @SUM( ITEMS: WEIGHT * INCLUDE) <= KNAPSACK_CAPACITY; @FOR( ITEMS: @BIN( INCLUDE));