MCPcopy Create free account
hub / github.com/PyVRP/PyVRP / to_csv

Method to_csv

pyvrp/Statistics.py:153–188  ·  view source on GitHub ↗

Writes this Statistics object to the given location, as a CSV file. Parameters ---------- where Filesystem location to write to. delimiter Value separator. Default comma. quoting Quoting strategy. Default only quot

(
        self,
        where: Path | str,
        delimiter: str = ",",
        quoting: Literal[0, 1, 2, 3] = csv.QUOTE_MINIMAL,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

151 return stats
152
153 def to_csv(
154 self,
155 where: Path | str,
156 delimiter: str = ",",
157 quoting: Literal[0, 1, 2, 3] = csv.QUOTE_MINIMAL,
158 **kwargs,
159 ):
160 """
161 Writes this Statistics object to the given location, as a CSV file.
162
163 Parameters
164 ----------
165 where
166 Filesystem location to write to.
167 delimiter
168 Value separator. Default comma.
169 quoting
170 Quoting strategy. Default only quotes values when necessary.
171 kwargs
172 Additional keyword arguments. These are passed to
173 :class:`csv.DictWriter`.
174 """
175 with open(where, "w") as fh:
176 header = ["runtime", *(f.name for f in fields(_Datum))]
177 writer = csv.DictWriter(
178 fh, header, delimiter=delimiter, quoting=quoting, **kwargs
179 )
180 writer.writeheader()
181
182 for datum, runtime in zip(self.data, self.runtimes):
183 row = {
184 f: int(v) if isinstance(v, bool) else v # bool as 0/1
185 for f, v in asdict(datum).items()
186 }
187 row["runtime"] = runtime
188 writer.writerow(row)

Callers 2

_solveFunction · 0.80

Calls

no outgoing calls

Tested by 1