LINGO (3)-example

Source: Internet
Author: User
1. one assembly line balancing model

1. assembly line balancing model

An assembly line contains a series of workstations. each workstation executes one or more specific tasks during the final product processing. The assembly line cycle refers to the maximum time it takes for all workstations to complete their respective tasks. The goal of the balanced assembly line is to assign processing tasks to each workstation so that each workstation can execute the same number of tasks as much as possible. The final criterion is that the distribution switching cycle is the shortest. Improper balancing of the assembly line will lead to bottlenecks-workstation with fewer tasks will be forced to wait for the previous multi-task workstation to be allocated.

The goal of this model is to minimize the assembly line cycle. There are two types of constraints:

(1) ensure that each task can only be assigned to one workstation for processing;

(2) ensure that all priorities of tasks are met.

In this example, one task (A-K) is assigned to four Workstation (1-4) and the task is ordered as follows. Each task takes the following time:

Task

Time

A

45

B

11

C

9

D

50

E

15

F

12

G

12

H

12

I

12

J

8

K

9

 

The solution model is provided here.

Model :! Assembly balancing model; sets :! TASK set, which has A completion time attribute T; TASK/a B c d e f g h I J K/: T ;! A set of priority relations among characters; PRED (TASK, TASK)/A, B, C, F C, G F, J G, J, K D, E, h e, I h, j I, J /;! Workstation set; STATION/1 .. 4/; TXS (TASK, STATION): X ;! X is an attribute of the derived set TXS. If X (I, K) = I, the I task is assigned to the K Workstation. endsetsdata :! The completion time of task a B c d e f g h I J K is estimated as follows; enddata! When there are more than 15 tasks, the model solving will be slow :! Each job must be assigned to a workstation. @ for (TASK (I): @ SUM (STATION (K): X (I, K) = 1 );! For each finite-relation job, the workstation I corresponding to the former must be smaller than the workstation J corresponding to the latter; @ for (PRED (I, J): @ sum (STATION (K): K * X (J, K)-K * X (I, K)> = 0 );! For each workstation, the time spent should not be greater than the assembly line cycle; @ for (STATION (K): @ SUM (TXS (I, K): T (I) * X (I, k) <+ CYCTIME );! Minimum distribution cycle for the target function; min = CYCTIME ;! Specify X (I, J) as the 0/1 variable; @ for (TXS: @ BIN (X); end

 

 

2. traveling salesman problem, also known as the cargo carrier problem

There is a salesman, starting from City 1, who wants to visit cities 2, 3 ,..., n times, and finally return to the City 1. it is known that the travel expenses from city I to j are Cij. in what order should he visit these cities? You can use multiple Chinese methods to represent the TSP as an integer programming model. Consider every solution to this problem as a tour.

In the above sense, the 0-1 integer variable is introduced
 

After several proofs, we will not discuss it here. we can convert TSP into a mixed integer programming problem.

 

 

Here we can use this question to solve a specific problem.

Question 1: Now we need to process n parts on one machine. these parts can be processed on the machine in any order. We want to minimize the total time for processing all parts. Due to the requirements of the processing technology, the machine of the processing Part j is not allowed to be in the corresponding state Sj (such as furnace temperature ). The machine is in S0 state when no parts are processed at the start, and the machine must be in S0 state after all parts are processed. It is known that it takes Cij time to adjust from Si status to Sj. The processing time of Part j is Pj. For convenience, a Xu part 0 is introduced, where the processing time is 0 and the status is S0. Then, a circle of {0, 1, 2,..., n} is converted to pi, which indicates a processing order for all parts. the time required to complete all processing is.

 

Here is a simple code for solving this model, that is, to apply the above model

! Travel salesman problem; model: sets: city/1 .. 5/: u; link (city, city): dist, x; endsets n = @ size (city); data: dist = @ qrand (1 );! Generated immediately. here we can change it to the data for the problem you want to solve; enddata! Target function; min = @ sum (link: dist * x); @ for (city (K): @ sum (city (I) | I # ne # K: x (I, K) = 1; @ sum (city (J) | J # ne # K: x (K, J) = 1 ;);! Ensure that no circles exist. @ for (city (I) | I # gt #1: @ for (city (J) | J # gt #1 # and # I # ne # j: u (I)-u (J) + n * x (I, J) <= n-1 ););! Define X as the 0/1 variable; @ for (link: @ bin (x); end


3. maximum short circuit problem

Given N point Pi to form a set {Pi}, the distance from any point Pi in the set to another point Pj is represented by Cij. if Pi to Pj is not connected by ARC, cij = positive infinity, Cii = 0, specify an endpoint PN, and the shortest route from Pi to PN is required. Here we use dynamic planning.

 

And LINGO, we can easily solve the above model.

! Transient problem; model: data: n = 10; enddatasets: cities/1 .. n/: F; roads (cities, cities)/108,109, 10/: D, p; endsetsdata: D = 6 5! This matrix is the legendary weight matrix 3 6 97 5 119 18 7 54 10579; enddataF (n) = 0; @ for (cities (I) | I # lt # n: F (I) = @ min (roads (I, j): D (I, j) + F (j )););! Obviously, if P (I, j) = 1, the first step of the shortest path of point I to point n is I -- j. otherwise, we can easily determine the shortest path; @ for (roads (I, j): P (I, j) = @ if (F (I) # eq # D (I, j) + F (j), 1, 0); end

 

4. allocation problem or assignment problem

This is the problem of assigning n jobs to n people to achieve the best effect. The average time required by I to complete the j tasks is Cij. You need to assign a task to each person and assign the task to minimize the total time required to complete all tasks. This problem can be expressed as follows:
 

This model can be easily solved using LINGO.

Model :! Seven workers: Allocation of seven jobs; sets: workers/w1.. w7/; jobs/j1.. j7/; links (workers, jobs): cost, volume; endsets! Target function; min = @ sum (links: cost * volume );! Each person can have only one job. @ for (workers (I): @ sum (jobs (J): volume (I, J) = 1;); data: cost = 6 2 6 7 4 2 5 4 9 5 3 8 5 5 2 1 9 7 4 3 6 7 3 9 2 2 2 3 9 5 7 6 5 5 2 2 8 11 4 9 2 3 12 4 5 10; enddataend


 

5. secondary allocation problems

This problem is roughly the same as the above allocation problem. We also need to introduce 0-1 variables, which have the same constraints as above. However, this problem is more complex than the constraints. We get the price coefficient Cijkl. the explanation is: when I (an element of S surfing the Internet) is allocated to j (an element of T), k (an element of s) the cost assigned to l (an element of T. Obviously, this charge is only incurred when xij = 1 and xkl = 1. At this time, our model will become like this.

To understand this model, we will add this example here. S is a collection of factories, and T is a collection of n cities. This problem is to set up a factory in every city and minimize the communication cost between factories. The communication fee depends on: (1) the number of communications between each pair of factories, tik; (2) the distance between two cities where each pair of factories is located, djl. So there is cijkl = tik * djl (you can see it ...). Therefore, the total cost can be expressed by the above objective function.

Here is a classic question, which is also the first modeling problem I encountered. I thought that I didn't know the benefits of lingo in the past, but I was stubborn about C ++. I used a stack and pulled out the linked list vector or something. how proud I was, hahaha.

 

For example, four students go to a company for three-phase interview: The company requires that each student first obtain the first Test from the secretary, then copy the test from the department director, and finally go to the manager for an interview, and cannot be inserted into the queue. Because of the different professional backgrounds of the four students, the interview time for no one in the three stages is different, as shown in the following table. The four asked them to leave the company after they completed all the interviews and asked them how soon they could complete the interview?

 

The solution code is provided here.

 

! Three-stage interview model; model: sets: students ;! Three-phase interview model for student sets; phases ;! Phase set; sp (students, phases): t, x; ss (students, students) | & 1 # lt # & 2: y; endsetsdata: students = s1 .. s4; phases = p1 .. p3; t = 13 15 2010 20 1820 16 108 10 15; enddatans = @ size (students );! Student count; np = @ size (phases );! Number of stages! Constraints on the sequence of individual student interviews; @ for (sp (I, J) | J # LT # np: x (I, J) + t (I, J) <= x (I, J + 1 ));! Constraints on changing the order of interviews among students; @ for (ss (I, K): @ for (phases (J): x (I, J) + t (I, j)-x (K, J) <= 200 * y (I, K); x (K, J) + t (K, J)-x (I, J) <= 200 * (1-y (I, K); min = TMAX; @ for (students (I): x (I, 3) + t (I, 3) <= TMAX );! Define Y as the 0-1 variable ;! Define the 0-1 variable for Y; @ for (ss: @ bin (y); end


If you encounter a better model in the future, I will choose to add it.

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.