NB. Copyright (c) 2013-2014 Michal Dobrogost NB. NB. Redistribution and use in source and binary forms, with or without NB. modification, are permitted provided that the following conditions NB. are met: NB. 1. Redistributions of source code must retain the above copyright NB. notice, this list of conditions and the following disclaimer. NB. 2. Redistributions in binary form must reproduce the above copyright NB. notice, this list of conditions and the following disclaimer in the NB. documentation and/or other materials provided with the distribution. NB. 3. The name of the author may not be used to endorse or promote products NB. derived from this software without specific prior written permission. NB. NB. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR NB. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES NB. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. NB. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, NB. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NB. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, NB. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY NB. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT NB. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF NB. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NB. NB. This is a 3-clause (or "modified") BSD license NB. This file provides a function for reading dimacs format maximum flow files NB. See: http://lpsolve.sourceforge.net/5.5/DIMACS_maxf.htm readDimacs=: 3 : 0 lines=.'b' fread y NB. Get the type of each line (that is the first character marker) types=. 0}"1 > lines NB. Get the s and t nodes from the 'n' type lines st=. (types = 'n') # lines st=. ,/ ('t' = (_1&{. @ >"1) st) { st NB. Ensure order is s then t st=. _1 + ". (_2&}. @ (2&}.) @ >"1) st NB. keep just the number parts NB. Get the edge capacities from the 'a' type lines caps=. (types = 'a') # lines caps=. _1 _1 0 +"1 (". @ (2&}.) @ >"1) caps arcs=. 0 1 {"1 caps caps=. 2 {"1 caps st ; arcs ; caps )