Skip to content

Multiple Depot Multiple Driver

Maciej Mionskowski edited this page Oct 28, 2016 · 3 revisions
import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/routing"
)

func main() {
	client := &route4me.NewClient("11111111111111111111111111111111")
	service := &routing.Service{Client: client}
	addresses := []*routing.Address{
		&routing.Address{AddressString: "3634 W Market St, Fairlawn, OH 44333", //all possible originating locations are depots, should be marked as true
			//stylistically we recommend all depots should be at the top of the destinations list
			IsDepot:   true,
			Latitude:  41.135762259364,
			Longitude: -81.629313826561,

			//the number of seconds at destination
			Time: 300,

			//together these two specify the time window of a destination
			//seconds offset relative to the route start time for the open availability of a destination
			TimeWindowStart: 28800,

			//seconds offset relative to the route end time for the open availability of a destination
			TimeWindowEnd: 29465},

		&routing.Address{AddressString: "1218 Ruth Ave, Cuyahoga Falls, OH 44221",
			Latitude:        41.135762259364,
			Longitude:       -81.629313826561,
			Time:            300,
			TimeWindowStart: 29465,
			TimeWindowEnd:   30529},

		&routing.Address{AddressString: "512 Florida Pl, Barberton, OH 44203",
			Latitude:        41.003671512008,
			Longitude:       -81.598461046815,
			Time:            300,
			TimeWindowStart: 30529,
			TimeWindowEnd:   33779},

		&routing.Address{AddressString: "512 Florida Pl, Barberton, OH 44203",
			Latitude:        41.003671512008,
			Longitude:       -81.598461046815,
			Time:            100,
			TimeWindowStart: 33779,
			TimeWindowEnd:   33944},

		&routing.Address{AddressString: "3495 Purdue St, Cuyahoga Falls, OH 44221",
			Latitude:        41.162971496582,
			Longitude:       -81.479049682617,
			Time:            300,
			TimeWindowStart: 33944,
			TimeWindowEnd:   34801},

		&routing.Address{AddressString: "1659 Hibbard Dr, Stow, OH 44224",
			Latitude:        41.194505989552,
			Longitude:       -81.443351581693,
			Time:            300,
			TimeWindowStart: 34801,
			TimeWindowEnd:   36366},

		&routing.Address{AddressString: "2705 N River Rd, Stow, OH 44224",
			Latitude:        41.145240783691,
			Longitude:       -81.410247802734,
			Time:            300,
			TimeWindowStart: 36366,
			TimeWindowEnd:   39173},

		&routing.Address{AddressString: "10159 Bissell Dr, Twinsburg, OH 44087",
			Latitude:        41.340042114258,
			Longitude:       -81.421226501465,
			Time:            300,
			TimeWindowStart: 39173,
			TimeWindowEnd:   41617},

		&routing.Address{AddressString: "367 Cathy Dr, Munroe Falls, OH 44262",
			Latitude:        41.148578643799,
			Longitude:       -81.429229736328,
			Time:            300,
			TimeWindowStart: 41617,
			TimeWindowEnd:   43660},

		&routing.Address{AddressString: "367 Cathy Dr, Munroe Falls, OH 44262",
			Latitude:        41.148578643799,
			Longitude:       -81.429229736328,
			Time:            300,
			TimeWindowStart: 43660,
			TimeWindowEnd:   46392},

		&routing.Address{AddressString: "512 Florida Pl, Barberton, OH 44203",
			Latitude:        41.003671512008,
			Longitude:       -81.598461046815,
			Time:            300,
			TimeWindowStart: 46392,
			TimeWindowEnd:   48389},

		&routing.Address{AddressString: "559 W Aurora Rd, Northfield, OH 44067",
			Latitude:        41.315116882324,
			Longitude:       -81.558746337891,
			Time:            50,
			TimeWindowStart: 48389,
			TimeWindowEnd:   48449},

		&routing.Address{AddressString: "3933 Klein Ave, Stow, OH 44224",
			Latitude:        41.169467926025,
			Longitude:       -81.429420471191,
			Time:            300,
			TimeWindowStart: 48449,
			TimeWindowEnd:   50152},

		&routing.Address{AddressString: "2148 8th St, Cuyahoga Falls, OH 44221",
			Latitude:        41.136692047119,
			Longitude:       -81.493492126465,
			Time:            300,
			TimeWindowStart: 50152,
			TimeWindowEnd:   51982},

		&routing.Address{AddressString: "3731 Osage St, Stow, OH 44224",
			Latitude:        41.161357879639,
			Longitude:       -81.42293548584,
			Time:            100,
			TimeWindowStart: 51982,
			TimeWindowEnd:   52180},

		&routing.Address{AddressString: "3731 Osage St, Stow, OH 44224",
			Latitude:        41.161357879639,
			Longitude:       -81.42293548584,
			Time:            300,
			TimeWindowStart: 52180,
			TimeWindowEnd:   54379},
	}
	routeParams := &routing.RouteParameters{
		AlgorithmType:        routing.CVRP_TW_MD,
		Name:                 "Multiple Depot, Multiple Driver",
		RouteDate:            time.Now().Unix(),
		RouteTime:            60 * 60 * 7,
		RouteMaxDuration:     86400,
		VehicleCapacity:      1,
		VehicleMaxDistanceMI: 1000,
		Optimize:             routing.Distance,
		DistanceUnit:         routing.Miles,
		DeviceType:           routing.Web,
		TravelMode:           routing.Driving,
	}

	optParams := &routing.OptimizationParameters{
		Addresses:  addresses,
		Parameters: routeParams,
	}
	_, err := service.RunOptimization(optParams)
}