| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 | 
							- package shuttle
 
- import (
 
- 	"fmt"
 
- )
 
- type cell struct {
 
- 	Tp     string
 
- 	AddrId string
 
- 	F      int
 
- 	C      int
 
- 	R      int
 
- 	Cnv    string
 
- 	Load   string
 
- }
 
- func newCell(tp string, f, c, r int) cell {
 
- 	addrId := getAddrId(f, c, r)
 
- 	return cell{tp, addrId, f, c, r, "", ""}
 
- }
 
- type lift struct {
 
- 	lft
 
- 	AddrId string
 
- }
 
- func newLift(l lft) lift {
 
- 	addrId := fmt.Sprintf("000%02d%02d", l.C, l.R)
 
- 	return lift{l, addrId}
 
- }
 
- type conveyor struct {
 
- 	cnv
 
- }
 
- type xTrack struct {
 
- 	xTrc
 
- 	cells []cell
 
- }
 
- // 放货的通道
 
- type slot struct {
 
- 	Id       string
 
- 	Cells    []cell
 
- 	CanStore bool
 
- }
 
- func (slt *slot) Append(cl cell) {
 
- 	if slt.Cells == nil {
 
- 		slt.Cells = []cell{}
 
- 	}
 
- 	if len(slt.Cells) <= 0 {
 
- 		slt.Id = cl.AddrId
 
- 	}
 
- 	slt.Cells = append(slt.Cells, cl)
 
- }
 
- func (slt slot) hasCell(f, c, r int) bool {
 
- 	for _, cl := range slt.Cells {
 
- 		if cl.F == f && cl.C == c && cl.R == r {
 
- 			return true
 
- 		}
 
- 	}
 
- 	return false
 
- }
 
- type floor struct {
 
- 	F       int
 
- 	Slots   []slot
 
- 	xTracks []*xTrack
 
- 	Cnvs    []conveyor
 
- 	Ins     []IO
 
- 	Outs    []IO
 
- }
 
- const (
 
- 	actNull = iota
 
- 	actUp
 
- 	actDown
 
- )
 
- const (
 
- 	taskStatusNo = iota
 
- 	taskStatusWait
 
- 	taskStatusRun
 
- 	taskStatusFinish = taskStatusNo
 
- )
 
- const (
 
- 	tskTypeMove = iota
 
- 	tskTypeFetch
 
- )
 
- // 单车任务
 
- type tsk struct {
 
- 	Id     int
 
- 	tp     int
 
- 	s      addr
 
- 	d      addr
 
- 	status int
 
- }
 
- type path struct {
 
- 	Idx  int
 
- 	List []addr
 
- }
 
- type carrier struct {
 
- 	Id   string
 
- 	F    int
 
- 	C    int
 
- 	R    int
 
- 	Load bool
 
- 	Task tsk
 
- 	Path path
 
- }
 
- // 计划
 
- type movePlan struct {
 
- 	Id      int
 
- 	SrcSlot string
 
- 	DstSlot string
 
- 	Num     int
 
- 	task    []tsk
 
- }
 
- type plan struct {
 
- 	MovePlan []movePlan
 
- }
 
- type warehouse struct {
 
- 	warehouseData
 
- 	Floors    map[int]floor
 
- 	Lifts     map[string]lift
 
- 	Conveyors map[string]conveyor
 
- 	Ports     map[string]pot
 
- 	NoCells   map[string]bool
 
- 	Carriers  map[string]carrier
 
- 	tasks     []tsk // 任务列表
 
- 	Task      []tsk // 同层的任务
 
- 	Plans     plan  // 预先下发的任务列表
 
- }
 
- func newXTrack(trc xTrc) *xTrack {
 
- 	ret := xTrack{trc, []cell{}}
 
- 	if trc.CE < trc.CS {
 
- 		ret.CS = trc.CE
 
- 		ret.CE = trc.CS
 
- 	}
 
- 	for c := trc.CS; c <= trc.CE; c++ {
 
- 		ret.cells = append(ret.cells, newCell(TpXTrack, trc.F, c, trc.R))
 
- 	}
 
- 	return &ret
 
- }
 
- func (w *warehouse) getCell(f, r, c int) cell {
 
- 	return newCell(w.getCelType(f, c, r), f, r, c)
 
- }
 
- func (w *warehouse) createFloorFromWarehouseData(d *warehouseData, f int) (err string) {
 
- 	flr := floor{f, []slot{}, []*xTrack{}, []conveyor{}, []IO{}, []IO{}}
 
- 	for _, xt := range d.XTrcs {
 
- 		xtr := newXTrack(xt)
 
- 		if len(xtr.cells) > 1 {
 
- 			flr.xTracks = append(flr.xTracks, xtr)
 
- 		}
 
- 	}
 
- 	for c := 1; c <= d.ColNum; c++ {
 
- 		slt := slot{
 
- 			Cells: make([]cell, 0),
 
- 		}
 
- 		slt.CanStore = true
 
- 		for r := 0; r <= d.RowNum+1; r++ {
 
- 			cur := d.newCell(f, c, r)
 
- 			if cur.Tp != TpNoCell {
 
- 				slt.Cells = append(slt.Cells, cur)
 
- 			}
 
- 			if w.isYTrac(f, c, r) || cur.Tp == TpPort || cur.Tp == TpLift || cur.Tp == TpConveyor {
 
- 				// 作为通道,不放货
 
- 				slt.CanStore = false
 
- 			}
 
- 			if cur.Tp == TpNoCell || cur.Tp == TpLift || cur.Tp == TpXTrack || cur.Tp == TpPort {
 
- 				if len(slt.Cells) > 0 {
 
- 					flr.Slots = append(flr.Slots, slt)
 
- 					if r < d.RowNum {
 
- 						slt = slot{
 
- 							Cells: make([]cell, 1),
 
- 						}
 
- 						slt.Cells[0] = d.newCell(f, c, r)
 
- 					}
 
- 				}
 
- 			}
 
- 		}
 
- 		return fmt.Sprintf("Floor data error at warehouse: %s(%d)", d.Name, f)
 
- 	}
 
- 	if len(flr.Slots) > 0 {
 
- 		w.Floors[f] = flr
 
- 	}
 
- 	return ""
 
- }
 
- func NewWarehouseFromData(d *warehouseData) (*warehouse, string) {
 
- 	w := &warehouse{
 
- 		warehouseData: *d,
 
- 		Floors:        map[int]floor{},
 
- 		Lifts:         map[string]lift{},
 
- 		Conveyors:     map[string]conveyor{},
 
- 		Ports:         d.Pots,
 
- 		NoCells:       map[string]bool{},
 
- 	}
 
- 	for _, n := range d.NoCels {
 
- 		w.NoCells[getAddrId(n.F, n.C, n.R)] = true
 
- 	}
 
- 	for _, c := range d.Cnvs {
 
- 		w.Conveyors[c.Id] = conveyor{c}
 
- 	}
 
- 	for _, l := range d.lfts {
 
- 		w.Lifts[l.getAddrId()] = newLift(lft{})
 
- 	}
 
- 	for f := 1; f <= d.FloorNum; f++ {
 
- 		if ret := w.createFloorFromWarehouseData(d, f); ret != "" {
 
- 			return nil, ret
 
- 		}
 
- 	}
 
- 	return w, ""
 
- }
 
- func (w warehouse) checkCellSrc(f, r, c int) bool {
 
- 	tp := w.getCelType(f, r, c)
 
- 	if tp == TpXTrack || tp == TpNoCell {
 
- 		return false
 
- 	}
 
- 	return true
 
- }
 
- func (w warehouse) getSlot(f, c, r int) *slot {
 
- 	if flt, ok := w.Floors[f]; ok {
 
- 		for _, slt := range flt.Slots {
 
- 			if slt.hasCell(f, c, r) {
 
- 				return &slt
 
- 			}
 
- 		}
 
- 	}
 
- 	return nil
 
- }
 
- // AddSlotToSlotPlan 增加一个巷道到巷道的任务
 
- func (w warehouse) AddSlotToSlotPlan(sf, sc, sr, df, dc, dr int) string {
 
- 	srcSlot := w.getSlot(sf, sc, sr)
 
- 	if srcSlot == nil {
 
- 		return "NoSrcSlot"
 
- 	}
 
- 	dstSlot := w.getSlot(df, dc, dr)
 
- 	if dstSlot == nil {
 
- 		return "NoDstSlot"
 
- 	}
 
- 	//	w.tasks = append(w.tasks)
 
- 	return ""
 
- }
 
- // 找到离取货点最近的车
 
- func (w warehouse) getNearestCarrier(sf, sc, sr int) string {
 
- 	return ""
 
- }
 
- func (w warehouse) exeTaskNoFollowLift(sf, sc, sr, df, dc, dr int) {
 
- 	// carrierId := w.getNearestCarrier(sf, sc, sr)
 
- }
 
- func (cr *carrier) SetTask(t tsk) bool {
 
- 	if cr.Load == true {
 
- 		return false
 
- 	}
 
- 	if cr.Task.status != taskStatusNo {
 
- 		return false
 
- 	}
 
- 	cr.Task = t
 
- 	return true
 
- }
 
- func (w warehouse) setCarrierTask(cId string, f, c, r int) bool {
 
- 	// cr, ok := w.Carriers[cId]
 
- 	// if !ok {
 
- 	// 	return false
 
- 	// }
 
- 	return true
 
- }
 
- type pathPoint struct {
 
- 	F int
 
- 	C int
 
- 	R int
 
- }
 
- func (w warehouse) getPath(f, c, r, df, dc, dr int) (path []pathPoint, ret string) {
 
- 	// 同一层
 
- 	if f == df {
 
- 	} else {
 
- 	}
 
- 	return path, ""
 
- }
 
 
  |